From 65720248721b5ef87c293adc0e5d7d18537d82e3 Mon Sep 17 00:00:00 2001 From: Frosty-J <60154347+Frosty-J@users.noreply.github.com> Date: Wed, 25 Sep 2024 20:58:33 +0100 Subject: [PATCH] Support predictive back gesture in fragments (#7466) --- .../badlogic/gdx/backends/android/DefaultAndroidInput.java | 4 ++-- .../com/badlogic/gdx/tests/android/FragmentTestStarter.java | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/DefaultAndroidInput.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/DefaultAndroidInput.java index dd4fbbb5241..9161e0af8d3 100644 --- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/DefaultAndroidInput.java +++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/DefaultAndroidInput.java @@ -186,7 +186,7 @@ public DefaultAndroidInput (Application activity, Context context, Object view, haptics = new AndroidHaptics(context); - if (Build.VERSION.SDK_INT >= 33) { + if (Build.VERSION.SDK_INT >= 33 && context instanceof Activity) { this.predictiveBackHandler = new PredictiveBackHandler(); } @@ -1452,7 +1452,7 @@ public void setCatchKey (int keycode, boolean catchKey) { @TargetApi(33) private class PredictiveBackHandler { - private final OnBackInvokedDispatcher dispatcher = ((Activity)app).getOnBackInvokedDispatcher(); + private final OnBackInvokedDispatcher dispatcher = ((Activity)context).getOnBackInvokedDispatcher(); private final OnBackInvokedCallback callback = new OnBackInvokedCallback() { @Override public void onBackInvoked () { diff --git a/tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/FragmentTestStarter.java b/tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/FragmentTestStarter.java index eb22f2dfa5b..998265c7c4f 100644 --- a/tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/FragmentTestStarter.java +++ b/tests/gdx-tests-android/src/com/badlogic/gdx/tests/android/FragmentTestStarter.java @@ -21,6 +21,7 @@ import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import com.badlogic.gdx.backends.android.AndroidFragmentApplication; +import com.badlogic.gdx.tests.BackTest; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.tests.utils.GdxTests; @@ -32,7 +33,8 @@ public class FragmentTestStarter extends FragmentActivity implements AndroidFrag @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); - GdxTests.tests.add(MatrixTest.class); + if (!GdxTests.tests.contains(MatrixTest.class)) GdxTests.tests.add(MatrixTest.class); + if (!GdxTests.tests.contains(BackTest.class)) GdxTests.tests.add(BackTest.class); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL);