diff --git a/res/values/cherish_arrays.xml b/res/values/cherish_arrays.xml index 25e71c1..56b72cc 100644 --- a/res/values/cherish_arrays.xml +++ b/res/values/cherish_arrays.xml @@ -12,4 +12,23 @@ limitations under the License. --> + + + + @string/theme_type_light + @string/theme_type_pitch_black + @string/theme_type_solarized_dark + @string/theme_type_baked_green + @string/theme_type_choco_x + @string/theme_type_du_pitchblack + + + + 1 + 2 + 3 + 4 + 5 + 6 + diff --git a/res/values/cherish_strings.xml b/res/values/cherish_strings.xml index 6d40caa..0f5b982 100644 --- a/res/values/cherish_strings.xml +++ b/res/values/cherish_strings.xml @@ -87,4 +87,14 @@ Lockscreen + + + System theme + Select theme + Light + Google dark + Solarized dark + Baked Green + Choco X + Pitch black diff --git a/res/xml/cherish_settings_theme.xml b/res/xml/cherish_settings_theme.xml index c1ab711..59aa0d2 100644 --- a/res/xml/cherish_settings_theme.xml +++ b/res/xml/cherish_settings_theme.xml @@ -17,4 +17,14 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/theme_title" xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"> + + \ No newline at end of file diff --git a/res/xml/cherish_settings_volume.xml b/res/xml/cherish_settings_volume.xml index f490769..14b5776 100644 --- a/res/xml/cherish_settings_volume.xml +++ b/res/xml/cherish_settings_volume.xml @@ -16,5 +16,4 @@ - diff --git a/src/com/cherish/settings/fragments/ThemeSettings.java b/src/com/cherish/settings/fragments/ThemeSettings.java index 4120f6e..87fa397 100644 --- a/src/com/cherish/settings/fragments/ThemeSettings.java +++ b/src/com/cherish/settings/fragments/ThemeSettings.java @@ -43,6 +43,11 @@ import net.margaritov.preference.colorpicker.ColorPickerPreference; public class ThemeSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener { + private static final String PREF_THEME_SWITCH = "theme_switch"; + + private IOverlayManager mOverlayService; + private UiModeManager mUiModeManager; + private ListPreference mThemeSwitch; @Override public void onCreate(Bundle icicle) { @@ -52,13 +57,140 @@ public class ThemeSettings extends SettingsPreferenceFragment implements PreferenceScreen prefScreen = getPreferenceScreen(); ContentResolver resolver = getActivity().getContentResolver(); + + mUiModeManager = getContext().getSystemService(UiModeManager.class); + + mOverlayService = IOverlayManager.Stub + .asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)); + + setupThemeSwitchPref(); } @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { + public boolean onPreferenceChange(Preference preference, Object objValue) { ContentResolver resolver = getActivity().getContentResolver(); + if (preference == mThemeSwitch) { + String theme_switch = (String) objValue; + final Context context = getContext(); + switch (theme_switch) { + case "1": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_NO, ThemesUtils.MATERIAL_OCEAN); + break; + case "2": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "3": + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "4": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "5": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "6": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "7": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "8": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(true, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + case "9": + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.SOLARIZED_DARK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.BAKED_GREEN); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.CHOCO_X); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.PITCH_BLACK); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.DARK_GREY); + handleBackgrounds(false, context, UiModeManager.MODE_NIGHT_YES, ThemesUtils.MATERIAL_OCEAN); + break; + } + try { + mOverlayService.reloadAndroidAssets(UserHandle.USER_CURRENT); + mOverlayService.reloadAssets("com.android.settings", UserHandle.USER_CURRENT); + mOverlayService.reloadAssets("com.android.systemui", UserHandle.USER_CURRENT); + } catch (RemoteException ignored) { + } + } + return true; + } - return false; + private void setupThemeSwitchPref() { + mThemeSwitch = (ListPreference) findPreference(PREF_THEME_SWITCH); + mThemeSwitch.setOnPreferenceChangeListener(this); + if (CherishUtils.isThemeEnabled("com.android.theme.darkgrey.system")) { + mThemeSwitch.setValue("7"); + } else if (CherishUtils.isThemeEnabled("com.android.theme.pitchblack.system")) { + mThemeSwitch.setValue("6"); + } else if (CherishUtils.isThemeEnabled("com.android.theme.materialocean.system")) { + mThemeSwitch.setValue("8"); + } else if (CherishUtils.isThemeEnabled("com.android.theme.chocox.system")) { + mThemeSwitch.setValue("5"); + } else if (CherishUtils.isThemeEnabled("com.android.theme.bakedgreen.system")) { + mThemeSwitch.setValue("4"); + } else if (CherishUtils.isThemeEnabled("com.android.theme.solarizeddark.system")) { + mThemeSwitch.setValue("3"); + } else if (mUiModeManager.getNightMode() == UiModeManager.MODE_NIGHT_YES) { + mThemeSwitch.setValue("2"); + } else { + mThemeSwitch.setValue("1"); + } + } + + private void handleBackgrounds(Boolean state, Context context, int mode, String[] overlays) { + if (context != null) { + Objects.requireNonNull(context.getSystemService(UiModeManager.class)) + .setNightMode(mode); + } + for (int i = 0; i < overlays.length; i++) { + String background = overlays[i]; + try { + mOverlayService.setEnabled(background, state, USER_SYSTEM); + } catch (RemoteException e) { + e.printStackTrace(); + } + } } @Override