Search in sources :

Example 41 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project double-espresso by JakeWharton.

the class PreferenceMatchersTest method testWithKey.

public void testWithKey() {
    CheckBoxPreference pref = new CheckBoxPreference(getInstrumentation().getContext());
    pref.setKey("foo");
    assertThat(pref, withKey("foo"));
    assertThat(pref, not(withKey("bar")));
    assertThat(pref, withKey(is("foo")));
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference)

Example 42 with CheckBoxPreference

use of android.preference.CheckBoxPreference 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)

Example 43 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project zxing by zxing.

the class PreferencesFragment method disableLastCheckedPref.

private void disableLastCheckedPref() {
    Collection<CheckBoxPreference> checked = new ArrayList<>(checkBoxPrefs.length);
    for (CheckBoxPreference pref : checkBoxPrefs) {
        if (pref.isChecked()) {
            checked.add(pref);
        }
    }
    boolean disable = checked.size() <= 1;
    for (CheckBoxPreference pref : checkBoxPrefs) {
        pref.setEnabled(!(disable && checked.contains(pref)));
    }
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) ArrayList(java.util.ArrayList)

Example 44 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project AisenWeiBo by wangdan.

the class BasicItemSettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    addPreferencesFromResource(R.xml.ui_basic_settings_item);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GlobalContext.getInstance());
    int value = 0;
    // 主题
    pTheme = (Preference) findPreference("pTheme");
    pTheme.setOnPreferenceClickListener(this);
    pTheme.setSummary(getResources().getStringArray(R.array.mdColorNames)[AppSettings.getThemeColor()]);
    //        findPreference("pThemeCustom").setOnPreferenceClickListener(this);
    pFastScrollBar = (CheckBoxPreference) findPreference("pFastScrollBar");
    if (pFastScrollBar != null)
        pFastScrollBar.setOnPreferenceChangeListener(this);
    pPicSavePath = (Preference) findPreference("pPicSavePath");
    pPicSavePath.setOnPreferenceClickListener(this);
    //		pPicSavePath.setSummary(SystemUtility.getSdcardPath() + File.separator + AppSettings.getImageSavePath() + File.separator);
    pPicSavePath.setSummary("/sdcard" + File.separator + AppSettings.getImageSavePath() + File.separator);
    pClearRecentMention = (Preference) findPreference("pClearRecentMention");
    pClearRecentMention.setOnPreferenceClickListener(this);
    setMentionHint();
    pTextSize = (ListPreference) findPreference("pTextSize");
    pTextSize.setOnPreferenceChangeListener(this);
    value = Integer.parseInt(prefs.getString("pTextSize", "4"));
    setTextSize(value);
    pShowRemark = (CheckBoxPreference) findPreference("pShowRemark");
    pShowRemark.setOnPreferenceChangeListener(this);
    pShowDefGroup = (CheckBoxPreference) findPreference("pShowDefGroup");
    if (pShowDefGroup != null)
        pShowDefGroup.setOnPreferenceChangeListener(this);
    //        CheckBoxPreference pDoubleClickToRefresh = (CheckBoxPreference) findPreference("pDoubleClickToRefresh");
    //		pDoubleClickToRefresh.setOnPreferenceChangeListener(this);
    pAutoRefresh = (CheckBoxPreference) findPreference("pAutoRefresh");
    pAutoRefresh.setOnPreferenceChangeListener(this);
    pAutoRefresh.setChecked(SettingUtility.getPermanentSettingAsBool("pAutoRefresh", true));
    pSwipebackEdgeMode = (ListPreference) findPreference("pSwipebackEdgeMode");
    pSwipebackEdgeMode.setOnPreferenceChangeListener(this);
    value = Integer.parseInt(prefs.getString("pSwipebackEdgeMode", "0"));
    setListSetting(value, R.array.swipebackEdgeMode, pSwipebackEdgeMode);
    //        pFabType = (ListPreference) findPreference("pFabType");
    //        pFabType.setOnPreferenceChangeListener(this);
    //        value = Integer.parseInt(prefs.getString("pFabType", "0"));
    //        setListSetting(value, R.array.fabTypes, pFabType);
    pFabPosition = (ListPreference) findPreference("pFabPosition");
    if (pFabPosition != null) {
        pFabPosition.setOnPreferenceChangeListener(this);
        value = Integer.parseInt(prefs.getString("pFabPosition", "1"));
        setListSetting(value, R.array.fabPosition, pFabPosition);
    }
    // 缓存清理
    Preference pClearCache = (Preference) findPreference("pClearCache");
    CacheClearFragment clearFragment = (CacheClearFragment) getActivity().getFragmentManager().findFragmentByTag("CacheClearFragment");
    if (clearFragment == null) {
        clearFragment = new CacheClearFragment();
        getActivity().getFragmentManager().beginTransaction().add(clearFragment, "CacheClearFragment").commit();
    }
    clearFragment.setPreference(pClearCache, MyApplication.getImagePath());
}
Also used : SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SuppressLint(android.annotation.SuppressLint)

Example 45 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project kdeconnect-android by KDE.

the class ShareSettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final CheckBoxPreference customDownloads = (CheckBoxPreference) findPreference("share_destination_custom");
    filePicker = findPreference("share_destination_folder_preference");
    if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
        customDownloads.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                updateFilePickerStatus((Boolean) newValue);
                return true;
            }
        });
        filePicker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
                startActivityForResult(intent, RESULT_PICKER);
                return true;
            }
        });
    } else {
        customDownloads.setEnabled(false);
        filePicker.setEnabled(false);
    }
    boolean customized = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREFERENCE_CUSTOMIZE_DESTINATION, false);
    updateFilePickerStatus(customized);
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) Intent(android.content.Intent)

Aggregations

CheckBoxPreference (android.preference.CheckBoxPreference)49 Preference (android.preference.Preference)31 ListPreference (android.preference.ListPreference)20 PreferenceScreen (android.preference.PreferenceScreen)11 SharedPreferences (android.content.SharedPreferences)10 EditTextPreference (android.preference.EditTextPreference)10 PreferenceCategory (android.preference.PreferenceCategory)9 Intent (android.content.Intent)8 ArrayList (java.util.ArrayList)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)6 Uri (android.net.Uri)5 View (android.view.View)5 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)4 PreferenceManager (android.preference.PreferenceManager)4 DialogInterface (android.content.DialogInterface)3 PackageInfo (android.content.pm.PackageInfo)3 Resources (android.content.res.Resources)3 Build (android.os.Build)3 Bundle (android.os.Bundle)3 SwitchPreference (android.preference.SwitchPreference)3