• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.sample.moreteapots;
18 
19 import android.app.NativeActivity;
20 import android.content.res.Configuration;
21 import android.os.Bundle;
22 import android.util.Log;
23 import android.view.Gravity;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup.MarginLayoutParams;
27 import android.view.WindowManager.LayoutParams;
28 import android.widget.LinearLayout;
29 import android.widget.PopupWindow;
30 import android.widget.TextView;
31 
32 public class MoreTeapotsNativeActivity extends NativeActivity {
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         //Hide toolbar
37         int SDK_INT = android.os.Build.VERSION.SDK_INT;
38         Log.i("OnCreate", "OnCreate!!!");
39         if(SDK_INT >= 19)
40         {
41             setImmersiveSticky();
42             View decorView = getWindow().getDecorView();
43             decorView.setOnSystemUiVisibilityChangeListener
44                     (new View.OnSystemUiVisibilityChangeListener() {
45                 @Override
46                 public void onSystemUiVisibilityChange(int visibility) {
47                     setImmersiveSticky();
48                 }
49             });
50         }
51 
52     }
53 
onResume()54     protected void onResume() {
55         super.onResume();
56 
57         //Hide toolbar
58         int SDK_INT = android.os.Build.VERSION.SDK_INT;
59         if(SDK_INT >= 11 && SDK_INT < 14)
60         {
61             getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
62         }
63         else if(SDK_INT >= 14 && SDK_INT < 19)
64         {
65             getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE);
66         }
67         else if(SDK_INT >= 19)
68         {
69             setImmersiveSticky();
70         }
71     }
72 
onPause()73     protected void onPause()
74     {
75         super.onPause();
76         if (_popupWindow != null) {
77 
78             _popupWindow.dismiss();
79             _popupWindow = null;
80         }
81     }
82     // Our popup window, you will call it from your C/C++ code later
83 
setImmersiveSticky()84     void setImmersiveSticky() {
85         View decorView = getWindow().getDecorView();
86         decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
87                 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
88                 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
89                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
90                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
91                 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
92     }
93 
94     MoreTeapotsNativeActivity _activity;
95     PopupWindow _popupWindow;
96     TextView _label;
97 
showUI()98     public void showUI()
99     {
100         if( _popupWindow != null )
101             return;
102 
103         _activity = this;
104 
105         this.runOnUiThread(new Runnable()  {
106             @Override
107             public void run()  {
108                 LayoutInflater layoutInflater
109                 = (LayoutInflater)getBaseContext()
110                 .getSystemService(LAYOUT_INFLATER_SERVICE);
111                 View popupView = layoutInflater.inflate(R.layout.widgets, null);
112                 _popupWindow = new PopupWindow(
113                         popupView,
114                         LayoutParams.WRAP_CONTENT,
115                         LayoutParams.WRAP_CONTENT);
116 
117                 LinearLayout mainLayout = new LinearLayout(_activity);
118                 MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
119                 params.setMargins(0, 0, 0, 0);
120                 _activity.setContentView(mainLayout, params);
121 
122                 // Show our UI over NativeActivity window
123                 _popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.LEFT, 10, 10);
124                 _popupWindow.update();
125 
126                 _label = (TextView)popupView.findViewById(R.id.textViewFPS);
127 
128             }});
129     }
130 
updateFPS(final float fFPS)131     public void updateFPS(final float fFPS)
132     {
133         if( _label == null )
134             return;
135 
136         _activity = this;
137         this.runOnUiThread(new Runnable()  {
138             @Override
139             public void run()  {
140                 _label.setText(String.format("%2.2f FPS", fFPS));
141             }});
142     }
143 }
144 
145 
146