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.
This commit is contained in:
Po Lu 2025-06-11 10:34:49 +08:00
parent f69b822fb0
commit 231c4f20ea
5 changed files with 100 additions and 3 deletions

View 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="35"/>
android:targetSdkVersion="36"/>
<application android:name="org.gnu.emacs.EmacsApplication"
android:label="Emacs"

View 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.
BUILDING WITH OLD NDK VERSIONS

View file

@ -50,6 +50,11 @@
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 @@ window, or some distributions of Android (e.g. Huawei HarmonyOS
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 @@ window, or some distributions of Android (e.g. Huawei HarmonyOS
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);

View file

@ -58,6 +58,7 @@
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 @@ else if (keyCode >= KeyEvent.KEYCODE_NUMPAD_0
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.

View file

@ -5099,6 +5099,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",