Simplify handling of command-line arguments on Android
* java/org/gnu/emacs/EmacsActivity.java (EXTRA_STARTUP_ARGUMENTS): New constant. (onCreate): Read a string array, not a string extra from the intent with this key. * java/org/gnu/emacs/EmacsOpenActivity.java (EmacsOpenActivity) <fileToOpen>: Delete field. (onCreate): Provide file name as a command line argument when starting the Emacs service. * java/org/gnu/emacs/EmacsPreferencesActivity.java (startEmacsQ) (startEmacsDebugInit): In like manner, replace ad-hoc command-line argument extra with a proper array. * java/org/gnu/emacs/EmacsService.java (EmacsService): Rename extraStartupArgument to extraStartupArguments, and change its type to a string array. (onCreate): Adjust to match. * java/org/gnu/emacs/EmacsThread.java (EmacsThread) <extraStartupArguments>: Ditto. <fileToOpen>: Delete field. (run): Adjust correspondingly.
This commit is contained in:
parent
ecfbd0ff99
commit
41dd78cd36
5 changed files with 32 additions and 41 deletions
|
@ -55,6 +55,9 @@ public class EmacsActivity extends Activity
|
|||
{
|
||||
public static final String TAG = "EmacsActivity";
|
||||
|
||||
/* Key of intent value providing extra startup argument. */
|
||||
public static final String EXTRA_STARTUP_ARGUMENTS;
|
||||
|
||||
/* ID for URIs from a granted document tree. */
|
||||
public static final int ACCEPT_DOCUMENT_TREE = 1;
|
||||
|
||||
|
@ -88,6 +91,7 @@ public class EmacsActivity extends Activity
|
|||
static
|
||||
{
|
||||
focusedActivities = new ArrayList<EmacsActivity> ();
|
||||
EXTRA_STARTUP_ARGUMENTS = "org.gnu.emacs.STARTUP_ARGUMENTS";
|
||||
};
|
||||
|
||||
public static void
|
||||
|
@ -242,8 +246,8 @@ children and RESETWHENCHILDLESS is set (implying it is a
|
|||
/* See if Emacs should be started with any extra arguments, such
|
||||
as `--quick'. */
|
||||
intent = getIntent ();
|
||||
EmacsService.extraStartupArgument
|
||||
= intent.getStringExtra ("org.gnu.emacs.STARTUP_ARGUMENT");
|
||||
EmacsService.extraStartupArguments
|
||||
= intent.getStringArrayExtra (EXTRA_STARTUP_ARGUMENTS);
|
||||
|
||||
matchParent = FrameLayout.LayoutParams.MATCH_PARENT;
|
||||
params
|
||||
|
|
|
@ -70,11 +70,6 @@ public final class EmacsOpenActivity extends Activity
|
|||
{
|
||||
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. */
|
||||
|
@ -697,9 +692,10 @@ else if (scheme.equals ("org-protocol"))
|
|||
|
||||
if (EmacsService.SERVICE == null)
|
||||
{
|
||||
fileToOpen = fileName;
|
||||
intent = new Intent (EmacsOpenActivity.this,
|
||||
EmacsActivity.class);
|
||||
intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS,
|
||||
new String [] { fileName, });
|
||||
finish ();
|
||||
startActivity (intent);
|
||||
return;
|
||||
|
|
|
@ -57,7 +57,8 @@ public class EmacsPreferencesActivity extends PreferenceActivity
|
|||
intent = new Intent (this, EmacsActivity.class);
|
||||
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--quick");
|
||||
intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS,
|
||||
new String[] {"--quick", });
|
||||
startActivity (intent);
|
||||
System.exit (0);
|
||||
}
|
||||
|
@ -74,7 +75,8 @@ public class EmacsPreferencesActivity extends PreferenceActivity
|
|||
intent = new Intent (this, EmacsActivity.class);
|
||||
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--debug-init");
|
||||
intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS,
|
||||
new String[] {"--debug-init", });
|
||||
startActivity (intent);
|
||||
System.exit (0);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -102,9 +103,9 @@ public final class EmacsService extends Service
|
|||
/* The started Emacs service object. */
|
||||
public static EmacsService SERVICE;
|
||||
|
||||
/* If non-NULL, an extra argument to pass to
|
||||
/* If non-NULL, an array of extra arguments to pass to
|
||||
`android_emacs_init'. */
|
||||
public static String extraStartupArgument;
|
||||
public static String[] extraStartupArguments;
|
||||
|
||||
/* The thread running Emacs C code. */
|
||||
private EmacsThread thread;
|
||||
|
@ -289,7 +290,9 @@ invocation of app_process (through android-emacs) can
|
|||
|
||||
Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir
|
||||
+ ", libDir = " + libDir + ", and classPath = " + classPath
|
||||
+ "; fileToOpen = " + EmacsOpenActivity.fileToOpen
|
||||
+ "; args = " + (extraStartupArguments != null
|
||||
? Arrays.toString (extraStartupArguments)
|
||||
: "(none)")
|
||||
+ "; display density: " + pixelDensityX + " by "
|
||||
+ pixelDensityY + " scaled to " + scaledDensity);
|
||||
|
||||
|
@ -306,9 +309,7 @@ invocation of app_process (through android-emacs) can
|
|||
classPath, EmacsService.this,
|
||||
Build.VERSION.SDK_INT);
|
||||
}
|
||||
}, extraStartupArgument,
|
||||
/* If any file needs to be opened, open it now. */
|
||||
EmacsOpenActivity.fileToOpen);
|
||||
}, extraStartupArguments);
|
||||
thread.start ();
|
||||
}
|
||||
catch (IOException exception)
|
||||
|
|
|
@ -28,24 +28,20 @@ public final class EmacsThread extends Thread
|
|||
{
|
||||
private static final String TAG = "EmacsThread";
|
||||
|
||||
/* Whether or not Emacs should be started with an additional
|
||||
argument, and that additional argument if non-NULL. */
|
||||
private String extraStartupArgument;
|
||||
/* Whether or not Emacs should be started with additional arguments,
|
||||
and those additional arguments if non-NULL. */
|
||||
private final String[] extraStartupArguments;
|
||||
|
||||
/* Runnable run to initialize Emacs. */
|
||||
private Runnable paramsClosure;
|
||||
|
||||
/* Whether or not to open a file after starting Emacs. */
|
||||
private String fileToOpen;
|
||||
private final Runnable paramsClosure;
|
||||
|
||||
public
|
||||
EmacsThread (EmacsService service, Runnable paramsClosure,
|
||||
String extraStartupArgument, String fileToOpen)
|
||||
String[] extraStartupArguments)
|
||||
{
|
||||
super ("Emacs main thread");
|
||||
this.extraStartupArgument = extraStartupArgument;
|
||||
this.extraStartupArguments = extraStartupArguments;
|
||||
this.paramsClosure = paramsClosure;
|
||||
this.fileToOpen = fileToOpen;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,23 +50,15 @@ public final class EmacsThread extends Thread
|
|||
{
|
||||
String args[];
|
||||
|
||||
if (fileToOpen == null)
|
||||
{
|
||||
if (extraStartupArgument == null)
|
||||
args = new String[] { "libandroid-emacs.so", };
|
||||
else
|
||||
args = new String[] { "libandroid-emacs.so",
|
||||
extraStartupArgument, };
|
||||
}
|
||||
if (extraStartupArguments == null)
|
||||
args = new String[] { "libandroid-emacs.so", };
|
||||
else
|
||||
{
|
||||
if (extraStartupArgument == null)
|
||||
args = new String[] { "libandroid-emacs.so",
|
||||
fileToOpen, };
|
||||
else
|
||||
args = new String[] { "libandroid-emacs.so",
|
||||
extraStartupArgument,
|
||||
fileToOpen, };
|
||||
/* Prepend "libandroid-emacs.so" to the list of arguments. */
|
||||
args = new String[extraStartupArguments.length + 1];
|
||||
args[0] = "libandroid-emacs.so";
|
||||
System.arraycopy (extraStartupArguments, 0, args,
|
||||
1, extraStartupArguments.length);
|
||||
}
|
||||
|
||||
paramsClosure.run ();
|
||||
|
|
Loading…
Add table
Reference in a new issue