add: floating window switch saves state on exit

This commit is contained in:
hyb1996
2017-10-28 15:07:22 +08:00
parent d830e13031
commit 02a9091ddb
4 changed files with 18 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ public class Pref {
private static final String KEY_SHOULD_SHOW_ANNUNCIATION = "Sing about all the things you forgot, things you are not"; private static final String KEY_SHOULD_SHOW_ANNUNCIATION = "Sing about all the things you forgot, things you are not";
private static final String KEY_FIRST_SHOW_AD = "En, Today is 17.7.7, but, I'm still love you so...."; private static final String KEY_FIRST_SHOW_AD = "En, Today is 17.7.7, but, I'm still love you so....";
private static final String KEY_LAST_SHOW_AD_MILLIS = "But... it seems that...you will not come back any more..."; private static final String KEY_LAST_SHOW_AD_MILLIS = "But... it seems that...you will not come back any more...";
private static final String KEY_FLOATING_MENU_SHOWN = "17.10.28 I have idea of what you think...maybe...I'm overthinking...";
private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() { private static SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
@@ -147,4 +148,12 @@ public class Pref {
public static String getDocumentationUrl() { public static String getDocumentationUrl() {
return "file:///android_asset/docs/"; return "file:///android_asset/docs/";
} }
public static boolean isFloatingMenuShown() {
return def().getBoolean(KEY_FLOATING_MENU_SHOWN, false);
}
public static void setFloatingMenuShown(boolean checked) {
def().edit().putBoolean(KEY_FLOATING_MENU_SHOWN, checked).apply();
}
} }

View File

@@ -246,7 +246,7 @@ public class CircularMenu implements Recorder.OnStateChangedListener {
} }
@Optional @Optional
@OnClick(R.id.package_name) @OnClick(R.id.class_name)
void copyActivityName() { void copyActivityName() {
dismissSettingsDialog(); dismissSettingsDialog();
if (TextUtils.isEmpty(mRunningActivity)) if (TextUtils.isEmpty(mRunningActivity))

View File

@@ -184,10 +184,10 @@ public class MainActivity extends BaseActivity implements OnActivityResultDelega
@Click(R.id.exit) @Click(R.id.exit)
public void exitCompletely() { public void exitCompletely() {
finish();
FloatyWindowManger.hideCircularMenu(); FloatyWindowManger.hideCircularMenu();
stopService(new Intent(this, FloatyService.class)); stopService(new Intent(this, FloatyService.class));
AutoJs.getInstance().getScriptEngineService().stopAll(); AutoJs.getInstance().getScriptEngineService().stopAll();
finish();
} }
@Override @Override

View File

@@ -89,7 +89,6 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
@ViewById(R.id.default_cover) @ViewById(R.id.default_cover)
View mDefaultCover; View mDefaultCover;
private Disposable mConnectionStateDisposable; private Disposable mConnectionStateDisposable;
@@ -101,6 +100,7 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
.doOnNext(connected -> mConnectionItem.getSwitchCompat().setChecked(connected)) .doOnNext(connected -> mConnectionItem.getSwitchCompat().setChecked(connected))
.subscribe(); .subscribe();
EventBus.getDefault().register(this); EventBus.getDefault().register(this);
} }
@Override @Override
@@ -118,6 +118,9 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
@AfterViews @AfterViews
void setUpViews() { void setUpViews() {
ThemeColorManager.addViewBackground(mHeaderView); ThemeColorManager.addViewBackground(mHeaderView);
if (Pref.isFloatingMenuShown()) {
mFloatingWindowItem.getSwitchCompat().setChecked(true);
}
} }
private void syncUserInfo() { private void syncUserInfo() {
@@ -204,6 +207,9 @@ public class DrawerFragment extends android.support.v4.app.Fragment {
void showOrDismissFloatingWindow() { void showOrDismissFloatingWindow() {
boolean isFloatingWindowShowing = FloatyWindowManger.isCircularMenuShowing(); boolean isFloatingWindowShowing = FloatyWindowManger.isCircularMenuShowing();
boolean checked = mFloatingWindowItem.getSwitchCompat().isChecked(); boolean checked = mFloatingWindowItem.getSwitchCompat().isChecked();
if (getActivity() != null && !getActivity().isFinishing()) {
Pref.setFloatingMenuShown(checked);
}
if (checked && !isFloatingWindowShowing) { if (checked && !isFloatingWindowShowing) {
FloatyWindowManger.showCircularMenu(); FloatyWindowManger.showCircularMenu();
enableAccessibilityServiceByRootIfNeeded(); enableAccessibilityServiceByRootIfNeeded();