optimize memory and image size. remove unnecessary language file

This commit is contained in:
hyb1996
2017-05-10 15:42:58 +08:00
parent e5ade55519
commit 1222e00adc
77 changed files with 590 additions and 436 deletions

View File

@@ -9,8 +9,8 @@ android {
applicationId "com.stardust.scriptdroid" applicationId "com.stardust.scriptdroid"
minSdkVersion 19 minSdkVersion 19
targetSdkVersion 23 targetSdkVersion 23
versionCode 123 versionCode 125
versionName "2.0.9d Alpha" versionName "2.0.9 Beta"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {
@@ -18,6 +18,11 @@ android {
} }
} }
buildTypes { buildTypes {
debug {
shrinkResources false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release { release {
shrinkResources false shrinkResources false
minifyEnabled false minifyEnabled false
@@ -42,17 +47,7 @@ android {
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk")) output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
} }
} }
packagingOptions {
pickFirst 'org/mozilla/javascript/tools/debugger/build.xml'
pickFirst 'org/mozilla/javascript/tools/debugger/test.js'
pickFirst 'org/mozilla/javascript/tools/idswitch/README'
pickFirst 'org/mozilla/javascript/NativeString.java.orig'
pickFirst 'org/mozilla/javascript/Node.java.orig'
pickFirst 'org/mozilla/javascript/resources/Messages_fr.properties'
pickFirst 'org/mozilla/javascript/resources/Messages.properties'
pickFirst 'org/mozilla/javascript/*.java.orig'
pickFirst 'org/mozilla/javascript/tools/resources/*.properties'
}
dexcount { dexcount {
format = "list" format = "list"
includeClasses = true includeClasses = true

Binary file not shown.

View File

@@ -93,19 +93,19 @@
} }
# Google Play Services library # Google Play Services library
-keep class * extends java.util.ListResourceBundle { -keep class * extends java.util.ListResourceBundle {
protected Object[ ][ ] getContents(); protected Object[ ][ ] getContents();
} }
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL; public static final *** NULL;
} }
-keepnames @com.google.android.gms.common.annotation.KeepName class * -keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * { -keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *; @com.google.android.gms.common.annotation.KeepName *;
} }
-keepnames class * implements android.os.Parcelable { -keepnames class * implements android.os.Parcelable {
public static final ** CREATOR; public static final ** CREATOR;
} }

View File

@@ -69,7 +69,9 @@
android:resource="@xml/provider_paths"/> android:resource="@xml/provider_paths"/>
</provider> </provider>
<activity android:name=".ui.edit.EditActivity" android:multiprocess="true"> <activity
android:name=".ui.edit.EditActivity"
android:multiprocess="true">
</activity> </activity>
<activity android:name=".ui.help.DocumentationActivity"/> <activity android:name=".ui.help.DocumentationActivity"/>
@@ -158,7 +160,7 @@
<activity <activity
android:name=".external.open.RunIntentActivity" android:name=".external.open.RunIntentActivity"
android:icon="@drawable/ic_play_green" android:icon="@drawable/ic_ali_run"
android:label="运行脚本"> android:label="运行脚本">
<intent-filter> <intent-filter>
@@ -198,7 +200,7 @@
<activity <activity
android:name=".external.open.ImportIntentActivity" android:name=".external.open.ImportIntentActivity"
android:icon="@drawable/ic_folder_open_outline_green" android:icon="@drawable/ic_import"
android:label="导入脚本文件"> android:label="导入脚本文件">
<intent-filter> <intent-filter>

View File

@@ -5,11 +5,11 @@ var dialogs = {};
dialogs.rawInput = function(title, prefill){ dialogs.rawInput = function(title, prefill){
prefill = prefill || ""; prefill = prefill || "";
return __runtime__.dialogs.rawInput(title, prefill); return String(__runtime__.dialogs.rawInput(title, prefill));
}; };
dialogs.input = function(title, prefill){ dialogs.input = function(title, prefill){
return eval(dialogs.rawInput(title, prefill) + ""); return eval(dialogs.rawInput(title, prefill));
} }
dialogs.prompt = dialogs.rawInput; dialogs.prompt = dialogs.rawInput;
@@ -25,6 +25,9 @@ dialogs.confirm = function(title, prefill){
} }
dialogs.select = function(title, items){ dialogs.select = function(title, items){
if(items instanceof Array){
return __runtime__.dialogs.select(title, items);
}
return __runtime__.dialogs.select(title, [].slice.call(arguments, 1)); return __runtime__.dialogs.select(title, [].slice.call(arguments, 1));
} }

View File

@@ -1,3 +1,3 @@
log("Hello world!!!"); log("Hello world!!!");
toast("Hello, AutoJs!"); toast("Hello, AutoJs!");
openConsole(); console.show();

View File

@@ -1,5 +1,5 @@
var num1 = dialogs.input("请输入第一个数字"); var num1 = dialogs.input("请输入第一个数字");
var op = dialogs.singleChoice("请选择运算", 0, "加", "减", "乘", "除", "幂"); var op = dialogs.singleChoice("请选择运算", ["加", "减", "乘", "除", "幂"]);
var num2 = dialogs.input("请输入第二个数字"); var num2 = dialogs.input("请输入第二个数字");
var result = 0; var result = 0;
switch(op){ switch(op){

View File

@@ -1,11 +1,10 @@
var sh = new Shell(); var sh = new Shell();
sh.setCallback({ sh.setCallback({
onNewLine: function(str){ onOutput: function(str){
console.log(str); print(str);
} }
}) })
console.show(); console.show();
console.info("请输入要运行命令:");
do { do {
var cmd = console.rawInput(); var cmd = console.rawInput();
sh.exec(cmd); sh.exec(cmd);

View File

@@ -45,5 +45,4 @@ public abstract class Fragment extends android.support.v4.app.Fragment {
public abstract View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState); public abstract View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState);
} }

View File

@@ -26,7 +26,7 @@ public class BlockedMaterialDialog extends MaterialDialog {
@Override @Override
public void show() { public void show() {
if (!isActivityContext(getContext())) { if (!isActivityContext(getContext())) {
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
} }
super.show(); super.show();
} }

View File

@@ -7,6 +7,8 @@ import android.graphics.Color;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build; import android.os.Build;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
@@ -75,9 +77,9 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
private View getTabViewInner(int index) { private View getTabViewInner(int index) {
String menuItemId = mTabIds.get(index); String menuItemId = mTabIds.get(index);
if (ID_MAIN.equals(menuItemId)) { if (ID_MAIN.equals(menuItemId)) {
return createTabView(R.drawable.ic_android_eat_js_100); return createTabView(R.drawable.ic_android_eat_js_64);
} else if (ID_RECORD.equals(menuItemId)) { } else if (ID_RECORD.equals(menuItemId)) {
return createTabView(R.drawable.ic_video_record); return createTabView(R.drawable.ic_ali_record);
} else if (ID_SCRIPT_LIST.equals(menuItemId)) { } else if (ID_SCRIPT_LIST.equals(menuItemId)) {
return createTabView(R.drawable.ic_menu); return createTabView(R.drawable.ic_menu);
} else { } else {
@@ -125,7 +127,7 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
Resources resources = mContext.getResources(); Resources resources = mContext.getResources();
int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, resources.getDisplayMetrics()); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, resources.getDisplayMetrics());
DemoTabView view = new DemoTabView(mContext, resources.getDrawable(R.drawable.tab_background), resources.getDrawable(tabBitmapRes)); DemoTabView view = new DemoTabView(mContext, getCircleDrawable(), resources.getDrawable(tabBitmapRes));
view.setTabBackgroundColor(backgroundColor); view.setTabBackgroundColor(backgroundColor);
view.setTabForegroundColor(iconColor); view.setTabForegroundColor(iconColor);
view.setPadding(padding, padding, padding, padding); view.setPadding(padding, padding, padding, padding);
@@ -135,6 +137,12 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
return view; return view;
} }
private Drawable getCircleDrawable() {
ShapeDrawable oval = new ShapeDrawable(new OvalShape());
return oval;
}
public class DemoTabView extends View { public class DemoTabView extends View {
private int mBackgroundColor; private int mBackgroundColor;
@@ -183,13 +191,8 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
@Override @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) { protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh); super.onSizeChanged(w, h, oldw, oldh);
// Make circle as large as View minus padding.
mCircleDrawable.setBounds(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom()); mCircleDrawable.setBounds(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom());
// Re-size the icon as necessary.
updateIconBounds(); updateIconBounds();
invalidate(); invalidate();
} }

View File

@@ -85,7 +85,6 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
} }
if (mConsole.submitInput(input)) { if (mConsole.submitInput(input)) {
mEditText.setText(""); mEditText.setText("");
mEditText.requestFocus();
} }
} }
@@ -93,6 +92,17 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
mEditText = (EditText) findViewById(R.id.input); mEditText = (EditText) findViewById(R.id.input);
mEditText.setFocusableInTouchMode(true); mEditText.setFocusableInTouchMode(true);
mInputContainer = (LinearLayout) findViewById(R.id.input_container); mInputContainer = (LinearLayout) findViewById(R.id.input_container);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
if (mWindow != null) {
mWindow.requestWindowFocus();
mEditText.requestFocus();
}
}
};
mEditText.setOnClickListener(listener);
mInputContainer.setOnClickListener(listener);
} }
public void setConsole(StardustConsole console) { public void setConsole(StardustConsole console) {
@@ -103,7 +113,6 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
@Override @Override
public void onNewLog(StardustConsole.Log log) { public void onNewLog(StardustConsole.Log log) {
log(log.level, log.content); log(log.level, log.content);
log(log.level, "\n");
} }
private void log(int level, CharSequence log) { private void log(int level, CharSequence log) {
@@ -114,6 +123,7 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
public void run() { public void run() {
mTextView.append(spannable); mTextView.append(spannable);
mContentContainer.fullScroll(View.FOCUS_DOWN); mContentContainer.fullScroll(View.FOCUS_DOWN);
mEditText.requestFocus();
} }
}); });

View File

@@ -50,6 +50,12 @@ public class JraskaConsole extends AbstractConsole {
Console.writeLine(getLevelSpannable(level, charSequence)); Console.writeLine(getLevelSpannable(level, charSequence));
} }
@Override
public void write(int level, CharSequence data) {
Console.write(getLevelSpannable(level, getTag(level)));
Console.write(getLevelSpannable(level, data));
}
private CharSequence getTag(int level) { private CharSequence getTag(int level) {
return TextUtils.join("", DATE_FORMAT.format(new Date()), TAGS.get(level), ": "); return TextUtils.join("", DATE_FORMAT.format(new Date()), TAGS.get(level), ": ");
} }
@@ -80,4 +86,6 @@ public class JraskaConsole extends AbstractConsole {
public void setTitle(CharSequence title) { public void setTitle(CharSequence title) {
} }
} }

View File

@@ -13,7 +13,6 @@ import com.stardust.enhancedfloaty.FloatyService;
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow; import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
import com.stardust.scriptdroid.R; import com.stardust.scriptdroid.R;
import com.stardust.scriptdroid.autojs.AutoJs; import com.stardust.scriptdroid.autojs.AutoJs;
import com.stardust.scriptdroid.autojs.api.VolatileBox;
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger; import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
import com.stardust.util.UiHandler; import com.stardust.util.UiHandler;
@@ -79,7 +78,7 @@ public class StardustConsole extends AbstractConsole {
@Override @Override
public void println(int level, CharSequence charSequence) { public void println(int level, CharSequence charSequence) {
Log log = new Log(level, charSequence); Log log = new Log(level, charSequence + "\n");
mLogs.add(log); mLogs.add(log);
GLOBAL_CONSOLE.println(level, charSequence); GLOBAL_CONSOLE.println(level, charSequence);
if (mLogListener != null) { if (mLogListener != null) {
@@ -88,6 +87,17 @@ public class StardustConsole extends AbstractConsole {
} }
@Override
public void write(int level, CharSequence charSequence) {
Log log = new Log(level, charSequence);
mLogs.add(log);
GLOBAL_CONSOLE.print(level, charSequence);
if (mLogListener != null) {
mLogListener.onNewLog(log);
}
}
@Override @Override
public void clear() { public void clear() {
mLogs.clear(); mLogs.clear();

View File

@@ -5,9 +5,11 @@ import android.content.ClipboardManager;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.util.SparseIntArray;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -27,16 +29,40 @@ import java.util.TimerTask;
public class ErrorReportActivity extends BaseActivity { public class ErrorReportActivity extends BaseActivity {
private static final String TAG = "ErrorReportActivity"; private static final String TAG = "ErrorReportActivity";
private static final SparseIntArray CRASH_COUNT = new SparseIntArray();
private static final String KEY_CRASH_COUNT = "Eating... you are my halo...";
static {
CRASH_COUNT.put(2, R.string.text_again);
CRASH_COUNT.put(3, R.string.text_again_and_again);
CRASH_COUNT.put(4, R.string.text_again_and_again_again);
CRASH_COUNT.put(5, R.string.text_again_and_again_again_again);
}
private String mTitle;
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
try { try {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mTitle = getCrashCountText() + getString(R.string.text_crash);
setUpUI(); setUpUI();
handleIntent(); handleIntent();
} catch (Throwable throwable) { } catch (Throwable throwable) {
Log.e(TAG, "", throwable); Log.e(TAG, "", throwable);
exit(); exit();
} }
}
private String getCrashCountText() {
int i = PreferenceManager.getDefaultSharedPreferences(this).getInt(KEY_CRASH_COUNT, 0);
i++;
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(KEY_CRASH_COUNT, i).apply();
if (i < 2)
return "";
if (i > 5)
i = 5;
return getString(CRASH_COUNT.get(i));
} }
@@ -49,7 +75,7 @@ public class ErrorReportActivity extends BaseActivity {
private void showErrorMessageByDialog(String message, final String errorDetail) { private void showErrorMessageByDialog(String message, final String errorDetail) {
new ThemeColorMaterialDialogBuilder(this) new ThemeColorMaterialDialogBuilder(this)
.title(R.string.text_crash) .title(mTitle)
.content(R.string.crash_feedback) .content(R.string.crash_feedback)
.positiveText(R.string.text_exit) .positiveText(R.string.text_exit)
.neutralText(R.string.text_copy_debug_info) .neutralText(R.string.text_copy_debug_info)

View File

@@ -1,39 +0,0 @@
package com.stardust.scriptdroid.ui.main;
import android.os.Bundle;
import android.support.annotation.CallSuper;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.stardust.scriptdroid.R;
/**
* Created by Stardust on 2017/3/23.
*/
public abstract class AppbarWithTabFragment extends BottomNavigationFragment {
@Nullable
@Override
public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_app_bar_tab, container, false);
FrameLayout contentContainer = (FrameLayout) view.findViewById(R.id.content);
contentContainer.addView(createContentView(inflater, contentContainer));
return view;
}
@CallSuper
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
}
protected abstract View createContentView(LayoutInflater inflater, @Nullable ViewGroup container);
}

View File

@@ -1,78 +0,0 @@
package com.stardust.scriptdroid.ui.main;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.stardust.app.Fragment;
import com.stardust.theme.ThemeColor;
import com.stardust.theme.ThemeColorManager;
import com.stardust.theme.ThemeColorMutable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Stardust on 2017/3/23.
*/
public abstract class BottomNavigationFragment extends Fragment {
public static class Builder implements BottomNavigationBar.OnTabSelectedListener, ThemeColorMutable {
private int mFragmentId;
private BottomNavigationBar mBottomNavigationBar;
private FragmentManager mFragmentManager;
private List<BottomNavigationFragment> mFragments = new ArrayList<>();
public Builder(int fragmentId, BottomNavigationBar bottomNavigationBar, FragmentManager fragmentManager) {
mFragmentId = fragmentId;
mBottomNavigationBar = bottomNavigationBar;
mFragmentManager = fragmentManager;
mBottomNavigationBar.setTabSelectedListener(this);
ThemeColorManager.add(this);
}
public Builder add(BottomNavigationFragment fragment) {
mFragments.add(fragment);
mBottomNavigationBar.addItem(new BottomNavigationItem(fragment.getIconResId(), fragment.getTitle()));
return this;
}
public void build() {
mBottomNavigationBar.setFirstSelectedPosition(0);
mBottomNavigationBar.initialise();
mFragmentManager.beginTransaction().replace(mFragmentId, mFragments.get(0)).commit();
}
@Override
public void onTabSelected(int position) {
BottomNavigationFragment fragment = mFragments.get(position);
mFragmentManager.beginTransaction().replace(mFragmentId, fragment).commit();
}
@Override
public void onTabUnselected(int position) {
}
@Override
public void onTabReselected(int position) {
}
@Override
public void setThemeColor(ThemeColor themeColor) {
mBottomNavigationBar.setActiveColor("#" + Integer.toHexString(themeColor.colorPrimary).substring(2));
}
}
protected abstract String getTitle();
protected abstract int getIconResId();
}

View File

@@ -27,8 +27,10 @@ import com.afollestad.materialdialogs.MaterialDialog;
import com.stardust.app.FragmentPagerAdapterBuilder; import com.stardust.app.FragmentPagerAdapterBuilder;
import com.stardust.app.NotAskAgainDialog; import com.stardust.app.NotAskAgainDialog;
import com.stardust.app.OnActivityResultDelegate; import com.stardust.app.OnActivityResultDelegate;
import com.stardust.enhancedfloaty.FloatyService;
import com.stardust.scriptdroid.BuildConfig; import com.stardust.scriptdroid.BuildConfig;
import com.stardust.scriptdroid.R; import com.stardust.scriptdroid.R;
import com.stardust.scriptdroid.autojs.AutoJs;
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger; import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
import com.stardust.scriptdroid.script.ScriptFile; import com.stardust.scriptdroid.script.ScriptFile;
import com.stardust.scriptdroid.script.StorageScriptProvider; import com.stardust.scriptdroid.script.StorageScriptProvider;
@@ -80,6 +82,7 @@ public class MainActivity extends BaseActivity {
private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver; private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver;
private VersionGuard mVersionGuard; private VersionGuard mVersionGuard;
private Intent mIntentToHandle; private Intent mIntentToHandle;
private ViewPager mViewPager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -164,15 +167,14 @@ public class MainActivity extends BaseActivity {
private void setUpTabViewPager() { private void setUpTabViewPager() {
TabLayout tabLayout = $(R.id.tab); TabLayout tabLayout = $(R.id.tab);
ViewPager viewPager = $(R.id.viewpager); mViewPager = $(R.id.viewpager);
mPagerAdapter = new FragmentPagerAdapterBuilder(this) mPagerAdapter = new FragmentPagerAdapterBuilder(this)
.add(new MyScriptListFragment(), R.string.text_my_script) .add(new MyScriptListFragment(), R.string.text_my_script)
.add(new SampleScriptListFragment(), R.string.text_sample_script) .add(new SampleScriptListFragment(), R.string.text_sample_script)
.add(new TaskManagerFragment(), R.string.text_task_manage) .add(new TaskManagerFragment(), R.string.text_task_manage)
.build(); .build();
viewPager.setAdapter(mPagerAdapter); mViewPager.setAdapter(mPagerAdapter);
viewPager.setOffscreenPageLimit(mPagerAdapter.getCount()); tabLayout.setupWithViewPager(mViewPager);
tabLayout.setupWithViewPager(viewPager);
mPagerAdapter.setOnFragmentInstantiateListener(new FragmentPagerAdapterBuilder.OnFragmentInstantiateListener() { mPagerAdapter.setOnFragmentInstantiateListener(new FragmentPagerAdapterBuilder.OnFragmentInstantiateListener() {
@Override @Override
public void OnInstantiate(Fragment fragment) { public void OnInstantiate(Fragment fragment) {
@@ -235,8 +237,11 @@ public class MainActivity extends BaseActivity {
} }
@ViewBinding.Click(R.id.exit) @ViewBinding.Click(R.id.exit)
public void finish() { public void exitCompletely() {
super.finish(); FloatingWindowManger.hideHoverMenu();
stopService(new Intent(this, FloatyService.class));
AutoJs.getInstance().getScriptEngineService().stopAll();
finish();
} }
@ViewBinding.Click(R.id.drawer_header_img) @ViewBinding.Click(R.id.drawer_header_img)
@@ -265,22 +270,38 @@ public class MainActivity extends BaseActivity {
handleRecordedScript(intent.getStringExtra(ARGUMENT_SCRIPT)); handleRecordedScript(intent.getStringExtra(ARGUMENT_SCRIPT));
break; break;
case ACTION_IMPORT_SCRIPT: case ACTION_IMPORT_SCRIPT:
getMyScriptListFragment().importFile(intent.getStringExtra(ARGUMENT_PATH)); handleImportScriptFile(intent);
break; break;
case ACTION_IMPORT_SAMPLE: case ACTION_IMPORT_SAMPLE:
importSample((Sample) intent.getSerializableExtra(ARGUMENT_SAMPLE)); handleImportSample(intent);
break; break;
} }
} }
private void importSample(Sample sample) { private void handleImportScriptFile(Intent intent) {
try { mViewPager.setCurrentItem(0, true);
getMyScriptListFragment().importFile(sample.name, getAssets().open(sample.path)); MyScriptListFragment fragment = getMyScriptListFragment();
} catch (IOException e) { if (fragment == null) {
e.printStackTrace(); mIntentToHandle = intent;
Snackbar.make(mDrawerLayout, R.string.text_import_fail, Snackbar.LENGTH_SHORT).show(); } else {
fragment.importFile(intent.getStringExtra(ARGUMENT_PATH));
} }
}
private void handleImportSample(Intent intent) {
mViewPager.setCurrentItem(0, true);
MyScriptListFragment fragment = getMyScriptListFragment();
if (fragment == null) {
mIntentToHandle = intent;
} else {
Sample sample = (Sample) intent.getSerializableExtra(ARGUMENT_SAMPLE);
try {
getMyScriptListFragment().importFile(sample.name, getAssets().open(sample.path));
} catch (IOException e) {
e.printStackTrace();
Snackbar.make(mDrawerLayout, R.string.text_import_fail, Snackbar.LENGTH_SHORT).show();
}
}
} }
private void handleRecordedScript(final String script) { private void handleRecordedScript(final String script) {

View File

@@ -21,26 +21,25 @@ import com.stardust.scriptdroid.ui.main.MainActivity;
public class SampleScriptListFragment extends Fragment { public class SampleScriptListFragment extends Fragment {
private SampleScriptListRecyclerView mSampleScriptListRecyclerView;
@Nullable @Nullable
@Override @Override
public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_sample_script_list, container, false); return inflater.inflate(R.layout.fragment_sample_script_list, container, false);
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
mSampleScriptListRecyclerView = $(R.id.script_list); SampleScriptListRecyclerView sampleScriptListRecyclerView = $(R.id.script_list);
mSampleScriptListRecyclerView.setSamples(SampleFileManager.getInstance().getSamplesFromAssets(getContext().getAssets(), "sample")); sampleScriptListRecyclerView.setSamples(SampleFileManager.getInstance().getSamplesFromAssets(getContext().getAssets(), "sample"));
mSampleScriptListRecyclerView.setOnItemLongClickListener(new SampleScriptListRecyclerView.OnItemLongClickListener() { sampleScriptListRecyclerView.setOnItemLongClickListener(new SampleScriptListRecyclerView.OnItemLongClickListener() {
@Override @Override
public void onItemLongClick(Sample sample) { public void onItemLongClick(Sample sample) {
showMenuDialog(sample); showMenuDialog(sample);
} }
}); });
mSampleScriptListRecyclerView.setOnItemClickListener(new SampleScriptListRecyclerView.OnItemClickListener() { sampleScriptListRecyclerView.setOnItemClickListener(new SampleScriptListRecyclerView.OnItemClickListener() {
@Override @Override
public void onItemClick(Sample sample) { public void onItemClick(Sample sample) {
viewSample(sample); viewSample(sample);

View File

@@ -61,6 +61,7 @@ public class MyScriptListFragment extends Fragment {
return inflater.inflate(R.layout.fragment_my_script_list, container, false); return inflater.inflate(R.layout.fragment_my_script_list, container, false);
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);

View File

@@ -84,6 +84,8 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
return; return;
} }
ScriptFile file = mAdapter.getScriptFileAt(position); ScriptFile file = mAdapter.getScriptFileAt(position);
if (file == null)
return;
if (file.isDirectory()) { if (file.isDirectory()) {
setCurrentDirectory(file, true); setCurrentDirectory(file, true);
} else if (mOnItemClickListener != null) { } else if (mOnItemClickListener != null) {
@@ -96,7 +98,10 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
if (mOnItemLongClickListener != null) { if (mOnItemLongClickListener != null) {
int position = getChildViewHolder(v).getAdapterPosition(); int position = getChildViewHolder(v).getAdapterPosition();
mOnItemLongClickListener.onLongClick(mAdapter.getScriptFileAt(position), position); ScriptFile file = mAdapter.getScriptFileAt(position);
if (file == null)
return false;
mOnItemLongClickListener.onLongClick(file, position);
return true; return true;
} }
return false; return false;
@@ -108,6 +113,8 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
public void onClick(View v) { public void onClick(View v) {
int position = getChildViewHolder((View) v.getParent()).getAdapterPosition(); int position = getChildViewHolder((View) v.getParent()).getAdapterPosition();
ScriptFile file = mAdapter.getScriptFileAt(position); ScriptFile file = mAdapter.getScriptFileAt(position);
if (file == null)
return;
Scripts.run(file); Scripts.run(file);
} }
}; };
@@ -337,8 +344,13 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
return getScriptFileAt(position).isDirectory() ? VIEW_TYPE_DIRECTORY : VIEW_TYPE_FILE; return getScriptFileAt(position).isDirectory() ? VIEW_TYPE_DIRECTORY : VIEW_TYPE_FILE;
} }
@Nullable
public ScriptFile getScriptFileAt(int position) { public ScriptFile getScriptFileAt(int position) {
return mScriptFileList[mCanGoBack ? position - 1 : position]; int actualPos = mCanGoBack ? position - 1 : position;
if (actualPos >= mScriptFileList.length || actualPos < 0) {
return null;
}
return mScriptFileList[actualPos];
} }
void setScripts(ScriptFile[] scriptFiles) { void setScripts(ScriptFile[] scriptFiles) {

View File

@@ -6,12 +6,16 @@ import android.content.ClipboardManager;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import com.stardust.automator.UiObject;
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
import com.stardust.scriptdroid.tool.IntentTool; import com.stardust.scriptdroid.tool.IntentTool;
import com.stardust.scriptdroid.ui.BaseActivity; import com.stardust.scriptdroid.ui.BaseActivity;
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder; import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
@@ -29,6 +33,7 @@ import moe.feng.alipay.zerosdk.AlipayZeroSdk;
public class AboutActivity extends BaseActivity { public class AboutActivity extends BaseActivity {
private static final String TAG = "AboutActivity";
private int mLolClickCount = 0; private int mLolClickCount = 0;
@Override @Override
@@ -100,18 +105,54 @@ public class AboutActivity extends BaseActivity {
mLolClickCount++; mLolClickCount++;
Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show();
if (mLolClickCount >= 5) { if (mLolClickCount >= 5) {
new ThemeColorMaterialDialogBuilder(this) crashTest();
.title("Crash Test")
.positiveText("Crash")
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
throw new RuntimeException("Crash Test");
}
}).show();
} }
} }
private void showEasterEgg() {
new MaterialDialog.Builder(this)
.customView(R.layout.paint_layout, false)
.show();
}
private void uiObjectCreateTest() {
new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
while (true) {
AccessibilityNodeInfo root = AccessibilityWatchDogService.getInstance().getRootInActiveWindow();
if (root != null) {
UiObject uiObject = UiObject.createRoot(root);
UiObject child = uiObject.child(0);
if (i % 1000 == 0) {
Log.v(TAG, String.valueOf(i));
Log.v(TAG, Runtime.getRuntime().totalMemory() + "/" + Runtime.getRuntime().maxMemory());
if (child != null)
Log.v(TAG, String.valueOf(child.getChildCount()));
}
if (child != null)
child.recycle();
i++;
}
}
}
}).start();
}
private void crashTest() {
new ThemeColorMaterialDialogBuilder(this)
.title("Crash Test")
.positiveText("Crash")
.onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
throw new RuntimeException("Crash Test");
}
}).show();
}
@ViewBinding.Click(R.id.developer) @ViewBinding.Click(R.id.developer)
private void hhh() { private void hhh() {
Toast.makeText(this, R.string.text_it_is_the_developer_of_app, Toast.LENGTH_LONG).show(); Toast.makeText(this, R.string.text_it_is_the_developer_of_app, Toast.LENGTH_LONG).show();

View File

@@ -0,0 +1,106 @@
package com.stardust.scriptdroid.ui.settings;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.stardust.theme.ThemeColorManagerCompat;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Stardust on 2017/5/10.
*/
public class PaintView extends View {
private List<Path> mPaths = new ArrayList<>();
private Path mCurrentPath;
private Paint mPaint;
public PaintView(Context context) {
super(context);
init();
}
public PaintView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public PaintView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public PaintView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
mPaint = new Paint();
mPaint.setColor(ThemeColorManagerCompat.getColorPrimary());
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);
setWillNotDraw(false);
setClickable(true);
setBackgroundColor(Color.TRANSPARENT);
}
@Override
protected void onDraw(Canvas canvas) {
for (Path path : mPaths) {
canvas.drawPath(path, mPaint);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getY();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
onTouchDown(x, y);
return true;
case MotionEvent.ACTION_MOVE:
onTouchMove(x, y);
return true;
case MotionEvent.ACTION_UP:
onTouchUp(x, y);
return true;
}
return super.onTouchEvent(event);
}
private void onTouchDown(float x, float y) {
if (mCurrentPath != null) {
mCurrentPath.close();
mPaths.add(mCurrentPath);
invalidate();
}
mCurrentPath = new Path();
mCurrentPath.moveTo(x, y);
}
private void onTouchMove(float x, float y) {
mCurrentPath.moveTo(x, y);
}
private void onTouchUp(float x, float y) {
mCurrentPath.close();
mPaths.add(mCurrentPath);
mCurrentPath = null;
invalidate();
}
}

View File

@@ -0,0 +1,57 @@
package com.stardust.theme.widget;
import android.content.Context;
import android.graphics.PorterDuff;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import com.stardust.theme.ThemeColor;
import com.stardust.theme.ThemeColorManager;
import com.stardust.theme.ThemeColorMutable;
/**
* Created by Stardust on 2017/5/10.
*/
public class ThemeColorImageViewCompat extends AppCompatImageView implements ThemeColorMutable {
private int mColor;
public ThemeColorImageViewCompat(Context context) {
super(context);
this.init();
}
public ThemeColorImageViewCompat(Context context, AttributeSet attrs) {
super(context, attrs);
this.init();
}
public ThemeColorImageViewCompat(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
this.init();
}
private void init() {
ThemeColorManager.add(this);
}
public void setThemeColor(ThemeColor color) {
if (this.mColor != color.colorPrimary) {
this.mColor = color.colorPrimary;
this.setColor(color.colorPrimary);
}
}
public void setImageResource(int resId) {
super.setImageResource(resId);
if (this.mColor != 0) {
this.setColor(this.mColor);
}
}
private void setColor(int color) {
getDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 806 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 989 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1014 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 713 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 905 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -20,7 +20,7 @@
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_developer_512"/> android:src="@drawable/ic_developer"/>
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -89,11 +89,11 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:padding="10dp" android:padding="10dp"
android:src="@drawable/ic_add_file_green"/> android:src="@drawable/ic_add_file"/>
<com.stardust.theme.widget.ThemeColorTextView <com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -114,7 +114,7 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:padding="10dp" android:padding="10dp"
@@ -140,11 +140,11 @@
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:padding="10dp" android:padding="10dp"
android:src="@drawable/ic_folder_open_outline_green"/> android:src="@drawable/ic_import"/>
<com.stardust.theme.widget.ThemeColorTextView <com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -16,6 +16,7 @@
android:id="@+id/content" android:id="@+id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:paddingLeft="3dp" android:paddingLeft="3dp"
android:textIsSelectable="true" android:textIsSelectable="true"
android:textSize="14sp" android:textSize="14sp"

View File

@@ -17,7 +17,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:src="@drawable/ic_ali_rename"/> android:src="@drawable/ic_ali_rename"/>
@@ -43,7 +43,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:src="@drawable/ic_ali_delete"/> android:src="@drawable/ic_ali_delete"/>

View File

@@ -17,7 +17,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:src="@drawable/ic_ali_rename"/> android:src="@drawable/ic_ali_rename"/>
@@ -43,7 +43,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:src="@drawable/ic_ali_open"/> android:src="@drawable/ic_ali_open"/>
@@ -69,7 +69,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:src="@drawable/ic_ali_shortcut"/> android:src="@drawable/ic_ali_shortcut"/>
@@ -95,7 +95,7 @@
android:paddingLeft="24dp" android:paddingLeft="24dp"
android:paddingTop="16dp"> android:paddingTop="16dp">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:src="@drawable/ic_ali_delete"/> android:src="@drawable/ic_ali_delete"/>

View File

@@ -63,8 +63,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="40dp" android:layout_height="40dp"
android:baselineAligned="false" android:layout_gravity="bottom"
android:layout_gravity="bottom"> android:baselineAligned="false">
<LinearLayout <LinearLayout
android:id="@+id/setting" android:id="@+id/setting"
@@ -75,7 +75,7 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:padding="6dp" android:padding="6dp"
@@ -98,7 +98,7 @@
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="40dp" android:layout_width="40dp"
android:layout_height="40dp" android:layout_height="40dp"
android:padding="6dp" android:padding="6dp"

View File

@@ -6,7 +6,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
@@ -20,7 +20,7 @@
android:textColor="@android:color/primary_text_light"/> android:textColor="@android:color/primary_text_light"/>
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:id="@+id/expand_hint" android:id="@+id/expand_hint"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="20dp" android:layout_height="20dp"

View File

@@ -1,197 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.stardust.scriptdroid.ui.main.MainActivity">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/app_bar_bg"
android:layout_width="match_parent"
android:layout_height="128.5dp"
android:scaleType="fitXY"
android:src="@drawable/toolbar_bg"/>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:clipToPadding="false"
android:paddingTop="24dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:title="@string/_app_name"
app:popupTheme="@style/AppTheme.PopupOverlay">
<ImageView
android:id="@+id/add"
android:layout_width="?android:attr/actionBarSize"
android:layout_height="match_parent"
android:layout_gravity="right"
android:foreground="?selectableItemBackgroundBorderless"
android:padding="12dp"
android:src="@drawable/ic_add_white_48dp"/>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="@+id/bottom_navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<com.stardust.widget.SlidingUpPanel
android:id="@+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@android:color/white"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/create_new_file"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical">
<com.stardust.theme.widget.ThemeColorImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="10dp"
android:src="@drawable/ic_add_file_green"/>
<com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_new_file"
android:textColor="@color/colorPrimary"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/import_from_file"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical">
<com.stardust.theme.widget.ThemeColorImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="10dp"
android:src="@drawable/ic_folder_open_outline_green"/>
<com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_import_from_file"
android:textColor="@color/colorPrimary"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/record"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<com.stardust.theme.widget.ThemeColorImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="10dp"
android:src="@drawable/ic_video_record"/>
<com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_script_record"
android:textColor="@color/colorPrimary"
android:textSize="16sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/root_record"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<com.stardust.theme.widget.ThemeColorImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="10dp"
android:src="@drawable/ic_video_record"/>
<com.stardust.theme.widget.ThemeColorTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/text_root_script_record"
android:textColor="@color/colorPrimary"
android:textSize="16sp"/>
</LinearLayout>
</LinearLayout>
</com.stardust.widget.SlidingUpPanel>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.DrawerLayout>

View File

@@ -13,7 +13,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
@@ -35,7 +35,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
@@ -57,7 +57,7 @@
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
android:gravity="center_vertical"> android:gravity="center_vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:id="@+id/icon_assist_service" android:id="@+id/icon_assist_service"
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"

View File

@@ -13,7 +13,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
@@ -35,11 +35,11 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_js"/> android:src="@drawable/ic_speech_bubble"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -56,7 +56,7 @@
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
android:gravity="center_vertical"> android:gravity="center_vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:id="@+id/icon_service" android:id="@+id/icon_service"
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
@@ -90,13 +90,13 @@
android:background="?selectableItemBackground" android:background="?selectableItemBackground"
android:gravity="center_vertical"> android:gravity="center_vertical">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:id="@+id/icon_assist_service" android:id="@+id/icon_assist_service"
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_robot_head_green"/> android:src="@drawable/ic_robot_64"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -124,7 +124,7 @@
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
<com.stardust.theme.widget.ThemeColorImageView <com.stardust.theme.widget.ThemeColorImageViewCompat
android:layout_width="20dp" android:layout_width="20dp"
android:layout_height="20dp" android:layout_height="20dp"
android:layout_margin="16dp" android:layout_margin="16dp"
@@ -138,4 +138,4 @@
android:textColor="@android:color/primary_text_light"/> android:textColor="@android:color/primary_text_light"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="600dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:padding="200dp"
android:src="@drawable/ic_android_eat_js"/>
<com.stardust.scriptdroid.ui.settings.PaintView
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>

View File

@@ -45,11 +45,11 @@
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:layout_width="32dp" android:layout_width="20dp"
android:layout_height="32dp" android:layout_height="20dp"
android:layout_gravity="center" android:layout_gravity="center"
android:contentDescription="@string/_app_name" android:contentDescription="@string/_app_name"
android:src="@drawable/ic_play"/> android:src="@drawable/ic_ali_run"/>
</LinearLayout> </LinearLayout>

View File

@@ -174,6 +174,10 @@
<string name="text_force_stop">强制停止</string> <string name="text_force_stop">强制停止</string>
<string name="text_execution_finished" formatted="false">\n------------\n[%s]运行结束,用时%f秒</string> <string name="text_execution_finished" formatted="false">\n------------\n[%s]运行结束,用时%f秒</string>
<string name="text_record_format_error">录制格式错误</string> <string name="text_record_format_error">录制格式错误</string>
<string name="text_again">又</string>
<string name="text_again_and_again">又双</string>
<string name="text_again_and_again_again">又双叒</string>
<string name="text_again_and_again_again_again">又双叒叕</string>
<string-array name="record_control_keys"> <string-array name="record_control_keys">
<item>无</item> <item>无</item>

View File

@@ -1,8 +1,13 @@
package com.stardust.autojs; package com.stardust.autojs;
import android.app.Instrumentation;
import android.app.UiAutomation;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import android.view.InputEvent;
import android.test.ActivityInstrumentationTestCase2;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;

View File

@@ -11,9 +11,9 @@ module.exports = function(__runtime__, scope){
return eval(console.rawInput.call(console, [].slice(arguments)) + ""); return eval(console.rawInput.call(console, [].slice(arguments)) + "");
} }
scope.print = console.log.bind(console); scope.print = console.print.bind(console, android.util.Log.DEBUG);
scope.log = scope.print; scope.log = console.log.bind(console);
scope.err = console.error.bind(console); scope.err = console.error.bind(console);

View File

@@ -3,7 +3,7 @@
module.exports = function(__runtime__, scope){ module.exports = function(__runtime__, scope){
scope.SetScreenMetrics = function(w, h){ scope.SetScreenMetrics = function(w, h){
__runtime__.getRootShell().SetScreenMetrics(x, y); __runtime__.getRootShell().SetScreenMetrics(w, h);
} }
scope.Tap = function(x, y){ scope.Tap = function(x, y){

View File

@@ -1,9 +1,103 @@
assert = console.assert.bind(console);
function test(){
//testInput();
///sleep(500);
//testLongClick();
//sleep(500);
testScrollAndShow();
}
Function.prototype.getName = function(){
return this.name || this.toString().match(/function\s*([^(]*)\(/)[1]
}
assert = function(){
if(arguments.length == 1){
if(!arguments[0]){
throw new Error("Assertion fail");
}
return;
}
if(arguments[0] != arguments[1]){
var msg = "Assertion fail: " + arguments[0] + " != " + arguments[1];
throw new Error(msg);
}
}
function testInput(){
log("testInput...");
id("add").findOne().click();
while(!click("新建文件"));
for(var i = 0; i < 9; i++){
input(i);
}
sleep(200);
assert('请输入名称012345678', editable().findOne().text());
sleep(400);
back();
sleep(200);
back();
sleep(200);
back();
}
function random(){
return ("" + Math.random()).substring(2);
}
function testLongClick(){
log("testLongClick...");
id("script_list_recycler_view").findOne().child(0).longClick();
while(!click("重命名"));
sleep(200);
var r = random();
editable().setText(r);
sleep(200);
while(!click("确定"));
sleep(200);
assert(text(r).exists());
}
function newFile(name){
name = name + random();
id("add").findOne().click();
sleep(400);
while(!click("新建文件"));
sleep(400);
editable().setText(name);
sleep(400);
while(!click("确定"));
sleep(500);
back();
sleep(200);
back();
return name;
}
function testScrollAndShow(){
var name1 = newFile("zzz");
for(var i = 0; i < 10; i++){
id("script_list_recycler_view").scrollForward();
}
assert(text(name1).findOne().visibleToUser());
sleep(500);
var name2 = newFile("000");
sleep(200);
for(var i = 0; i < 10; i++){
id("script_list_recycler_view").scrollForward();
}
sleep(500);
text(name2).findOne().show();
assert(text(name2).findOne().visibleToUser());
}
function testApp(){ function testApp(){
print('正在测试模块:app'); before();
assert("com.tencent.mm" == app.getPackageName("微信")); assert("com.tencent.mm" == app.getPackageName("微信"));
assert("com.tencent.mobileqq" == app.getPackageName("QQ")); assert("com.tencent.mobileqq" == app.getPackageName("QQ"));
}
} module.exports = test;

View File

@@ -4,7 +4,6 @@ import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import com.stardust.autojs.runtime.ScriptStopException; import com.stardust.autojs.runtime.ScriptStopException;
import com.stardust.autojs.runtime.api.Console;
/** /**
* Created by Stardust on 2017/5/1. * Created by Stardust on 2017/5/1.
@@ -24,6 +23,12 @@ public abstract class AbstractConsole implements Console {
return String.format(data.toString(), options); return String.format(data.toString(), options);
} }
@Override
public void print(int level, Object data, Object... options) {
write(level, format(data, options));
}
protected abstract void write(int level, CharSequence data);
@Override @Override
public void verbose(@Nullable Object data, Object... options) { public void verbose(@Nullable Object data, Object... options) {

View File

@@ -16,6 +16,9 @@ public interface Console {
@ScriptInterface @ScriptInterface
void log(@Nullable Object data, Object... options); void log(@Nullable Object data, Object... options);
@ScriptInterface
void print(int level, Object data, Object... options);
@ScriptInterface @ScriptInterface
void info(@Nullable Object data, Object... options); void info(@Nullable Object data, Object... options);

View File

@@ -151,7 +151,6 @@ public class UiSelector extends UiGlobalSelector {
} else { } else {
super.id(id); super.id(id);
} }
Intent intent;
return this; return this;
} }
@@ -160,6 +159,11 @@ public class UiSelector extends UiGlobalSelector {
return untilFind().performAction(action, arguments); return untilFind().performAction(action, arguments);
} }
public boolean exists() {
UiObjectCollection collection = find();
return collection != null && collection.size() > 0;
}
@ScriptInterface @ScriptInterface
public boolean click() { public boolean click() {
return performAction(ACTION_CLICK); return performAction(ACTION_CLICK);

View File

@@ -25,6 +25,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations' exclude group: 'com.android.support', module: 'support-annotations'
}) })
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
compile project(path: ':common') compile project(path: ':common')
} }

View File

@@ -4,6 +4,7 @@ import android.app.UiAutomation;
import android.content.Intent; import android.content.Intent;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.util.Pools; import android.support.v4.util.Pools;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat; import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
@@ -129,8 +130,10 @@ public class UiObject extends AccessibilityNodeInfoCompat {
return getViewIdResourceName(); return getViewIdResourceName();
} }
@NonNull
public CharSequence text() { public CharSequence text() {
return getText(); CharSequence t = getText();
return t == null ? "" : t;
} }
public CharSequence desc() { public CharSequence desc() {
@@ -305,6 +308,10 @@ public class UiObject extends AccessibilityNodeInfoCompat {
return mAllocator.getParent(this); return mAllocator.getParent(this);
} }
public boolean visibleToUser() {
return isVisibleToUser();
}
@Override @Override
public List<AccessibilityNodeInfoCompat> findAccessibilityNodeInfosByText(String text) { public List<AccessibilityNodeInfoCompat> findAccessibilityNodeInfosByText(String text) {
if (mAllocator == null) if (mAllocator == null)

View File

@@ -48,7 +48,7 @@ public class ActionFactory {
@Override @Override
protected void performAction(UiObject node) { protected void performAction(UiObject node) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, text); args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE, node.text() + text);
node.performAction(getAction(), args); node.performAction(getAction(), args);
} }
}; };

View File

@@ -0,0 +1,35 @@
package com.stardust.uiautomator;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.InstrumentationInfo;
import android.widget.Toast;
import java.util.List;
/**
* Created by Stardust on 2017/5/9.
*/
public class Test {
private void runTests(Context context) {
final String packageName = context.getPackageName();
final List<InstrumentationInfo> list =
context.getPackageManager().queryInstrumentation(packageName, 0);
if (list.isEmpty()) {
Toast.makeText(context, "Cannot find instrumentation for " + packageName,
Toast.LENGTH_SHORT).show();
return;
}
final InstrumentationInfo instrumentationInfo = list.get(0);
final ComponentName componentName =
new ComponentName(instrumentationInfo.packageName,
instrumentationInfo.name);
if (!context.startInstrumentation(componentName, null, null)) {
Toast.makeText(context, "Cannot run instrumentation for " + packageName,
Toast.LENGTH_SHORT).show();
}
}
}