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.teapot; 18 19 import android.app.NativeActivity; 20 import android.os.Bundle; 21 import android.view.Gravity; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup.MarginLayoutParams; 25 import android.view.WindowManager.LayoutParams; 26 import android.widget.LinearLayout; 27 import android.widget.PopupWindow; 28 import android.widget.TextView; 29 30 public class TeapotNativeActivity extends NativeActivity { 31 @Override 32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 //Hide toolbar 35 int SDK_INT = android.os.Build.VERSION.SDK_INT; 36 if(SDK_INT >= 19) 37 { 38 setImmersiveSticky(); 39 40 View decorView = getWindow().getDecorView(); 41 decorView.setOnSystemUiVisibilityChangeListener 42 (new View.OnSystemUiVisibilityChangeListener() { 43 @Override 44 public void onSystemUiVisibilityChange(int visibility) { 45 setImmersiveSticky(); 46 } 47 }); 48 } 49 50 } 51 52 protected void onResume() { 53 super.onResume(); 54 55 //Hide toolbar 56 int SDK_INT = android.os.Build.VERSION.SDK_INT; 57 if(SDK_INT >= 11 && SDK_INT < 14) 58 { 59 getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN); 60 } 61 else if(SDK_INT >= 14 && SDK_INT < 19) 62 { 63 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE); 64 } 65 else if(SDK_INT >= 19) 66 { 67 setImmersiveSticky(); 68 } 69 70 } 71 // Our popup window, you will call it from your C/C++ code later 72 73 void setImmersiveSticky() { 74 View decorView = getWindow().getDecorView(); 75 decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN 76 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 77 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY 78 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 79 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 80 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 81 } 82 83 TeapotNativeActivity _activity; 84 PopupWindow _popupWindow; 85 TextView _label; 86 87 public void showUI() 88 { 89 if( _popupWindow != null ) 90 return; 91 92 _activity = this; 93 94 this.runOnUiThread(new Runnable() { 95 @Override 96 public void run() { 97 LayoutInflater layoutInflater 98 = (LayoutInflater)getBaseContext() 99 .getSystemService(LAYOUT_INFLATER_SERVICE); 100 View popupView = layoutInflater.inflate(R.layout.widgets, null); 101 _popupWindow = new PopupWindow( 102 popupView, 103 LayoutParams.WRAP_CONTENT, 104 LayoutParams.WRAP_CONTENT); 105 106 LinearLayout mainLayout = new LinearLayout(_activity); 107 MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 108 params.setMargins(0, 0, 0, 0); 109 _activity.setContentView(mainLayout, params); 110 111 // Show our UI over NativeActivity window 112 _popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.LEFT, 10, 10); 113 _popupWindow.update(); 114 115 _label = (TextView)popupView.findViewById(R.id.textViewFPS); 116 117 }}); 118 } 119 120 protected void onPause() 121 { 122 super.onPause(); 123 if (_popupWindow != null) { 124 _popupWindow.dismiss(); 125 _popupWindow = null; 126 } 127 } 128 129 public void updateFPS(final float fFPS) 130 { 131 if( _label == null ) 132 return; 133 134 _activity = this; 135 this.runOnUiThread(new Runnable() { 136 @Override 137 public void run() { 138 _label.setText(String.format("%2.2f FPS", fFPS)); 139 140 }}); 141 } 142 } 143 144 145