Add: tasker plugin support, injectable webview
This commit is contained in:
14
app/src/main/java/com/stardust/scriptdroid/external/CommonUtils.java
vendored
Normal file
14
app/src/main/java/com/stardust/scriptdroid/external/CommonUtils.java
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.stardust.scriptdroid.external;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/4/1.
|
||||
*/
|
||||
|
||||
public class CommonUtils {
|
||||
|
||||
public static final String EXTRA_KEY_PATH = "path";
|
||||
|
||||
public static final String EXTRA_KEY_PREPARE_SCRIPT = "script";
|
||||
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
private final Set<ContentChangeListener> mContentChangeListeners = new HashSet<>();
|
||||
private View[] mViews;
|
||||
|
||||
public HoverMenuAdapter(@NonNull Context context) {
|
||||
public HoverMenuAdapter(@NonNull HoverMenuService context) {
|
||||
mContext = context;
|
||||
|
||||
mData.put(HoverMenuAdapter.ID_MAIN, new MainMenuNavigatorContent(context));
|
||||
|
||||
@@ -40,6 +40,7 @@ import io.mattcarroll.hover.defaulthovermenu.window.WindowViewController;
|
||||
|
||||
public class HoverMenuService extends Service {
|
||||
|
||||
|
||||
public static class ServiceStateChangedEvent {
|
||||
ServiceStateChangedEvent(boolean state) {
|
||||
this.state = state;
|
||||
@@ -57,6 +58,7 @@ public class HoverMenuService extends Service {
|
||||
public static final String MESSAGE_MENU_EXIT = "MESSAGE_MENU_EXIT";
|
||||
|
||||
private static boolean sIsRunning;
|
||||
private static EventBus eventBus = new EventBus();
|
||||
|
||||
public static void startService(Context context) {
|
||||
context.startService(new Intent(context, HoverMenuService.class));
|
||||
@@ -72,6 +74,14 @@ public class HoverMenuService extends Service {
|
||||
EventBus.getDefault().post(new ServiceStateChangedEvent(sIsRunning));
|
||||
}
|
||||
|
||||
public static void postEvent(MessageEvent event) {
|
||||
eventBus.post(event);
|
||||
}
|
||||
|
||||
|
||||
public static EventBus getEventBus() {
|
||||
return eventBus;
|
||||
}
|
||||
|
||||
private static final String TAG = "HoverMenuService";
|
||||
|
||||
@@ -194,15 +204,13 @@ public class HoverMenuService extends Service {
|
||||
public void onMessageEvent(MessageEvent event) {
|
||||
switch (event.message) {
|
||||
case MESSAGE_SHOW_AND_EXPAND_MENU:
|
||||
showView(mWindowHoverMenu.getHoverMenuView());
|
||||
showAndExpandMenu();
|
||||
break;
|
||||
case MESSAGE_SHOW_LAYOUT_HIERARCHY:
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutHierarchyView);
|
||||
showLayoutHierarchy();
|
||||
break;
|
||||
case MESSAGE_SHOW_LAYOUT_BOUNDS:
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutBoundsView);
|
||||
showLayoutBounds();
|
||||
break;
|
||||
case MESSAGE_COLLAPSE_MENU:
|
||||
mWindowHoverMenu.collapseMenu();
|
||||
@@ -210,6 +218,21 @@ public class HoverMenuService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
private void showLayoutBounds() {
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutBoundsView);
|
||||
}
|
||||
|
||||
public void showLayoutHierarchy() {
|
||||
mWindowHoverMenu.getHoverMenuView().setVisibility(View.GONE);
|
||||
showView(mFloatingLayoutHierarchyView);
|
||||
}
|
||||
|
||||
public void showAndExpandMenu() {
|
||||
showView(mWindowHoverMenu.getHoverMenuView());
|
||||
}
|
||||
|
||||
|
||||
private void showView(View view) {
|
||||
view.setVisibility(View.VISIBLE);
|
||||
mWindowViewController.makeTouchable(view);
|
||||
|
||||
@@ -50,12 +50,11 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
private String mCurrentPackage, mCurrentActivity;
|
||||
private Context mContext;
|
||||
|
||||
|
||||
public MainMenuNavigatorContent(Context context) {
|
||||
mContext = context;
|
||||
mView = View.inflate(context, R.layout.floating_window_main_menu, null);
|
||||
ViewBinder.bind(this);
|
||||
EventBus.getDefault().register(this);
|
||||
HoverMenuService.getEventBus().register(this);
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.layout_hierarchy)
|
||||
@@ -63,7 +62,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
if (LayoutInspector.getInstance().getCapture() == null) {
|
||||
Toast.makeText(mView.getContext(), R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
EventBus.getDefault().post(new MessageEvent(HoverMenuService.MESSAGE_SHOW_LAYOUT_HIERARCHY));
|
||||
HoverMenuService.postEvent(new MessageEvent(HoverMenuService.MESSAGE_SHOW_LAYOUT_HIERARCHY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +71,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
if (LayoutInspector.getInstance().getCapture() == null) {
|
||||
Toast.makeText(mView.getContext(), R.string.text_no_accessibility_permission_to_capture, Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
EventBus.getDefault().post(new MessageEvent(HoverMenuService.MESSAGE_SHOW_LAYOUT_BOUNDS));
|
||||
HoverMenuService.postEvent(new MessageEvent(HoverMenuService.MESSAGE_SHOW_LAYOUT_BOUNDS));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +84,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
private void openMainActivity() {
|
||||
App.getApp().startActivity(new Intent(App.getApp(), MainActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
EventBus.getDefault().post(new MessageEvent(HoverMenuService.MESSAGE_COLLAPSE_MENU));
|
||||
HoverMenuService.postEvent(new MessageEvent(HoverMenuService.MESSAGE_COLLAPSE_MENU));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -129,7 +128,7 @@ public class MainMenuNavigatorContent implements NavigatorContent {
|
||||
if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXPANDING)) {
|
||||
syncCurrentInfo();
|
||||
} else if (event.message.equals(HoverMenuService.MESSAGE_MENU_EXIT)) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
HoverMenuService.getEventBus().unregister(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class FloatingLayoutBoundsView extends LayoutBoundsView {
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||||
EventBus.getDefault().post(new MessageEvent(HoverMenuService.MESSAGE_SHOW_AND_EXPAND_MENU));
|
||||
HoverMenuService.postEvent(new MessageEvent(HoverMenuService.MESSAGE_SHOW_AND_EXPAND_MENU));
|
||||
setVisibility(GONE);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class FloatingScriptFileListView extends RecyclerView {
|
||||
scriptFileOperations.add(new ScriptFileOperation.Rename() {
|
||||
@Override
|
||||
public void operate(final RecyclerView recyclerView, final ScriptFileList scriptFileList, final int position) {
|
||||
String oldName = scriptFileList.get(position).name;
|
||||
String oldName = scriptFileList.get(position).getSimplifiedName();
|
||||
MaterialDialog dialog = new ThemeColorMaterialDialogBuilder(recyclerView.getContext())
|
||||
.title(R.string.text_rename)
|
||||
.checkBoxPrompt(App.getApp().getString(R.string.text_rename_file_meanwhile), false, null)
|
||||
@@ -180,17 +180,8 @@ public class FloatingScriptFileListView extends RecyclerView {
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
ScriptFile scriptFile = mScriptFileList.get(position);
|
||||
holder.name.setText(scriptFile.name);
|
||||
holder.path.setText(trimFilePath(scriptFile.path));
|
||||
}
|
||||
|
||||
private final String SD_CARD_PATH = Environment.getExternalStorageDirectory().toString();
|
||||
|
||||
private String trimFilePath(String path) {
|
||||
if (path.startsWith(SD_CARD_PATH)) {
|
||||
path = path.substring(SD_CARD_PATH.length());
|
||||
}
|
||||
return path;
|
||||
holder.name.setText(scriptFile.getSimplifiedName());
|
||||
holder.path.setText(scriptFile.getSimplifiedPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,25 +40,13 @@ public class ImportIntentActivity extends BaseActivity {
|
||||
private void handleIntent() {
|
||||
Intent intent = getIntent();
|
||||
final String path = intent.getData().getPath();
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.title(R.string.text_please_input_name)
|
||||
.input(getString(R.string.text_name), FileUtils.getNameWithoutExtension(path), new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
ScriptFileList.getImpl().add(new ScriptFile(input.toString(), path));
|
||||
startMainActivity();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
if (!TextUtils.isEmpty(path))
|
||||
MainActivity.importScriptFile(this, path);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void startMainActivity() {
|
||||
startActivity(new Intent(this, MainActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,16 @@ import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.external.shortcut.ShortcutActivity;
|
||||
import com.stardust.scriptdroid.droid.Droid;
|
||||
import com.stardust.scriptdroid.droid.PathChecker;
|
||||
import com.stardust.scriptdroid.droid.RunningConfig;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/22.
|
||||
*/
|
||||
@@ -30,11 +34,20 @@ public class RunIntentActivity extends Activity {
|
||||
|
||||
private void handleIntent() {
|
||||
Intent intent = getIntent();
|
||||
String path = intent.getData().getPath();
|
||||
if (!TextUtils.isEmpty(path)) {
|
||||
startActivity(new Intent(this, ShortcutActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("path", path));
|
||||
String path = getPath(intent);
|
||||
String script = intent.getStringExtra(CommonUtils.EXTRA_KEY_PREPARE_SCRIPT);
|
||||
if (path == null && script != null) {
|
||||
Droid.getInstance().runScript(script);
|
||||
} else {
|
||||
if (new PathChecker(this).checkAndToastError(path)) {
|
||||
Droid.getInstance().runScriptFile(new File(path), null, new RunningConfig().prepareScript(script));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath(Intent intent) {
|
||||
if (intent.getData() != null && intent.getData().getPath() != null)
|
||||
return intent.getData().getPath();
|
||||
return intent.getStringExtra(CommonUtils.EXTRA_KEY_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,25 @@
|
||||
package com.stardust.scriptdroid.external.shortcut;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.stardust.scriptdroid.droid.Droid;
|
||||
import com.stardust.scriptdroid.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
import com.stardust.scriptdroid.droid.PathChecker;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/23.
|
||||
*/
|
||||
public class ShortcutActivity extends Activity {
|
||||
|
||||
interface BooleanSupplier {
|
||||
boolean getAsBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
final String path = getIntent().getStringExtra("path");
|
||||
if (!ensure(new BooleanSupplier() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return !TextUtils.isEmpty(path);
|
||||
}
|
||||
}, R.string.text_path_is_empty))
|
||||
return;
|
||||
final File scriptFile = new File(path);
|
||||
new Domino()
|
||||
.then(new Tile() {
|
||||
@Override
|
||||
public boolean fall() {
|
||||
return ShortcutActivity.this.ensure(new BooleanSupplier() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return scriptFile.exists();
|
||||
}
|
||||
}, R.string.text_file_not_exists);
|
||||
}
|
||||
})
|
||||
.then(new Tile() {
|
||||
@Override
|
||||
public boolean fall() {
|
||||
return ShortcutActivity.this.ensure(new BooleanSupplier() {
|
||||
@Override
|
||||
public boolean getAsBoolean() {
|
||||
return ShortcutActivity.this.hasStorageReadPermission();
|
||||
}
|
||||
}, R.string.text_no_file_rw_permission);
|
||||
}
|
||||
})
|
||||
.then(new Tile() {
|
||||
@Override
|
||||
public boolean fall() {
|
||||
ShortcutActivity.this.runScriptFile(path);
|
||||
return true;
|
||||
}
|
||||
})
|
||||
.fall();
|
||||
final String path = getIntent().getStringExtra(CommonUtils.EXTRA_KEY_PATH);
|
||||
if(new PathChecker(this).checkAndToastError(path)){
|
||||
runScriptFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
@@ -84,45 +36,4 @@ public class ShortcutActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean ensure(BooleanSupplier bool, String message) {
|
||||
boolean b = bool.getAsBoolean();
|
||||
if (!b) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
private boolean ensure(BooleanSupplier bool, int resId) {
|
||||
return ensure(bool, getString(resId));
|
||||
}
|
||||
|
||||
private boolean hasStorageReadPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
|
||||
checkSelfPermission(READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
interface Tile {
|
||||
boolean fall();
|
||||
}
|
||||
|
||||
public static class Domino {
|
||||
|
||||
private List<Tile> mTiles = new LinkedList<>();
|
||||
|
||||
Domino then(Tile next) {
|
||||
mTiles.add(next);
|
||||
return this;
|
||||
}
|
||||
|
||||
void fall() {
|
||||
for (Tile tile : mTiles) {
|
||||
if (!tile.fall())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
44
app/src/main/java/com/stardust/scriptdroid/external/tasker/FireSettingReceiver.java
vendored
Normal file
44
app/src/main/java/com/stardust/scriptdroid/external/tasker/FireSettingReceiver.java
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.stardust.scriptdroid.external.tasker;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.external.open.RunIntentActivity;
|
||||
import com.stardust.scriptdroid.external.shortcut.ShortcutActivity;
|
||||
import com.twofortyfouram.locale.sdk.client.receiver.AbstractPluginSettingReceiver;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/27.
|
||||
*/
|
||||
|
||||
public class FireSettingReceiver extends AbstractPluginSettingReceiver {
|
||||
|
||||
private static final String TAG = "FireSettingReceiver";
|
||||
|
||||
@Override
|
||||
protected boolean isBundleValid(@NonNull Bundle bundle) {
|
||||
Log.v(TAG, "isBundleValid: " + bundle);
|
||||
return bundle.containsKey(CommonUtils.EXTRA_KEY_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAsync() {
|
||||
Log.v(TAG, "isAsync");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void firePluginSetting(@NonNull Context context, @NonNull Bundle bundle) {
|
||||
Log.v(TAG, "firePluginSetting:" + bundle);
|
||||
context.startActivity(new Intent(App.getApp(), RunIntentActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(CommonUtils.EXTRA_KEY_PATH, bundle.getString(CommonUtils.EXTRA_KEY_PATH))
|
||||
.putExtra(CommonUtils.EXTRA_KEY_PREPARE_SCRIPT, bundle.getString(CommonUtils.EXTRA_KEY_PREPARE_SCRIPT)));
|
||||
}
|
||||
}
|
||||
74
app/src/main/java/com/stardust/scriptdroid/external/tasker/TaskPrefEditActivity.java
vendored
Normal file
74
app/src/main/java/com/stardust/scriptdroid/external/tasker/TaskPrefEditActivity.java
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
package com.stardust.scriptdroid.external.tasker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.droid.script.file.ScriptFile;
|
||||
import com.stardust.scriptdroid.external.CommonUtils;
|
||||
import com.stardust.scriptdroid.ui.main.my_script_list.ScriptAndFolderListRecyclerView;
|
||||
import com.twofortyfouram.locale.sdk.client.ui.activity.AbstractPluginActivity;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/27.
|
||||
*/
|
||||
|
||||
public class TaskPrefEditActivity extends AbstractPluginActivity {
|
||||
|
||||
private static final String TAG = "TaskPrefEditActivity";
|
||||
private String mSelectedScriptFilePath;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v(TAG, "onCreate");
|
||||
setContentView(R.layout.activity_tasker_edit);
|
||||
initScriptListRecyclerView();
|
||||
}
|
||||
|
||||
private void initScriptListRecyclerView() {
|
||||
ScriptAndFolderListRecyclerView scriptListRecyclerView = (ScriptAndFolderListRecyclerView) findViewById(R.id.script_list);
|
||||
scriptListRecyclerView.setOnItemClickListener(new ScriptAndFolderListRecyclerView.OnScriptFileClickListener() {
|
||||
@Override
|
||||
public void onClick(ScriptFile file) {
|
||||
mSelectedScriptFilePath = file.getPath();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isBundleValid(@NonNull Bundle bundle) {
|
||||
boolean valid = bundle.getString(CommonUtils.EXTRA_KEY_PATH) != null;
|
||||
Log.v(TAG, "isBundleValid: " + valid);
|
||||
Context context;
|
||||
return valid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPostCreateWithPreviousResult(@NonNull Bundle bundle, @NonNull String s) {
|
||||
Log.v(TAG, "onPostCreateWithPreviousResult: bundle=" + bundle + " str=" + s);
|
||||
mSelectedScriptFilePath = bundle.getString(CommonUtils.EXTRA_KEY_PATH);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Bundle getResultBundle() {
|
||||
Log.v(TAG, "getResultBundle");
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(CommonUtils.EXTRA_KEY_PATH, mSelectedScriptFilePath);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getResultBlurb(@NonNull Bundle bundle) {
|
||||
Log.v(TAG, "getResultBlurb");
|
||||
return bundle.getString(CommonUtils.EXTRA_KEY_PATH, getString(R.string.text_path_is_empty));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user