Search in sources :

Example 26 with PreferenceScreen

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

the class SingleWebsitePreferences method resetSite.

/**
     * Resets the current site, clearing all permissions and storage used (inc. cookies).
     */
@VisibleForTesting
protected void resetSite() {
    if (getActivity() == null)
        return;
    // Clear the screen.
    // TODO(mvanouwerkerk): Refactor this class so that it does not depend on the screen state
    // for its logic. This class should maintain its own data model, and only update the screen
    // after a change is made.
    PreferenceScreen screen = getPreferenceScreen();
    for (String key : PERMISSION_PREFERENCE_KEYS) {
        Preference preference = screen.findPreference(key);
        if (preference != null)
            screen.removePreference(preference);
    }
    // Clear the permissions.
    mSite.setAutoplayPermission(ContentSetting.DEFAULT);
    mSite.setBackgroundSyncPermission(ContentSetting.DEFAULT);
    mSite.setCameraPermission(ContentSetting.DEFAULT);
    mSite.setCookiePermission(ContentSetting.DEFAULT);
    WebsitePreferenceBridge.nativeClearCookieData(mSite.getAddress().getTitle());
    mSite.setFullscreenPermission(ContentSetting.DEFAULT);
    mSite.setGeolocationPermission(ContentSetting.DEFAULT);
    mSite.setJavaScriptPermission(ContentSetting.DEFAULT);
    mSite.setKeygenPermission(ContentSetting.DEFAULT);
    mSite.setMicrophonePermission(ContentSetting.DEFAULT);
    mSite.setMidiPermission(ContentSetting.DEFAULT);
    mSite.setNotificationPermission(ContentSetting.DEFAULT);
    mSite.setPopupPermission(ContentSetting.DEFAULT);
    mSite.setProtectedMediaIdentifierPermission(ContentSetting.DEFAULT);
    for (UsbInfo info : mSite.getUsbInfo()) info.revoke();
    // Clear the storage and finish the activity if necessary.
    if (mSite.getTotalUsage() > 0) {
        clearStoredData();
    } else {
        // Clearing stored data implies popping back to parent menu if there
        // is nothing left to show. Therefore, we only need to explicitly
        // close the activity if there's no stored data to begin with.
        getActivity().finish();
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) VisibleForTesting(org.chromium.base.VisibleForTesting)

Example 27 with PreferenceScreen

use of android.preference.PreferenceScreen 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 28 with PreferenceScreen

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

the class PreferencesFragment method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.preferences);
    PreferenceScreen preferences = getPreferenceScreen();
    preferences.getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    checkBoxPrefs = findDecodePrefs(preferences, PreferencesActivity.KEY_DECODE_1D_PRODUCT, PreferencesActivity.KEY_DECODE_1D_INDUSTRIAL, PreferencesActivity.KEY_DECODE_QR, PreferencesActivity.KEY_DECODE_DATA_MATRIX, PreferencesActivity.KEY_DECODE_AZTEC, PreferencesActivity.KEY_DECODE_PDF417);
    disableLastCheckedPref();
    EditTextPreference customProductSearch = (EditTextPreference) preferences.findPreference(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH);
    customProductSearch.setOnPreferenceChangeListener(new CustomSearchURLValidator());
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference)

Example 29 with PreferenceScreen

use of android.preference.PreferenceScreen in project KISS by Neamar.

the class SettingsActivity method onCreate.

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String theme = prefs.getString("theme", "light");
    if (theme.contains("dark")) {
        setTheme(R.style.SettingThemeDark);
    }
    // Do it here to make the transition as smooth as possible
    if (prefs.getBoolean("force-portrait", true)) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
    }
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    ListPreference iconsPack = (ListPreference) findPreference("icons-pack");
    setListPreferenceIconsPacksData(iconsPack);
    fixSummaries();
    addExcludedAppSettings(prefs);
    addSearchProvidersSelector(prefs);
    UiTweaks.updateThemePrimaryColor(this);
    // Notification color can't be updated before Lollipop
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        PreferenceScreen screen = (PreferenceScreen) findPreference("ui-holder");
        Preference pref = findPreference("notification-bar-color");
        screen.removePreference(pref);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) MultiSelectListPreference(android.preference.MultiSelectListPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) MultiSelectListPreference(android.preference.MultiSelectListPreference) ListPreference(android.preference.ListPreference)

Example 30 with PreferenceScreen

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

the class SettingsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(this);
    setPreferenceScreen(preferenceScreen);
    if (getIntent().hasExtra("deviceId")) {
        deviceId = getIntent().getStringExtra("deviceId");
    }
    BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() {

        @Override
        public void onServiceStart(BackgroundService service) {
            final Device device = service.getDevice(deviceId);
            if (device == null) {
                SettingsActivity.this.runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        SettingsActivity.this.finish();
                    }
                });
                return;
            }
            List<String> plugins = device.getSupportedPlugins();
            for (final String pluginKey : plugins) {
                PluginPreference pref = new PluginPreference(SettingsActivity.this, pluginKey, device);
                preferenceScreen.addPreference(pref);
            }
        }
    });
}
Also used : BackgroundService(org.kde.kdeconnect.BackgroundService) PreferenceScreen(android.preference.PreferenceScreen) Device(org.kde.kdeconnect.Device) List(java.util.List)

Aggregations

PreferenceScreen (android.preference.PreferenceScreen)83 Preference (android.preference.Preference)36 ListPreference (android.preference.ListPreference)21 PreferenceCategory (android.preference.PreferenceCategory)17 CheckBoxPreference (android.preference.CheckBoxPreference)16 EditTextPreference (android.preference.EditTextPreference)14 Bundle (android.os.Bundle)13 Method (java.lang.reflect.Method)11 SharedPreferences (android.content.SharedPreferences)9 Intent (android.content.Intent)6 Dialog (android.app.Dialog)5 ArrayList (java.util.ArrayList)5 DialogInterface (android.content.DialogInterface)4 Activity (android.app.Activity)3 Context (android.content.Context)3 MultiSelectListPreference (android.preference.MultiSelectListPreference)3 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)3 PreferenceManager (android.preference.PreferenceManager)3 TwoStatePreference (android.preference.TwoStatePreference)3 View (android.view.View)3