From f6bf9e62ca115ab8769bcbc6a2c705866ebdd39b Mon Sep 17 00:00:00 2001 From: Clayton Wilkinson Date: Thu, 11 Jan 2018 11:44:50 -0800 Subject: [PATCH] Adding back Java methods called from native code. Change-Id: I3f0b594b439a3787e166515ab8fc650c13730f4a --- .../nativegame/NativeGameActivity.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameActivity.java b/samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameActivity.java index 0873271..f67407d 100644 --- a/samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameActivity.java +++ b/samples-android/Teapot/src/main/java/com/google/example/nativegame/NativeGameActivity.java @@ -92,6 +92,58 @@ void setImmersiveSticky() { 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); + if (layoutInflater != null) { + 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.START, 10, 10); + _popupWindow.update(); + + _label = popupView.findViewById(R.id.textViewFPS); + } else { + throw new IllegalStateException("Cannot get layout service!"); + } + + }}); + } + + public void updateFPS(final float fFPS) + { + if( _label == null ) + return; + + _activity = this; + this.runOnUiThread(new Runnable() { + @Override + public void run() { + _label.setText(String.format(Locale.getDefault(),"%2.2f FPS", fFPS)); + + }}); + } + protected void onPause() { super.onPause(); if (_popupWindow != null) {