diff options
| author | Po Lu | 2024-05-04 16:06:00 +0800 |
|---|---|---|
| committer | Po Lu | 2024-05-04 16:13:24 +0800 |
| commit | 41dd78cd362a80f1becc006a37f163119b93df10 (patch) | |
| tree | a70aadac807e63052922b214e82dfa0de95dab87 /java | |
| parent | ecfbd0ff992adcb5b1b4b37884db8dbfda2fca6b (diff) | |
| download | emacs-41dd78cd362a80f1becc006a37f163119b93df10.tar.gz emacs-41dd78cd362a80f1becc006a37f163119b93df10.zip | |
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.
Diffstat (limited to 'java')
| -rw-r--r-- | java/org/gnu/emacs/EmacsActivity.java | 8 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsOpenActivity.java | 8 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsPreferencesActivity.java | 6 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsService.java | 13 | ||||
| -rw-r--r-- | java/org/gnu/emacs/EmacsThread.java | 38 |
5 files changed, 32 insertions, 41 deletions
diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 90be9a385cf..118c3375ad5 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java | |||
| @@ -55,6 +55,9 @@ public class EmacsActivity extends Activity | |||
| 55 | { | 55 | { |
| 56 | public static final String TAG = "EmacsActivity"; | 56 | public static final String TAG = "EmacsActivity"; |
| 57 | 57 | ||
| 58 | /* Key of intent value providing extra startup argument. */ | ||
| 59 | public static final String EXTRA_STARTUP_ARGUMENTS; | ||
| 60 | |||
| 58 | /* ID for URIs from a granted document tree. */ | 61 | /* ID for URIs from a granted document tree. */ |
| 59 | public static final int ACCEPT_DOCUMENT_TREE = 1; | 62 | public static final int ACCEPT_DOCUMENT_TREE = 1; |
| 60 | 63 | ||
| @@ -88,6 +91,7 @@ public class EmacsActivity extends Activity | |||
| 88 | static | 91 | static |
| 89 | { | 92 | { |
| 90 | focusedActivities = new ArrayList<EmacsActivity> (); | 93 | focusedActivities = new ArrayList<EmacsActivity> (); |
| 94 | EXTRA_STARTUP_ARGUMENTS = "org.gnu.emacs.STARTUP_ARGUMENTS"; | ||
| 91 | }; | 95 | }; |
| 92 | 96 | ||
| 93 | public static void | 97 | public static void |
| @@ -242,8 +246,8 @@ public class EmacsActivity extends Activity | |||
| 242 | /* See if Emacs should be started with any extra arguments, such | 246 | /* See if Emacs should be started with any extra arguments, such |
| 243 | as `--quick'. */ | 247 | as `--quick'. */ |
| 244 | intent = getIntent (); | 248 | intent = getIntent (); |
| 245 | EmacsService.extraStartupArgument | 249 | EmacsService.extraStartupArguments |
| 246 | = intent.getStringExtra ("org.gnu.emacs.STARTUP_ARGUMENT"); | 250 | = intent.getStringArrayExtra (EXTRA_STARTUP_ARGUMENTS); |
| 247 | 251 | ||
| 248 | matchParent = FrameLayout.LayoutParams.MATCH_PARENT; | 252 | matchParent = FrameLayout.LayoutParams.MATCH_PARENT; |
| 249 | params | 253 | params |
diff --git a/java/org/gnu/emacs/EmacsOpenActivity.java b/java/org/gnu/emacs/EmacsOpenActivity.java index cdc68aea2bf..28e1e261821 100644 --- a/java/org/gnu/emacs/EmacsOpenActivity.java +++ b/java/org/gnu/emacs/EmacsOpenActivity.java | |||
| @@ -70,11 +70,6 @@ public final class EmacsOpenActivity extends Activity | |||
| 70 | { | 70 | { |
| 71 | private static final String TAG = "EmacsOpenActivity"; | 71 | private static final String TAG = "EmacsOpenActivity"; |
| 72 | 72 | ||
| 73 | /* The name of any file that should be opened as EmacsThread starts | ||
| 74 | Emacs. This is never cleared, even if EmacsOpenActivity is | ||
| 75 | started a second time, as EmacsThread only starts once. */ | ||
| 76 | public static String fileToOpen; | ||
| 77 | |||
| 78 | /* Any currently focused EmacsOpenActivity. Used to show pop ups | 73 | /* Any currently focused EmacsOpenActivity. Used to show pop ups |
| 79 | while the activity is active and Emacs doesn't have permission to | 74 | while the activity is active and Emacs doesn't have permission to |
| 80 | display over other programs. */ | 75 | display over other programs. */ |
| @@ -697,9 +692,10 @@ public final class EmacsOpenActivity extends Activity | |||
| 697 | 692 | ||
| 698 | if (EmacsService.SERVICE == null) | 693 | if (EmacsService.SERVICE == null) |
| 699 | { | 694 | { |
| 700 | fileToOpen = fileName; | ||
| 701 | intent = new Intent (EmacsOpenActivity.this, | 695 | intent = new Intent (EmacsOpenActivity.this, |
| 702 | EmacsActivity.class); | 696 | EmacsActivity.class); |
| 697 | intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS, | ||
| 698 | new String [] { fileName, }); | ||
| 703 | finish (); | 699 | finish (); |
| 704 | startActivity (intent); | 700 | startActivity (intent); |
| 705 | return; | 701 | return; |
diff --git a/java/org/gnu/emacs/EmacsPreferencesActivity.java b/java/org/gnu/emacs/EmacsPreferencesActivity.java index 766e2e11d46..a3edd6388b4 100644 --- a/java/org/gnu/emacs/EmacsPreferencesActivity.java +++ b/java/org/gnu/emacs/EmacsPreferencesActivity.java | |||
| @@ -57,7 +57,8 @@ public class EmacsPreferencesActivity extends PreferenceActivity | |||
| 57 | intent = new Intent (this, EmacsActivity.class); | 57 | intent = new Intent (this, EmacsActivity.class); |
| 58 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | 58 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK |
| 59 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); | 59 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 60 | intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--quick"); | 60 | intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS, |
| 61 | new String[] {"--quick", }); | ||
| 61 | startActivity (intent); | 62 | startActivity (intent); |
| 62 | System.exit (0); | 63 | System.exit (0); |
| 63 | } | 64 | } |
| @@ -74,7 +75,8 @@ public class EmacsPreferencesActivity extends PreferenceActivity | |||
| 74 | intent = new Intent (this, EmacsActivity.class); | 75 | intent = new Intent (this, EmacsActivity.class); |
| 75 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK | 76 | intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK |
| 76 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); | 77 | | Intent.FLAG_ACTIVITY_CLEAR_TASK); |
| 77 | intent.putExtra ("org.gnu.emacs.STARTUP_ARGUMENT", "--debug-init"); | 78 | intent.putExtra (EmacsActivity.EXTRA_STARTUP_ARGUMENTS, |
| 79 | new String[] {"--debug-init", }); | ||
| 78 | startActivity (intent); | 80 | startActivity (intent); |
| 79 | System.exit (0); | 81 | System.exit (0); |
| 80 | } | 82 | } |
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java index ced9f599960..5548748ddfa 100644 --- a/java/org/gnu/emacs/EmacsService.java +++ b/java/org/gnu/emacs/EmacsService.java | |||
| @@ -25,6 +25,7 @@ import java.io.IOException; | |||
| 25 | import java.io.UnsupportedEncodingException; | 25 | import java.io.UnsupportedEncodingException; |
| 26 | 26 | ||
| 27 | import java.util.ArrayList; | 27 | import java.util.ArrayList; |
| 28 | import java.util.Arrays; | ||
| 28 | import java.util.HashSet; | 29 | import java.util.HashSet; |
| 29 | import java.util.List; | 30 | import java.util.List; |
| 30 | 31 | ||
| @@ -102,9 +103,9 @@ public final class EmacsService extends Service | |||
| 102 | /* The started Emacs service object. */ | 103 | /* The started Emacs service object. */ |
| 103 | public static EmacsService SERVICE; | 104 | public static EmacsService SERVICE; |
| 104 | 105 | ||
| 105 | /* If non-NULL, an extra argument to pass to | 106 | /* If non-NULL, an array of extra arguments to pass to |
| 106 | `android_emacs_init'. */ | 107 | `android_emacs_init'. */ |
| 107 | public static String extraStartupArgument; | 108 | public static String[] extraStartupArguments; |
| 108 | 109 | ||
| 109 | /* The thread running Emacs C code. */ | 110 | /* The thread running Emacs C code. */ |
| 110 | private EmacsThread thread; | 111 | private EmacsThread thread; |
| @@ -289,7 +290,9 @@ public final class EmacsService extends Service | |||
| 289 | 290 | ||
| 290 | Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir | 291 | Log.d (TAG, "Initializing Emacs, where filesDir = " + filesDir |
| 291 | + ", libDir = " + libDir + ", and classPath = " + classPath | 292 | + ", libDir = " + libDir + ", and classPath = " + classPath |
| 292 | + "; fileToOpen = " + EmacsOpenActivity.fileToOpen | 293 | + "; args = " + (extraStartupArguments != null |
| 294 | ? Arrays.toString (extraStartupArguments) | ||
| 295 | : "(none)") | ||
| 293 | + "; display density: " + pixelDensityX + " by " | 296 | + "; display density: " + pixelDensityX + " by " |
| 294 | + pixelDensityY + " scaled to " + scaledDensity); | 297 | + pixelDensityY + " scaled to " + scaledDensity); |
| 295 | 298 | ||
| @@ -306,9 +309,7 @@ public final class EmacsService extends Service | |||
| 306 | classPath, EmacsService.this, | 309 | classPath, EmacsService.this, |
| 307 | Build.VERSION.SDK_INT); | 310 | Build.VERSION.SDK_INT); |
| 308 | } | 311 | } |
| 309 | }, extraStartupArgument, | 312 | }, extraStartupArguments); |
| 310 | /* If any file needs to be opened, open it now. */ | ||
| 311 | EmacsOpenActivity.fileToOpen); | ||
| 312 | thread.start (); | 313 | thread.start (); |
| 313 | } | 314 | } |
| 314 | catch (IOException exception) | 315 | catch (IOException exception) |
diff --git a/java/org/gnu/emacs/EmacsThread.java b/java/org/gnu/emacs/EmacsThread.java index 4adcb98b2f7..a90eb73b1ef 100644 --- a/java/org/gnu/emacs/EmacsThread.java +++ b/java/org/gnu/emacs/EmacsThread.java | |||
| @@ -28,24 +28,20 @@ public final class EmacsThread extends Thread | |||
| 28 | { | 28 | { |
| 29 | private static final String TAG = "EmacsThread"; | 29 | private static final String TAG = "EmacsThread"; |
| 30 | 30 | ||
| 31 | /* Whether or not Emacs should be started with an additional | 31 | /* Whether or not Emacs should be started with additional arguments, |
| 32 | argument, and that additional argument if non-NULL. */ | 32 | and those additional arguments if non-NULL. */ |
| 33 | private String extraStartupArgument; | 33 | private final String[] extraStartupArguments; |
| 34 | 34 | ||
| 35 | /* Runnable run to initialize Emacs. */ | 35 | /* Runnable run to initialize Emacs. */ |
| 36 | private Runnable paramsClosure; | 36 | private final Runnable paramsClosure; |
| 37 | |||
| 38 | /* Whether or not to open a file after starting Emacs. */ | ||
| 39 | private String fileToOpen; | ||
| 40 | 37 | ||
| 41 | public | 38 | public |
| 42 | EmacsThread (EmacsService service, Runnable paramsClosure, | 39 | EmacsThread (EmacsService service, Runnable paramsClosure, |
| 43 | String extraStartupArgument, String fileToOpen) | 40 | String[] extraStartupArguments) |
| 44 | { | 41 | { |
| 45 | super ("Emacs main thread"); | 42 | super ("Emacs main thread"); |
| 46 | this.extraStartupArgument = extraStartupArgument; | 43 | this.extraStartupArguments = extraStartupArguments; |
| 47 | this.paramsClosure = paramsClosure; | 44 | this.paramsClosure = paramsClosure; |
| 48 | this.fileToOpen = fileToOpen; | ||
| 49 | } | 45 | } |
| 50 | 46 | ||
| 51 | @Override | 47 | @Override |
| @@ -54,23 +50,15 @@ public final class EmacsThread extends Thread | |||
| 54 | { | 50 | { |
| 55 | String args[]; | 51 | String args[]; |
| 56 | 52 | ||
| 57 | if (fileToOpen == null) | 53 | if (extraStartupArguments == null) |
| 58 | { | 54 | args = new String[] { "libandroid-emacs.so", }; |
| 59 | if (extraStartupArgument == null) | ||
| 60 | args = new String[] { "libandroid-emacs.so", }; | ||
| 61 | else | ||
| 62 | args = new String[] { "libandroid-emacs.so", | ||
| 63 | extraStartupArgument, }; | ||
| 64 | } | ||
| 65 | else | 55 | else |
| 66 | { | 56 | { |
| 67 | if (extraStartupArgument == null) | 57 | /* Prepend "libandroid-emacs.so" to the list of arguments. */ |
| 68 | args = new String[] { "libandroid-emacs.so", | 58 | args = new String[extraStartupArguments.length + 1]; |
| 69 | fileToOpen, }; | 59 | args[0] = "libandroid-emacs.so"; |
| 70 | else | 60 | System.arraycopy (extraStartupArguments, 0, args, |
| 71 | args = new String[] { "libandroid-emacs.so", | 61 | 1, extraStartupArguments.length); |
| 72 | extraStartupArgument, | ||
| 73 | fileToOpen, }; | ||
| 74 | } | 62 | } |
| 75 | 63 | ||
| 76 | paramsClosure.run (); | 64 | paramsClosure.run (); |