Skip to content

Commit

Permalink
Auto-restart on settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriDellal committed Nov 23, 2017
1 parent a489167 commit 0e006e8
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="successfulRestore">Pomyślnie przywrócono</string>
<string name="restorePrefs">Przywróć preferencje</string>
<string name="restart">Uruchom ponownie launcher</string>
<string name="restartToImplement">Uruchom ponownie launcher w celu wprowadzenia zmian</string>
<!--<string name="restart_needed">Uruchom ponownie launcher w celu wprowadzenia zmian</string>-->


<string name="launcherSettings">Ustawienia Launcher Emerald</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<string name="backupPrefs">Создать копию настроек</string>
<string name="restorePrefs">Восстановить настройки</string>
<string name="restart">Перезапустить лаунчер</string>
<string name="restartToImplement">Перезапустите лаунчер, чтобы осуществить изменения</string>
<string name="restart_needed">Лаунчер будет перезапущен</string>

<string name="dock_is_full">Док заполнен</string>
<string name="dock_preferences">Настройки дока</string>
Expand Down
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="successfulRestore">Successfully restored.</string>
<string name="restorePrefs">Restore preferences</string>
<string name="restart">Restart launcher</string>
<string name="restartToImplement">Restart launcher to implement changes</string>
<string name="restart_needed">Launcher will be restarted</string>


<string name="launcherSettings">Launcher settings</string>
Expand Down
6 changes: 3 additions & 3 deletions res/xml/options.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<ru.henridellal.emerald.RestartPreference
android:title="@string/restart"
android:key="restart"/>
<PreferenceScreen android:title="@string/appearancePrefs">
<ListPreference
android:defaultValue="3"
Expand Down Expand Up @@ -142,4 +139,7 @@
android:summary="Only for Android 3.0+"
android:defaultValue="false"
android:key="keepInMemory"/>
<ru.henridellal.emerald.RestartPreference
android:title="@string/restart"
android:key="restart"/>
</PreferenceScreen>
23 changes: 8 additions & 15 deletions src/ru/henridellal/emerald/Apps.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ru.henridellal.emerald;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -604,24 +605,13 @@ public void onCreate(Bundle savedInstanceState) {
//Log.v(APP_TAG, "onCreate get preferences");
ManagerContainer.setIconPackManager(this);
//Log.v(APP_TAG, "onCreate set preference listener");
prefListener = new OnSharedPreferenceChangeListener() {
options.edit().putBoolean("message_shown", false).commit();
prefListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
String key) {
// Log.v(APP_TAG, "pref change detected");
if (key.equals(Options.PREF_ORIENTATION) || key.equals("scrollbar") || key.equals("keepInMemory")) {
Toast.makeText(Apps.this, getResources().getString(R.string.restartToImplement), Toast.LENGTH_LONG).show();
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//setRequestedOrientation(Integer.parseInt(sharedPreferences.getString(Options.PREF_ORIENTATION, "1")));
}
/*else if (key.equals("scrollbar")) {
setScrollbar();
}*/
else if (key.equals(Options.PREF_BAR_BACKGROUND)) {
findViewById(R.id.topbar).setBackgroundColor(options.getInt(Options.PREF_BAR_BACKGROUND, 0));
} else if (key.equals(Options.PREF_APPS_WINDOW_BACKGROUND)) {
findViewById(R.id.appsWindow).setBackgroundColor(options.getInt(Options.PREF_APPS_WINDOW_BACKGROUND, 0));
} else if (key.equals(Options.PREF_ICON_PACK) || key.equals(Options.PREF_TRANSFORM_DRAWABLE)) {
if (key.equals(Options.PREF_ICON_PACK) || key.equals(Options.PREF_TRANSFORM_DRAWABLE)) {
MyCache.deleteIcons(Apps.this);
ManagerContainer.getIconPackManager().setIconPack(sharedPreferences.getString(Options.PREF_ICON_PACK, "default"));
if (scanner != null && scanner.getStatus() == AsyncTask.Status.RUNNING)
Expand All @@ -630,12 +620,15 @@ else if (key.equals(Options.PREF_BAR_BACKGROUND)) {
scanner.execute(true);
loadFilteredApps();
setSpinner();
return;
} else if (key.equals(Options.PREF_DIRTY) && sharedPreferences.getBoolean(Options.PREF_DIRTY, false)) {
if (scanner == null || scanner.getStatus() != AsyncTask.Status.RUNNING) {
scanner = new GetApps(Apps.this);
scanner.execute(false);
}
} else if (!sharedPreferences.getBoolean(Options.MESSAGE_SHOWN, false) && Arrays.asList(Options.noRestartKeys).indexOf(key) == -1) {
Toast.makeText(Apps.this, getResources().getString(R.string.restart_needed), Toast.LENGTH_LONG).show();
Toast.makeText(Apps.this, key, Toast.LENGTH_LONG).show();
sharedPreferences.edit().putBoolean(Options.MESSAGE_SHOWN, true).commit();
}
}
};
Expand Down
12 changes: 11 additions & 1 deletion src/ru/henridellal/emerald/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Options extends PreferenceActivity {
public static final int WALLPAPER_DARK = 4;

public final static String SHOW_TUTORIAL = "show_tutorial";
public final static String MESSAGE_SHOWN = "message_shown";

public final static String PREF_BAR_BACKGROUND = "bar_background";
public final static String PREF_DOCK_BACKGROUND = "dock_background";
Expand Down Expand Up @@ -65,6 +66,8 @@ public class Options extends PreferenceActivity {
public static final String PREF_HISTORY_SIZE = "history_size";
public static final String PREF_PASSWORD = "password";

public static final String[] noRestartKeys = {PREF_CATEGORY, PREF_DIRTY, SHOW_TUTORIAL, MESSAGE_SHOWN};

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle icicle) {
Expand All @@ -73,6 +76,14 @@ public void onCreate(Bundle icicle) {
setIconPacksList(ManagerContainer.getIconPackManager(this).getIconPacks());
}
@Override
public void onBackPressed() {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(MESSAGE_SHOWN, false)) {
System.exit(0);
} else {
super.onBackPressed();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
Expand All @@ -84,7 +95,6 @@ public void setIconPacksList(Map<String, String> iconPacks) {
v[0] = "default";
Set<Map.Entry<String, String>> entryset = iconPacks.entrySet();
short i=1;
//for (int i = 1; i <= values.size(); i++) {
for (Map.Entry<String, String> entry: entryset) {
e[i] = entry.getKey();
v[i] = entry.getValue();
Expand Down

0 comments on commit 0e006e8

Please sign in to comment.