Search in sources :

Example 1 with SettingsActivity

use of com.naman14.timber.activities.SettingsActivity in project Timber by naman14.

the class SettingsFragment method invalidateSettings.

public void invalidateSettings() {
    mAteKey = ((SettingsActivity) getActivity()).getATEKey();
    ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
    primaryColorPref.setColor(Config.primaryColor(getActivity(), mAteKey), Color.BLACK);
    primaryColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            new ColorChooserDialog.Builder((SettingsActivity) getActivity(), R.string.primary_color).preselect(Config.primaryColor(getActivity(), mAteKey)).show();
            return true;
        }
    });
    ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
    accentColorPref.setColor(Config.accentColor(getActivity(), mAteKey), Color.BLACK);
    accentColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            new ColorChooserDialog.Builder((SettingsActivity) getActivity(), R.string.accent_color).preselect(Config.accentColor(getActivity(), mAteKey)).show();
            return true;
        }
    });
    findPreference("dark_theme").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            // Marks both theme configs as changed so MainActivity restarts itself on return
            Config.markChanged(getActivity(), "light_theme");
            Config.markChanged(getActivity(), "dark_theme");
            // The dark_theme preference value gets saved by Android in the default PreferenceManager.
            // It's used in getATEKey() of both the Activities.
            getActivity().recreate();
            return true;
        }
    });
    final ATECheckBoxPreference statusBarPref = (ATECheckBoxPreference) findPreference("colored_status_bar");
    final ATECheckBoxPreference navBarPref = (ATECheckBoxPreference) findPreference("colored_nav_bar");
    statusBarPref.setChecked(Config.coloredStatusBar(getActivity(), mAteKey));
    statusBarPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ATE.config(getActivity(), mAteKey).coloredStatusBar((Boolean) newValue).apply(getActivity());
            return true;
        }
    });
    navBarPref.setChecked(Config.coloredNavigationBar(getActivity(), mAteKey));
    navBarPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            ATE.config(getActivity(), mAteKey).coloredNavigationBar((Boolean) newValue).apply(getActivity());
            return true;
        }
    });
}
Also used : ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ATECheckBoxPreference(com.afollestad.appthemeengine.prefs.ATECheckBoxPreference) ATEColorPreference(com.afollestad.appthemeengine.prefs.ATEColorPreference) SwitchPreference(android.preference.SwitchPreference) ColorChooserDialog(com.afollestad.materialdialogs.color.ColorChooserDialog) ATECheckBoxPreference(com.afollestad.appthemeengine.prefs.ATECheckBoxPreference) ATEColorPreference(com.afollestad.appthemeengine.prefs.ATEColorPreference) SettingsActivity(com.naman14.timber.activities.SettingsActivity)

Aggregations

ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 SwitchPreference (android.preference.SwitchPreference)1 ATECheckBoxPreference (com.afollestad.appthemeengine.prefs.ATECheckBoxPreference)1 ATEColorPreference (com.afollestad.appthemeengine.prefs.ATEColorPreference)1 ColorChooserDialog (com.afollestad.materialdialogs.color.ColorChooserDialog)1 SettingsActivity (com.naman14.timber.activities.SettingsActivity)1