diff options
| author | Po Lu | 2023-06-08 20:50:02 +0800 |
|---|---|---|
| committer | Po Lu | 2023-06-08 20:50:02 +0800 |
| commit | 1661762784520eb6834aa9831dcb646396efde73 (patch) | |
| tree | 3ae23231862b09b568956948595d7b902e770da8 /java | |
| parent | b1bd40dce197d2938426d1ec33cebd3d51ccc8cf (diff) | |
| download | emacs-1661762784520eb6834aa9831dcb646396efde73.tar.gz emacs-1661762784520eb6834aa9831dcb646396efde73.zip | |
Correctly display popup dialogs from Emacsclient
* java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu):
Make subclasses final.
* java/org/gnu/emacs/EmacsDialog.java (display1): Check if an
instance of EmacsOpenActivity is open; if it is, try using it to
display the pop up dialog.
* java/org/gnu/emacs/EmacsDialogButtonLayout.java
(EmacsDialogButtonLayout): Make final.
* java/org/gnu/emacs/EmacsHolder.java (EmacsHolder<T>):
Likewise.
* java/org/gnu/emacs/EmacsOpenActivity.java (EmacsOpenActivity):
New field `currentActivity'.
(onCreate, onDestroy, onWindowFocusChanged, onPause): Set that
field as appropriate.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsContextMenu.java | 2 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsDialog.java | 17 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsDialogButtonLayout.java | 2 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsHolder.java | 2 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsOpenActivity.java | 70 |
5 files changed, 85 insertions, 8 deletions
diff --git a/java/org/gnu/emacs/EmacsContextMenu.java b/java/org/gnu/emacs/EmacsContextMenu.java index 60f2db67fb0..d69d0263b93 100644 --- a/java/org/gnu/emacs/EmacsContextMenu.java +++ b/java/org/gnu/emacs/EmacsContextMenu.java | |||
| @@ -58,7 +58,7 @@ public final class EmacsContextMenu | |||
| 58 | /* The last group ID used for a menu item. */ | 58 | /* The last group ID used for a menu item. */ |
| 59 | public int lastGroupId; | 59 | public int lastGroupId; |
| 60 | 60 | ||
| 61 | private static class Item implements MenuItem.OnMenuItemClickListener | 61 | private static final class Item implements MenuItem.OnMenuItemClickListener |
| 62 | { | 62 | { |
| 63 | public int itemID; | 63 | public int itemID; |
| 64 | public String itemName, tooltip; | 64 | public String itemName, tooltip; |
diff --git a/java/org/gnu/emacs/EmacsDialog.java b/java/org/gnu/emacs/EmacsDialog.java index afdce3c50ec..3f8fe0109c0 100644 --- a/java/org/gnu/emacs/EmacsDialog.java +++ b/java/org/gnu/emacs/EmacsDialog.java | |||
| @@ -68,8 +68,8 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener | |||
| 68 | /* The menu serial associated with this dialog box. */ | 68 | /* The menu serial associated with this dialog box. */ |
| 69 | private int menuEventSerial; | 69 | private int menuEventSerial; |
| 70 | 70 | ||
| 71 | private class EmacsButton implements View.OnClickListener, | 71 | private final class EmacsButton implements View.OnClickListener, |
| 72 | DialogInterface.OnClickListener | 72 | DialogInterface.OnClickListener |
| 73 | { | 73 | { |
| 74 | /* Name of this button. */ | 74 | /* Name of this button. */ |
| 75 | public String name; | 75 | public String name; |
| @@ -244,13 +244,22 @@ public final class EmacsDialog implements DialogInterface.OnDismissListener | |||
| 244 | if (EmacsActivity.focusedActivities.isEmpty ()) | 244 | if (EmacsActivity.focusedActivities.isEmpty ()) |
| 245 | { | 245 | { |
| 246 | /* If focusedActivities is empty then this dialog may have | 246 | /* If focusedActivities is empty then this dialog may have |
| 247 | been displayed immediately after a popup dialog is | 247 | been displayed immediately after another popup dialog was |
| 248 | dismissed. Or Emacs might legitimately be in the | 248 | dismissed. Or Emacs might legitimately be in the |
| 249 | background. Try the service context first if possible. */ | 249 | background, possibly displaying this popup in response to |
| 250 | an Emacsclient request. Try the service context if it will | ||
| 251 | work, then any focused EmacsOpenActivity, and finally the | ||
| 252 | last EmacsActivity to be focused. */ | ||
| 253 | |||
| 254 | Log.d (TAG, "display1: no focused activities..."); | ||
| 255 | Log.d (TAG, ("display1: EmacsOpenActivity.currentActivity: " | ||
| 256 | + EmacsOpenActivity.currentActivity)); | ||
| 250 | 257 | ||
| 251 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M | 258 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M |
| 252 | || Settings.canDrawOverlays (EmacsService.SERVICE)) | 259 | || Settings.canDrawOverlays (EmacsService.SERVICE)) |
| 253 | context = EmacsService.SERVICE; | 260 | context = EmacsService.SERVICE; |
| 261 | else if (EmacsOpenActivity.currentActivity != null) | ||
| 262 | context = EmacsOpenActivity.currentActivity; | ||
| 254 | else | 263 | else |
| 255 | context = EmacsActivity.lastFocusedActivity; | 264 | context = EmacsActivity.lastFocusedActivity; |
| 256 | 265 | ||
diff --git a/java/org/gnu/emacs/EmacsDialogButtonLayout.java b/java/org/gnu/emacs/EmacsDialogButtonLayout.java index 5d97eea32aa..fd8d63d81d3 100644 --- a/java/org/gnu/emacs/EmacsDialogButtonLayout.java +++ b/java/org/gnu/emacs/EmacsDialogButtonLayout.java | |||
| @@ -37,7 +37,7 @@ import android.view.ViewGroup; | |||
| 37 | 37 | ||
| 38 | 38 | ||
| 39 | 39 | ||
| 40 | public class EmacsDialogButtonLayout extends ViewGroup | 40 | public final class EmacsDialogButtonLayout extends ViewGroup |
| 41 | { | 41 | { |
| 42 | public | 42 | public |
| 43 | EmacsDialogButtonLayout (Context context) | 43 | EmacsDialogButtonLayout (Context context) |
diff --git a/java/org/gnu/emacs/EmacsHolder.java b/java/org/gnu/emacs/EmacsHolder.java index 3ca803d1640..6cd48ba57ce 100644 --- a/java/org/gnu/emacs/EmacsHolder.java +++ b/java/org/gnu/emacs/EmacsHolder.java | |||
| @@ -24,7 +24,7 @@ package org.gnu.emacs; | |||
| 24 | /* This class serves as a simple reference to an object of type T. | 24 | /* This class serves as a simple reference to an object of type T. |
| 25 | Nothing could be found inside the standard library. */ | 25 | Nothing could be found inside the standard library. */ |
| 26 | 26 | ||
| 27 | public class EmacsHolder<T> | 27 | public final class EmacsHolder<T> |
| 28 | { | 28 | { |
| 29 | T thing; | 29 | T thing; |
| 30 | }; | 30 | }; |
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java b/java/org/gnu/emacs/EmacsOpenActivity.java index f402e25c7fb..6af2b2d2e94 100644 --- a/java/org/gnu/emacs/EmacsOpenActivity.java +++ b/java/org/gnu/emacs/EmacsOpenActivity.java | |||
| @@ -72,8 +72,17 @@ public final class EmacsOpenActivity extends Activity | |||
| 72 | DialogInterface.OnCancelListener | 72 | DialogInterface.OnCancelListener |
| 73 | { | 73 | { |
| 74 | private static final String TAG = "EmacsOpenActivity"; | 74 | private static final String TAG = "EmacsOpenActivity"; |
| 75 | |||
| 76 | /* The name of any file that should be opened as EmacsThread starts | ||
| 77 | Emacs. This is never cleared, even if EmacsOpenActivity is | ||
| 78 | started a second time, as EmacsThread only starts once. */ | ||
| 75 | public static String fileToOpen; | 79 | public static String fileToOpen; |
| 76 | 80 | ||
| 81 | /* Any currently focused EmacsOpenActivity. Used to show pop ups | ||
| 82 | while the activity is active and Emacs doesn't have permission to | ||
| 83 | display over other programs. */ | ||
| 84 | public static EmacsOpenActivity currentActivity; | ||
| 85 | |||
| 77 | private class EmacsClientThread extends Thread | 86 | private class EmacsClientThread extends Thread |
| 78 | { | 87 | { |
| 79 | private ProcessBuilder builder; | 88 | private ProcessBuilder builder; |
| @@ -362,6 +371,15 @@ public final class EmacsOpenActivity extends Activity | |||
| 362 | thread.start (); | 371 | thread.start (); |
| 363 | } | 372 | } |
| 364 | 373 | ||
| 374 | /* Run emacsclient to open the file specified in the Intent that | ||
| 375 | caused this activity to start. | ||
| 376 | |||
| 377 | Determine the name of the file corresponding to the URI specified | ||
| 378 | in that intent; then, run emacsclient and wait for it to finish. | ||
| 379 | |||
| 380 | Finally, display any error message, transfer the focus to an | ||
| 381 | Emacs frame, and finish the activity. */ | ||
| 382 | |||
| 365 | @Override | 383 | @Override |
| 366 | public void | 384 | public void |
| 367 | onCreate (Bundle savedInstanceState) | 385 | onCreate (Bundle savedInstanceState) |
| @@ -463,10 +481,60 @@ public final class EmacsOpenActivity extends Activity | |||
| 463 | } | 481 | } |
| 464 | } | 482 | } |
| 465 | 483 | ||
| 466 | /* And start emacsclient. */ | 484 | /* And start emacsclient. Set `currentActivity' to this now. |
| 485 | Presumably, it will shortly become capable of displaying | ||
| 486 | dialogs. */ | ||
| 487 | currentActivity = this; | ||
| 467 | startEmacsClient (fileName); | 488 | startEmacsClient (fileName); |
| 468 | } | 489 | } |
| 469 | else | 490 | else |
| 470 | finish (); | 491 | finish (); |
| 471 | } | 492 | } |
| 493 | |||
| 494 | |||
| 495 | |||
| 496 | @Override | ||
| 497 | public void | ||
| 498 | onDestroy () | ||
| 499 | { | ||
| 500 | Log.d (TAG, "onDestroy: " + this); | ||
| 501 | |||
| 502 | /* Clear `currentActivity' if it refers to the activity being | ||
| 503 | destroyed. */ | ||
| 504 | |||
| 505 | if (currentActivity == this) | ||
| 506 | this.currentActivity = null; | ||
| 507 | |||
| 508 | super.onDestroy (); | ||
| 509 | } | ||
| 510 | |||
| 511 | @Override | ||
| 512 | public void | ||
| 513 | onWindowFocusChanged (boolean isFocused) | ||
| 514 | { | ||
| 515 | Log.d (TAG, "onWindowFocusChanged: " + this + ", is now focused: " | ||
| 516 | + isFocused); | ||
| 517 | |||
| 518 | if (isFocused) | ||
| 519 | currentActivity = this; | ||
| 520 | else if (currentActivity == this) | ||
| 521 | currentActivity = null; | ||
| 522 | |||
| 523 | super.onWindowFocusChanged (isFocused); | ||
| 524 | } | ||
| 525 | |||
| 526 | @Override | ||
| 527 | public void | ||
| 528 | onPause () | ||
| 529 | { | ||
| 530 | Log.d (TAG, "onPause: " + this); | ||
| 531 | |||
| 532 | /* XXX: clear currentActivity here as well; I don't know whether | ||
| 533 | or not onWindowFocusChanged is always called prior to this. */ | ||
| 534 | |||
| 535 | if (currentActivity == this) | ||
| 536 | currentActivity = null; | ||
| 537 | |||
| 538 | super.onPause (); | ||
| 539 | } | ||
| 472 | } | 540 | } |