aboutsummaryrefslogtreecommitdiffstats
path: root/java/org
diff options
context:
space:
mode:
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;
50 50
51import android.widget.FrameLayout; 51import android.widget.FrameLayout;
52 52
53import android.window.BackEvent;
54import android.window.OnBackAnimationCallback;
55import android.window.OnBackInvokedCallback;
56import android.window.OnBackInvokedDispatcher;
57
53public class EmacsActivity extends Activity 58public 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;
58import android.util.Log; 58import android.util.Log;
59 59
60import android.os.Build; 60import android.os.Build;
61import 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.