add:
* offline docs * tow-row input method enhance bar * long press hint to show function manual * docs drawer
This commit is contained in:
@@ -144,4 +144,7 @@ public class Pref {
|
||||
return def().getBoolean(getString(R.string.key_stable_mode), false);
|
||||
}
|
||||
|
||||
public static String getDocumentationUrl() {
|
||||
return "file:///android_asset/docs/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.stardust.scriptdroid.ui.doc;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.util.BackPressedHandler;
|
||||
import com.stardust.widget.EWebView;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
import org.androidannotations.annotations.ViewById;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/24.
|
||||
*/
|
||||
@EActivity(R.layout.activity_documentation)
|
||||
public class DocumentationActivity extends BaseActivity {
|
||||
|
||||
public static final String EXTRA_URL = "url";
|
||||
|
||||
@ViewById(R.id.eweb_view)
|
||||
EWebView mEWebView;
|
||||
|
||||
WebView mWebView;
|
||||
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
setToolbarAsBack(getString(R.string.text_tutorial));
|
||||
mWebView = mEWebView.getWebView();
|
||||
String url = getIntent().getStringExtra(EXTRA_URL);
|
||||
if (url == null) {
|
||||
url = Pref.getDocumentationUrl() + "index.html";
|
||||
}
|
||||
mWebView.loadUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mWebView.canGoBack()) {
|
||||
mWebView.goBack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.stardust.scriptdroid.ui.doc;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.widget.EWebView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/10/24.
|
||||
*/
|
||||
|
||||
public class ManualDialog {
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView mTitle;
|
||||
|
||||
@BindView(R.id.eweb_view)
|
||||
EWebView mEWebView;
|
||||
|
||||
@BindView(R.id.pin_to_left)
|
||||
View mPinToLeft;
|
||||
|
||||
Dialog mDialog;
|
||||
private Context mContext;
|
||||
|
||||
public ManualDialog(Context context) {
|
||||
mContext = context;
|
||||
View view = View.inflate(context, R.layout.floating_manual_dialog, null);
|
||||
ButterKnife.bind(this, view);
|
||||
mDialog = new MaterialDialog.Builder(context)
|
||||
.customView(view, false)
|
||||
.build();
|
||||
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
|
||||
public ManualDialog title(String title) {
|
||||
mTitle.setText(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ManualDialog url(String url) {
|
||||
mEWebView.getWebView().loadUrl(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ManualDialog pinToLeft(View.OnClickListener listener) {
|
||||
mPinToLeft.setOnClickListener(v -> {
|
||||
mDialog.dismiss();
|
||||
listener.onClick(v);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public ManualDialog show() {
|
||||
mDialog.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
@OnClick(R.id.close)
|
||||
void close() {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
|
||||
@OnClick(R.id.fullscreen)
|
||||
void viewInNewActivity() {
|
||||
mDialog.dismiss();
|
||||
DocumentationActivity_.intent(mContext)
|
||||
.extra(DocumentationActivity.EXTRA_URL, mEWebView.getWebView().getUrl())
|
||||
.start();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.stardust.scriptdroid.ui.main.doc;
|
||||
package com.stardust.scriptdroid.ui.doc;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@@ -8,6 +8,7 @@ import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.main.ViewPagerFragment;
|
||||
import com.stardust.util.BackPressedHandler;
|
||||
@@ -23,6 +24,8 @@ import org.androidannotations.annotations.ViewById;
|
||||
@EFragment(R.layout.fragment_online_docs)
|
||||
public class OnlineDocsFragment extends ViewPagerFragment implements BackPressedHandler {
|
||||
|
||||
public static final String ARGUMENT_URL = "url";
|
||||
|
||||
@ViewById(R.id.eweb_view)
|
||||
EWebView mEWebView;
|
||||
WebView mWebView;
|
||||
@@ -35,7 +38,11 @@ public class OnlineDocsFragment extends ViewPagerFragment implements BackPressed
|
||||
@AfterViews
|
||||
void setUpViews() {
|
||||
mWebView = mEWebView.getWebView();
|
||||
mWebView.loadUrl("https://hyb1996.github.io/AutoJs-Docs/");
|
||||
String url = Pref.getDocumentationUrl() + "index.html";
|
||||
if (getArguments() != null) {
|
||||
url = getArguments().getString(ARGUMENT_URL, url);
|
||||
}
|
||||
mWebView.loadUrl(url);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
public interface Callback {
|
||||
void onChange();
|
||||
|
||||
void updateCodeCompletion(int fromLine, int fromCh, int toLine, int toCh, String[] list);
|
||||
void updateCodeCompletion(int fromLine, int fromCh, int toLine, int toCh, String[] list, String[] urls);
|
||||
}
|
||||
|
||||
private static String[] sAvailableThemes;
|
||||
@@ -388,14 +388,14 @@ public class CodeMirrorEditor extends FrameLayout {
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void updateCodeCompletion(final int fromLine, final int fromCh, final int toLine, final int toCh, final String[] list) {
|
||||
public void updateCodeCompletion(final int fromLine, final int fromCh, final int toLine, final int toCh, final String[] list, final String[] urls) {
|
||||
if (mCallback == null) {
|
||||
return;
|
||||
}
|
||||
mWebView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list);
|
||||
mCallback.updateCodeCompletion(fromLine, fromCh, toLine, toCh, list, urls);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,15 +4,18 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.model.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
import com.stardust.widget.EWebView;
|
||||
|
||||
import org.androidannotations.annotations.AfterViews;
|
||||
import org.androidannotations.annotations.EActivity;
|
||||
@@ -31,6 +34,7 @@ public class EditActivity extends BaseActivity {
|
||||
@ViewById(R.id.editor_view)
|
||||
EditorView mEditor;
|
||||
|
||||
|
||||
private EditorMenu mEditorMenu;
|
||||
|
||||
public static void editFile(Context context, String path) {
|
||||
|
||||
@@ -7,7 +7,9 @@ import android.content.IntentFilter;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
@@ -17,12 +19,15 @@ import com.stardust.autojs.engine.JavaScriptEngine;
|
||||
import com.stardust.autojs.execution.ScriptExecution;
|
||||
import com.stardust.autojs.script.JavaScriptFileSource;
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.scriptdroid.Pref;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.model.script.Scripts;
|
||||
import com.stardust.scriptdroid.ui.doc.ManualDialog;
|
||||
import com.stardust.scriptdroid.ui.edit.completion.CodeCompletions;
|
||||
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.EWebView;
|
||||
import com.stardust.widget.ToolbarMenuItem;
|
||||
import com.stardust.widget.ViewSwitcher;
|
||||
|
||||
@@ -36,7 +41,6 @@ import java.util.Arrays;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static com.stardust.scriptdroid.model.script.Scripts.ACTION_ON_EXECUTION_FINISHED;
|
||||
@@ -45,7 +49,7 @@ import static com.stardust.scriptdroid.model.script.Scripts.ACTION_ON_EXECUTION_
|
||||
* Created by Stardust on 2017/9/28.
|
||||
*/
|
||||
@EViewGroup(R.layout.editor_view)
|
||||
public class EditorView extends FrameLayout {
|
||||
public class EditorView extends FrameLayout implements CodeCompletionBar.OnHintClickListener {
|
||||
|
||||
public static final String EXTRA_PATH = "Still Love Eating 17.4.5";
|
||||
public static final String EXTRA_NAME = "Still love you 17.6.29 But....(ಥ_ಥ)";
|
||||
@@ -69,8 +73,17 @@ public class EditorView extends FrameLayout {
|
||||
@ViewById(R.id.input_method_enhance_bar)
|
||||
View mInputMethodEnhanceBar;
|
||||
|
||||
@ViewById(R.id.symbols)
|
||||
ImageView mSymbols;
|
||||
@ViewById(R.id.symbol_bar)
|
||||
CodeCompletionBar mSymbolBar;
|
||||
|
||||
@ViewById(R.id.functions)
|
||||
ImageView mFunctions;
|
||||
|
||||
@ViewById(R.id.docs)
|
||||
EWebView mEWebView;
|
||||
|
||||
@ViewById(R.id.drawer_layout)
|
||||
DrawerLayout mDrawerLayout;
|
||||
|
||||
private static final String KEY_EDITOR_THEME = "我...深爱着...你呀...17.9.28";
|
||||
|
||||
@@ -80,8 +93,6 @@ 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) {
|
||||
@@ -168,21 +179,15 @@ public class EditorView extends FrameLayout {
|
||||
setUpEditor();
|
||||
setUpInputMethodEnhancedBar();
|
||||
setMenuItemStatus(R.id.save, false);
|
||||
mEWebView.getWebView().getSettings().setDisplayZoomControls(true);
|
||||
mEWebView.getWebView().loadUrl(Pref.getDocumentationUrl() + "index.html");
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
mSymbolBar.setCodeCompletions(Symbols.getSymbols());
|
||||
mCodeCompletionBar.setOnHintClickListener(this);
|
||||
mSymbolBar.setOnHintClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,11 +203,12 @@ public class EditorView extends FrameLayout {
|
||||
|
||||
|
||||
@Override
|
||||
public void updateCodeCompletion(int fromLine, int fromCh, int toLine, int toCh, final String[] list) {
|
||||
public void updateCodeCompletion(int fromLine, int fromCh, int toLine, int toCh, final String[] list, final String[] urls) {
|
||||
mCodeCompletionBar.setCodeCompletions(new CodeCompletions(
|
||||
new CodeCompletions.Pos(fromLine, fromCh),
|
||||
new CodeCompletions.Pos(toLine, toCh),
|
||||
Arrays.asList(list)
|
||||
Arrays.asList(list),
|
||||
Arrays.asList(urls)
|
||||
));
|
||||
}
|
||||
});
|
||||
@@ -215,30 +221,19 @@ public class EditorView extends FrameLayout {
|
||||
mInputMethodEnhanceBar.setBackgroundColor(InputMethodEnhancedBarColors.getBackgroundColor(theme));
|
||||
int textColor = InputMethodEnhancedBarColors.getTextColor(theme);
|
||||
mCodeCompletionBar.setTextColor(textColor);
|
||||
mSymbols.setColorFilter(textColor);
|
||||
mSymbolBar.setTextColor(textColor);
|
||||
mFunctions.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.functions)
|
||||
void showFunctionList() {
|
||||
|
||||
}
|
||||
|
||||
@Click(R.id.run)
|
||||
public void runAndSaveFileIfNeeded() {
|
||||
save().observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(@io.reactivex.annotations.NonNull String s) throws Exception {
|
||||
run();
|
||||
}
|
||||
});
|
||||
.subscribe(s -> run());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
@@ -261,19 +256,11 @@ public class EditorView extends FrameLayout {
|
||||
public Observable<String> save() {
|
||||
return mEditor.getText()
|
||||
.observeOn(Schedulers.io())
|
||||
.doOnNext(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(@io.reactivex.annotations.NonNull String s) throws Exception {
|
||||
PFiles.write(mFile, s);
|
||||
}
|
||||
})
|
||||
.doOnNext(s -> PFiles.write(mFile, s))
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(new Consumer<String>() {
|
||||
@Override
|
||||
public void accept(@io.reactivex.annotations.NonNull String s) throws Exception {
|
||||
mTextChanged = false;
|
||||
setMenuItemStatus(R.id.save, false);
|
||||
}
|
||||
.doOnNext(s -> {
|
||||
mTextChanged = false;
|
||||
setMenuItemStatus(R.id.save, false);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -337,15 +324,12 @@ public class EditorView extends FrameLayout {
|
||||
new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.text_editor_theme)
|
||||
.items((CharSequence[]) themes)
|
||||
.itemsCallbackSingleChoice(i, new MaterialDialog.ListCallbackSingleChoice() {
|
||||
@Override
|
||||
public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
|
||||
.putString(KEY_EDITOR_THEME, text.toString())
|
||||
.apply();
|
||||
setTheme(text.toString());
|
||||
return true;
|
||||
}
|
||||
.itemsCallbackSingleChoice(i, (dialog, itemView, which, text) -> {
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).edit()
|
||||
.putString(KEY_EDITOR_THEME, text.toString())
|
||||
.apply();
|
||||
setTheme(text.toString());
|
||||
return true;
|
||||
})
|
||||
.show();
|
||||
}
|
||||
@@ -369,4 +353,31 @@ public class EditorView extends FrameLayout {
|
||||
public void replaceAll(String keywords, String replacement, boolean usingRegex) {
|
||||
mEditor.replaceAll(keywords, replacement, usingRegex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHintClick(CodeCompletions completions, int pos) {
|
||||
if (completions.shouldBeInserted()) {
|
||||
mEditor.insert(completions.getHints().get(pos));
|
||||
showFunctionList();
|
||||
return;
|
||||
}
|
||||
mEditor.replace(completions.getHints().get(pos), completions.getFrom().line, completions.getFrom().ch,
|
||||
completions.getTo().line, completions.getTo().ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHintLongClick(CodeCompletions completions, int pos) {
|
||||
String url = completions.getUrltAt(pos);
|
||||
if (url == null)
|
||||
return;
|
||||
String absUrl = Pref.getDocumentationUrl() + url;
|
||||
new ManualDialog(getContext())
|
||||
.title(completions.getHints().get(pos))
|
||||
.url(absUrl)
|
||||
.pinToLeft(v -> {
|
||||
mEWebView.getWebView().loadUrl(absUrl);
|
||||
mDrawerLayout.openDrawer(Gravity.START);
|
||||
})
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.model.sample.Sample;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
||||
import com.stardust.scriptdroid.ui.help.HelpCatalogueActivity;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
import com.stardust.util.AssetsCache;
|
||||
import com.stardust.util.SparseArrayEntries;
|
||||
@@ -145,7 +144,7 @@ public class ViewSampleActivity extends AppCompatActivity implements OnActivityR
|
||||
showLog();
|
||||
return true;
|
||||
case R.id.action_help:
|
||||
HelpCatalogueActivity.showMainCatalogue(this);
|
||||
|
||||
return true;
|
||||
case R.id.action_import:
|
||||
new ScriptOperations(this, mView)
|
||||
|
||||
@@ -40,6 +40,8 @@ public class CodeCompletionBar extends RecyclerView {
|
||||
|
||||
public interface OnHintClickListener {
|
||||
void onHintClick(CodeCompletions completions, int pos);
|
||||
|
||||
void onHintLongClick(CodeCompletions completions, int pos);
|
||||
}
|
||||
|
||||
private int mTextColor;
|
||||
@@ -64,8 +66,9 @@ public class CodeCompletionBar extends RecyclerView {
|
||||
int position = getChildViewHolder(v).getAdapterPosition();
|
||||
if (position < 0 || position >= mCodeCompletions.getHints().size())
|
||||
return false;
|
||||
ClipboardUtil.setClip(getContext(), mCodeCompletions.getHints().get(position));
|
||||
Toast.makeText(getContext(), R.string.text_copied, Toast.LENGTH_SHORT).show();
|
||||
if (mOnHintClickListener != null) {
|
||||
mOnHintClickListener.onHintLongClick(mCodeCompletions, position);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -120,7 +123,7 @@ public class CodeCompletionBar extends RecyclerView {
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
TextView textView = ((TextView) holder.itemView);
|
||||
textView.setText(mCodeCompletions.getHints().get(position));
|
||||
if(mTextColor != 0){
|
||||
if (mTextColor != 0) {
|
||||
textView.setTextColor(mTextColor);
|
||||
}
|
||||
}
|
||||
@@ -140,29 +143,6 @@ public class CodeCompletionBar extends RecyclerView {
|
||||
}
|
||||
}
|
||||
|
||||
private static void readCompletions(Context context, String path) {
|
||||
try {
|
||||
JsonParser parser = new JsonParser();
|
||||
JsonObject object = parser.parse(new InputStreamReader(context.getAssets().open(path))).getAsJsonObject();
|
||||
//InputMethodEnhanceBar.global = readGlobal(object.remove("global").getAsJsonObject());
|
||||
readModules(object);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void readModules(JsonObject object) {
|
||||
for (Map.Entry<String, JsonElement> module : object.entrySet()) {
|
||||
//variables.put(module.getKey(), GsonUtils.toStringList(module.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<String> readGlobal(JsonObject global) {
|
||||
List<String> globalFunctions = new ArrayList<>();
|
||||
for (Map.Entry<String, JsonElement> moduleGlobal : global.entrySet()) {
|
||||
globalFunctions.addAll(GsonUtils.toStringList(moduleGlobal.getValue()));
|
||||
}
|
||||
return globalFunctions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by Stardust on 2017/9/27.
|
||||
*/
|
||||
|
||||
// TODO: 2017/10/24 refactor
|
||||
public class CodeCompletions {
|
||||
|
||||
public static class Pos {
|
||||
@@ -21,15 +21,17 @@ public class CodeCompletions {
|
||||
private Pos mFrom;
|
||||
private Pos mTo;
|
||||
private List<String> mHints;
|
||||
private List<String> mUrls;
|
||||
|
||||
public CodeCompletions(Pos from, Pos to, List<String> hints) {
|
||||
public CodeCompletions(Pos from, Pos to, List<String> hints, List<String> urls) {
|
||||
mFrom = from;
|
||||
mTo = to;
|
||||
mHints = hints;
|
||||
mUrls = urls;
|
||||
}
|
||||
|
||||
public static CodeCompletions just(List<String> hints) {
|
||||
return new CodeCompletions(null, null, hints);
|
||||
return new CodeCompletions(null, null, hints, null);
|
||||
}
|
||||
|
||||
public Pos getFrom() {
|
||||
@@ -40,6 +42,12 @@ public class CodeCompletions {
|
||||
return mTo;
|
||||
}
|
||||
|
||||
public String getUrltAt(int pos) {
|
||||
if (mUrls == null)
|
||||
return null;
|
||||
return mUrls.get(pos);
|
||||
}
|
||||
|
||||
public List<String> getHints() {
|
||||
return mHints;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import java.util.Arrays;
|
||||
public class Symbols {
|
||||
|
||||
private static CodeCompletions sSymbols = CodeCompletions.just(Arrays.asList(
|
||||
"=", "\"", "(", ")", "{", "}", ";", "!", "|", "&", "[", "]", "/", "\\",
|
||||
"<", ">"));
|
||||
"\"", "(", ")", "=", ";", "/", "{", "}", "!", "|", "&", "-",
|
||||
"[", "]", "+", "-", "<", ">", "\\", "*", "?"));
|
||||
|
||||
public static CodeCompletions getSymbols() {
|
||||
return sSymbols;
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.help;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.stardust.theme.ThemeColorManagerCompat;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
import com.stardust.widget.CommonMarkdownView;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.wang.avi.AVLoadingIndicatorView;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/2/1.
|
||||
*/
|
||||
|
||||
|
||||
public class DocumentationActivity extends BaseActivity {
|
||||
|
||||
private CommonMarkdownView mCommonMarkdownView;
|
||||
|
||||
public static void openDocumentation(Context context, String title, String assetPath) {
|
||||
context.startActivity(new Intent(context, DocumentationActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("title", title)
|
||||
.putExtra("path", assetPath));
|
||||
}
|
||||
|
||||
private volatile String mDocumentation;
|
||||
private String mTitle;
|
||||
private AVLoadingIndicatorView mLoadingIndicatorView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
handleIntent(getIntent());
|
||||
setToolbarAsBack(mTitle);
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
mTitle = intent.getStringExtra("title");
|
||||
final String path = intent.getStringExtra("path");
|
||||
if (path == null)
|
||||
return;
|
||||
UnderuseExecutors.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
mDocumentation = PFiles.read(getAssets().open("help/" + path));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loadDocument();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_document);
|
||||
setUpLoadingView();
|
||||
}
|
||||
|
||||
private void setUpLoadingView() {
|
||||
mLoadingIndicatorView = $(R.id.loading);
|
||||
mLoadingIndicatorView.setIndicatorColor(ThemeColorManagerCompat.getColorPrimary());
|
||||
}
|
||||
|
||||
private void loadDocument() {
|
||||
mCommonMarkdownView = $(R.id.markdown);
|
||||
mCommonMarkdownView.setOnPageFinishedListener(new CommonMarkdownView.OnPageFinishedListener() {
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
mLoadingIndicatorView.hide();
|
||||
}
|
||||
});
|
||||
try {
|
||||
mCommonMarkdownView.loadMarkdown(mDocumentation);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mCommonMarkdownView.setText(R.string.text_load_failed);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mCommonMarkdownView.canGoBack()) {
|
||||
mCommonMarkdownView.goBack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.help;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Keep;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.workground.WrapContentLinearLayoutManager;
|
||||
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.scriptdroid.App;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.theme.ThemeColorManagerCompat;
|
||||
import com.stardust.util.UnderuseExecutors;
|
||||
import com.wang.avi.AVLoadingIndicatorView;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/6.
|
||||
*/
|
||||
|
||||
public class HelpCatalogueActivity extends BaseActivity {
|
||||
|
||||
|
||||
public static void showCatalogue(Context context, String title, String catalogue) {
|
||||
context.startActivity(new Intent(context, HelpCatalogueActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("title", title)
|
||||
.putExtra("catalogue", catalogue));
|
||||
}
|
||||
|
||||
public static void showMainCatalogue(Context context) {
|
||||
context.startActivity(new Intent(context, HelpCatalogueActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
private static Map<String, List<Item>> CATALOGUES;
|
||||
|
||||
private static class Item extends JSONObject {
|
||||
|
||||
String title;
|
||||
String summary;
|
||||
@Keep
|
||||
private String type;
|
||||
@Keep
|
||||
private String path;
|
||||
|
||||
Item(String title, String summary) {
|
||||
this.title = title;
|
||||
this.summary = summary;
|
||||
}
|
||||
|
||||
Item(String title) {
|
||||
this(title, null);
|
||||
}
|
||||
|
||||
void redirect(Context context) {
|
||||
switch (type) {
|
||||
case "markdown":
|
||||
DocumentationActivity.openDocumentation(context, title, path + "/" + title + ".md");
|
||||
break;
|
||||
case "catalogue":
|
||||
showCatalogue(context, title, title);
|
||||
break;
|
||||
case "html":
|
||||
LocalWebViewActivity.openAssetsHtml(context, title, path + "/" + title + ".html");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List<Item> mItems;
|
||||
private RecyclerView mRecyclerView;
|
||||
private AVLoadingIndicatorView mLoadingIndicatorView;
|
||||
private String mTitle;
|
||||
private View.OnClickListener mOnItemClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(v);
|
||||
if (holder != null) {
|
||||
mItems.get(holder.getAdapterPosition()).redirect(HelpCatalogueActivity.this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setUpUI();
|
||||
if (CATALOGUES == null) {
|
||||
readCatalogues();
|
||||
} else {
|
||||
onCataloguesAvailable();
|
||||
}
|
||||
}
|
||||
|
||||
private void onCataloguesAvailable(){
|
||||
mLoadingIndicatorView.hide();
|
||||
handleIntent();
|
||||
setToolbarAsBack(mTitle);
|
||||
}
|
||||
|
||||
private void readCatalogues() {
|
||||
UnderuseExecutors.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
readCatalogues("help/catalogue.json");
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
onCataloguesAvailable();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleIntent() {
|
||||
String catalogue = getIntent().getStringExtra("catalogue");
|
||||
if (catalogue == null)
|
||||
catalogue = "main";
|
||||
mTitle = getIntent().getStringExtra("title");
|
||||
if (mTitle == null)
|
||||
mTitle = getString(R.string.text_help);
|
||||
mItems = CATALOGUES.get(catalogue);
|
||||
mRecyclerView.setAdapter(new Adapter());
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_help);
|
||||
setUpRecyclerView();
|
||||
setUpLoadingView();
|
||||
}
|
||||
|
||||
private void setUpRecyclerView() {
|
||||
mRecyclerView = $(R.id.catalogue);
|
||||
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this));
|
||||
mRecyclerView.addItemDecoration(new DividerItemDecoration(this, RecyclerView.VERTICAL));
|
||||
}
|
||||
|
||||
private void setUpLoadingView() {
|
||||
mLoadingIndicatorView = $(R.id.loading);
|
||||
mLoadingIndicatorView.setIndicatorColor(ThemeColorManagerCompat.getColorPrimary());
|
||||
}
|
||||
|
||||
private class Adapter extends RecyclerView.Adapter<ViewHolder> {
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
int view = R.layout.activity_help_catalogue_item;
|
||||
return new ViewHolder(LayoutInflater.from(HelpCatalogueActivity.this).inflate(view, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Item item = mItems.get(position);
|
||||
holder.title.setText(item.title);
|
||||
if (item.summary != null) {
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
holder.summary.setText(item.summary);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mItems.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView title, summary;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
itemView.setOnClickListener(mOnItemClickListener);
|
||||
title = (TextView) itemView.findViewById(R.id.title);
|
||||
summary = (TextView) itemView.findViewById(R.id.summary);
|
||||
}
|
||||
}
|
||||
|
||||
private static void readCatalogues(String path) {
|
||||
Map<String, List<Item>> fromJson;
|
||||
try {
|
||||
String json = PFiles.read(App.getApp().getAssets().open(path));
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<Map<String, List<Item>>>() {
|
||||
}.getType();
|
||||
fromJson = gson.fromJson(json, type);
|
||||
} catch (IOException e) {
|
||||
fromJson = new HashMap<>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
CATALOGUES = fromJson;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package com.stardust.scriptdroid.ui.help;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.stardust.pio.PFiles;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.ui.BaseActivity;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Stardust on 2017/3/14.
|
||||
*/
|
||||
|
||||
public class LocalWebViewActivity extends BaseActivity {
|
||||
|
||||
// TODO: 2017/3/14 缓存asset
|
||||
|
||||
private String mTitle;
|
||||
private String mHtml;
|
||||
private WebView mWebView;
|
||||
|
||||
public static void openAssetsHtml(Context context, String title, String path) {
|
||||
context.startActivity(new Intent(context, LocalWebViewActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra("title", title)
|
||||
.putExtra("path", path));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
handleIntent(getIntent());
|
||||
setUpUI();
|
||||
}
|
||||
|
||||
private void handleIntent(Intent intent) {
|
||||
mTitle = intent.getStringExtra("title");
|
||||
String path = intent.getStringExtra("path");
|
||||
if (path != null)
|
||||
try {
|
||||
mHtml = PFiles.read(getAssets().open("help/" + path));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
mHtml = getString(R.string.text_load_failed);
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpUI() {
|
||||
setContentView(R.layout.activity_local_webview);
|
||||
setToolbarAsBack(mTitle);
|
||||
loadHtml();
|
||||
}
|
||||
|
||||
private void loadHtml() {
|
||||
mWebView = $(R.id.webView);
|
||||
try {
|
||||
mWebView.loadDataWithBaseURL(null, mHtml, "text/html", "utf-8", null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
mWebView.loadDataWithBaseURL(null, getString(R.string.text_load_failed), "text/html", "utf-8", null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mWebView.canGoBack()) {
|
||||
mWebView.goBack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,10 @@ import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.ui.common.NotAskAgainDialog;
|
||||
import com.stardust.scriptdroid.ui.common.ScriptOperations;
|
||||
import com.stardust.scriptdroid.ui.doc.OnlineDocsFragment_;
|
||||
import com.stardust.scriptdroid.ui.floating.FloatyWindowManger;
|
||||
import com.stardust.scriptdroid.io.StorageFileProvider;
|
||||
import com.stardust.scriptdroid.ui.main.community.CommunityFragment_;
|
||||
import com.stardust.scriptdroid.ui.main.doc.OnlineDocsFragment_;
|
||||
import com.stardust.scriptdroid.ui.main.scripts.MyScriptListFragment_;
|
||||
import com.stardust.scriptdroid.ui.main.task.TaskManagerFragment_;
|
||||
import com.stardust.theme.ThemeColorManager;
|
||||
|
||||
@@ -140,7 +140,7 @@ public class EWebView extends FrameLayout implements SwipeRefreshLayout.OnRefres
|
||||
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://") || url.startsWith("file://")) {
|
||||
view.loadUrl(url);
|
||||
} else {
|
||||
getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||
|
||||
Reference in New Issue
Block a user