optimize memory and image size. remove unnecessary language file
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class BlockedMaterialDialog extends MaterialDialog {
|
||||
@Override
|
||||
public void show() {
|
||||
if (!isActivityContext(getContext())) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE);
|
||||
}
|
||||
super.show();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.annotation.DrawableRes;
|
||||
@@ -75,9 +77,9 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
private View getTabViewInner(int index) {
|
||||
String menuItemId = mTabIds.get(index);
|
||||
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)) {
|
||||
return createTabView(R.drawable.ic_video_record);
|
||||
return createTabView(R.drawable.ic_ali_record);
|
||||
} else if (ID_SCRIPT_LIST.equals(menuItemId)) {
|
||||
return createTabView(R.drawable.ic_menu);
|
||||
} else {
|
||||
@@ -125,7 +127,7 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
Resources resources = mContext.getResources();
|
||||
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.setTabForegroundColor(iconColor);
|
||||
view.setPadding(padding, padding, padding, padding);
|
||||
@@ -135,6 +137,12 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
return view;
|
||||
}
|
||||
|
||||
private Drawable getCircleDrawable() {
|
||||
ShapeDrawable oval = new ShapeDrawable(new OvalShape());
|
||||
return oval;
|
||||
}
|
||||
|
||||
|
||||
public class DemoTabView extends View {
|
||||
|
||||
private int mBackgroundColor;
|
||||
@@ -183,13 +191,8 @@ public class HoverMenuAdapter implements io.mattcarroll.hover.HoverMenuAdapter {
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
// Make circle as large as View minus padding.
|
||||
mCircleDrawable.setBounds(getPaddingLeft(), getPaddingTop(), w - getPaddingRight(), h - getPaddingBottom());
|
||||
|
||||
// Re-size the icon as necessary.
|
||||
updateIconBounds();
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,6 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
|
||||
}
|
||||
if (mConsole.submitInput(input)) {
|
||||
mEditText.setText("");
|
||||
mEditText.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +92,17 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
|
||||
mEditText = (EditText) findViewById(R.id.input);
|
||||
mEditText.setFocusableInTouchMode(true);
|
||||
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) {
|
||||
@@ -103,7 +113,6 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
|
||||
@Override
|
||||
public void onNewLog(StardustConsole.Log log) {
|
||||
log(log.level, log.content);
|
||||
log(log.level, "\n");
|
||||
}
|
||||
|
||||
private void log(int level, CharSequence log) {
|
||||
@@ -114,6 +123,7 @@ public class ConsoleView extends FrameLayout implements StardustConsole.LogListe
|
||||
public void run() {
|
||||
mTextView.append(spannable);
|
||||
mContentContainer.fullScroll(View.FOCUS_DOWN);
|
||||
mEditText.requestFocus();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -50,6 +50,12 @@ public class JraskaConsole extends AbstractConsole {
|
||||
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) {
|
||||
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) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.enhancedfloaty.ResizableExpandableFloatyWindow;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.autojs.api.VolatileBox;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.util.UiHandler;
|
||||
|
||||
@@ -79,7 +78,7 @@ public class StardustConsole extends AbstractConsole {
|
||||
|
||||
@Override
|
||||
public void println(int level, CharSequence charSequence) {
|
||||
Log log = new Log(level, charSequence);
|
||||
Log log = new Log(level, charSequence + "\n");
|
||||
mLogs.add(log);
|
||||
GLOBAL_CONSOLE.println(level, charSequence);
|
||||
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
|
||||
public void clear() {
|
||||
mLogs.clear();
|
||||
|
||||
@@ -5,9 +5,11 @@ import android.content.ClipboardManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.util.SparseIntArray;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -27,16 +29,40 @@ import java.util.TimerTask;
|
||||
public class ErrorReportActivity extends BaseActivity {
|
||||
|
||||
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) {
|
||||
try {
|
||||
super.onCreate(savedInstanceState);
|
||||
mTitle = getCrashCountText() + getString(R.string.text_crash);
|
||||
setUpUI();
|
||||
handleIntent();
|
||||
} catch (Throwable throwable) {
|
||||
Log.e(TAG, "", throwable);
|
||||
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) {
|
||||
new ThemeColorMaterialDialogBuilder(this)
|
||||
.title(R.string.text_crash)
|
||||
.title(mTitle)
|
||||
.content(R.string.crash_feedback)
|
||||
.positiveText(R.string.text_exit)
|
||||
.neutralText(R.string.text_copy_debug_info)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
}
|
||||
@@ -27,8 +27,10 @@ import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.stardust.app.FragmentPagerAdapterBuilder;
|
||||
import com.stardust.app.NotAskAgainDialog;
|
||||
import com.stardust.app.OnActivityResultDelegate;
|
||||
import com.stardust.enhancedfloaty.FloatyService;
|
||||
import com.stardust.scriptdroid.BuildConfig;
|
||||
import com.stardust.scriptdroid.R;
|
||||
import com.stardust.scriptdroid.autojs.AutoJs;
|
||||
import com.stardust.scriptdroid.external.floating_window.FloatingWindowManger;
|
||||
import com.stardust.scriptdroid.script.ScriptFile;
|
||||
import com.stardust.scriptdroid.script.StorageScriptProvider;
|
||||
@@ -80,6 +82,7 @@ public class MainActivity extends BaseActivity {
|
||||
private DrawableSaver mDrawerHeaderBackgroundSaver, mAppbarBackgroundSaver;
|
||||
private VersionGuard mVersionGuard;
|
||||
private Intent mIntentToHandle;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -164,15 +167,14 @@ public class MainActivity extends BaseActivity {
|
||||
|
||||
private void setUpTabViewPager() {
|
||||
TabLayout tabLayout = $(R.id.tab);
|
||||
ViewPager viewPager = $(R.id.viewpager);
|
||||
mViewPager = $(R.id.viewpager);
|
||||
mPagerAdapter = new FragmentPagerAdapterBuilder(this)
|
||||
.add(new MyScriptListFragment(), R.string.text_my_script)
|
||||
.add(new SampleScriptListFragment(), R.string.text_sample_script)
|
||||
.add(new TaskManagerFragment(), R.string.text_task_manage)
|
||||
.build();
|
||||
viewPager.setAdapter(mPagerAdapter);
|
||||
viewPager.setOffscreenPageLimit(mPagerAdapter.getCount());
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
mViewPager.setAdapter(mPagerAdapter);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
mPagerAdapter.setOnFragmentInstantiateListener(new FragmentPagerAdapterBuilder.OnFragmentInstantiateListener() {
|
||||
@Override
|
||||
public void OnInstantiate(Fragment fragment) {
|
||||
@@ -235,8 +237,11 @@ public class MainActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.exit)
|
||||
public void finish() {
|
||||
super.finish();
|
||||
public void exitCompletely() {
|
||||
FloatingWindowManger.hideHoverMenu();
|
||||
stopService(new Intent(this, FloatyService.class));
|
||||
AutoJs.getInstance().getScriptEngineService().stopAll();
|
||||
finish();
|
||||
}
|
||||
|
||||
@ViewBinding.Click(R.id.drawer_header_img)
|
||||
@@ -265,22 +270,38 @@ public class MainActivity extends BaseActivity {
|
||||
handleRecordedScript(intent.getStringExtra(ARGUMENT_SCRIPT));
|
||||
break;
|
||||
case ACTION_IMPORT_SCRIPT:
|
||||
getMyScriptListFragment().importFile(intent.getStringExtra(ARGUMENT_PATH));
|
||||
handleImportScriptFile(intent);
|
||||
break;
|
||||
case ACTION_IMPORT_SAMPLE:
|
||||
importSample((Sample) intent.getSerializableExtra(ARGUMENT_SAMPLE));
|
||||
handleImportSample(intent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void importSample(Sample 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 handleImportScriptFile(Intent intent) {
|
||||
mViewPager.setCurrentItem(0, true);
|
||||
MyScriptListFragment fragment = getMyScriptListFragment();
|
||||
if (fragment == null) {
|
||||
mIntentToHandle = intent;
|
||||
} 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) {
|
||||
|
||||
@@ -21,26 +21,25 @@ import com.stardust.scriptdroid.ui.main.MainActivity;
|
||||
|
||||
public class SampleScriptListFragment extends Fragment {
|
||||
|
||||
private SampleScriptListRecyclerView mSampleScriptListRecyclerView;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_sample_script_list, container, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mSampleScriptListRecyclerView = $(R.id.script_list);
|
||||
mSampleScriptListRecyclerView.setSamples(SampleFileManager.getInstance().getSamplesFromAssets(getContext().getAssets(), "sample"));
|
||||
mSampleScriptListRecyclerView.setOnItemLongClickListener(new SampleScriptListRecyclerView.OnItemLongClickListener() {
|
||||
SampleScriptListRecyclerView sampleScriptListRecyclerView = $(R.id.script_list);
|
||||
sampleScriptListRecyclerView.setSamples(SampleFileManager.getInstance().getSamplesFromAssets(getContext().getAssets(), "sample"));
|
||||
sampleScriptListRecyclerView.setOnItemLongClickListener(new SampleScriptListRecyclerView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public void onItemLongClick(Sample sample) {
|
||||
showMenuDialog(sample);
|
||||
}
|
||||
});
|
||||
mSampleScriptListRecyclerView.setOnItemClickListener(new SampleScriptListRecyclerView.OnItemClickListener() {
|
||||
sampleScriptListRecyclerView.setOnItemClickListener(new SampleScriptListRecyclerView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(Sample sample) {
|
||||
viewSample(sample);
|
||||
|
||||
@@ -61,6 +61,7 @@ public class MyScriptListFragment extends Fragment {
|
||||
return inflater.inflate(R.layout.fragment_my_script_list, container, false);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
@@ -84,6 +84,8 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
|
||||
return;
|
||||
}
|
||||
ScriptFile file = mAdapter.getScriptFileAt(position);
|
||||
if (file == null)
|
||||
return;
|
||||
if (file.isDirectory()) {
|
||||
setCurrentDirectory(file, true);
|
||||
} else if (mOnItemClickListener != null) {
|
||||
@@ -96,7 +98,10 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
|
||||
public boolean onLongClick(View v) {
|
||||
if (mOnItemLongClickListener != null) {
|
||||
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 false;
|
||||
@@ -108,6 +113,8 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
|
||||
public void onClick(View v) {
|
||||
int position = getChildViewHolder((View) v.getParent()).getAdapterPosition();
|
||||
ScriptFile file = mAdapter.getScriptFileAt(position);
|
||||
if (file == null)
|
||||
return;
|
||||
Scripts.run(file);
|
||||
}
|
||||
};
|
||||
@@ -337,8 +344,13 @@ public class ScriptAndFolderListRecyclerView extends RecyclerView {
|
||||
return getScriptFileAt(position).isDirectory() ? VIEW_TYPE_DIRECTORY : VIEW_TYPE_FILE;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
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) {
|
||||
|
||||
@@ -6,12 +6,16 @@ import android.content.ClipboardManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.afollestad.materialdialogs.DialogAction;
|
||||
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.ui.BaseActivity;
|
||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||
@@ -29,6 +33,7 @@ import moe.feng.alipay.zerosdk.AlipayZeroSdk;
|
||||
|
||||
public class AboutActivity extends BaseActivity {
|
||||
|
||||
private static final String TAG = "AboutActivity";
|
||||
private int mLolClickCount = 0;
|
||||
|
||||
@Override
|
||||
@@ -100,18 +105,54 @@ public class AboutActivity extends BaseActivity {
|
||||
mLolClickCount++;
|
||||
Toast.makeText(this, R.string.text_lll, Toast.LENGTH_LONG).show();
|
||||
if (mLolClickCount >= 5) {
|
||||
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();
|
||||
crashTest();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
private void hhh() {
|
||||
Toast.makeText(this, R.string.text_it_is_the_developer_of_app, Toast.LENGTH_LONG).show();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user