[Scummvm-git-logs] scummvm master -> 56951518f50f98a0984d2d17238097e44aac7821
antoniou79
a.antoniou79 at gmail.com
Tue Aug 11 11:12:45 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
56951518f5 ANDROID: Restore Immersive Fullscreen after keyboard hide
Commit: 56951518f50f98a0984d2d17238097e44aac7821
https://github.com/scummvm/scummvm/commit/56951518f50f98a0984d2d17238097e44aac7821
Author: antoniou (a.antoniou79 at gmail.com)
Date: 2020-08-11T14:11:53+03:00
Commit Message:
ANDROID: Restore Immersive Fullscreen after keyboard hide
This in some older devices (eg. Android 7.2.2) had issues before this fix
Changed paths:
A backends/platform/android/org/scummvm/scummvm/OnKeyboardVisibilityListener.java
backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
diff --git a/backends/platform/android/org/scummvm/scummvm/OnKeyboardVisibilityListener.java b/backends/platform/android/org/scummvm/scummvm/OnKeyboardVisibilityListener.java
new file mode 100644
index 0000000000..9d651e558f
--- /dev/null
+++ b/backends/platform/android/org/scummvm/scummvm/OnKeyboardVisibilityListener.java
@@ -0,0 +1,5 @@
+package org.scummvm.scummvm;
+
+public interface OnKeyboardVisibilityListener {
+ void onVisibilityChanged(boolean visible);
+}
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
index 01bebeb55c..1a1c79c6af 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVMActivity.java
@@ -7,6 +7,7 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.graphics.Rect;
import android.media.AudioManager;
import android.net.Uri;
import android.net.wifi.WifiManager;
@@ -17,7 +18,10 @@ import android.os.Environment;
import android.text.ClipboardManager;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.util.TypedValue;
import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
import android.view.SurfaceView;
import android.view.SurfaceHolder;
import android.view.MotionEvent;
@@ -35,7 +39,7 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
-public class ScummVMActivity extends Activity {
+public class ScummVMActivity extends Activity implements OnKeyboardVisibilityListener {
/* Establish whether the hover events are available */
private static boolean _hoverAvailable;
@@ -265,6 +269,9 @@ public class ScummVMActivity extends Activity {
// On screen button listener
((ImageView)findViewById(R.id.show_keyboard)).setOnClickListener(keyboardBtnOnClickListener);
+ // Keyboard visibility listener
+ setKeyboardVisibilityListener(this);
+
main_surface.setOnKeyListener(_events);
main_surface.setOnTouchListener(_events);
@@ -409,18 +416,22 @@ public class ScummVMActivity extends Activity {
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
+ // Show or hide the Android keyboard.
+ // Called by the override of showVirtualKeyboard()
private void showKeyboard(boolean show) {
SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface);
InputMethodManager imm = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
- if (show)
+ if (show) {
imm.showSoftInput(main_surface, InputMethodManager.SHOW_IMPLICIT);
- else
- imm.hideSoftInputFromWindow(main_surface.getWindowToken(),
- InputMethodManager.HIDE_IMPLICIT_ONLY);
+ } else {
+ imm.hideSoftInputFromWindow(main_surface.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
+ }
}
+ // Toggle showing or hiding the virtual keyboard.
+ // Called by keyboardBtnOnClickListener()
private void toggleKeyboard() {
SurfaceView main_surface = (SurfaceView)findViewById(R.id.main_surface);
InputMethodManager imm = (InputMethodManager)
@@ -431,13 +442,16 @@ public class ScummVMActivity extends Activity {
InputMethodManager.HIDE_IMPLICIT_ONLY);
}
+ // Show or hide the semi-transparent keyboard btn (which is used to explicitly bring up the android keyboard).
+ // Called by the override of showKeyboardControl()
private void showKeyboardView(boolean show) {
ImageView keyboardBtn = (ImageView)findViewById(R.id.show_keyboard);
- if (show)
+ if (show) {
keyboardBtn.setVisibility(View.VISIBLE);
- else
+ } else {
keyboardBtn.setVisibility(View.GONE);
+ }
}
private void showMouseCursor(boolean show) {
@@ -457,7 +471,41 @@ public class ScummVMActivity extends Activity {
}
}
- // Auxilliary function to overwrite a file (used for overwriting the scummvm.ini file with an existing other one)
+ // Listener to check for keyboard visibility changes
+ // https://stackoverflow.com/a/36259261
+ private void setKeyboardVisibilityListener(final OnKeyboardVisibilityListener onKeyboardVisibilityListener) {
+ final View parentView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
+ parentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
+
+ private boolean alreadyOpen;
+ private final int defaultKeyboardHeightDP = 100;
+ private final int EstimatedKeyboardDP = defaultKeyboardHeightDP + (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? 48 : 0);
+ private final Rect rect = new Rect();
+
+ @Override
+ public void onGlobalLayout() {
+ int estimatedKeyboardHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, EstimatedKeyboardDP, parentView.getResources().getDisplayMetrics());
+ parentView.getWindowVisibleDisplayFrame(rect);
+ int heightDiff = parentView.getRootView().getHeight() - (rect.bottom - rect.top);
+ boolean isShown = heightDiff >= estimatedKeyboardHeight;
+
+ if (isShown == alreadyOpen) {
+ Log.i("Keyboard state", "Ignoring global layout change...");
+ return;
+ }
+ alreadyOpen = isShown;
+ onKeyboardVisibilityListener.onVisibilityChanged(isShown);
+ }
+ });
+ }
+
+ @Override
+ public void onVisibilityChanged(boolean visible) {
+// Toast.makeText(HomeActivity.this, visible ? "Keyboard is active" : "Keyboard is Inactive", Toast.LENGTH_SHORT).show();
+ hideSystemUI();
+ }
+
+ // Auxiliary function to overwrite a file (used for overwriting the scummvm.ini file with an existing other one)
private static void copyFileUsingStream(File source, File dest) throws IOException {
InputStream is = null;
OutputStream os = null;
More information about the Scummvm-git-logs
mailing list