diff --git a/android/res/values-v21/styles.xml b/android/res/values-v21/styles.xml deleted file mode 100644 index 5028a4ecaa..0000000000 --- a/android/res/values-v21/styles.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - #FF000000 - - diff --git a/android/res/values-v28/styles.xml b/android/res/values-v28/styles.xml index ce481678d0..f82b1df63b 100644 --- a/android/res/values-v28/styles.xml +++ b/android/res/values-v28/styles.xml @@ -1,7 +1,7 @@ #FF000000 - diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 5b55c8c84a..296a6d29ae 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -32,8 +32,10 @@ import android.os.PowerManager; import android.os.Vibrator; import android.provider.MediaStore; +import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; import androidx.documentfile.provider.DocumentFile; import android.text.InputType; import android.util.Log; @@ -60,7 +62,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; @SuppressWarnings("ConstantConditions") -public abstract class NativeActivity extends Activity implements SensorEventListener { +public abstract class NativeActivity extends AppCompatActivity implements SensorEventListener { // Remember to loadLibrary your JNI .so in a static {} block // Adjust these as necessary @@ -648,7 +650,7 @@ public abstract class NativeActivity extends Activity implements SensorEventList } else { updateSystemUiVisibility(); - mSurfaceView = new NativeSurfaceView(NativeActivity.this); + mSurfaceView = new NativeSurfaceView(this); sizeManager.setSurfaceView(mSurfaceView); setContentView(mSurfaceView); startRenderLoopThread(); @@ -661,6 +663,29 @@ public abstract class NativeActivity extends Activity implements SensorEventList shortcutParam = null; } + // Set up the back key handling to be future-compatible + OnBackPressedCallback callback = new OnBackPressedCallback(true) { + // Note: For "pretty" back handling internally, we could handle things like handleOnBackProgressed etc + // if we want to implement our own back previews. + @Override + public void handleOnBackPressed() { + if (NativeApp.isAtTopLevel()) { + // Pass through to normal logic, allowing backing out of the main screen. + // The setEnabled dance seems to be the normal way of handling this, to avoid recursive loops. + setEnabled(false); + NativeActivity.this.getOnBackPressedDispatcher().onBackPressed(); + setEnabled(true); + } else { + // Pass straight into the native code. + NativeApp.keyDown(NativeApp.DEVICE_ID_DEFAULT, KeyEvent.KEYCODE_BACK, false); + NativeApp.keyUp(NativeApp.DEVICE_ID_DEFAULT, KeyEvent.KEYCODE_BACK); + } + } + }; + + // Add the callback to the dispatcher + getOnBackPressedDispatcher().addCallback(this, callback); + Log.i(TAG, "onCreate end"); } @@ -1109,12 +1134,8 @@ public abstract class NativeActivity extends Activity implements SensorEventList case KeyEvent.KEYCODE_BACK: if (event.isAltPressed()) { NativeApp.keyDown(NativeApp.DEVICE_ID_PAD_0, 1004, repeat); // special custom keycode for the O button on Xperia Play - } else if (NativeApp.isAtTopLevel()) { - Log.i(TAG, "IsAtTopLevel returned true."); - // Pass through the back event. - return super.onKeyDown(keyCode, event); } else { - NativeApp.keyDown(NativeApp.DEVICE_ID_DEFAULT, keyCode, repeat); + super.onKeyDown(keyCode, event); } return true; case KeyEvent.KEYCODE_MENU: @@ -1147,11 +1168,8 @@ public abstract class NativeActivity extends Activity implements SensorEventList case KeyEvent.KEYCODE_BACK: if (event.isAltPressed()) { NativeApp.keyUp(NativeApp.DEVICE_ID_PAD_0, 1004); // special custom keycode - } else if (NativeApp.isAtTopLevel()) { - Log.i(TAG, "IsAtTopLevel returned true."); - return super.onKeyUp(keyCode, event); } else { - NativeApp.keyUp(NativeApp.DEVICE_ID_DEFAULT, keyCode); + return super.onKeyUp(keyCode, event); } return true; case KeyEvent.KEYCODE_MENU: