diff options
| author | Po Lu | 2025-06-11 10:34:49 +0800 |
|---|---|---|
| committer | Po Lu | 2025-06-11 10:34:49 +0800 |
| commit | 231c4f20ea17a406519d5797e8ea1afdd0111a7c (patch) | |
| tree | d974ea77ed5c8d8794185f77566078c63e04872d /java/org | |
| parent | f69b822fb0e804a13ff7a4eb55fc2ae618e0de72 (diff) | |
| download | emacs-231c4f20ea17a406519d5797e8ea1afdd0111a7c.tar.gz emacs-231c4f20ea17a406519d5797e8ea1afdd0111a7c.zip | |
Port to Android API 36
* java/AndroidManifest.xml.in: Update targetSdkVersion to 36.
* java/INSTALL: Document revised compilation dependencies.
* java/org/gnu/emacs/EmacsActivity.java (interceptBackGesture):
New function.
(onCreate): Invoke the same to register back gesture callbacks
on Android 16 or better.
* java/org/gnu/emacs/EmacsWindow.java (onBackInvoked): New
function.
* src/keyboard.c (lispy_function_keys): Amend with new symbols
introduced in Android API 36.
Diffstat (limited to 'java/org')
| -rw-r--r-- | java/org/gnu/emacs/EmacsActivity.java | 63 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindow.java | 15 |
2 files changed, 78 insertions, 0 deletions
diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 439a8defa32..6970728998b 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java | |||
| @@ -50,6 +50,11 @@ import android.view.WindowInsetsController; | |||
| 50 | 50 | ||
| 51 | import android.widget.FrameLayout; | 51 | import android.widget.FrameLayout; |
| 52 | 52 | ||
| 53 | import android.window.BackEvent; | ||
| 54 | import android.window.OnBackAnimationCallback; | ||
| 55 | import android.window.OnBackInvokedCallback; | ||
| 56 | import android.window.OnBackInvokedDispatcher; | ||
| 57 | |||
| 53 | public class EmacsActivity extends Activity | 58 | public class EmacsActivity extends Activity |
| 54 | implements EmacsWindowManager.WindowConsumer, | 59 | implements EmacsWindowManager.WindowConsumer, |
| 55 | ViewTreeObserver.OnGlobalLayoutListener | 60 | ViewTreeObserver.OnGlobalLayoutListener |
| @@ -252,6 +257,59 @@ public class EmacsActivity extends Activity | |||
| 252 | return window; | 257 | return window; |
| 253 | } | 258 | } |
| 254 | 259 | ||
| 260 | private void | ||
| 261 | interceptBackGesture () | ||
| 262 | { | ||
| 263 | OnBackInvokedDispatcher dispatcher; | ||
| 264 | int priority = OnBackInvokedDispatcher.PRIORITY_DEFAULT; | ||
| 265 | OnBackInvokedCallback callback; | ||
| 266 | |||
| 267 | dispatcher = getOnBackInvokedDispatcher (); | ||
| 268 | callback = new OnBackAnimationCallback () { | ||
| 269 | @Override | ||
| 270 | public void | ||
| 271 | onBackInvoked () | ||
| 272 | { | ||
| 273 | View view = EmacsActivity.this.getCurrentFocus (); | ||
| 274 | EmacsWindow window; | ||
| 275 | |||
| 276 | if (view instanceof EmacsView) | ||
| 277 | { | ||
| 278 | window = ((EmacsView) view).window; | ||
| 279 | window.onBackInvoked (); | ||
| 280 | } | ||
| 281 | } | ||
| 282 | |||
| 283 | /* The three functions are overridden to prevent a misleading | ||
| 284 | back animation from being displayed, as Emacs intercepts all | ||
| 285 | back gestures and will not return to the home screen. */ | ||
| 286 | |||
| 287 | @Override | ||
| 288 | public void | ||
| 289 | onBackCancelled () | ||
| 290 | { | ||
| 291 | |||
| 292 | } | ||
| 293 | |||
| 294 | @Override | ||
| 295 | public void | ||
| 296 | onBackProgressed (BackEvent gestureEvent) | ||
| 297 | { | ||
| 298 | |||
| 299 | } | ||
| 300 | |||
| 301 | @Override | ||
| 302 | public void | ||
| 303 | onBackStarted (BackEvent gestureEvent) | ||
| 304 | { | ||
| 305 | |||
| 306 | } | ||
| 307 | }; | ||
| 308 | dispatcher.registerOnBackInvokedCallback (priority, callback); | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | |||
| 255 | @Override | 313 | @Override |
| 256 | public void | 314 | public void |
| 257 | onCreate (Bundle savedInstanceState) | 315 | onCreate (Bundle savedInstanceState) |
| @@ -286,6 +344,11 @@ public class EmacsActivity extends Activity | |||
| 286 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) | 344 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) |
| 287 | layout.setFitsSystemWindows (true); | 345 | layout.setFitsSystemWindows (true); |
| 288 | 346 | ||
| 347 | /* Android 16 replaces KEYCODE_BACK with a callback registered at | ||
| 348 | the window level. */ | ||
| 349 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA) | ||
| 350 | interceptBackGesture (); | ||
| 351 | |||
| 289 | /* Maybe start the Emacs service if necessary. */ | 352 | /* Maybe start the Emacs service if necessary. */ |
| 290 | EmacsService.startEmacsService (this); | 353 | EmacsService.startEmacsService (this); |
| 291 | 354 | ||
diff --git a/java/org/gnu/emacs/EmacsWindow.java b/java/org/gnu/emacs/EmacsWindow.java index 394b2c26414..fffa2cc5d49 100644 --- a/java/org/gnu/emacs/EmacsWindow.java +++ b/java/org/gnu/emacs/EmacsWindow.java | |||
| @@ -58,6 +58,7 @@ import android.util.SparseArray; | |||
| 58 | import android.util.Log; | 58 | import android.util.Log; |
| 59 | 59 | ||
| 60 | import android.os.Build; | 60 | import android.os.Build; |
| 61 | import android.os.SystemClock; | ||
| 61 | 62 | ||
| 62 | /* This defines a window, which is a handle. Windows represent a | 63 | /* This defines a window, which is a handle. Windows represent a |
| 63 | rectangular subset of the screen with their own contents. | 64 | rectangular subset of the screen with their own contents. |
| @@ -890,6 +891,20 @@ public final class EmacsWindow extends EmacsHandleObject | |||
| 890 | EmacsNative.sendWindowAction (this.handle, 0); | 891 | EmacsNative.sendWindowAction (this.handle, 0); |
| 891 | } | 892 | } |
| 892 | 893 | ||
| 894 | /* Dispatch a back gesture invocation as a KeyPress event. Lamentably | ||
| 895 | the platform does not appear to support reporting keyboard | ||
| 896 | modifiers with these events. */ | ||
| 897 | |||
| 898 | public void | ||
| 899 | onBackInvoked () | ||
| 900 | { | ||
| 901 | long time = SystemClock.uptimeMillis (); | ||
| 902 | EmacsNative.sendKeyPress (this.handle, time, 0, | ||
| 903 | KeyEvent.KEYCODE_BACK, 0); | ||
| 904 | EmacsNative.sendKeyRelease (this.handle, time, 0, | ||
| 905 | KeyEvent.KEYCODE_BACK, 0); | ||
| 906 | } | ||
| 907 | |||
| 893 | 908 | ||
| 894 | 909 | ||
| 895 | /* Mouse and touch event handling. | 910 | /* Mouse and touch event handling. |