add: symbol and text color, background color adapter for input method enhance bar
This commit is contained in:
@@ -56,7 +56,11 @@ public class AccessibilityServiceTool {
|
||||
|
||||
public static boolean enableAccessibilityServiceByRoot(Class<? extends android.accessibilityservice.AccessibilityService> accessibilityService) {
|
||||
String serviceName = App.getApp().getPackageName() + "/" + accessibilityService.getName();
|
||||
return TextUtils.isEmpty(ProcessShell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
try {
|
||||
return TextUtils.isEmpty(ProcessShell.execCommand(String.format(Locale.getDefault(), cmd, serviceName), true).error);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean enableAccessibilityServiceByRootAndWaitFor(long timeOut) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletionBar;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
@@ -32,9 +32,6 @@ public class EditActivity extends BaseActivity {
|
||||
@ViewById(R.id.editor_view)
|
||||
EditorView mEditor;
|
||||
|
||||
@ViewById(R.id.input_method_enhance_bar)
|
||||
InputMethodEnhanceBar mInputMethodEnhanceBar;
|
||||
|
||||
private EditorMenu mEditorMenu;
|
||||
|
||||
public static void editFile(Context context, String path) {
|
||||
|
||||
@@ -4,12 +4,14 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.autojs.engine.JavaScriptEngine;
|
||||
@@ -19,7 +21,9 @@ import com.stardust.pio.PFile;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.script.Scripts;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletions;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhanceBar;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletionBar;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.InputMethodEnhancedBarColors;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.Symbols;
|
||||
import com.stardust.widget.ToolbarMenuItem;
|
||||
import com.stardust.widget.ViewSwitcher;
|
||||
|
||||
@@ -54,8 +58,8 @@ public class EditorView extends FrameLayout {
|
||||
@ViewById(R.id.editor)
|
||||
CodeMirrorEditor mEditor;
|
||||
|
||||
@ViewById(R.id.input_method_enhance_bar)
|
||||
InputMethodEnhanceBar mInputMethodEnhanceBar;
|
||||
@ViewById(R.id.code_completion_bar)
|
||||
CodeCompletionBar mCodeCompletionBar;
|
||||
|
||||
@ViewById(R.id.toolbar_switcher)
|
||||
ViewSwitcher mToolbarSwitcher;
|
||||
@@ -63,6 +67,12 @@ public class EditorView extends FrameLayout {
|
||||
@ViewById(R.id.replace)
|
||||
ToolbarMenuItem mReplaceMenuItem;
|
||||
|
||||
@ViewById(R.id.input_method_enhance_bar)
|
||||
View mInputMethodEnhanceBar;
|
||||
|
||||
@ViewById(R.id.symbols)
|
||||
ImageView mSymbols;
|
||||
|
||||
private static final String KEY_EDITOR_THEME = "我...深爱着...你呀...17.9.28";
|
||||
|
||||
private String mName;
|
||||
@@ -71,6 +81,8 @@ public class EditorView extends FrameLayout {
|
||||
|
||||
private ScriptExecution mScriptExecution;
|
||||
private boolean mTextChanged = false;
|
||||
private CodeCompletions mCodeCompletions;
|
||||
private boolean mSymbolsShown = false;
|
||||
private BroadcastReceiver mOnRunFinishedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
@@ -150,10 +162,27 @@ public class EditorView extends FrameLayout {
|
||||
@AfterViews
|
||||
void init() {
|
||||
setUpEditor();
|
||||
setUpInputMethodEnhancedBar();
|
||||
}
|
||||
|
||||
private void setUpInputMethodEnhancedBar() {
|
||||
mCodeCompletionBar.setOnHintClickListener(new CodeCompletionBar.OnHintClickListener() {
|
||||
@Override
|
||||
public void onHintClick(CodeCompletions completions, int pos) {
|
||||
if (completions.shouldBeInserted()) {
|
||||
mEditor.insert(completions.getHints().get(pos));
|
||||
showOrHideSymbols();
|
||||
return;
|
||||
}
|
||||
mEditor.replace(completions.getHints().get(pos), completions.getFrom().line, completions.getFrom().ch,
|
||||
completions.getTo().line, completions.getTo().ch);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void setUpEditor() {
|
||||
mEditor.setTheme(PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||
setTheme(PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||
.getString(KEY_EDITOR_THEME, mEditor.getTheme()));
|
||||
mEditor.setCallback(new CodeMirrorEditor.Callback() {
|
||||
@Override
|
||||
@@ -165,23 +194,36 @@ public class EditorView extends FrameLayout {
|
||||
|
||||
@Override
|
||||
public void updateCodeCompletion(int fromLine, int fromCh, int toLine, int toCh, final String[] list) {
|
||||
mInputMethodEnhanceBar.setCodeCompletions(new CodeCompletions(
|
||||
mCodeCompletionBar.setCodeCompletions(new CodeCompletions(
|
||||
new CodeCompletions.Pos(fromLine, fromCh),
|
||||
new CodeCompletions.Pos(toLine, toCh),
|
||||
Arrays.asList(list)
|
||||
));
|
||||
}
|
||||
});
|
||||
mInputMethodEnhanceBar.setOnHintClickListener(new InputMethodEnhanceBar.OnHintClickListener() {
|
||||
@Override
|
||||
public void onHintClick(CodeCompletions completions, int pos) {
|
||||
mEditor.replace(completions.getHints().get(pos), completions.getFrom().line, completions.getFrom().ch,
|
||||
completions.getTo().line, completions.getTo().ch);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void setTheme(String theme) {
|
||||
mEditor.setTheme(theme);
|
||||
mInputMethodEnhanceBar.setBackgroundColor(InputMethodEnhancedBarColors.getBackgroundColor(theme));
|
||||
int textColor = InputMethodEnhancedBarColors.getTextColor(theme);
|
||||
mCodeCompletionBar.setTextColor(textColor);
|
||||
mSymbols.setColorFilter(textColor);
|
||||
}
|
||||
|
||||
@Click(R.id.symbols)
|
||||
void showOrHideSymbols() {
|
||||
if (mSymbolsShown) {
|
||||
mCodeCompletionBar.setCodeCompletions(mCodeCompletions);
|
||||
mCodeCompletions = null;
|
||||
} else {
|
||||
mCodeCompletions = mCodeCompletionBar.getCodeCompletions();
|
||||
mCodeCompletionBar.setCodeCompletions(Symbols.getSymbols());
|
||||
}
|
||||
mSymbolsShown = !mSymbolsShown;
|
||||
}
|
||||
|
||||
@Click(R.id.run)
|
||||
public void runAndSaveFileIfNeeded() {
|
||||
@@ -296,7 +338,7 @@ public class EditorView extends FrameLayout {
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
|
||||
.putString(KEY_EDITOR_THEME, text.toString())
|
||||
.apply();
|
||||
mEditor.setTheme(text.toString());
|
||||
setTheme(text.toString());
|
||||
return true;
|
||||
}
|
||||
})
|
||||
|
||||
@@ -36,12 +36,13 @@ import java.util.Map;
|
||||
* Created by Stardust on 2017/2/17.
|
||||
*/
|
||||
|
||||
public class InputMethodEnhanceBar extends RecyclerView {
|
||||
public class CodeCompletionBar extends RecyclerView {
|
||||
|
||||
public interface OnHintClickListener {
|
||||
void onHintClick(CodeCompletions completions, int pos);
|
||||
}
|
||||
|
||||
private int mTextColor;
|
||||
private CodeCompletions mCodeCompletions;
|
||||
private OnHintClickListener mOnHintClickListener;
|
||||
private final OnClickListener mOnCodeCompletionItemClickListener = new OnClickListener() {
|
||||
@@ -69,17 +70,17 @@ public class InputMethodEnhanceBar extends RecyclerView {
|
||||
}
|
||||
};
|
||||
|
||||
public InputMethodEnhanceBar(Context context) {
|
||||
public CodeCompletionBar(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public InputMethodEnhanceBar(Context context, @Nullable AttributeSet attrs) {
|
||||
public CodeCompletionBar(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public InputMethodEnhanceBar(Context context, @Nullable AttributeSet attrs, int defStyle) {
|
||||
public CodeCompletionBar(Context context, @Nullable AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
init();
|
||||
}
|
||||
@@ -93,6 +94,16 @@ public class InputMethodEnhanceBar extends RecyclerView {
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public CodeCompletions getCodeCompletions() {
|
||||
return mCodeCompletions;
|
||||
}
|
||||
|
||||
public void setTextColor(int textColor) {
|
||||
mTextColor = textColor;
|
||||
getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
private void init() {
|
||||
setAdapter(new CodeCompletionAdapter());
|
||||
setLayoutManager(new WrapContentLinearLayoutManager(getContext(), HORIZONTAL, false));
|
||||
@@ -107,7 +118,11 @@ public class InputMethodEnhanceBar extends RecyclerView {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
((TextView) holder.itemView).setText(mCodeCompletions.getHints().get(position));
|
||||
TextView textView = ((TextView) holder.itemView);
|
||||
textView.setText(mCodeCompletions.getHints().get(position));
|
||||
if(mTextColor != 0){
|
||||
textView.setTextColor(mTextColor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -28,6 +28,10 @@ public class CodeCompletions {
|
||||
mHints = hints;
|
||||
}
|
||||
|
||||
public static CodeCompletions just(List<String> hints) {
|
||||
return new CodeCompletions(null, null, hints);
|
||||
}
|
||||
|
||||
public Pos getFrom() {
|
||||
return mFrom;
|
||||
}
|
||||
@@ -39,4 +43,10 @@ public class CodeCompletions {
|
||||
public List<String> getHints() {
|
||||
return mHints;
|
||||
}
|
||||
|
||||
|
||||
public boolean shouldBeInserted() {
|
||||
return mFrom == null && mTo == null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.stardust.scriptdroid.ui.edit.completion;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.stardust.util.MapEntries;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/28.
|
||||
*/
|
||||
|
||||
public class InputMethodEnhancedBarColors {
|
||||
|
||||
private static final Map<String, Integer> sEditorThemeColors = new MapEntries<String, Integer>()
|
||||
.entry("3024-day", 0xf7f7f7)
|
||||
.entry("3024-night", 0x090300)
|
||||
.entry("abcdef", 0x0f0f0f)
|
||||
.entry("ambiance-mobile", 0xffffff)
|
||||
.entry("ambiance", 0xffffff)
|
||||
.entry("base16-dark", 0x151515)
|
||||
.entry("base16-light", 0xf5f5f5)
|
||||
.entry("bespin", 0x28211c)
|
||||
.entry("dracula", 0x282a36)
|
||||
.entry("duotone-dark", 0x2a2734)
|
||||
.entry("duotone-light", 0xfaf8f5)
|
||||
.entry("eclipse", 0xffffff)
|
||||
.entry("icecoder", 0x1d1d1b)
|
||||
.entry("material", 0x263238)
|
||||
.entry("mbo", 0x2c2c2c)
|
||||
.entry("mdn-like", 0xfefefe)
|
||||
.entry("monokai", 0x272822)
|
||||
.entry("neat", 0xffffff)
|
||||
.entry("neo", 0xffffff)
|
||||
.entry("night", 0x0a001f)
|
||||
.entry("panda-syntax", 0x292a2b)
|
||||
.entry("paraiso-dark", 0x2f1e2e)
|
||||
.entry("paraiso-light", 0xe7e9db)
|
||||
.entry("pastel-on-dark", 0x2c2827)
|
||||
.entry("railscasts", 0x2b2b2b)
|
||||
.entry("rubyblue", 0x112435)
|
||||
.entry("seti", 0x151718)
|
||||
.entry("solarized", 0xffffff)
|
||||
.entry("the-matrix", 0x000000)
|
||||
.entry("tomorrow-night-bright", 0x000000)
|
||||
.entry("tomorrow-night-eighties", 0x000000)
|
||||
.entry("ttcn", 0xffffff)
|
||||
.entry("twilight", 0x141414)
|
||||
.entry("xq-light", 0xffffff)
|
||||
.entry("zenburn", 0x3f3f3f)
|
||||
.map();
|
||||
|
||||
public static int getBackgroundColor(String theme) {
|
||||
int themeColor = sEditorThemeColors.get(theme);
|
||||
if (themeColor == 0xffffff) {
|
||||
return 0x828389;
|
||||
}
|
||||
return themeColor | 0xdd000000;
|
||||
}
|
||||
|
||||
public static int getTextColor(String theme) {
|
||||
int c = sEditorThemeColors.get(theme);
|
||||
if (isBrightColor(c)) {
|
||||
return Color.BLACK;
|
||||
} else {
|
||||
return Color.WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBrightColor(int color) {
|
||||
int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
|
||||
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1]
|
||||
* rgb[1] * .691 + rgb[2] * rgb[2] * .068);
|
||||
return brightness >= 200;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.stardust.scriptdroid.ui.edit.completion;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/9/28.
|
||||
*/
|
||||
|
||||
public class Symbols {
|
||||
|
||||
private static CodeCompletions sSymbols = CodeCompletions.just(Arrays.asList(
|
||||
"=", "\"", "(", ")", "{", "}", ";", "!", "|", "&", "[", "]", "/", "\\",
|
||||
"<", ">"));
|
||||
|
||||
public static CodeCompletions getSymbols() {
|
||||
return sSymbols;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user