diff options
| author | Po Lu | 2023-03-14 09:48:02 +0800 |
|---|---|---|
| committer | Po Lu | 2023-03-14 09:48:02 +0800 |
| commit | 5964051fcefc52e02c88a41b91797cc7a785d550 (patch) | |
| tree | d6d7bd2219632d3c899912a4e81f15bf19c431c9 /java | |
| parent | e0417a4577134f7705d9112bbd8af1e7916b5504 (diff) | |
| download | emacs-5964051fcefc52e02c88a41b91797cc7a785d550.tar.gz emacs-5964051fcefc52e02c88a41b91797cc7a785d550.zip | |
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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsDialog.java | 45 |
1 files changed, 37 insertions, 8 deletions
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; | |||
| 23 | import java.util.ArrayList; | 23 | import java.util.ArrayList; |
| 24 | 24 | ||
| 25 | import android.app.AlertDialog; | 25 | import android.app.AlertDialog; |
| 26 | import android.content.DialogInterface; | 26 | |
| 27 | import android.content.Context; | 27 | import android.content.Context; |
| 28 | import android.content.DialogInterface; | ||
| 29 | |||
| 30 | import android.os.Build; | ||
| 31 | |||
| 32 | import android.provider.Settings; | ||
| 33 | |||
| 28 | import android.util.Log; | 34 | import android.util.Log; |
| 29 | 35 | ||
| 30 | import android.widget.Button; | 36 | import android.widget.Button; |
| @@ -33,6 +39,8 @@ import android.widget.FrameLayout; | |||
| 33 | 39 | ||
| 34 | import android.view.View; | 40 | import android.view.View; |
| 35 | import android.view.ViewGroup; | 41 | import android.view.ViewGroup; |
| 42 | import android.view.Window; | ||
| 43 | import android.view.WindowManager; | ||
| 36 | 44 | ||
| 37 | /* Toolkit dialog implementation. This object is built from JNI and | 45 | /* Toolkit dialog implementation. This object is built from JNI and |
| 38 | describes a single alert dialog. Then, `inflate' turns it into | 46 | describes a single alert dialog. Then, `inflate' turns it into |
| @@ -225,33 +233,54 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener | |||
| 225 | 233 | ||
| 226 | /* Internal helper for display run on the main thread. */ | 234 | /* Internal helper for display run on the main thread. */ |
| 227 | 235 | ||
| 236 | @SuppressWarnings("deprecation") | ||
| 228 | private boolean | 237 | private boolean |
| 229 | display1 () | 238 | display1 () |
| 230 | { | 239 | { |
| 231 | EmacsActivity activity; | 240 | Context context; |
| 232 | int size; | 241 | int size, type; |
| 233 | Button buttonView; | 242 | Button buttonView; |
| 234 | EmacsButton button; | 243 | EmacsButton button; |
| 235 | AlertDialog dialog; | 244 | AlertDialog dialog; |
| 245 | Window window; | ||
| 246 | |||
| 247 | /* First, try to display a dialog using the service context. */ | ||
| 236 | 248 | ||
| 237 | if (EmacsActivity.focusedActivities.isEmpty ()) | 249 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
| 250 | || Settings.canDrawOverlays (EmacsService.SERVICE)) | ||
| 251 | context = EmacsService.SERVICE; | ||
| 252 | else if (EmacsActivity.focusedActivities.isEmpty ()) | ||
| 238 | { | 253 | { |
| 239 | /* If focusedActivities is empty then this dialog may have | 254 | /* If focusedActivities is empty then this dialog may have |
| 240 | been displayed immediately after a popup dialog is | 255 | been displayed immediately after a popup dialog is |
| 241 | dismissed. */ | 256 | dismissed. */ |
| 242 | 257 | ||
| 243 | activity = EmacsActivity.lastFocusedActivity; | 258 | context = EmacsActivity.lastFocusedActivity; |
| 244 | 259 | ||
| 245 | if (activity == null) | 260 | if (context == null) |
| 246 | return false; | 261 | return false; |
| 247 | } | 262 | } |
| 248 | else | 263 | else |
| 249 | activity = EmacsActivity.focusedActivities.get (0); | 264 | context = EmacsActivity.focusedActivities.get (0); |
| 265 | |||
| 266 | Log.d (TAG, "display1: using context " + context); | ||
| 250 | 267 | ||
| 251 | dialog = dismissDialog = toAlertDialog (activity); | 268 | dialog = dismissDialog = toAlertDialog (context); |
| 252 | 269 | ||
| 253 | try | 270 | try |
| 254 | { | 271 | { |
| 272 | if (context == EmacsService.SERVICE) | ||
| 273 | { | ||
| 274 | /* Apply the system alert window type to make sure this | ||
| 275 | dialog can be displayed. */ | ||
| 276 | |||
| 277 | window = dialog.getWindow (); | ||
| 278 | type = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O | ||
| 279 | ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY | ||
| 280 | : WindowManager.LayoutParams.TYPE_PHONE); | ||
| 281 | window.setType (type); | ||
| 282 | } | ||
| 283 | |||
| 255 | dismissDialog.show (); | 284 | dismissDialog.show (); |
| 256 | } | 285 | } |
| 257 | catch (Exception exception) | 286 | catch (Exception exception) |