Search in sources :

Example 11 with PreferenceManager

use of android.preference.PreferenceManager in project XposedInstaller by rovo89.

the class DownloadDetailsSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Module module = mActivity.getModule();
    if (module == null)
        return;
    final String packageName = module.packageName;
    PreferenceManager prefManager = getPreferenceManager();
    prefManager.setSharedPreferencesName("module_settings");
    PrefixedSharedPreferences.injectToPreferenceManager(prefManager, module.packageName);
    addPreferencesFromResource(R.xml.module_prefs);
    SharedPreferences prefs = getActivity().getSharedPreferences("module_settings", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    if (prefs.getBoolean("no_global", true)) {
        for (Map.Entry<String, ?> k : prefs.getAll().entrySet()) {
            if (prefs.getString(k.getKey(), "").equals("global")) {
                editor.putString(k.getKey(), "").apply();
            }
        }
        editor.putBoolean("no_global", false).apply();
    }
    findPreference("release_type").setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            RepoLoader.getInstance().setReleaseTypeLocal(packageName, (String) newValue);
            return true;
        }
    });
}
Also used : PrefixedSharedPreferences(de.robv.android.xposed.installer.util.PrefixedSharedPreferences) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) Module(de.robv.android.xposed.installer.repo.Module) PreferenceManager(android.preference.PreferenceManager) Map(java.util.Map)

Example 12 with PreferenceManager

use of android.preference.PreferenceManager in project material-dialogs by afollestad.

the class PrefUtil method unregisterOnActivityDestroyListener.

static void unregisterOnActivityDestroyListener(@NonNull Preference preference, @NonNull PreferenceManager.OnActivityDestroyListener listener) {
    try {
        PreferenceManager pm = preference.getPreferenceManager();
        Method method = pm.getClass().getDeclaredMethod("unregisterOnActivityDestroyListener", PreferenceManager.OnActivityDestroyListener.class);
        method.setAccessible(true);
        method.invoke(pm, listener);
    } catch (Exception ignored) {
    }
}
Also used : Method(java.lang.reflect.Method) PreferenceManager(android.preference.PreferenceManager)

Example 13 with PreferenceManager

use of android.preference.PreferenceManager in project android_packages_apps_DSPManager by CyanogenMod.

the class DSPScreen method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    PreferenceManager prefMgr = getPreferenceManager();
    prefMgr.getSharedPreferences().unregisterOnSharedPreferenceChangeListener(listener);
}
Also used : PreferenceManager(android.preference.PreferenceManager)

Example 14 with PreferenceManager

use of android.preference.PreferenceManager in project assertj-android by square.

the class AbstractPreferenceAssert method hasPreferenceManager.

public S hasPreferenceManager(PreferenceManager manager) {
    isNotNull();
    PreferenceManager actualManager = actual.getPreferenceManager();
    //
    assertThat(actualManager).overridingErrorMessage("Expected preference manager <%s> but was <%s>.", manager, //
    actualManager).isSameAs(manager);
    return myself;
}
Also used : PreferenceManager(android.preference.PreferenceManager)

Example 15 with PreferenceManager

use of android.preference.PreferenceManager in project Etar-Calendar by Etar-Group.

the class GeneralPreferences method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    final Activity activity = getActivity();
    // Make sure to always use the same preferences file regardless of the package name
    // we're running under
    final PreferenceManager preferenceManager = getPreferenceManager();
    final SharedPreferences sharedPreferences = getSharedPreferences(activity);
    preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);
    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.general_preferences);
    final PreferenceScreen preferenceScreen = getPreferenceScreen();
    mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
    mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
    Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null || !vibrator.hasVibrator()) {
        PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
        mAlertGroup.removePreference(mVibrate);
    }
    mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
    String ringToneUri = Utils.getRingTonePreference(activity);
    // Set the ringToneUri to the backup-able shared pref only so that
    // the Ringtone dialog will open up with the correct value.
    final Editor editor = preferenceScreen.getEditor();
    editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();
    String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
    mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);
    mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
    mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
    mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
    mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
    mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
    mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
    mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
    mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
    mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
    mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
    buildSnoozeDelayEntries();
    mTheme.setSummary(mTheme.getEntry());
    mWeekStart.setSummary(mWeekStart.getEntry());
    mDayWeek.setSummary(mDayWeek.getEntry());
    mDefaultReminder.setSummary(mDefaultReminder.getEntry());
    mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
    mDefaultStart.setSummary(mDefaultStart.getEntry());
    // This triggers an asynchronous call to the provider to refresh the data in shared pref
    mTimeZoneId = Utils.getTimeZone(activity, null);
    SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);
    // off, we will explicitly read it.
    if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
        mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
    }
    mHomeTZ.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            showTimezoneDialog();
            return true;
        }
    });
    if (mTzPickerUtils == null) {
        mTzPickerUtils = new TimeZonePickerUtils(getActivity());
    }
    CharSequence timezoneName = mTzPickerUtils.getGmtDisplayName(getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
    mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);
    TimeZonePickerDialog tzpd = (TimeZonePickerDialog) activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
    if (tzpd != null) {
        tzpd.setOnTimeZoneSetListener(this);
    }
    migrateOldPreferences(sharedPreferences);
    updateChildPreferences();
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) PreferenceManager(android.preference.PreferenceManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) TimeZonePickerUtils(com.android.timezonepicker.TimeZonePickerUtils) TimeZonePickerDialog(com.android.timezonepicker.TimeZonePickerDialog) Vibrator(android.os.Vibrator) Editor(android.content.SharedPreferences.Editor)

Aggregations

PreferenceManager (android.preference.PreferenceManager)16 Activity (android.app.Activity)3 SharedPreferences (android.content.SharedPreferences)3 Preference (android.preference.Preference)3 Method (java.lang.reflect.Method)3 Test (org.junit.Test)2 TimePickerDialog (android.app.TimePickerDialog)1 Editor (android.content.SharedPreferences.Editor)1 Vibrator (android.os.Vibrator)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 ListPreference (android.preference.ListPreference)1 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)1 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)1 PreferenceCategory (android.preference.PreferenceCategory)1 PreferenceScreen (android.preference.PreferenceScreen)1 RingtonePreference (android.preference.RingtonePreference)1 ListView (android.widget.ListView)1 TimeZonePickerDialog (com.android.timezonepicker.TimeZonePickerDialog)1 TimeZonePickerUtils (com.android.timezonepicker.TimeZonePickerUtils)1 Module (de.robv.android.xposed.installer.repo.Module)1