From d5f2d742575a079aac208f65697147ecb3b30c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 6 Oct 2019 13:25:10 +0200 Subject: [PATCH] Android: Preparation for future cutout (notch) support --- android/res/values-v28/styles.xml | 13 ++++++++ .../src/org/ppsspp/ppsspp/NativeActivity.java | 30 ++++++++++++++++++- .../src/org/ppsspp/ppsspp/NativeGLView.java | 2 -- .../org/ppsspp/ppsspp/NativeSurfaceView.java | 2 -- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 android/res/values-v28/styles.xml diff --git a/android/res/values-v28/styles.xml b/android/res/values-v28/styles.xml new file mode 100644 index 0000000000..19a29a3a42 --- /dev/null +++ b/android/res/values-v28/styles.xml @@ -0,0 +1,13 @@ + + + #FF000000 + + diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 2f6ffa029a..a1d38ecdf3 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -31,6 +31,7 @@ import android.text.InputType; import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; +import android.view.DisplayCutout; import android.view.Gravity; import android.view.HapticFeedbackConstants; import android.view.InputDevice; @@ -119,6 +120,11 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C private int pixelWidth; private int pixelHeight; + private int safeInsetLeft = 0; + private int safeInsetRight = 0; + private int safeInsetTop = 0; + private int safeInsetBottom = 0; + private static final String[] permissionsForStorage = { Manifest.permission.WRITE_EXTERNAL_STORAGE, }; @@ -673,7 +679,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C @TargetApi(Build.VERSION_CODES.KITKAT) void setupSystemUiCallback() { - View decorView = getWindow().peekDecorView(); + final View decorView = getWindow().peekDecorView(); if (decorView == null || decorView == navigationCallbackView) { return; } @@ -688,6 +694,7 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C navigationHidden = ((visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0); // TODO: Check here if it's the state we want. Log.i(TAG, "SystemUiVisibilityChange! visibility=" + visibility + " navigationHidden: " + navigationHidden); + Log.i(TAG, "decorView: " + decorView.getWidth() + "x" + decorView.getHeight()); updateDisplayMeasurements(); } }); @@ -813,6 +820,27 @@ public abstract class NativeActivity extends Activity implements SurfaceHolder.C } } + @Override + public void onAttachedToWindow() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + Log.i(TAG, "onAttachedToWindow"); + DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout(); + if (cutout != null) { + safeInsetLeft = cutout.getSafeInsetLeft(); + safeInsetRight = cutout.getSafeInsetRight(); + safeInsetTop = cutout.getSafeInsetTop(); + safeInsetBottom = cutout.getSafeInsetBottom(); + Log.i(TAG, "Safe insets: left: " + safeInsetLeft + " right: " + safeInsetRight + " top: " + safeInsetTop + " bottom: " + safeInsetBottom); + } else { + Log.i(TAG, "Cutout was null"); + safeInsetLeft = 0; + safeInsetRight = 0; + safeInsetTop = 0; + safeInsetBottom = 0; + } + } + } + @Override public void onConfigurationChanged(Configuration newConfig) { Log.i(TAG, "onConfigurationChanged"); diff --git a/android/src/org/ppsspp/ppsspp/NativeGLView.java b/android/src/org/ppsspp/ppsspp/NativeGLView.java index 901630e045..b56380358d 100644 --- a/android/src/org/ppsspp/ppsspp/NativeGLView.java +++ b/android/src/org/ppsspp/ppsspp/NativeGLView.java @@ -125,7 +125,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, @Override public void onResume() { - Log.i(TAG, "onResume"); super.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); if (mController != null) { @@ -136,7 +135,6 @@ public class NativeGLView extends GLSurfaceView implements SensorEventListener, } public void onDestroy() { - Log.i(TAG, "onDestroy"); if (mController != null) { mController.exit(); } diff --git a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java index e855a3212c..01686be52f 100644 --- a/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java +++ b/android/src/org/ppsspp/ppsspp/NativeSurfaceView.java @@ -116,7 +116,6 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene } public void onPause() { - Log.i(TAG, "onPause"); mSensorManager.unregisterListener(this); if (mController != null) { mController.onPause(); @@ -133,7 +132,6 @@ public class NativeSurfaceView extends SurfaceView implements SensorEventListene } public void onDestroy() { - Log.i(TAG, "onDestroy"); if (mController != null) { mController.exit(); }