forked from kuri65536/sl4a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntentBuilders.java
157 lines (143 loc) · 5.57 KB
/
IntentBuilders.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (C) 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.googlecode.android_scripting;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import com.googlecode.android_scripting.interpreter.Interpreter;
import java.io.File;
public class IntentBuilders {
/** An arbitrary value that is used to identify pending intents for executing scripts. */
private static final int EXECUTE_SCRIPT_REQUEST_CODE = 0x12f412a;
private IntentBuilders() {
// Utility class.
}
public static Intent buildTriggerServiceIntent() {
Intent intent = new Intent();
intent.setComponent(Constants.TRIGGER_SERVICE_COMPONENT_NAME);
return intent;
}
/**
* Builds an intent that will launch a script in the background.
*
* @param script
* the script to launch
* @return the intent that will launch the script
*/
public static Intent buildStartInBackgroundIntent(File script) {
final ComponentName componentName = Constants.SL4A_SERVICE_LAUNCHER_COMPONENT_NAME;
Intent intent = new Intent();
intent.setComponent(componentName);
intent.setAction(Constants.ACTION_LAUNCH_BACKGROUND_SCRIPT);
intent.putExtra(Constants.EXTRA_SCRIPT_PATH, script.getAbsolutePath());
return intent;
}
/**
* Builds an intent that launches a script in a terminal.
*
* @param script
* the script to launch
* @return the intent that will launch the script
*/
public static Intent buildStartInTerminalIntent(File script) {
final ComponentName componentName = Constants.SL4A_SERVICE_LAUNCHER_COMPONENT_NAME;
Intent intent = new Intent();
intent.setComponent(componentName);
intent.setAction(Constants.ACTION_LAUNCH_FOREGROUND_SCRIPT);
intent.putExtra(Constants.EXTRA_SCRIPT_PATH, script.getAbsolutePath());
return intent;
}
/**
* Builds an intent that launches an interpreter.
*
* @param interpreterName
* the interpreter to launch
* @return the intent that will launch the interpreter
*/
public static Intent buildStartInterpreterIntent(String interpreterName) {
final ComponentName componentName = Constants.SL4A_SERVICE_LAUNCHER_COMPONENT_NAME;
Intent intent = new Intent();
intent.setComponent(componentName);
intent.setAction(Constants.ACTION_LAUNCH_INTERPRETER);
intent.putExtra(Constants.EXTRA_INTERPRETER_NAME, interpreterName);
return intent;
}
/**
* Builds an intent that creates a shortcut to launch the provided interpreter.
*
* @param interpreter
* the interpreter to link to
* @param iconResource
* the icon resource to associate with the shortcut
* @return the intent that will create the shortcut
*/
public static Intent buildInterpreterShortcutIntent(Interpreter interpreter,
Parcelable iconResource) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
buildStartInterpreterIntent(interpreter.getName()));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, interpreter.getNiceName());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
return intent;
}
/**
* Builds an intent that creates a shortcut to launch the provided script in the background.
*
* @param script
* the script to link to
* @param iconResource
* the icon resource to associate with the shortcut
* @return the intent that will create the shortcut
*/
public static Intent buildBackgroundShortcutIntent(File script, Parcelable iconResource) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, buildStartInBackgroundIntent(script));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, script.getName());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
return intent;
}
/**
* Builds an intent that creates a shortcut to launch the provided script in a terminal.
*
* @param script
* the script to link to
* @param iconResource
* the icon resource to associate with the shortcut
* @return the intent that will create the shortcut
*/
public static Intent buildTerminalShortcutIntent(File script, Parcelable iconResource) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, buildStartInTerminalIntent(script));
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, script.getName());
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
return intent;
}
/**
* Creates a pending intent that can be used to start the trigger service.
*
* @param context
* the context under whose authority to launch the intent
*
* @return {@link PendingIntent} object for running the trigger service
*/
public static PendingIntent buildTriggerServicePendingIntent(Context context) {
final Intent intent = buildTriggerServiceIntent();
return PendingIntent.getService(context, EXECUTE_SCRIPT_REQUEST_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
}