Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
renyuneyun committed Apr 23, 2018
2 parents cd4c748 + 971a87b commit 17790c2
Show file tree
Hide file tree
Showing 16 changed files with 442 additions and 31 deletions.
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);
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/ryey/easer/plugins/PluginRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import ryey.easer.plugins.operation.command.CommandOperationPlugin;
import ryey.easer.plugins.operation.event_control.EventControlOperationPlugin;
import ryey.easer.plugins.operation.hotspot.HotspotOperationPlugin;
import ryey.easer.plugins.operation.launch_app.LaunchAppOperationPlugin;
import ryey.easer.plugins.operation.media_control.MediaControlOperationPlugin;
import ryey.easer.plugins.operation.network_transmission.NetworkTransmissionOperationPlugin;
import ryey.easer.plugins.operation.ringer_mode.RingerModeOperationPlugin;
Expand Down Expand Up @@ -122,6 +123,7 @@ final public class PluginRegistry {
operation().registerPlugin(AlarmOperationPlugin.class);
operation().registerPlugin(EventControlOperationPlugin.class);
operation().registerPlugin(VolumeOperationPlugin.class);
operation().registerPlugin(LaunchAppOperationPlugin.class);
//TODO: write more plugins
}

Expand Down
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;
}
}
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();
}
}
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);
}
}
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);
}

}
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@

public class VolumeOpeartionPluginViewFragment extends PluginViewFragment<VolumeOperationData> {

CheckBox checkBox_ring, checkBox_media, checkBox_alarm, checkBox_notification;
SeekBar seekBar_ring, seekBar_media, seekBar_alarm, seekBar_notification;
private static final int STREAM_BLUETOOTH = 6;

CheckBox checkBox_ring, checkBox_media, checkBox_alarm, checkBox_notification, checkBox_bt;
SeekBar seekBar_ring, seekBar_media, seekBar_alarm, seekBar_notification, seekBar_bt;

@NonNull
@Override
Expand Down Expand Up @@ -95,6 +97,16 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
}
});

seekBar_bt = view.findViewById(R.id.seekBar_bt);
seekBar_bt.setMax(audioManager.getStreamMaxVolume(STREAM_BLUETOOTH));
checkBox_bt = view.findViewById(R.id.checkBox_bt);
checkBox_bt.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
seekBar_bt.setVisibility(b? View.VISIBLE : View.GONE);
}
});

return view;
}

Expand All @@ -104,6 +116,7 @@ protected void _fill(@ValidData @NonNull VolumeOperationData data) {
setVolumeVisual(checkBox_media, seekBar_media, data.vol_media);
setVolumeVisual(checkBox_alarm, seekBar_alarm, data.vol_alarm);
setVolumeVisual(checkBox_notification, seekBar_notification, data.vol_notification);
setVolumeVisual(checkBox_bt, seekBar_bt, data.vol_bt);
}

@ValidData
Expand All @@ -114,7 +127,8 @@ public VolumeOperationData getData() throws InvalidDataInputException {
Integer vol_media = getVolume(seekBar_media);
Integer vol_alarm = getVolume(seekBar_alarm);
Integer vol_notification = getVolume(seekBar_notification);
return new VolumeOperationData(vol_ring, vol_media, vol_alarm, vol_notification);
Integer vol_bt = getVolume(seekBar_bt);
return new VolumeOperationData(vol_ring, vol_media, vol_alarm, vol_notification, vol_bt);
}

private static void setVolumeVisual(CheckBox checkBox, SeekBar seekBar, Integer value) {
Expand Down
Loading

0 comments on commit 17790c2

Please sign in to comment.