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 | |
| 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')
| -rw-r--r-- | java/AndroidManifest.xml.in | 2 | ||||
| -rw-r--r-- | java/INSTALL | 4 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsActivity.java | 63 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsWindow.java | 15 |
4 files changed, 81 insertions, 3 deletions
diff --git a/java/AndroidManifest.xml.in b/java/AndroidManifest.xml.in index ceec7a97b98..77abdf0e180 100644 --- a/java/AndroidManifest.xml.in +++ b/java/AndroidManifest.xml.in | |||
| @@ -207,7 +207,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. --> | |||
| 207 | <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/> | 207 | <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/> |
| 208 | 208 | ||
| 209 | <uses-sdk android:minSdkVersion="@ANDROID_MIN_SDK@" | 209 | <uses-sdk android:minSdkVersion="@ANDROID_MIN_SDK@" |
| 210 | android:targetSdkVersion="35"/> | 210 | android:targetSdkVersion="36"/> |
| 211 | 211 | ||
| 212 | <application android:name="org.gnu.emacs.EmacsApplication" | 212 | <application android:name="org.gnu.emacs.EmacsApplication" |
| 213 | android:label="Emacs" | 213 | android:label="Emacs" |
diff --git a/java/INSTALL b/java/INSTALL index 6fbf7ba5d6c..1c6195c6d08 100644 --- a/java/INSTALL +++ b/java/INSTALL | |||
| @@ -39,7 +39,7 @@ script like so: | |||
| 39 | Replacing the paths in the command line above with: | 39 | Replacing the paths in the command line above with: |
| 40 | 40 | ||
| 41 | - the path to the `android.jar' headers which come with the Android | 41 | - the path to the `android.jar' headers which come with the Android |
| 42 | SDK. They must correspond to Android version 15 (API level 35). | 42 | SDK. They must correspond to Android version 16 (API level 36). |
| 43 | 43 | ||
| 44 | - the path to the C compiler in the Android NDK, for the kind of CPU | 44 | - the path to the C compiler in the Android NDK, for the kind of CPU |
| 45 | you are building Emacs to run on. | 45 | you are building Emacs to run on. |
| @@ -116,7 +116,7 @@ DEX format employed by Android. There is one subdirectory for each | |||
| 116 | version of the build tools, but the version you opt for is not of | 116 | version of the build tools, but the version you opt for is not of |
| 117 | paramount significance: if your version does not work, configure will | 117 | paramount significance: if your version does not work, configure will |
| 118 | protest, so install a newer one. We anticipate that most recent | 118 | protest, so install a newer one. We anticipate that most recent |
| 119 | releases will work, such as those from the 34.0.x, and 35.0.x series. | 119 | releases will work, such as those from the 35.0.x and 36.0.x series. |
| 120 | 120 | ||
| 121 | 121 | ||
| 122 | BUILDING WITH OLD NDK VERSIONS | 122 | BUILDING WITH OLD NDK VERSIONS |
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. |