Search in sources :

Example 71 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project Signal-Android by WhisperSystems.

the class AdvancedPreferenceFragment method initializePushMessagingToggle.

private void initializePushMessagingToggle() {
    CheckBoxPreference preference = (CheckBoxPreference) this.findPreference(PUSH_MESSAGING_PREF);
    if (TextSecurePreferences.isPushRegistered(getActivity())) {
        preference.setChecked(true);
        preference.setSummary(TextSecurePreferences.getLocalNumber(getActivity()));
    } else {
        preference.setChecked(false);
        preference.setSummary(R.string.preferences__free_private_messages_and_calls);
    }
    preference.setOnPreferenceChangeListener(new PushMessagingClickListener());
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference)

Example 72 with CheckBoxPreference

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

the class Preferences method onCreate.

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    getDelegate().installViewFactory();
    getDelegate().onCreate(savedInstanceState);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.actionbar_settings);
    // For adding content description tag to a title field in the action bar
    int actionBarTitleId = getResources().getIdentifier("action_bar_title", "id", "android");
    View actionBarTitleView = getWindow().getDecorView().findViewById(actionBarTitleId);
    if (actionBarTitleView != null) {
        // it's null in Android 2.x
        getWindow().getDecorView().findViewById(actionBarTitleId).setContentDescription(getString(R.string.actionbar_settings));
    }
    // Load package info
    String temp;
    try {
        PackageInfo pkg = getPackageManager().getPackageInfo(getPackageName(), 0);
        temp = pkg.versionName;
    } catch (NameNotFoundException e) {
        temp = "";
        Log_OC.e(TAG, "Error while showing about dialog", e);
    }
    final String appVersion = temp;
    // Register context menu for list of preferences.
    registerForContextMenu(getListView());
    pCode = (CheckBoxPreference) findPreference(PassCodeActivity.PREFERENCE_SET_PASSCODE);
    if (pCode != null) {
        pCode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Intent i = new Intent(getApplicationContext(), PassCodeActivity.class);
                Boolean incoming = (Boolean) newValue;
                i.setAction(incoming ? PassCodeActivity.ACTION_REQUEST_WITH_RESULT : PassCodeActivity.ACTION_CHECK_WITH_RESULT);
                startActivityForResult(i, incoming ? ACTION_REQUEST_PASSCODE : ACTION_CONFIRM_PASSCODE);
                // Don't update just yet, we will decide on it in onActivityResult
                return false;
            }
        });
    }
    PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
    boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
    Preference pHelp = findPreference("help");
    if (pHelp != null) {
        if (helpEnabled) {
            pHelp.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String helpWeb = (String) getText(R.string.url_help);
                    if (helpWeb != null && helpWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(helpWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pHelp);
        }
    }
    boolean recommendEnabled = getResources().getBoolean(R.bool.recommend_enabled);
    Preference pRecommend = findPreference("recommend");
    if (pRecommend != null) {
        if (recommendEnabled) {
            pRecommend.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("text/plain");
                    intent.setData(Uri.parse(getString(R.string.mail_recommend)));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    String appName = getString(R.string.app_name);
                    String downloadUrl = getString(R.string.url_app_download);
                    String recommendSubject = String.format(getString(R.string.recommend_subject), appName);
                    String recommendText = String.format(getString(R.string.recommend_text), appName, downloadUrl);
                    intent.putExtra(Intent.EXTRA_SUBJECT, recommendSubject);
                    intent.putExtra(Intent.EXTRA_TEXT, recommendText);
                    startActivity(intent);
                    return (true);
                }
            });
        } else {
            preferenceCategory.removePreference(pRecommend);
        }
    }
    boolean feedbackEnabled = getResources().getBoolean(R.bool.feedback_enabled);
    Preference pFeedback = findPreference("feedback");
    if (pFeedback != null) {
        if (feedbackEnabled) {
            pFeedback.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String feedbackMail = (String) getText(R.string.mail_feedback);
                    String feedback = (String) getText(R.string.prefs_feedback) + " - android v" + appVersion;
                    Intent intent = new Intent(Intent.ACTION_SENDTO);
                    intent.setType("text/plain");
                    intent.putExtra(Intent.EXTRA_SUBJECT, feedback);
                    intent.setData(Uri.parse(feedbackMail));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pFeedback);
        }
    }
    boolean privacyPolicyEnabled = getResources().getBoolean(R.bool.privacy_policy_enabled);
    Preference pPrivacyPolicy = findPreference("privacyPolicy");
    if (pPrivacyPolicy != null) {
        if (privacyPolicyEnabled) {
            pPrivacyPolicy.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent privacyPolicyIntent = new Intent(getApplicationContext(), PrivacyPolicyActivity.class);
                    startActivity(privacyPolicyIntent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pPrivacyPolicy);
        }
    }
    boolean loggerEnabled = getResources().getBoolean(R.bool.logger_enabled) || BuildConfig.DEBUG;
    Preference pLogger = findPreference("logger");
    if (pLogger != null) {
        if (loggerEnabled) {
            pLogger.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    Intent loggerIntent = new Intent(getApplicationContext(), LogHistoryActivity.class);
                    startActivity(loggerIntent);
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pLogger);
        }
    }
    boolean imprintEnabled = getResources().getBoolean(R.bool.imprint_enabled);
    Preference pImprint = findPreference("imprint");
    if (pImprint != null) {
        if (imprintEnabled) {
            pImprint.setOnPreferenceClickListener(new OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    String imprintWeb = (String) getText(R.string.url_imprint);
                    if (imprintWeb != null && imprintWeb.length() > 0) {
                        Uri uriUrl = Uri.parse(imprintWeb);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
                        startActivity(intent);
                    }
                    //ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
                    return true;
                }
            });
        } else {
            preferenceCategory.removePreference(pImprint);
        }
    }
    mPrefInstantUploadPath = findPreference("instant_upload_path");
    if (mPrefInstantUploadPath != null) {
        mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
                    mUploadPath += OCFile.PATH_SEPARATOR;
                }
                Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
                startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
                return true;
            }
        });
    }
    mPrefInstantUploadCategory = (PreferenceCategory) findPreference("instant_uploading_category");
    mPrefInstantUploadWiFi = findPreference("instant_upload_on_wifi");
    mPrefInstantUpload = findPreference("instant_uploading");
    toggleInstantPictureOptions(((CheckBoxPreference) mPrefInstantUpload).isChecked());
    mPrefInstantUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean enableInstantPicture = (Boolean) newValue;
            toggleInstantPictureOptions(enableInstantPicture);
            toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), enableInstantPicture);
            return true;
        }
    });
    mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path");
    if (mPrefInstantVideoUploadPath != null) {
        mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
                    mUploadVideoPath += OCFile.PATH_SEPARATOR;
                }
                Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
                startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
                return true;
            }
        });
    }
    mPrefInstantVideoUploadWiFi = findPreference("instant_video_upload_on_wifi");
    mPrefInstantVideoUpload = findPreference("instant_video_uploading");
    toggleInstantVideoOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked());
    mPrefInstantVideoUpload.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            toggleInstantVideoOptions((Boolean) newValue);
            toggleInstantUploadCommonOptions((Boolean) newValue, ((CheckBoxPreference) mPrefInstantUpload).isChecked());
            return true;
        }
    });
    mPrefInstantUploadSourcePath = findPreference("instant_upload_source_path");
    if (mPrefInstantUploadSourcePath != null) {
        mPrefInstantUploadSourcePath.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (!mSourcePath.endsWith(File.separator)) {
                    mSourcePath += File.separator;
                }
                LocalFolderPickerActivity.startLocalFolderPickerActivityForResult(Preferences.this, mSourcePath, ACTION_SELECT_SOURCE_PATH);
                return true;
            }
        });
    } else {
        Log_OC.e(TAG, "Lost preference instant_upload_source_path");
    }
    mPrefInstantUploadBehaviour = findPreference("prefs_instant_behaviour");
    toggleInstantUploadCommonOptions(((CheckBoxPreference) mPrefInstantVideoUpload).isChecked(), ((CheckBoxPreference) mPrefInstantUpload).isChecked());
    /* About App */
    pAboutApp = (Preference) findPreference("about_app");
    if (pAboutApp != null) {
        pAboutApp.setTitle(String.format(getString(R.string.about_android), getString(R.string.app_name)));
        pAboutApp.setSummary(String.format(getString(R.string.about_version), appVersion));
    }
    loadInstantUploadPath();
    loadInstantUploadVideoPath();
    loadInstantUploadSourcePath();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) CheckBoxPreference(android.preference.CheckBoxPreference) PackageInfo(android.content.pm.PackageInfo) Intent(android.content.Intent) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View) Uri(android.net.Uri) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ActionBar(android.support.v7.app.ActionBar)

Example 73 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project SeriesGuide by UweTrottmann.

the class ListWidgetPreferenceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // use the settings file specific to widgets
    getPreferenceManager().setSharedPreferencesName(WidgetSettings.SETTINGS_FILE);
    getPreferenceManager().setSharedPreferencesMode(0);
    // create a widget specific settings screen
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    int appWidgetId = getArguments().getInt("appWidgetId");
    // widget type setting
    final ListPreference typePref = new ListPreference(getActivity());
    typePref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_LISTTYPE + appWidgetId);
    typePref.setTitle(R.string.pref_widget_type);
    typePref.setEntries(R.array.widgetType);
    typePref.setEntryValues(R.array.widgetTypeData);
    typePref.setDefaultValue(getString(R.string.widget_default_type));
    typePref.setPositiveButtonText(null);
    typePref.setNegativeButtonText(null);
    preferenceScreen.addPreference(typePref);
    // widget show type sort order setting
    final ListPreference sortPref = new ListPreference(getActivity());
    sortPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_SHOWS_SORT_ORDER + appWidgetId);
    sortPref.setTitle(R.string.action_shows_sort);
    sortPref.setEntries(R.array.widgetShowSortOrder);
    sortPref.setEntryValues(R.array.widgetShowSortOrderData);
    sortPref.setDefaultValue(getString(R.string.widget_default_show_sort_order));
    sortPref.setPositiveButtonText(null);
    sortPref.setNegativeButtonText(null);
    preferenceScreen.addPreference(sortPref);
    // only favorite shows setting
    final CheckBoxPreference onlyFavoritesPref = new CheckBoxPreference(getActivity());
    onlyFavoritesPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_ONLY_FAVORITES + appWidgetId);
    onlyFavoritesPref.setTitle(R.string.only_favorites);
    onlyFavoritesPref.setDefaultValue(false);
    preferenceScreen.addPreference(onlyFavoritesPref);
    // hide watched setting
    final CheckBoxPreference hideWatchedPreference = new CheckBoxPreference(getActivity());
    hideWatchedPreference.setKey(WidgetSettings.KEY_PREFIX_WIDGET_HIDE_WATCHED + appWidgetId);
    hideWatchedPreference.setTitle(R.string.hide_watched);
    hideWatchedPreference.setDefaultValue(true);
    preferenceScreen.addPreference(hideWatchedPreference);
    // widget theme setting
    ListPreference themePref = new ListPreference(getActivity());
    themePref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_THEME + appWidgetId);
    themePref.setTitle(R.string.pref_theme);
    themePref.setEntries(R.array.widgetTheme);
    themePref.setEntryValues(R.array.widgetThemeData);
    themePref.setDefaultValue("0");
    themePref.setPositiveButtonText(null);
    themePref.setNegativeButtonText(null);
    preferenceScreen.addPreference(themePref);
    // background setting
    ListPreference backgroundPref = new ListPreference(getActivity());
    backgroundPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_BACKGROUND_OPACITY + appWidgetId);
    backgroundPref.setTitle(R.string.pref_widget_opacity);
    backgroundPref.setEntries(R.array.widgetOpacity);
    backgroundPref.setEntryValues(R.array.widgetOpacityData);
    backgroundPref.setDefaultValue(WidgetSettings.DEFAULT_WIDGET_BACKGROUND_OPACITY);
    backgroundPref.setPositiveButtonText(null);
    backgroundPref.setNegativeButtonText(null);
    preferenceScreen.addPreference(backgroundPref);
    setPreferenceScreen(preferenceScreen);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), typePref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), sortPref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), backgroundPref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), themePref);
    // disable type and background pref for non-supporters
    if (!Utils.hasAccessToX(getActivity())) {
        typePref.setEnabled(false);
        typePref.setSummary(R.string.onlyx);
        themePref.setEnabled(false);
        themePref.setSummary(R.string.onlyx);
        backgroundPref.setEnabled(false);
        backgroundPref.setSummary(R.string.onlyx);
    }
    // disable episode related setting if selecting show widget type
    preferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            if (!isAdded()) {
                // no longer attached to activity
                return;
            }
            if (typePref.getKey().equals(key)) {
                String newTypeValue = typePref.getValue();
                boolean displayingShows = getString(R.string.widget_type_shows).equals(newTypeValue);
                sortPref.setEnabled(displayingShows);
                hideWatchedPreference.setEnabled(!displayingShows);
            }
        }
    };
    // trigger the listener to handle the current state
    preferenceChangeListener.onSharedPreferenceChanged(getPreferenceManager().getSharedPreferences(), typePref.getKey());
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(preferenceChangeListener);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) ListPreference(android.preference.ListPreference)

Example 74 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 75 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)

Aggregations

CheckBoxPreference (android.preference.CheckBoxPreference)138 Preference (android.preference.Preference)70 ListPreference (android.preference.ListPreference)53 Intent (android.content.Intent)28 SharedPreferences (android.content.SharedPreferences)23 EditTextPreference (android.preference.EditTextPreference)23 PreferenceCategory (android.preference.PreferenceCategory)22 PreferenceScreen (android.preference.PreferenceScreen)22 ArrayList (java.util.ArrayList)17 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)13 DialogInterface (android.content.DialogInterface)11 Context (android.content.Context)10 PackageManager (android.content.pm.PackageManager)10 SuppressLint (android.annotation.SuppressLint)8 Bundle (android.os.Bundle)7 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)7 PreferenceManager (android.preference.PreferenceManager)7 File (java.io.File)7 AlertDialog (android.app.AlertDialog)6 Uri (android.net.Uri)6