/* The menu serial associated with this dialog box. */
private int menuEventSerial;
- private class EmacsButton implements View.OnClickListener,
- DialogInterface.OnClickListener
+ private final class EmacsButton implements View.OnClickListener,
+ DialogInterface.OnClickListener
{
/* Name of this button. */
public String name;
if (EmacsActivity.focusedActivities.isEmpty ())
{
/* If focusedActivities is empty then this dialog may have
- been displayed immediately after a popup dialog is
+ been displayed immediately after another popup dialog was
dismissed. Or Emacs might legitimately be in the
- background. Try the service context first if possible. */
+ background, possibly displaying this popup in response to
+ an Emacsclient request. Try the service context if it will
+ work, then any focused EmacsOpenActivity, and finally the
+ last EmacsActivity to be focused. */
+
+ Log.d (TAG, "display1: no focused activities...");
+ Log.d (TAG, ("display1: EmacsOpenActivity.currentActivity: "
+ + EmacsOpenActivity.currentActivity));
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M
|| Settings.canDrawOverlays (EmacsService.SERVICE))
context = EmacsService.SERVICE;
+ else if (EmacsOpenActivity.currentActivity != null)
+ context = EmacsOpenActivity.currentActivity;
else
context = EmacsActivity.lastFocusedActivity;
DialogInterface.OnCancelListener
{
private static final String TAG = "EmacsOpenActivity";
+
+ /* The name of any file that should be opened as EmacsThread starts
+ Emacs. This is never cleared, even if EmacsOpenActivity is
+ started a second time, as EmacsThread only starts once. */
public static String fileToOpen;
+ /* Any currently focused EmacsOpenActivity. Used to show pop ups
+ while the activity is active and Emacs doesn't have permission to
+ display over other programs. */
+ public static EmacsOpenActivity currentActivity;
+
private class EmacsClientThread extends Thread
{
private ProcessBuilder builder;
thread.start ();
}
+ /* Run emacsclient to open the file specified in the Intent that
+ caused this activity to start.
+
+ Determine the name of the file corresponding to the URI specified
+ in that intent; then, run emacsclient and wait for it to finish.
+
+ Finally, display any error message, transfer the focus to an
+ Emacs frame, and finish the activity. */
+
@Override
public void
onCreate (Bundle savedInstanceState)
}
}
- /* And start emacsclient. */
+ /* And start emacsclient. Set `currentActivity' to this now.
+ Presumably, it will shortly become capable of displaying
+ dialogs. */
+ currentActivity = this;
startEmacsClient (fileName);
}
else
finish ();
}
+
+\f
+
+ @Override
+ public void
+ onDestroy ()
+ {
+ Log.d (TAG, "onDestroy: " + this);
+
+ /* Clear `currentActivity' if it refers to the activity being
+ destroyed. */
+
+ if (currentActivity == this)
+ this.currentActivity = null;
+
+ super.onDestroy ();
+ }
+
+ @Override
+ public void
+ onWindowFocusChanged (boolean isFocused)
+ {
+ Log.d (TAG, "onWindowFocusChanged: " + this + ", is now focused: "
+ + isFocused);
+
+ if (isFocused)
+ currentActivity = this;
+ else if (currentActivity == this)
+ currentActivity = null;
+
+ super.onWindowFocusChanged (isFocused);
+ }
+
+ @Override
+ public void
+ onPause ()
+ {
+ Log.d (TAG, "onPause: " + this);
+
+ /* XXX: clear currentActivity here as well; I don't know whether
+ or not onWindowFocusChanged is always called prior to this. */
+
+ if (currentActivity == this)
+ currentActivity = null;
+
+ super.onPause ();
+ }
}