Skip to content

Commit

Permalink
Fix landscape/reverse landscape cutout padding issue, see #12779
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Mar 31, 2020
1 parent 3965341 commit 7dfe895
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import android.view.InputEvent;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
Expand Down Expand Up @@ -571,6 +572,16 @@ public void onCreate(Bundle savedInstanceState) {
}
mGLSurfaceView.setRenderer(nativeRenderer);
setContentView(mGLSurfaceView);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mGLSurfaceView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
checkInsets(windowInsets);
return windowInsets;
}
});
}
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
updateSystemUiVisibility();
Expand All @@ -582,6 +593,16 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(mSurfaceView);
Log.i(TAG, "setcontentview after");
ensureRenderLoop();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
mSurfaceView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
checkInsets(windowInsets);
return windowInsets;
}
});
}
}
}

Expand Down Expand Up @@ -843,13 +864,12 @@ protected void onResume() {
}
}

@Override
public void onAttachedToWindow() {
Log.i(TAG, "onAttachedToWindow");
super.onAttachedToWindow();

private void checkInsets(WindowInsets insets) {
if (insets == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
DisplayCutout cutout = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
DisplayCutout cutout = insets.getDisplayCutout();
if (cutout != null) {
safeInsetLeft = cutout.getSafeInsetLeft();
safeInsetRight = cutout.getSafeInsetRight();
Expand All @@ -865,6 +885,12 @@ public void onAttachedToWindow() {
}
NativeApp.sendMessage("safe_insets", safeInsetLeft + ":" + safeInsetRight + ":" + safeInsetTop + ":" + safeInsetBottom);
}
}

@Override
public void onAttachedToWindow() {
Log.i(TAG, "onAttachedToWindow");
super.onAttachedToWindow();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
setupSystemUiCallback();
Expand Down

0 comments on commit 7dfe895

Please sign in to comment.