-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
442 additions
and
31 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
.../androidTest/java/ryey/easer/plugins/operation/launch_app/LaunchAppOperationDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.os.Parcel; | ||
|
||
import org.junit.Test; | ||
|
||
import ryey.easer.plugins.TestHelper; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class LaunchAppOperationDataTest { | ||
|
||
@Test | ||
public void testParcel() { | ||
LaunchAppOperationData dummyData = new LaunchAppOperationDataFactory().dummyData(); | ||
Parcel parcel = TestHelper.writeToParcel(dummyData); | ||
LaunchAppOperationData parceledData = LaunchAppOperationData.CREATOR.createFromParcel(parcel); | ||
assertEquals(dummyData, parceledData); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
app/src/main/java/ryey/easer/plugins/operation/launch_app/LaunchAppLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.annotation.NonNull; | ||
|
||
import ryey.easer.commons.plugindef.ValidData; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationLoader; | ||
|
||
public class LaunchAppLoader extends OperationLoader<LaunchAppOperationData> { | ||
LaunchAppLoader(Context context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public boolean load(@ValidData @NonNull LaunchAppOperationData data) { | ||
Intent intent = context.getPackageManager().getLaunchIntentForPackage(data.app_package); | ||
if (intent != null) { | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
context.startActivity(intent); | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
app/src/main/java/ryey/easer/plugins/operation/launch_app/LaunchAppOperationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.os.Parcel; | ||
import android.support.annotation.NonNull; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import ryey.easer.Utils; | ||
import ryey.easer.commons.C; | ||
import ryey.easer.commons.IllegalStorageDataException; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationData; | ||
|
||
public class LaunchAppOperationData implements OperationData { | ||
private static final String K_APP_PACKAGE = "package"; | ||
|
||
final String app_package; | ||
|
||
LaunchAppOperationData(String app_package) { | ||
this.app_package = app_package; | ||
} | ||
|
||
LaunchAppOperationData(@NonNull String data, @NonNull C.Format format, int version) throws IllegalStorageDataException { | ||
switch (format) { | ||
default: | ||
try { | ||
JSONObject jsonObject = new JSONObject(data); | ||
app_package = jsonObject.getString(K_APP_PACKAGE); | ||
} catch (JSONException e) { | ||
throw new IllegalStorageDataException(e); | ||
} | ||
} | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String serialize(@NonNull C.Format format) { | ||
String ret; | ||
switch (format) { | ||
default: | ||
try { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put(K_APP_PACKAGE, app_package); | ||
ret = jsonObject.toString(); | ||
} catch (JSONException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
@SuppressWarnings({"SimplifiableIfStatement", "RedundantIfStatement"}) | ||
@Override | ||
public boolean isValid() { | ||
return app_package != null && !Utils.isBlank(app_package); | ||
} | ||
|
||
@SuppressWarnings({"SimplifiableIfStatement", "RedundantIfStatement"}) | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == this) | ||
return true; | ||
if (obj == null || !(obj instanceof LaunchAppOperationData)) | ||
return false; | ||
if (!Utils.nullableEqual(app_package, ((LaunchAppOperationData) obj).app_package)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(Parcel dest, int flags) { | ||
dest.writeString(app_package); | ||
} | ||
|
||
public static final Creator<LaunchAppOperationData> CREATOR | ||
= new Creator<LaunchAppOperationData>() { | ||
public LaunchAppOperationData createFromParcel(Parcel in) { | ||
return new LaunchAppOperationData(in); | ||
} | ||
|
||
public LaunchAppOperationData[] newArray(int size) { | ||
return new LaunchAppOperationData[size]; | ||
} | ||
}; | ||
|
||
private LaunchAppOperationData(Parcel in) { | ||
app_package = in.readString(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/ryey/easer/plugins/operation/launch_app/LaunchAppOperationDataFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import ryey.easer.commons.C; | ||
import ryey.easer.commons.IllegalStorageDataException; | ||
import ryey.easer.commons.plugindef.ValidData; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationDataFactory; | ||
|
||
class LaunchAppOperationDataFactory implements OperationDataFactory<LaunchAppOperationData> { | ||
@NonNull | ||
@Override | ||
public Class<LaunchAppOperationData> dataClass() { | ||
return LaunchAppOperationData.class; | ||
} | ||
|
||
@ValidData | ||
@NonNull | ||
@Override | ||
public LaunchAppOperationData dummyData() { | ||
return new LaunchAppOperationData("com.dummy.app.package"); | ||
} | ||
|
||
@ValidData | ||
@NonNull | ||
@Override | ||
public LaunchAppOperationData parse(@NonNull String data, @NonNull C.Format format, int version) throws IllegalStorageDataException { | ||
return new LaunchAppOperationData(data, format, version); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
app/src/main/java/ryey/easer/plugins/operation/launch_app/LaunchAppOperationPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
|
||
import ryey.easer.R; | ||
import ryey.easer.commons.plugindef.PluginViewFragment; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationDataFactory; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationLoader; | ||
import ryey.easer.commons.plugindef.operationplugin.OperationPlugin; | ||
import ryey.easer.commons.plugindef.operationplugin.PrivilegeUsage; | ||
|
||
public class LaunchAppOperationPlugin implements OperationPlugin<LaunchAppOperationData> { | ||
|
||
@NonNull | ||
@Override | ||
public String id() { | ||
return "launch_app"; | ||
} | ||
|
||
@Override | ||
public int name() { | ||
return R.string.op_launch_app; | ||
} | ||
|
||
@Override | ||
public boolean isCompatible(@NonNull final Context context) { | ||
return true; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public PrivilegeUsage privilege() { | ||
return PrivilegeUsage.no_root; | ||
} | ||
|
||
@Override | ||
public int maxExistence() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean checkPermissions(@NonNull Context context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void requestPermissions(@NonNull Activity activity, int requestCode) { | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public OperationDataFactory<LaunchAppOperationData> dataFactory() { | ||
return new LaunchAppOperationDataFactory(); | ||
|
||
} | ||
|
||
@NonNull | ||
@Override | ||
public PluginViewFragment<LaunchAppOperationData> view() { | ||
return new LaunchAppPluginViewFragment(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public OperationLoader<LaunchAppOperationData> loader(@NonNull Context context) { | ||
return new LaunchAppLoader(context); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/ryey/easer/plugins/operation/launch_app/LaunchAppPluginViewFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ryey.easer.plugins.operation.launch_app; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.EditText; | ||
|
||
import ryey.easer.R; | ||
import ryey.easer.commons.plugindef.InvalidDataInputException; | ||
import ryey.easer.commons.plugindef.PluginViewFragment; | ||
import ryey.easer.commons.plugindef.ValidData; | ||
|
||
public class LaunchAppPluginViewFragment extends PluginViewFragment<LaunchAppOperationData> { | ||
EditText et_app_package; | ||
|
||
@NonNull | ||
@Override | ||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.plugin_operation__launch_app, container, false); | ||
et_app_package = view.findViewById(R.id.editText_app_package); | ||
return view; | ||
} | ||
|
||
@Override | ||
protected void _fill(@ValidData @NonNull LaunchAppOperationData data) { | ||
et_app_package.setText(data.app_package); | ||
} | ||
|
||
@ValidData | ||
@NonNull | ||
@Override | ||
public LaunchAppOperationData getData() throws InvalidDataInputException { | ||
return new LaunchAppOperationData(et_app_package.getText().toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.