[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/android 5964051fcef 2/2: Update Android port
From: |
Po Lu |
Subject: |
feature/android 5964051fcef 2/2: Update Android port |
Date: |
Mon, 13 Mar 2023 21:51:34 -0400 (EDT) |
branch: feature/android
commit 5964051fcefc52e02c88a41b91797cc7a785d550
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Update Android port
* doc/emacs/android.texi (Android Windowing): Document how to
display dialogs when Emacs is in the background.
* java/org/gnu/emacs/EmacsDialog.java (display1): Use system
dialogs if possible.
---
doc/emacs/android.texi | 15 ++++++++++++-
java/org/gnu/emacs/EmacsDialog.java | 45 ++++++++++++++++++++++++++++++-------
2 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/doc/emacs/android.texi b/doc/emacs/android.texi
index 15415f12570..c92700980de 100644
--- a/doc/emacs/android.texi
+++ b/doc/emacs/android.texi
@@ -507,12 +507,25 @@ application via cut-and-paste.
@cindex volume/multimedia buttons, Android
The volume keys are normally reserved by Emacs and used to provide
the ability to quit Emacs without a physical keyboard
-(@pxref{On-Screen-Keyboards}.) However, if you want them to adjust
+(@pxref{On-Screen Keyboards}.) However, if you want them to adjust
the volume instead, you can set the variable
@code{android-pass-multimedia-buttons-to-system} to a non-@code{nil}
value; note that you will no longer be able to quit Emacs using the
volume buttons in that case.
+@cindex dialog boxes, android
+ Emacs is unable to display dialog boxes (@pxref{Dialog Boxes}) while
+it does not have the input focus on Android 6.0 or later. If this is
+important to you, this ability can be restored by granting Emacs
+permission to display over other programs. Normally, this can be done
+from the:
+
+@indentedblock
+System -> Apps -> Emacs -> More -> Display over other apps
+@end indentedblock
+
+menu in the system settings, but this procedure may vary by device.
+
@node Android Fonts
@section Font backends and selection under Android
@cindex fonts, android
diff --git a/java/org/gnu/emacs/EmacsDialog.java
b/java/org/gnu/emacs/EmacsDialog.java
index aed84de29e5..de5a37bd5c5 100644
--- a/java/org/gnu/emacs/EmacsDialog.java
+++ b/java/org/gnu/emacs/EmacsDialog.java
@@ -23,8 +23,14 @@ import java.util.List;
import java.util.ArrayList;
import android.app.AlertDialog;
-import android.content.DialogInterface;
+
import android.content.Context;
+import android.content.DialogInterface;
+
+import android.os.Build;
+
+import android.provider.Settings;
+
import android.util.Log;
import android.widget.Button;
@@ -33,6 +39,8 @@ import android.widget.FrameLayout;
import android.view.View;
import android.view.ViewGroup;
+import android.view.Window;
+import android.view.WindowManager;
/* Toolkit dialog implementation. This object is built from JNI and
describes a single alert dialog. Then, `inflate' turns it into
@@ -225,33 +233,54 @@ public final class EmacsDialog implements
DialogInterface.OnDismissListener
/* Internal helper for display run on the main thread. */
+ @SuppressWarnings("deprecation")
private boolean
display1 ()
{
- EmacsActivity activity;
- int size;
+ Context context;
+ int size, type;
Button buttonView;
EmacsButton button;
AlertDialog dialog;
+ Window window;
+
+ /* First, try to display a dialog using the service context. */
- if (EmacsActivity.focusedActivities.isEmpty ())
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
+ || Settings.canDrawOverlays (EmacsService.SERVICE))
+ context = EmacsService.SERVICE;
+ else if (EmacsActivity.focusedActivities.isEmpty ())
{
/* If focusedActivities is empty then this dialog may have
been displayed immediately after a popup dialog is
dismissed. */
- activity = EmacsActivity.lastFocusedActivity;
+ context = EmacsActivity.lastFocusedActivity;
- if (activity == null)
+ if (context == null)
return false;
}
else
- activity = EmacsActivity.focusedActivities.get (0);
+ context = EmacsActivity.focusedActivities.get (0);
+
+ Log.d (TAG, "display1: using context " + context);
- dialog = dismissDialog = toAlertDialog (activity);
+ dialog = dismissDialog = toAlertDialog (context);
try
{
+ if (context == EmacsService.SERVICE)
+ {
+ /* Apply the system alert window type to make sure this
+ dialog can be displayed. */
+
+ window = dialog.getWindow ();
+ type = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+ ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+ : WindowManager.LayoutParams.TYPE_PHONE);
+ window.setType (type);
+ }
+
dismissDialog.show ();
}
catch (Exception exception)