| package com.sample.teapot; |
| |
| import android.app.NativeActivity; |
| import android.os.Bundle; |
| import android.view.Gravity; |
| import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.ViewGroup.MarginLayoutParams; |
| import android.view.WindowManager.LayoutParams; |
| import android.widget.LinearLayout; |
| import android.widget.PopupWindow; |
| import android.widget.TextView; |
| |
| public class TeapotNativeActivity extends NativeActivity { |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| } |
| |
| protected void onResume() { |
| super.onResume(); |
| |
| //Hide toolbar |
| int SDK_INT = android.os.Build.VERSION.SDK_INT; |
| if(SDK_INT >= 11 && SDK_INT < 14) { |
| getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN); |
| }else if(SDK_INT >= 14){ |
| getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LOW_PROFILE); |
| } |
| |
| } |
| |
| // Our popup window, you will call it from your C/C++ code later |
| |
| TeapotNativeActivity _activity; |
| PopupWindow _popupWindow; |
| TextView _label; |
| |
| public void showUI() |
| { |
| if( _popupWindow != null ) |
| return; |
| |
| _activity = this; |
| |
| this.runOnUiThread(new Runnable() { |
| @Override |
| public void run() { |
| LayoutInflater layoutInflater |
| = (LayoutInflater)getBaseContext() |
| .getSystemService(LAYOUT_INFLATER_SERVICE); |
| View popupView = layoutInflater.inflate(R.layout.widgets, null); |
| _popupWindow = new PopupWindow( |
| popupView, |
| LayoutParams.WRAP_CONTENT, |
| LayoutParams.WRAP_CONTENT); |
| |
| LinearLayout mainLayout = new LinearLayout(_activity); |
| MarginLayoutParams params = new MarginLayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); |
| params.setMargins(0, 0, 0, 0); |
| _activity.setContentView(mainLayout, params); |
| |
| // Show our UI over NativeActivity window |
| _popupWindow.showAtLocation(mainLayout, Gravity.TOP | Gravity.LEFT, 10, 10); |
| _popupWindow.update(); |
| |
| _label = (TextView)popupView.findViewById(R.id.textViewFPS); |
| |
| }}); |
| } |
| |
| public void updateFPS(final float fFPS) |
| { |
| if( _label == null ) |
| return; |
| |
| _activity = this; |
| this.runOnUiThread(new Runnable() { |
| @Override |
| public void run() { |
| _label.setText(String.format("%2.2f FPS", fFPS)); |
| |
| }}); |
| } |
| } |
| |
| |