Search in sources :

Example 16 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project AndroidChromium by JackyAndroid.

the class SyncCustomizationFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mProfileSyncService = ProfileSyncService.get();
    assert mProfileSyncService != null;
    mIsBackendInitialized = mProfileSyncService.isBackendInitialized();
    mIsPassphraseRequired = mIsBackendInitialized && mProfileSyncService.isPassphraseRequiredForDecryption();
    getActivity().setTitle(R.string.sign_in_sync);
    View view = super.onCreateView(inflater, container, savedInstanceState);
    addPreferencesFromResource(R.xml.sync_customization_preferences);
    mSyncEverything = (SwitchPreference) findPreference(PREFERENCE_SYNC_EVERYTHING);
    mSyncAutofill = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_AUTOFILL);
    mSyncBookmarks = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_BOOKMARKS);
    mSyncOmnibox = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_OMNIBOX);
    mSyncPasswords = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_PASSWORDS);
    mSyncRecentTabs = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_RECENT_TABS);
    mSyncSettings = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_SETTINGS);
    mPaymentsIntegration = (CheckBoxPreference) findPreference(PREFERENCE_PAYMENTS_INTEGRATION);
    mSyncEncryption = findPreference(PREFERENCE_ENCRYPTION);
    mSyncEncryption.setOnPreferenceClickListener(this);
    mManageSyncData = findPreference(PREFERENCE_SYNC_MANAGE_DATA);
    mManageSyncData.setOnPreferenceClickListener(this);
    mSyncErrorCard = findPreference(PREFERENCE_SYNC_ERROR_CARD);
    mSyncErrorCard.setOnPreferenceClickListener(this);
    mAllTypes = new CheckBoxPreference[] { mSyncAutofill, mSyncBookmarks, mSyncOmnibox, mSyncPasswords, mSyncRecentTabs, mSyncSettings, mPaymentsIntegration };
    mSyncEverything.setOnPreferenceChangeListener(this);
    for (CheckBoxPreference type : mAllTypes) {
        type.setOnPreferenceChangeListener(this);
    }
    mSyncSwitchPreference = (ChromeSwitchPreference) findPreference(PREF_SYNC_SWITCH);
    mSyncSwitchPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            assert canDisableSync();
            if ((boolean) newValue) {
                mProfileSyncService.requestStart();
            } else {
                stopSync();
            }
            // Must be done asynchronously because the switch state isn't updated
            // until after this function exits.
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    updateSyncStateFromSwitch();
                }
            });
            return true;
        }
    });
    mSyncedAccountPreference = (SyncedAccountPreference) findPreference(PREFERENCE_SYNC_ACCOUNT_LIST);
    mSyncedAccountPreference.setOnPreferenceChangeListener(new SyncAccountSwitcher(getActivity(), mSyncedAccountPreference));
    return view;
}
Also used : SyncAccountSwitcher(org.chromium.chrome.browser.sync.SyncAccountSwitcher) CheckBoxPreference(android.preference.CheckBoxPreference) ChromeSwitchPreference(org.chromium.chrome.browser.preferences.ChromeSwitchPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) SyncedAccountPreference(org.chromium.chrome.browser.preferences.SyncedAccountPreference) SwitchPreference(android.preference.SwitchPreference) Handler(android.os.Handler) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) View(android.view.View)

Example 17 with CheckBoxPreference

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

the class PreferenceController method buildAutodownloadSelectedNetworsPreference.

private void buildAutodownloadSelectedNetworsPreference() {
    final Activity activity = ui.getActivity();
    if (selectedNetworks != null) {
        clearAutodownloadSelectedNetworsPreference();
    }
    // get configured networks
    WifiManager wifiservice = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    List<WifiConfiguration> networks = wifiservice.getConfiguredNetworks();
    if (networks != null) {
        Collections.sort(networks, new Comparator<WifiConfiguration>() {

            @Override
            public int compare(WifiConfiguration x, WifiConfiguration y) {
                return x.SSID.compareTo(y.SSID);
            }
        });
        selectedNetworks = new CheckBoxPreference[networks.size()];
        List<String> prefValues = Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks());
        PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN);
        Preference.OnPreferenceClickListener clickListener = preference -> {
            if (preference instanceof CheckBoxPreference) {
                String key = preference.getKey();
                List<String> prefValuesList = new ArrayList<>(Arrays.asList(UserPreferences.getAutodownloadSelectedNetworks()));
                boolean newValue = ((CheckBoxPreference) preference).isChecked();
                Log.d(TAG, "Selected network " + key + ". New state: " + newValue);
                int index = prefValuesList.indexOf(key);
                if (index >= 0 && !newValue) {
                    prefValuesList.remove(index);
                } else if (index < 0 && newValue) {
                    prefValuesList.add(key);
                }
                UserPreferences.setAutodownloadSelectedNetworks(prefValuesList.toArray(new String[prefValuesList.size()]));
                return true;
            } else {
                return false;
            }
        };
        // value
        for (int i = 0; i < networks.size(); i++) {
            WifiConfiguration config = networks.get(i);
            CheckBoxPreference pref = new CheckBoxPreference(activity);
            String key = Integer.toString(config.networkId);
            pref.setTitle(config.SSID);
            pref.setKey(key);
            pref.setOnPreferenceClickListener(clickListener);
            pref.setPersistent(false);
            pref.setChecked(prefValues.contains(key));
            selectedNetworks[i] = pref;
            prefScreen.addPreference(pref);
        }
    } else {
        Log.e(TAG, "Couldn't get list of configure Wi-Fi networks");
    }
}
Also used : Arrays(java.util.Arrays) DateUtils(android.text.format.DateUtils) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) FlattrUtils(de.danoeh.antennapod.core.util.flattr.FlattrUtils) PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) Manifest(android.Manifest) ExportWorker(de.danoeh.antennapod.asynctask.ExportWorker) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) GpodnetSyncService(de.danoeh.antennapod.core.service.GpodnetSyncService) Log(android.util.Log) WifiConfiguration(android.net.wifi.WifiConfiguration) GpodnetSetHostnameDialog(de.danoeh.antennapod.dialog.GpodnetSetHostnameDialog) GregorianCalendar(java.util.GregorianCalendar) ContextCompat(android.support.v4.content.ContextCompat) ActivityCompat(android.support.v4.app.ActivityCompat) DateFormat(android.text.format.DateFormat) ListPreference(android.preference.ListPreference) List(java.util.List) MainActivity(de.danoeh.antennapod.activity.MainActivity) HtmlWriter(de.danoeh.antennapod.core.export.html.HtmlWriter) ActivityNotFoundException(android.content.ActivityNotFoundException) Html(android.text.Html) AutoFlattrPreferenceDialog(de.danoeh.antennapod.dialog.AutoFlattrPreferenceDialog) ListView(android.widget.ListView) Snackbar(android.support.design.widget.Snackbar) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Subscription(rx.Subscription) TextWatcher(android.text.TextWatcher) Converter(de.danoeh.antennapod.core.util.Converter) Context(android.content.Context) TimePickerDialog(android.app.TimePickerDialog) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) AuthenticationDialog(de.danoeh.antennapod.dialog.AuthenticationDialog) ExportWriter(de.danoeh.antennapod.core.export.ExportWriter) Intent(android.content.Intent) CheckBoxPreference(android.preference.CheckBoxPreference) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Editable(android.text.Editable) ArrayList(java.util.ArrayList) Observable(rx.Observable) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) SuppressLint(android.annotation.SuppressLint) OpmlWriter(de.danoeh.antennapod.core.export.opml.OpmlWriter) Calendar(java.util.Calendar) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Toast(android.widget.Toast) CrashReportWriter(de.danoeh.antennapod.CrashReportWriter) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Build(android.os.Build) ProxyDialog(de.danoeh.antennapod.dialog.ProxyDialog) R(de.danoeh.antennapod.R) PreferenceActivityGingerbread(de.danoeh.antennapod.activity.PreferenceActivityGingerbread) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) TimeUnit(java.util.concurrent.TimeUnit) WifiManager(android.net.wifi.WifiManager) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) GpodnetPreferences(de.danoeh.antennapod.core.preferences.GpodnetPreferences) Comparator(java.util.Comparator) Activity(android.app.Activity) Collections(java.util.Collections) EditText(android.widget.EditText) Resources(android.content.res.Resources) WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration) PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) MainActivity(de.danoeh.antennapod.activity.MainActivity) AboutActivity(de.danoeh.antennapod.activity.AboutActivity) StatisticsActivity(de.danoeh.antennapod.activity.StatisticsActivity) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) DirectoryChooserActivity(de.danoeh.antennapod.activity.DirectoryChooserActivity) Activity(android.app.Activity) SuppressLint(android.annotation.SuppressLint) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) List(java.util.List) ArrayList(java.util.ArrayList)

Example 18 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project weex-example by KalicyZhou.

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 19 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project Lightning-Browser by anthonycr.

the class PrivacySettingsFragment method initPrefs.

private void initPrefs() {
    Preference clearcache = findPreference(SETTINGS_CLEARCACHE);
    Preference clearhistory = findPreference(SETTINGS_CLEARHISTORY);
    Preference clearcookies = findPreference(SETTINGS_CLEARCOOKIES);
    Preference clearwebstorage = findPreference(SETTINGS_CLEARWEBSTORAGE);
    CheckBoxPreference cblocation = (CheckBoxPreference) findPreference(SETTINGS_LOCATION);
    CheckBoxPreference cb3cookies = (CheckBoxPreference) findPreference(SETTINGS_THIRDPCOOKIES);
    CheckBoxPreference cbsavepasswords = (CheckBoxPreference) findPreference(SETTINGS_SAVEPASSWORD);
    CheckBoxPreference cbcacheexit = (CheckBoxPreference) findPreference(SETTINGS_CACHEEXIT);
    CheckBoxPreference cbhistoryexit = (CheckBoxPreference) findPreference(SETTINGS_HISTORYEXIT);
    CheckBoxPreference cbcookiesexit = (CheckBoxPreference) findPreference(SETTINGS_COOKIEEXIT);
    CheckBoxPreference cbwebstorageexit = (CheckBoxPreference) findPreference(SETTINGS_WEBSTORAGEEXIT);
    CheckBoxPreference cbDoNotTrack = (CheckBoxPreference) findPreference(SETTINGS_DONOTTRACK);
    CheckBoxPreference cbIdentifyingHeaders = (CheckBoxPreference) findPreference(SETTINGS_IDENTIFYINGHEADERS);
    clearcache.setOnPreferenceClickListener(this);
    clearhistory.setOnPreferenceClickListener(this);
    clearcookies.setOnPreferenceClickListener(this);
    clearwebstorage.setOnPreferenceClickListener(this);
    cblocation.setOnPreferenceChangeListener(this);
    cb3cookies.setOnPreferenceChangeListener(this);
    cbsavepasswords.setOnPreferenceChangeListener(this);
    cbcacheexit.setOnPreferenceChangeListener(this);
    cbhistoryexit.setOnPreferenceChangeListener(this);
    cbcookiesexit.setOnPreferenceChangeListener(this);
    cbwebstorageexit.setOnPreferenceChangeListener(this);
    cbDoNotTrack.setOnPreferenceChangeListener(this);
    cbIdentifyingHeaders.setOnPreferenceChangeListener(this);
    cblocation.setChecked(mPreferenceManager.getLocationEnabled());
    cbsavepasswords.setChecked(mPreferenceManager.getSavePasswordsEnabled());
    cbcacheexit.setChecked(mPreferenceManager.getClearCacheExit());
    cbhistoryexit.setChecked(mPreferenceManager.getClearHistoryExitEnabled());
    cbcookiesexit.setChecked(mPreferenceManager.getClearCookiesExitEnabled());
    cb3cookies.setChecked(mPreferenceManager.getBlockThirdPartyCookiesEnabled());
    cbwebstorageexit.setChecked(mPreferenceManager.getClearWebStorageExitEnabled());
    cbDoNotTrack.setChecked(mPreferenceManager.getDoNotTrackEnabled() && Utils.doesSupportHeaders());
    cbIdentifyingHeaders.setChecked(mPreferenceManager.getRemoveIdentifyingHeadersEnabled() && Utils.doesSupportHeaders());
    cbDoNotTrack.setEnabled(Utils.doesSupportHeaders());
    cbIdentifyingHeaders.setEnabled(Utils.doesSupportHeaders());
    String identifyingHeadersSummary = LightningView.HEADER_REQUESTED_WITH + ", " + LightningView.HEADER_WAP_PROFILE;
    cbIdentifyingHeaders.setSummary(identifyingHeadersSummary);
    cb3cookies.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
}
Also used : CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) CheckBoxPreference(android.preference.CheckBoxPreference)

Example 20 with CheckBoxPreference

use of android.preference.CheckBoxPreference in project android_packages_apps_FM by CyanogenMod.

the class Settings method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    int index = 0;
    if (mPrefs == null) {
        return null;
    }
    // Root
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(this);
    // Band/Country
    String[] summaryBandItems = getResources().getStringArray(R.array.regional_band_summary);
    mBandPreference = new ListPreference(this);
    mBandPreference.setEntries(R.array.regional_band_entries);
    mBandPreference.setEntryValues(R.array.regional_band_values);
    mBandPreference.setDialogTitle(R.string.sel_band_menu);
    mBandPreference.setKey(REGIONAL_BAND_KEY);
    mBandPreference.setTitle(R.string.regional_band);
    index = FmSharedPreferences.getCountry();
    Log.d(LOGTAG, "createPreferenceHierarchy: Country: " + index);
    // Get the preference and list the value.
    if ((index < 0) || (index >= summaryBandItems.length)) {
        index = 0;
    }
    Log.d(LOGTAG, "createPreferenceHierarchy: CountrySummary: " + summaryBandItems[index]);
    mBandPreference.setSummary(summaryBandItems[index]);
    mBandPreference.setValueIndex(index);
    root.addPreference(mBandPreference);
    if (mRxMode) {
        // Audio Output (Stereo or Mono)
        String[] summaryAudioModeItems = getResources().getStringArray(R.array.ster_mon_entries);
        mAudioPreference = new ListPreference(this);
        mAudioPreference.setEntries(R.array.ster_mon_entries);
        mAudioPreference.setEntryValues(R.array.ster_mon_values);
        mAudioPreference.setDialogTitle(R.string.sel_audio_output);
        mAudioPreference.setKey(AUDIO_OUTPUT_KEY);
        mAudioPreference.setTitle(R.string.aud_output_mode);
        boolean audiomode = FmSharedPreferences.getAudioOutputMode();
        if (audiomode) {
            index = 0;
        } else {
            index = 1;
        }
        Log.d(LOGTAG, "createPreferenceHierarchy: audiomode: " + audiomode);
        mAudioPreference.setSummary(summaryAudioModeItems[index]);
        mAudioPreference.setValueIndex(index);
        root.addPreference(mAudioPreference);
        // AF Auto Enable (Checkbox)
        mAfPref = new CheckBoxPreference(this);
        mAfPref.setKey(AUTO_AF);
        mAfPref.setTitle(R.string.auto_select_af);
        mAfPref.setSummaryOn(R.string.auto_select_af_enabled);
        mAfPref.setSummaryOff(R.string.auto_select_af_disabled);
        boolean bAFAutoSwitch = FmSharedPreferences.getAutoAFSwitch();
        Log.d(LOGTAG, "createPreferenceHierarchy: bAFAutoSwitch: " + bAFAutoSwitch);
        mAfPref.setChecked(bAFAutoSwitch);
        root.addPreference(mAfPref);
        if (FMRadio.RECORDING_ENABLE) {
            String[] summaryRecordItems = getResources().getStringArray(R.array.record_durations_entries);
            mRecordDurPreference = new ListPreference(this);
            mRecordDurPreference.setEntries(R.array.record_durations_entries);
            mRecordDurPreference.setEntryValues(R.array.record_duration_values);
            mRecordDurPreference.setDialogTitle(R.string.sel_rec_dur);
            mRecordDurPreference.setKey(RECORD_DURATION_KEY);
            mRecordDurPreference.setTitle(R.string.record_dur);
            index = FmSharedPreferences.getRecordDuration();
            Log.d(LOGTAG, "createPreferenceHierarchy: recordDuration: " + index);
            // Get the preference and list the value.
            if ((index < 0) || (index >= summaryRecordItems.length)) {
                index = 0;
            }
            Log.d(LOGTAG, "createPreferenceHierarchy: recordDurationSummary: " + summaryRecordItems[index]);
            mRecordDurPreference.setSummary(summaryRecordItems[index]);
            mRecordDurPreference.setValueIndex(index);
            root.addPreference(mRecordDurPreference);
        }
    }
    mBluetoothBehaviour = new ListPreference(this);
    mBluetoothBehaviour.setEntries(R.array.bt_exit_behaviour_entries);
    mBluetoothBehaviour.setEntryValues(R.array.bt_exit_behaviour_values);
    mBluetoothBehaviour.setDialogTitle(R.string.pref_bt_behaviour_on_exit_dialog_title);
    mBluetoothBehaviour.setKey(BT_EXIT_BEHAVIOUR);
    mBluetoothBehaviour.setTitle(R.string.pref_bt_behaviour_on_exit_title);
    mBluetoothBehaviour.setSummary(R.string.pref_bt_behaviour_on_exit_summary);
    root.addPreference(mBluetoothBehaviour);
    mRemoveHeadset = new CheckBoxPreference(this);
    mRemoveHeadset.setKey(HEADSET_DC_BEHAVIOUR);
    mRemoveHeadset.setTitle(R.string.pref_headset_behaviour_title);
    mRemoveHeadset.setSummary(R.string.pref_headset_behaviour_summary);
    mRemoveHeadset.setChecked(FmSharedPreferences.getHeadsetDcBehaviour());
    root.addPreference(mRemoveHeadset);
    mRestoreDefaultPreference = new Preference(this);
    mRestoreDefaultPreference.setTitle(R.string.settings_revert_defaults_title);
    mRestoreDefaultPreference.setKey(RESTORE_FACTORY_DEFAULT);
    mRestoreDefaultPreference.setSummary(R.string.settings_revert_defaults_summary);
    mRestoreDefaultPreference.setOnPreferenceClickListener(this);
    root.addPreference(mRestoreDefaultPreference);
    // Add a new category
    PreferenceCategory prefCat = new PreferenceCategory(this);
    prefCat.setTitle(R.string.about_title);
    root.addPreference(prefCat);
    mAboutPreference = new Preference(this);
    mAboutPreference.setTitle(R.string.about_title);
    mAboutPreference.setKey(ABOUT_KEY);
    mAboutPreference.setSummary(R.string.about_summary);
    mAboutPreference.setOnPreferenceClickListener(this);
    root.addPreference(mAboutPreference);
    return root;
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference)

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