File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
allegro/src/main/java/org/liballeg/android Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 25
25
import java .util .Vector ;
26
26
import android .os .Build ;
27
27
import android .view .View ;
28
+ import android .view .KeyEvent ;
29
+ import android .window .OnBackInvokedCallback ;
30
+ import android .window .OnBackInvokedDispatcher ;
28
31
29
32
public class AllegroActivity extends Activity
30
33
{
@@ -339,6 +342,22 @@ public void onCreate(Bundle savedInstanceState)
339
342
requestWindowFeature (Window .FEATURE_NO_TITLE );
340
343
this .getWindow ().addFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
341
344
345
+ if (Build .VERSION .SDK_INT >= 33 ) {
346
+ // handle the back button / gesture on API level 33+
347
+ getOnBackInvokedDispatcher ().registerOnBackInvokedCallback (
348
+ OnBackInvokedDispatcher .PRIORITY_DEFAULT , new OnBackInvokedCallback () {
349
+ @ Override
350
+ public void onBackInvoked () {
351
+ // these will be mapped to ALLEGRO_KEY_BACK
352
+ KeyEvent keyDown = new KeyEvent (KeyEvent .ACTION_DOWN , KeyEvent .KEYCODE_BACK );
353
+ KeyEvent keyUp = new KeyEvent (KeyEvent .ACTION_UP , KeyEvent .KEYCODE_BACK );
354
+ dispatchKeyEvent (keyDown );
355
+ dispatchKeyEvent (keyUp );
356
+ }
357
+ }
358
+ );
359
+ }
360
+
342
361
Log .d ("AllegroActivity" , "onCreate end" );
343
362
}
344
363
Original file line number Diff line number Diff line change 4
4
android : versionCode =" 1"
5
5
android : versionName =" 1.0" >
6
6
<uses-permission android : name =" android.permission.WRITE_EXTERNAL_STORAGE" />
7
- <application android : label =" ${APP_ID}" >
7
+ <application android : label =" ${APP_ID}"
8
+ android : enableOnBackInvokedCallback =" true" >
8
9
<activity android : name =" .MainActivity"
9
10
android : launchMode =" singleTask"
10
11
android : screenOrientation =" unspecified"
You can’t perform that action at this time.
0 commit comments