Search in sources :

Example 1 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ApplicationSettings method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.application_settings);
    mToggleAdvancedSettings = (CheckBoxPreference) findPreference(KEY_TOGGLE_ADVANCED_SETTINGS);
    mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
    getPreferenceScreen().removePreference(mToggleAdvancedSettings);
    // not ready for prime time yet
    if (false) {
        getPreferenceScreen().removePreference(mInstallLocation);
    }
    mInstallLocation = (ListPreference) findPreference(KEY_APP_INSTALL_LOCATION);
    // Is app default install location set?
    boolean userSetInstLocation = (Settings.Global.getInt(getContentResolver(), Settings.Global.SET_INSTALL_LOCATION, 0) != 0);
    if (!userSetInstLocation) {
        getPreferenceScreen().removePreference(mInstallLocation);
    } else {
        mInstallLocation.setValue(getAppInstallLocation());
        mInstallLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

            public boolean onPreferenceChange(Preference preference, Object newValue) {
                String value = (String) newValue;
                handleUpdateAppInstallLocation(value);
                return false;
            }
        });
    }
}
Also used : Preference(android.support.v7.preference.Preference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceChangeListener(android.support.v7.preference.Preference.OnPreferenceChangeListener)

Example 2 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class KeyboardLayoutPickerFragment method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceManager().createPreferenceScreen(getActivity());
    Context context = getActivity();
    for (KeyboardLayout layout : mKeyboardLayouts) {
        CheckBoxPreference pref = new CheckBoxPreference(getPrefContext());
        pref.setTitle(layout.getLabel());
        pref.setSummary(layout.getCollection());
        root.addPreference(pref);
        mPreferenceMap.put(pref, layout);
    }
    return root;
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) KeyboardLayout(android.hardware.input.KeyboardLayout)

Example 3 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LocationSettings method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    final SettingsActivity activity = (SettingsActivity) getActivity();
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.location_settings);
    root = getPreferenceScreen();
    setupManagedProfileCategory(root);
    mLocationMode = root.findPreference(KEY_LOCATION_MODE);
    mLocationMode.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            activity.startPreferencePanel(LocationMode.class.getName(), null, R.string.location_mode_screen_title, null, LocationSettings.this, 0);
            return true;
        }
    });
    mAgpsEnabled = getActivity().getResources().getBoolean(R.bool.config_agps_enabled);
    mAssistedGps = (CheckBoxPreference) root.findPreference(KEY_ASSISTED_GPS);
    if (!mAgpsEnabled) {
        root.removePreference(mAssistedGps);
    }
    if (mAssistedGps != null) {
        mAssistedGps.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.ASSISTED_GPS_ENABLED, 0) == 1);
    }
    mCategoryRecentLocationRequests = (PreferenceCategory) root.findPreference(KEY_RECENT_LOCATION_REQUESTS);
    RecentLocationApps recentApps = new RecentLocationApps(activity);
    List<RecentLocationApps.Request> recentLocationRequests = recentApps.getAppList();
    List<Preference> recentLocationPrefs = new ArrayList<>(recentLocationRequests.size());
    for (final RecentLocationApps.Request request : recentLocationRequests) {
        DimmableIconPreference pref = new DimmableIconPreference(getPrefContext(), request.contentDescription);
        pref.setIcon(request.icon);
        pref.setTitle(request.label);
        if (request.isHighBattery) {
            pref.setSummary(R.string.location_high_battery_use);
        } else {
            pref.setSummary(R.string.location_low_battery_use);
        }
        pref.setOnPreferenceClickListener(new PackageEntryClickedListener(request.packageName, request.userHandle));
        recentLocationPrefs.add(pref);
    }
    if (recentLocationRequests.size() > 0) {
        addPreferencesSorted(recentLocationPrefs, mCategoryRecentLocationRequests);
    } else {
        // If there's no item to display, add a "No recent apps" item.
        Preference banner = new Preference(getPrefContext());
        banner.setLayoutResource(R.layout.location_list_no_item);
        banner.setTitle(R.string.location_no_recent_apps);
        banner.setSelectable(false);
        mCategoryRecentLocationRequests.addPreference(banner);
    }
    boolean lockdownOnLocationAccess = false;
    // injected location services must not be shown.
    if (mManagedProfile != null && mUm.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, mManagedProfile)) {
        lockdownOnLocationAccess = true;
    }
    addLocationServices(activity, root, lockdownOnLocationAccess);
    refreshLocationMode();
    return root;
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) ArrayList(java.util.ArrayList) RecentLocationApps(com.android.settingslib.location.RecentLocationApps) DimmableIconPreference(com.android.settings.DimmableIconPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) DimmableIconPreference(com.android.settings.DimmableIconPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) SettingsActivity(com.android.settings.SettingsActivity)

Example 4 with CheckBoxPreference

use of android.support.v7.preference.CheckBoxPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AdvancedWifiSettings method initPreferences.

private void initPreferences() {
    final Context context = getActivity();
    Intent intent = new Intent(Credentials.INSTALL_AS_USER_ACTION);
    intent.setClassName("com.android.certinstaller", "com.android.certinstaller.CertInstallerMain");
    intent.putExtra(Credentials.EXTRA_INSTALL_AS_UID, android.os.Process.WIFI_UID);
    Preference pref = findPreference(KEY_INSTALL_CREDENTIALS);
    pref.setIntent(intent);
    SwitchPreference enableHs2 = (SwitchPreference) findPreference(KEY_ENABLE_HS2);
    if (enableHs2 != null && getResources().getBoolean(com.android.internal.R.bool.config_passpoint_setting_on)) {
        enableHs2.setOnPreferenceClickListener(new OnPreferenceClickListener() {

            public boolean onPreferenceClick(Preference preference) {
                String key = preference.getKey();
                if (KEY_ENABLE_HS2.equals(key)) {
                    Settings.Global.putInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, ((SwitchPreference) preference).isChecked() ? 1 : 0);
                }
                return true;
            }
        });
        enableHs2.setChecked(Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_HOTSPOT2_ENABLED, WIFI_HS2_DISABLED) == WIFI_HS2_ENABLED);
    } else {
        if (enableHs2 != null) {
            getPreferenceScreen().removePreference(enableHs2);
        }
    }
    Intent wifiDirectIntent = new Intent(context, com.android.settings.Settings.WifiP2pSettingsActivity.class);
    Preference wifiDirectPref = findPreference(KEY_WIFI_DIRECT);
    wifiDirectPref.setIntent(wifiDirectIntent);
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPushPref = findPreference(KEY_WPS_PUSH);
    wpsPushPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.PBC);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PUSH);
            return true;
        }
    });
    // WpsDialog: Create the dialog like WifiSettings does.
    Preference wpsPinPref = findPreference(KEY_WPS_PIN);
    wpsPinPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            WpsFragment wpsFragment = new WpsFragment(WpsInfo.DISPLAY);
            wpsFragment.show(getFragmentManager(), KEY_WPS_PIN);
            return true;
        }
    });
    // Wifi extension requirement
    Preference prioritySettingPref = findPreference(KEY_PRIORITY_SETTINGS);
    if (prioritySettingPref != null) {
        if (!getResources().getBoolean(R.bool.set_wifi_priority)) {
            getPreferenceScreen().removePreference(prioritySettingPref);
        }
    } else {
        Log.d(TAG, "Fail to get priority pref...");
    }
    ListPreference ccodePref = (ListPreference) findPreference(KEY_COUNTRY_CODE);
    if (ccodePref != null) {
        boolean hideWifiRegion = getResources().getBoolean(R.bool.config_hideWifiRegionCode);
        if (hideWifiRegion) {
            removePreference(KEY_COUNTRY_CODE);
        } else {
            ccodePref.setOnPreferenceChangeListener(this);
            String value = mWifiManager.getCountryCode();
            if (value != null) {
                ccodePref.setValue(value);
            } else {
                Log.e(TAG, "Failed to fetch country code");
            }
        }
    }
    mAutoConnectEnablePref = (CheckBoxPreference) findPreference(KEY_AUTO_CONNECT_ENABLE);
    if (mAutoConnectEnablePref != null) {
        if (getResources().getBoolean(R.bool.config_auto_connect_wifi_enabled)) {
            mAutoConnectEnablePref.setChecked(isAutoConnectEnabled());
            mAutoConnectEnablePref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mAutoConnectEnablePref);
        }
    }
    mCellularToWlanPref = (ListPreference) findPreference(KEY_CELLULAR_TO_WLAN);
    if (mCellularToWlanPref != null) {
        if (getResources().getBoolean(R.bool.cell_to_wifi)) {
            int value = getCellularToWlanValue();
            mCellularToWlanPref.setValue(String.valueOf(value));
            updateCellToWlanSummary(mCellularToWlanPref, value);
            mCellularToWlanPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanPref);
        }
    }
    CheckBoxPreference wlanToCellularHintPref = (CheckBoxPreference) findPreference(KEY_WLAN_TO_CELLULAR_HINT);
    if (wlanToCellularHintPref != null) {
        if (getResources().getBoolean(R.bool.wifi_to_cell)) {
            wlanToCellularHintPref.setChecked(isWlanToCellHintEnable());
            wlanToCellularHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(wlanToCellularHintPref);
        }
    }
    CheckBoxPreference notifyConnectedApPref = (CheckBoxPreference) findPreference(KEY_CONNECT_NOTIFY);
    if (notifyConnectedApPref != null) {
        if (getResources().getBoolean(R.bool.connect_to_cmcc_notify)) {
            notifyConnectedApPref.setChecked(ifNotifyConnect());
            notifyConnectedApPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(notifyConnectedApPref);
        }
    }
    mCellularToWlanHintPref = (CheckBoxPreference) findPreference(KEY_CELLULAR_TO_WLAN_HINT);
    if (mCellularToWlanHintPref != null) {
        if (getResources().getBoolean(R.bool.cellular_to_wlan_hint)) {
            mCellularToWlanHintPref.setChecked(isCellularToWlanHintEnable());
            mCellularToWlanHintPref.setOnPreferenceChangeListener(this);
        } else {
            getPreferenceScreen().removePreference(mCellularToWlanHintPref);
        }
    }
}
Also used : Context(android.content.Context) SwitchPreference(android.support.v14.preference.SwitchPreference) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) Intent(android.content.Intent) ListPreference(android.support.v7.preference.ListPreference) OnPreferenceClickListener(android.support.v7.preference.Preference.OnPreferenceClickListener) CheckBoxPreference(android.support.v7.preference.CheckBoxPreference) ListPreference(android.support.v7.preference.ListPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) Settings(android.provider.Settings)

Example 5 with CheckBoxPreference

use of android.support.v7.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)

Aggregations

CheckBoxPreference (android.support.v7.preference.CheckBoxPreference)31 Preference (android.support.v7.preference.Preference)17 ListPreference (android.support.v7.preference.ListPreference)13 Intent (android.content.Intent)10 CheckBoxPreference (android.preference.CheckBoxPreference)8 Context (android.content.Context)7 SharedPreferences (android.content.SharedPreferences)7 OnPreferenceChangeListener (android.support.v7.preference.Preference.OnPreferenceChangeListener)7 Preference (android.preference.Preference)6 AlertDialog (android.support.v7.app.AlertDialog)6 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 SwitchPreferenceCompat (android.support.v7.preference.SwitchPreferenceCompat)5 Uri (android.net.Uri)4 Build (android.os.Build)4 PreferenceScreen (android.preference.PreferenceScreen)4 View (android.view.View)4 ArrayList (java.util.ArrayList)4 PackageManager (android.content.pm.PackageManager)3 Bundle (android.os.Bundle)3 ListPreference (android.preference.ListPreference)3