Search in sources :

Example 81 with PreferenceCategory

use of android.preference.PreferenceCategory in project android by nextcloud.

the class SettingsActivity method setupGeneralCategory.

private void setupGeneralCategory(int accentColor) {
    PreferenceCategory preferenceCategoryGeneral = (PreferenceCategory) findPreference("general");
    preferenceCategoryGeneral.setTitle(ThemeTextUtils.getColoredTitle(getString(R.string.prefs_category_general), accentColor));
    prefStoragePath = (ListPreference) findPreference(AppPreferencesImpl.STORAGE_PATH);
    if (prefStoragePath != null) {
        StoragePoint[] storageOptions = DataStorageProvider.getInstance().getAvailableStoragePoints();
        String[] entries = new String[storageOptions.length];
        String[] values = new String[storageOptions.length];
        for (int i = 0; i < storageOptions.length; ++i) {
            entries[i] = storageOptions[i].getDescription();
            values[i] = storageOptions[i].getPath();
        }
        prefStoragePath.setEntries(entries);
        prefStoragePath.setEntryValues(values);
        prefStoragePath.setOnPreferenceChangeListener((preference, newValue) -> {
            String newPath = (String) newValue;
            if (storagePath.equals(newPath)) {
                return true;
            }
            StorageMigration storageMigration = new StorageMigration(this, user, storagePath, newPath);
            storageMigration.setStorageMigrationProgressListener(this);
            storageMigration.migrate();
            return false;
        });
    }
    loadStoragePath();
    ListPreference themePref = (ListPreference) findPreference("darkMode");
    List<String> themeEntries = new ArrayList<>(3);
    themeEntries.add(getString(R.string.prefs_value_theme_light));
    themeEntries.add(getString(R.string.prefs_value_theme_dark));
    themeEntries.add(getString(R.string.prefs_value_theme_system));
    List<String> themeValues = new ArrayList<>(3);
    themeValues.add(DarkMode.LIGHT.name());
    themeValues.add(DarkMode.DARK.name());
    themeValues.add(DarkMode.SYSTEM.name());
    themePref.setEntries(themeEntries.toArray(new String[0]));
    themePref.setEntryValues(themeValues.toArray(new String[0]));
    if (TextUtils.isEmpty(themePref.getEntry())) {
        themePref.setValue(DarkMode.SYSTEM.name());
        themePref.setSummary(TextUtils.isEmpty(themePref.getEntry()) ? DarkMode.SYSTEM.name() : themePref.getEntry());
    }
    themePref.setOnPreferenceChangeListener((preference, newValue) -> {
        DarkMode mode = DarkMode.valueOf((String) newValue);
        preferences.setDarkThemeMode(mode);
        MainApp.setAppTheme(mode);
        return true;
    });
}
Also used : DarkMode(com.nextcloud.client.preferences.DarkMode) PreferenceCategory(android.preference.PreferenceCategory) StoragePoint(com.owncloud.android.datastorage.StoragePoint) ArrayList(java.util.ArrayList) ListPreference(android.preference.ListPreference) StoragePoint(com.owncloud.android.datastorage.StoragePoint)

Aggregations

PreferenceCategory (android.preference.PreferenceCategory)81 Preference (android.preference.Preference)49 PreferenceScreen (android.preference.PreferenceScreen)31 ListPreference (android.preference.ListPreference)30 CheckBoxPreference (android.preference.CheckBoxPreference)26 Intent (android.content.Intent)19 EditTextPreference (android.preference.EditTextPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 SwitchPreference (android.preference.SwitchPreference)8 ArrayList (java.util.ArrayList)7 Uri (android.net.Uri)6 SharedPreferences (android.content.SharedPreferences)5 Bundle (android.os.Bundle)5 View (android.view.View)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 Context (android.content.Context)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)3 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)3 RingtonePreference (android.preference.RingtonePreference)3 ListView (android.widget.ListView)3