summaryrefslogtreecommitdiff
path: root/java/org
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2025-06-11 10:34:49 +0800
committerPo Lu <luangruo@yahoo.com>2025-06-11 10:34:49 +0800
commit231c4f20ea17a406519d5797e8ea1afdd0111a7c (patch)
treed974ea77ed5c8d8794185f77566078c63e04872d /java/org
parentf69b822fb0e804a13ff7a4eb55fc2ae618e0de72 (diff)
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.java63
-rw-r--r--java/org/gnu/emacs/EmacsWindow.java15
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;
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);
+ }
+
+
+
@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);
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;
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);
+ }
+
/* Mouse and touch event handling.