change to java 7 and min sdk version 19
This commit is contained in:
@@ -4,6 +4,8 @@ import android.os.Build;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static android.content.pm.PackageManager.PERMISSION_DENIED;
|
||||
@@ -22,11 +24,20 @@ public class BaseActivity extends AppCompatActivity {
|
||||
|
||||
protected void checkPermission(String... permissions) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
String[] requestPermissions = Stream.of(permissions).filter(permission -> checkSelfPermission(permission) == PERMISSION_DENIED).toArray(String[]::new);
|
||||
|
||||
String[] requestPermissions = getRequestPermissions(permissions);
|
||||
if (requestPermissions.length > 0)
|
||||
requestPermissions(requestPermissions, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getRequestPermissions(String[] permissions) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String permission : permissions) {
|
||||
if (checkSelfPermission(permission) == PERMISSION_DENIED) {
|
||||
list.add(permission);
|
||||
}
|
||||
}
|
||||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.stardust.scriptdroid;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.InputType;
|
||||
@@ -10,7 +12,9 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.jecelyin.editor.v2.core.widget.JecEditText;
|
||||
import com.stardust.scriptdroid.droid.runtime.action.ActionPerformService;
|
||||
import com.stardust.scriptdroid.droid.script.file.ScriptFile;
|
||||
import com.stardust.scriptdroid.droid.script.file.ScriptFileList;
|
||||
@@ -23,8 +27,8 @@ import com.stardust.scriptdroid.ui.SlidingUpPanel;
|
||||
import com.stardust.util.MapEntries;
|
||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class MainActivity extends BaseActivity {
|
||||
@@ -54,6 +58,7 @@ public class MainActivity extends BaseActivity {
|
||||
private void checkPermissions() {
|
||||
checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
goToAccessibilityPermissionSettingIfDisabled();
|
||||
JecEditText jecEditText = new JecEditText(this);
|
||||
}
|
||||
|
||||
private void goToAccessibilityPermissionSettingIfDisabled() {
|
||||
@@ -62,19 +67,37 @@ public class MainActivity extends BaseActivity {
|
||||
.content(R.string.explain_accessibility_permission)
|
||||
.positiveText(R.string.text_go_to_setting)
|
||||
.negativeText(R.string.text_cancel)
|
||||
.onPositive((dialog, which) -> AccessibilityServiceUtils.goToPermissionSetting(this)).show();
|
||||
.onPositive(new MaterialDialog.SingleButtonCallback() {
|
||||
@Override
|
||||
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
|
||||
AccessibilityServiceUtils.goToPermissionSetting(MainActivity.this);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpFileChooser() {
|
||||
mFileChooser = new FileChooser(this);
|
||||
mFileChooser.setOnFileChoseListener(inputStream -> Optional.ofNullable(FileUtils.getPath(inputStream)).ifPresent(this::addScriptFile));
|
||||
mFileChooser.setOnFileChoseListener(new FileChooser.OnFileChoseListener() {
|
||||
@Override
|
||||
public void onFileChose(InputStream inputStream) {
|
||||
String path = FileUtils.getPath(inputStream);
|
||||
if (path != null) {
|
||||
MainActivity.this.addScriptFile(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addScriptFile(final String path) {
|
||||
new MaterialDialog.Builder(this).title(R.string.text_name)
|
||||
.inputType(InputType.TYPE_CLASS_TEXT)
|
||||
.input(getString(R.string.text_please_input_name), "", (dialog, input) -> addScriptFile(input.toString(), path)).show();
|
||||
.input(getString(R.string.text_please_input_name), "", new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
MainActivity.this.addScriptFile(input.toString(), path);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void addScriptFile(String name, String path) {
|
||||
@@ -107,17 +130,35 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void setUpListener() {
|
||||
$(R.id.fab).setOnClickListener(view -> mSlidingUpPanel.show());
|
||||
$(R.id.import_from_file).setOnClickListener(v -> showFileChooser());
|
||||
$(R.id.create_new_file).setOnClickListener(v -> createScriptFile());
|
||||
$(R.id.fab).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mSlidingUpPanel.show();
|
||||
}
|
||||
});
|
||||
$(R.id.import_from_file).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity.this.showFileChooser();
|
||||
}
|
||||
});
|
||||
$(R.id.create_new_file).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MainActivity.this.createScriptFile();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createScriptFile() {
|
||||
new MaterialDialog.Builder(this).title(R.string.text_name)
|
||||
.inputType(InputType.TYPE_CLASS_TEXT)
|
||||
.input(getString(R.string.text_please_input_name), "", (dialog, input) -> {
|
||||
String path = ScriptFile.DEFAULT_FOLDER + input + ".js";
|
||||
createScriptFile(input.toString(), path);
|
||||
.input(getString(R.string.text_please_input_name), "", new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
String path = ScriptFile.DEFAULT_FOLDER + input + ".js";
|
||||
MainActivity.this.createScriptFile(input.toString(), path);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
@@ -131,9 +172,12 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void showFileChooser() {
|
||||
mFileChooser.startFileManagerToChoose("*/*", (exception, mimeType) -> {
|
||||
exception.printStackTrace();
|
||||
Snackbar.make(mView, R.string.text_file_manager_not_found, Snackbar.LENGTH_SHORT).show();
|
||||
mFileChooser.startFileManagerToChoose("*/*", new FileChooser.FileManagerNotFoundHandler() {
|
||||
@Override
|
||||
public void handle(ActivityNotFoundException exception, String mimeType) {
|
||||
exception.printStackTrace();
|
||||
Snackbar.make(mView, R.string.text_file_manager_not_found, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -145,8 +189,24 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
|
||||
private final Map<Integer, Runnable> mOptionActionMap = new MapEntries<Integer, Runnable>()
|
||||
.entry(R.id.action_exit, this::finish)
|
||||
.entry(R.id.action_disable_service, this::disableAccessibilityService)
|
||||
.entry(R.id.action_exit, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.this.finish();
|
||||
}
|
||||
})
|
||||
.entry(R.id.action_disable_service, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainActivity.this.disableAccessibilityService();
|
||||
}
|
||||
})
|
||||
.entry(R.id.action_test, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startActivity(new Intent(MainActivity.this, TestActivity.class));
|
||||
}
|
||||
})
|
||||
.map();
|
||||
|
||||
|
||||
@@ -156,7 +216,9 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void disableAccessibilityService() {
|
||||
Optional.ofNullable(ActionPerformService.getInstance()).ifPresent(ActionPerformService::disableSelf);
|
||||
if (ActionPerformService.getInstance() != null) {
|
||||
ActionPerformService.getInstance().disableSelf();
|
||||
}
|
||||
Snackbar.make(mView, R.string.text_service_disabled, Snackbar.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,19 +22,51 @@ import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
*/
|
||||
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(() -> !TextUtils.isEmpty(path), R.string.text_path_is_empty))
|
||||
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(() -> ensure(scriptFile::exists, R.string.text_file_not_exists))
|
||||
.then(() -> ensure(this::hasStorageReadPermission, R.string.text_no_file_rw_permission))
|
||||
.then(() -> {
|
||||
runScriptFile(path);
|
||||
return true;
|
||||
.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();
|
||||
}
|
||||
@@ -70,7 +102,6 @@ public class ShortcutActivity extends Activity {
|
||||
checkSelfPermission(READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface Tile {
|
||||
boolean fall();
|
||||
}
|
||||
|
||||
61
app/src/main/java/com/stardust/scriptdroid/TestActivity.java
Normal file
61
app/src/main/java/com/stardust/scriptdroid/TestActivity.java
Normal file
@@ -0,0 +1,61 @@
|
||||
package com.stardust.scriptdroid;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.jecelyin.editor.v2.Pref;
|
||||
import com.jecelyin.editor.v2.common.Command;
|
||||
import com.jecelyin.editor.v2.ui.EditorDelegate;
|
||||
import com.jecelyin.editor.v2.ui.IActivity;
|
||||
import com.jecelyin.editor.v2.ui.TabManager;
|
||||
import com.jecelyin.editor.v2.view.EditorView;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/1/29.
|
||||
*/
|
||||
|
||||
public class TestActivity extends BaseActivity implements IActivity{
|
||||
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
Pref.getInstance(this).setTheme(0);
|
||||
setContentView(R.layout.edit_layout);
|
||||
EditorDelegate editorDelegate = new EditorDelegate(0, "Hello 920 Editor", "Hello 920");
|
||||
EditorView editorView = $(R.id.editor);
|
||||
editorDelegate.setEditorView(editorView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startPickPathActivity(String s, String s1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doNextCommand() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabManager getTabManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMenuStatus(int i, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentChanged(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doCommand(Command command) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFile(String s, String s1, int i) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,12 +35,15 @@ public class Droid {
|
||||
runScriptFile(new File(path));
|
||||
}
|
||||
|
||||
public void runScript(String script) {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
JAVA_SCRIPT_ENGINE.execute(script);
|
||||
} catch (Exception e) {
|
||||
RUNTIME.toast("错误" + e.getMessage());
|
||||
public void runScript(final String script) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
JAVA_SCRIPT_ENGINE.execute(script);
|
||||
} catch (Exception e) {
|
||||
RUNTIME.toast("错误" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@@ -148,8 +148,13 @@ public class DroidRuntime implements IDroidRuntime {
|
||||
|
||||
|
||||
@Override
|
||||
public void toast(String text) {
|
||||
mUIHandler.post(() -> Toast.makeText(App.getApp(), text, Toast.LENGTH_SHORT).show());
|
||||
public void toast(final String text) {
|
||||
mUIHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(App.getApp(), text, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,11 +13,36 @@ import com.stardust.util.SparseArrayEntries;
|
||||
public interface Able {
|
||||
|
||||
SparseArray<Able> ABLE_MAP = new SparseArrayEntries<Able>()
|
||||
.entry(AccessibilityNodeInfo.ACTION_CLICK, AccessibilityNodeInfo::isClickable)
|
||||
.entry(AccessibilityNodeInfo.ACTION_LONG_CLICK, AccessibilityNodeInfo::isLongClickable)
|
||||
.entry(AccessibilityNodeInfo.ACTION_FOCUS, AccessibilityNodeInfo::isFocusable)
|
||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, AccessibilityNodeInfo::isScrollable)
|
||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, AccessibilityNodeInfo::isScrollable)
|
||||
.entry(AccessibilityNodeInfo.ACTION_CLICK, new Able() {
|
||||
@Override
|
||||
public boolean isAble(AccessibilityNodeInfo nodeInfo) {
|
||||
return nodeInfo.isClickable();
|
||||
}
|
||||
})
|
||||
.entry(AccessibilityNodeInfo.ACTION_LONG_CLICK, new Able() {
|
||||
@Override
|
||||
public boolean isAble(AccessibilityNodeInfo nodeInfo) {
|
||||
return nodeInfo.isLongClickable();
|
||||
}
|
||||
})
|
||||
.entry(AccessibilityNodeInfo.ACTION_FOCUS, new Able() {
|
||||
@Override
|
||||
public boolean isAble(AccessibilityNodeInfo nodeInfo) {
|
||||
return nodeInfo.isFocusable();
|
||||
}
|
||||
})
|
||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD, new Able() {
|
||||
@Override
|
||||
public boolean isAble(AccessibilityNodeInfo nodeInfo) {
|
||||
return nodeInfo.isScrollable();
|
||||
}
|
||||
})
|
||||
.entry(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD, new Able() {
|
||||
@Override
|
||||
public boolean isAble(AccessibilityNodeInfo nodeInfo) {
|
||||
return nodeInfo.isScrollable();
|
||||
}
|
||||
})
|
||||
.sparseArray();
|
||||
|
||||
boolean isAble(AccessibilityNodeInfo node);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.stardust.scriptdroid.ui;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
@@ -91,9 +92,12 @@ public abstract class ScriptFileOperation {
|
||||
public void operate(final ScriptListRecyclerView recyclerView, final ScriptFileList scriptFileList, final int position) {
|
||||
String oldName = scriptFileList.get(position).name;
|
||||
new MaterialDialog.Builder(recyclerView.getContext()).title("重命名")
|
||||
.input("输入新名称", oldName, (dialog, input) -> {
|
||||
scriptFileList.rename(position, input.toString());
|
||||
recyclerView.getAdapter().notifyItemChanged(position);
|
||||
.input("输入新名称", oldName, new MaterialDialog.InputCallback() {
|
||||
@Override
|
||||
public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
|
||||
scriptFileList.rename(position, input.toString());
|
||||
recyclerView.getAdapter().notifyItemChanged(position);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,9 +86,12 @@ public class ScriptListRecyclerView extends RecyclerView {
|
||||
|
||||
private void initScriptFileOperationPopupMenu() {
|
||||
mScriptFileOperationPopupMenu = new ScriptFileOperationPopupMenu(getContext());
|
||||
mScriptFileOperationPopupMenu.setOnItemClickListener((view, position) -> {
|
||||
ScriptFileOperation.getOperation(position).operate(ScriptListRecyclerView.this, mScriptFileList, mOperateFileIndex);
|
||||
mScriptFileOperationPopupMenu.dismiss();
|
||||
mScriptFileOperationPopupMenu.setOnItemClickListener(new ScriptFileOperationPopupMenu.OnItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, int position) {
|
||||
ScriptFileOperation.getOperation(position).operate(ScriptListRecyclerView.this, mScriptFileList, mOperateFileIndex);
|
||||
mScriptFileOperationPopupMenu.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -99,7 +102,12 @@ public class ScriptListRecyclerView extends RecyclerView {
|
||||
|
||||
private void showOperationDialog(final int position) {
|
||||
new MaterialDialog.Builder(getContext()).items(ScriptFileOperation.getOperationNames())
|
||||
.itemsCallback((dialog, itemView, operation, text) -> ScriptFileOperation.getOperation(operation).operate(ScriptListRecyclerView.this, mScriptFileList, position)).show();
|
||||
.itemsCallback(new MaterialDialog.ListCallback() {
|
||||
@Override
|
||||
public void onSelection(MaterialDialog dialog, View itemView, int operation, CharSequence text) {
|
||||
ScriptFileOperation.getOperation(operation).operate(ScriptListRecyclerView.this, mScriptFileList, position);
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void showOrDismissOperationPopupMenu(View v) {
|
||||
|
||||
@@ -56,7 +56,12 @@ public class SlidingUpPanel extends FrameLayout {
|
||||
|
||||
public void dismiss() {
|
||||
mContentContainer.startAnimation(mSlideDownAnimation);
|
||||
postDelayed(() -> setVisibility(GONE), mSlideDownAnimation.getDuration());
|
||||
postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SlidingUpPanel.this.setVisibility(GONE);
|
||||
}
|
||||
}, mSlideDownAnimation.getDuration());
|
||||
mShowing = false;
|
||||
}
|
||||
|
||||
@@ -85,7 +90,12 @@ public class SlidingUpPanel extends FrameLayout {
|
||||
|
||||
private void initShadow() {
|
||||
mShadow = findViewById(R.id.shadow);
|
||||
mShadow.setOnClickListener(v -> dismiss());
|
||||
mShadow.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SlidingUpPanel.this.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user