Skip to content

Commit

Permalink
Support predictive back gesture in fragments (libgdx#7466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frosty-J authored Sep 25, 2024
1 parent d52faea commit 6572024
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 6572024

Please sign in to comment.