]> git.eshelyaron.com Git - emacs.git/commitdiff
Port to Android API 36
authorPo Lu <luangruo@yahoo.com>
Wed, 11 Jun 2025 02:34:49 +0000 (10:34 +0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 18 Jun 2025 08:03:22 +0000 (10:03 +0200)
* 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.

(cherry picked from commit 231c4f20ea17a406519d5797e8ea1afdd0111a7c)

java/AndroidManifest.xml.in
java/INSTALL
java/org/gnu/emacs/EmacsActivity.java
java/org/gnu/emacs/EmacsWindow.java
src/keyboard.c

index 711d34cff301a741bc85b6b963a2a964faa80a47..e141d80d6bd1d988fc57d638c49cd63689bebf10 100644 (file)
@@ -207,7 +207,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>. -->
   <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE"/>
 
   <uses-sdk android:minSdkVersion="@ANDROID_MIN_SDK@"
-           android:targetSdkVersion="34"/>
+           android:targetSdkVersion="36"/>
 
   <application android:name="org.gnu.emacs.EmacsApplication"
               android:label="Emacs"
index 6fbf7ba5d6c4eecf1803511e884440c3af6e9b90..1c6195c6d08a4906d84f58df8def59a613e47819 100644 (file)
@@ -39,7 +39,7 @@ script like so:
 Replacing the paths in the command line above with:
 
   - the path to the `android.jar' headers which come with the Android
-    SDK.  They must correspond to Android version 15 (API level 35).
+    SDK.  They must correspond to Android version 16 (API level 36).
 
   - the path to the C compiler in the Android NDK, for the kind of CPU
     you are building Emacs to run on.
@@ -116,7 +116,7 @@ DEX format employed by Android.  There is one subdirectory for each
 version of the build tools, but the version you opt for is not of
 paramount significance: if your version does not work, configure will
 protest, so install a newer one.  We anticipate that most recent
-releases will work, such as those from the 34.0.x, and 35.0.x series.
+releases will work, such as those from the 35.0.x and 36.0.x series.
 
 \f
 BUILDING WITH OLD NDK VERSIONS
index 439a8defa32431b638602c97ba04ada19acb162a..6970728998b828be9aa5cd1ca1dcd1d95a1669ab 100644 (file)
@@ -50,6 +50,11 @@ import android.view.WindowInsetsController;
 
 import android.widget.FrameLayout;
 
+import android.window.BackEvent;
+import android.window.OnBackAnimationCallback;
+import android.window.OnBackInvokedCallback;
+import android.window.OnBackInvokedDispatcher;
+
 public class EmacsActivity extends Activity
   implements EmacsWindowManager.WindowConsumer,
   ViewTreeObserver.OnGlobalLayoutListener
@@ -252,6 +257,59 @@ public class EmacsActivity extends Activity
     return window;
   }
 
+  private void
+  interceptBackGesture ()
+  {
+    OnBackInvokedDispatcher dispatcher;
+    int priority = OnBackInvokedDispatcher.PRIORITY_DEFAULT;
+    OnBackInvokedCallback callback;
+
+    dispatcher = getOnBackInvokedDispatcher ();
+    callback = new OnBackAnimationCallback () {
+       @Override
+       public void
+       onBackInvoked ()
+       {
+         View view = EmacsActivity.this.getCurrentFocus ();
+         EmacsWindow window;
+
+         if (view instanceof EmacsView)
+           {
+             window = ((EmacsView) view).window;
+             window.onBackInvoked ();
+           }
+       }
+
+       /* The three functions are overridden to prevent a misleading
+          back animation from being displayed, as Emacs intercepts all
+          back gestures and will not return to the home screen.  */
+
+       @Override
+       public void
+       onBackCancelled ()
+       {
+
+       }
+
+       @Override
+       public void
+       onBackProgressed (BackEvent gestureEvent)
+       {
+
+       }
+
+       @Override
+       public void
+       onBackStarted (BackEvent gestureEvent)
+       {
+
+       }
+    };
+    dispatcher.registerOnBackInvokedCallback (priority, callback);
+  }
+
+\f
+
   @Override
   public void
   onCreate (Bundle savedInstanceState)
@@ -286,6 +344,11 @@ public class EmacsActivity extends Activity
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
       layout.setFitsSystemWindows (true);
 
+    /* Android 16 replaces KEYCODE_BACK with a callback registered at
+       the window level.  */
+    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.BAKLAVA)
+      interceptBackGesture ();
+
     /* Maybe start the Emacs service if necessary.  */
     EmacsService.startEmacsService (this);
 
index 6123ad33549bf764568afe4215eb3972c1a4fec0..e0d0b743ad9a4ee8ec1ff9656021bc4190f02254 100644 (file)
@@ -58,6 +58,7 @@ import android.util.SparseArray;
 import android.util.Log;
 
 import android.os.Build;
+import android.os.SystemClock;
 
 /* This defines a window, which is a handle.  Windows represent a
    rectangular subset of the screen with their own contents.
@@ -890,6 +891,20 @@ public final class EmacsWindow extends EmacsHandleObject
     EmacsNative.sendWindowAction (this.handle, 0);
   }
 
+  /* Dispatch a back gesture invocation as a KeyPress event.  Lamentably
+     the platform does not appear to support reporting keyboard
+     modifiers with these events.  */
+
+  public void
+  onBackInvoked ()
+  {
+    long time = SystemClock.uptimeMillis ();
+    EmacsNative.sendKeyPress (this.handle, time, 0,
+                             KeyEvent.KEYCODE_BACK, 0);
+    EmacsNative.sendKeyRelease (this.handle, time, 0,
+                               KeyEvent.KEYCODE_BACK, 0);
+  }
+
 \f
 
   /* Mouse and touch event handling.
index 790928246036bafb928d6ea555054a85d6406434..d7f15aeb4e114229497f4a2c5a6602c1dcf0396d 100644 (file)
@@ -5055,6 +5055,25 @@ static const char *const lispy_function_keys[] =
     [285] = "browser-refresh",
     [28]  = "clear",
     [300] = "XF86Forward",
+    [319] = "dictate",
+    [320] = "new",
+    [321] = "close",
+    [322] = "do-not-disturb",
+    [323] = "print",
+    [324] = "lock",
+    [325] = "fullscreen",
+    [326] = "f13",
+    [327] = "f14",
+    [328] = "f15",
+    [329] = "f16",
+    [330] = "f17",
+    [331] = "f18",
+    [332] = "f19",
+    [333] = "f20",
+    [334] = "f21",
+    [335] = "f22",
+    [336] = "f23",
+    [337] = "f24",
     [4]          = "XF86Back",
     [61]  = "tab",
     [66]  = "return",