This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
### text(文件控件)
|
||||||
@@ -18,6 +18,7 @@ import com.stardust.scriptdroid.ui.error.ErrorReportActivity;
|
|||||||
import com.stardust.theme.ThemeColor;
|
import com.stardust.theme.ThemeColor;
|
||||||
import com.stardust.theme.ThemeColorManager;
|
import com.stardust.theme.ThemeColorManager;
|
||||||
import com.stardust.util.ScreenMetrics;
|
import com.stardust.util.ScreenMetrics;
|
||||||
|
import com.stardust.util.UiHandler;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ public class App extends MultiDexApplication {
|
|||||||
private static final String TAG = "App";
|
private static final String TAG = "App";
|
||||||
|
|
||||||
private static WeakReference<App> instance;
|
private static WeakReference<App> instance;
|
||||||
|
private UiHandler mUiHandler;
|
||||||
|
|
||||||
public static App getApp() {
|
public static App getApp() {
|
||||||
return instance.get();
|
return instance.get();
|
||||||
@@ -40,6 +42,7 @@ public class App extends MultiDexApplication {
|
|||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
instance = new WeakReference<>(this);
|
instance = new WeakReference<>(this);
|
||||||
|
mUiHandler = new UiHandler(this);
|
||||||
setUpStaticsTool();
|
setUpStaticsTool();
|
||||||
setUpDebugEnvironment();
|
setUpDebugEnvironment();
|
||||||
init();
|
init();
|
||||||
@@ -91,4 +94,8 @@ public class App extends MultiDexApplication {
|
|||||||
public VolumeChangeObserver getVolumeChangeObserver() {
|
public VolumeChangeObserver getVolumeChangeObserver() {
|
||||||
return mVolumeChangeObserver;
|
return mVolumeChangeObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UiHandler getUiHandler() {
|
||||||
|
return mUiHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class RecordNavigatorContent implements NavigatorContent, Recorder.OnStat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
Toast.makeText(mContext, R.string.text_start_record, Toast.LENGTH_SHORT).show();
|
App.getApp().getUiHandler().toast(R.string.text_start_record);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
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.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -49,7 +50,9 @@ import com.stardust.scriptdroid.ui.settings.SettingsActivity;
|
|||||||
import com.stardust.scriptdroid.ui.update.VersionGuard;
|
import com.stardust.scriptdroid.ui.update.VersionGuard;
|
||||||
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
import com.stardust.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||||
import com.stardust.util.BackPressedHandler;
|
import com.stardust.util.BackPressedHandler;
|
||||||
|
import com.stardust.util.Callback;
|
||||||
import com.stardust.util.MessageEvent;
|
import com.stardust.util.MessageEvent;
|
||||||
|
import com.stardust.view.DrawerAutoClose;
|
||||||
import com.stardust.view.ViewBinder;
|
import com.stardust.view.ViewBinder;
|
||||||
import com.stardust.view.ViewBinding;
|
import com.stardust.view.ViewBinding;
|
||||||
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
import com.stardust.view.accessibility.AccessibilityServiceUtils;
|
||||||
@@ -130,7 +133,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
registerBackPressedHandler(new BackPressedHandler.DrawerAutoClose(mDrawerLayout, Gravity.START));
|
registerBackPressedHandler(new DrawerAutoClose(mDrawerLayout, Gravity.START));
|
||||||
registerBackPressedHandler(new BackPressedHandler.DoublePressExit(this, R.string.text_press_again_to_exit));
|
registerBackPressedHandler(new BackPressedHandler.DoublePressExit(this, R.string.text_press_again_to_exit));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,12 +219,22 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
|
|
||||||
@ViewBinding.Click(R.id.create_new_file)
|
@ViewBinding.Click(R.id.create_new_file)
|
||||||
private void createScriptFile() {
|
private void createScriptFile() {
|
||||||
getMyScriptListFragment().newScriptFile();
|
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||||
|
@Override
|
||||||
|
public void call(MyScriptListFragment myScriptListFragment) {
|
||||||
|
myScriptListFragment.newScriptFile();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBinding.Click(R.id.create_new_directory)
|
@ViewBinding.Click(R.id.create_new_directory)
|
||||||
private void createNewDirectory() {
|
private void createNewDirectory() {
|
||||||
getMyScriptListFragment().newDirectory();
|
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||||
|
@Override
|
||||||
|
public void call(MyScriptListFragment myScriptListFragment) {
|
||||||
|
myScriptListFragment.newDirectory();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBinding.Click(R.id.import_from_file)
|
@ViewBinding.Click(R.id.import_from_file)
|
||||||
@@ -231,10 +244,15 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
.scriptProvider(provider)
|
.scriptProvider(provider)
|
||||||
.fileCallback(new ScriptFileChooserDialogBuilder.FileCallback() {
|
.fileCallback(new ScriptFileChooserDialogBuilder.FileCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onFileSelection(MaterialDialog dialog, ScriptFile file) {
|
public void onFileSelection(MaterialDialog dialog, final ScriptFile file) {
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
provider.clearCacheExceptInitialDirectory();
|
provider.clearCacheExceptInitialDirectory();
|
||||||
getMyScriptListFragment().importFile(file.getPath());
|
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||||
|
@Override
|
||||||
|
public void call(MyScriptListFragment myScriptListFragment) {
|
||||||
|
myScriptListFragment.importFile(file.getPath());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.title(R.string.text_please_choose_file_to_import)
|
.title(R.string.text_please_choose_file_to_import)
|
||||||
@@ -317,13 +335,18 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
if (fragment == null) {
|
if (fragment == null) {
|
||||||
mIntentToHandle = intent;
|
mIntentToHandle = intent;
|
||||||
} else {
|
} else {
|
||||||
Sample sample = (Sample) intent.getSerializableExtra(ARGUMENT_SAMPLE);
|
final Sample sample = (Sample) intent.getSerializableExtra(ARGUMENT_SAMPLE);
|
||||||
try {
|
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||||
getMyScriptListFragment().importFile(sample.name, getAssets().open(sample.path));
|
@Override
|
||||||
} catch (IOException e) {
|
public void call(MyScriptListFragment myScriptListFragment) {
|
||||||
e.printStackTrace();
|
try {
|
||||||
Snackbar.make(mDrawerLayout, R.string.text_import_fail, Snackbar.LENGTH_SHORT).show();
|
myScriptListFragment.importFile(sample.name, getAssets().open(sample.path));
|
||||||
}
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Snackbar.make(mDrawerLayout, R.string.text_import_fail, Snackbar.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,7 +358,12 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
@Override
|
@Override
|
||||||
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
getMyScriptListFragment().newScriptFileForScript(script);
|
doWithMyScriptListFragment(new Callback<MyScriptListFragment>() {
|
||||||
|
@Override
|
||||||
|
public void call(MyScriptListFragment myScriptListFragment) {
|
||||||
|
myScriptListFragment.newScriptFileForScript(script);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
((ClipboardManager) getSystemService(CLIPBOARD_SERVICE))
|
((ClipboardManager) getSystemService(CLIPBOARD_SERVICE))
|
||||||
.setPrimaryClip(ClipData.newPlainText("script", script));
|
.setPrimaryClip(ClipData.newPlainText("script", script));
|
||||||
@@ -369,7 +397,30 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
.putExtra(ARGUMENT_SAMPLE, sample));
|
.putExtra(ARGUMENT_SAMPLE, sample));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doWithMyScriptListFragment(final Callback<MyScriptListFragment> callback) {
|
||||||
|
MyScriptListFragment fragment = ((MyScriptListFragment) mPagerAdapter.getStoredFragment(0));
|
||||||
|
if (fragment != null) {
|
||||||
|
callback.call(fragment);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mViewPager.setCurrentItem(0);
|
||||||
|
mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onPageSelected(int position) {
|
||||||
|
if (position == 0) {
|
||||||
|
mViewPager.removeOnPageChangeListener(this);
|
||||||
|
doWithMyScriptListFragment(callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public MyScriptListFragment getMyScriptListFragment() {
|
public MyScriptListFragment getMyScriptListFragment() {
|
||||||
|
MyScriptListFragment fragment = ((MyScriptListFragment) mPagerAdapter.getStoredFragment(0));
|
||||||
|
if (fragment == null) {
|
||||||
|
mViewPager.setCurrentItem(0);
|
||||||
|
}
|
||||||
return ((MyScriptListFragment) mPagerAdapter.getStoredFragment(0));
|
return ((MyScriptListFragment) mPagerAdapter.getStoredFragment(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,6 +463,7 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
|
|||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public OnActivityResultDelegate.Mediator getOnActivityResultDelegateMediator() {
|
public OnActivityResultDelegate.Mediator getOnActivityResultDelegateMediator() {
|
||||||
return mActivityResultMediator;
|
return mActivityResultMediator;
|
||||||
|
|||||||
30
app/src/main/java/com/stardust/view/DrawerAutoClose.java
Normal file
30
app/src/main/java/com/stardust/view/DrawerAutoClose.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package com.stardust.view;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
|
|
||||||
|
import com.stardust.util.BackPressedHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Stardust on 2017/6/19.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DrawerAutoClose implements BackPressedHandler {
|
||||||
|
|
||||||
|
private DrawerLayout mDrawerLayout;
|
||||||
|
private int mGravity;
|
||||||
|
|
||||||
|
public DrawerAutoClose(DrawerLayout drawerLayout, int gravity){
|
||||||
|
mDrawerLayout = drawerLayout;
|
||||||
|
mGravity = gravity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onBackPressed(Activity activity) {
|
||||||
|
if (mDrawerLayout.isDrawerOpen(mGravity)) {
|
||||||
|
mDrawerLayout.closeDrawer(mGravity);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -37,7 +37,6 @@ dependencies {
|
|||||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
compile 'com.github.hyb1996:DynamicLayoutInflator:0.1'
|
compile 'com.github.hyb1996:DynamicLayoutInflator:0.1'
|
||||||
compile 'org.greenrobot:eventbus:3.0.0'
|
compile 'org.greenrobot:eventbus:3.0.0'
|
||||||
compile 'com.android.support:support-annotations:25.3.0'
|
|
||||||
compile 'net.lingala.zip4j:zip4j:1.3.2'
|
compile 'net.lingala.zip4j:zip4j:1.3.2'
|
||||||
compile project(path: ':common')
|
compile project(path: ':common')
|
||||||
compile project(path: ':automator')
|
compile project(path: ':automator')
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ dependencies {
|
|||||||
})
|
})
|
||||||
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
|
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
compile 'com.android.support:appcompat-v7:25.3.0'
|
||||||
compile project(path: ':common')
|
compile project(path: ':common')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.2'
|
classpath 'com.android.tools.build:gradle:2.3.3'
|
||||||
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
|
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.4'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
|||||||
@@ -25,6 +25,6 @@ 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'
|
||||||
})
|
})
|
||||||
compile 'com.android.support:appcompat-v7:25.3.0'
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
compile 'com.android.support:support-annotations:25.3.0'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.stardust.util;
|
package com.stardust.util;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
@@ -68,23 +67,5 @@ public interface BackPressedHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DrawerAutoClose implements BackPressedHandler {
|
|
||||||
|
|
||||||
private DrawerLayout mDrawerLayout;
|
|
||||||
private int mGravity;
|
|
||||||
|
|
||||||
public DrawerAutoClose(DrawerLayout drawerLayout, int gravity){
|
|
||||||
mDrawerLayout = drawerLayout;
|
|
||||||
mGravity = gravity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onBackPressed(Activity activity) {
|
|
||||||
if (mDrawerLayout.isDrawerOpen(mGravity)) {
|
|
||||||
mDrawerLayout.closeDrawer(mGravity);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.stardust.util;
|
package com.stardust.util;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -39,19 +38,6 @@ public class StateObserver {
|
|||||||
mSharedPreferences = sharedPreferences;
|
mSharedPreferences = sharedPreferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(final String key, SwitchCompat switchCompat) {
|
|
||||||
final WeakReference<SwitchCompat> switchCompatWeakReference = new WeakReference<>(switchCompat);
|
|
||||||
register(key, new SimpleOnStateChangedListener() {
|
|
||||||
@Override
|
|
||||||
public void onStateChanged(boolean newState) {
|
|
||||||
if (switchCompatWeakReference.get() != null) {
|
|
||||||
switchCompatWeakReference.get().setChecked(newState);
|
|
||||||
} else {
|
|
||||||
unregister(key, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void register(String key, OnStateChangedListener listener) {
|
public void register(String key, OnStateChangedListener listener) {
|
||||||
initState(key, listener);
|
initState(key, listener);
|
||||||
|
|||||||
Reference in New Issue
Block a user