Search in sources :

Example 71 with Preference

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

the class PreferenceController method checkItemVisibility.

@SuppressWarnings("deprecation")
private void checkItemVisibility() {
    boolean hasFlattrToken = FlattrUtils.hasToken();
    ui.findPreference(PreferenceController.PREF_FLATTR_SETTINGS).setEnabled(FlattrUtils.hasAPICredentials());
    ui.findPreference(PreferenceController.PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken);
    ui.findPreference(PreferenceController.PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken);
    ui.findPreference(PreferenceController.PREF_AUTO_FLATTR_PREFS).setEnabled(hasFlattrToken);
    boolean autoDownload = UserPreferences.isEnableAutodownload();
    ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(autoDownload);
    ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload);
    ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload);
    setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter());
    ui.findPreference(PREF_SEND_CRASH_REPORT).setEnabled(CrashReportWriter.getFile().exists());
    if (Build.VERSION.SDK_INT >= 16) {
        ui.findPreference(UserPreferences.PREF_SONIC).setEnabled(true);
    } else {
        Preference prefSonic = ui.findPreference(UserPreferences.PREF_SONIC);
        prefSonic.setSummary("[Android 4.1+]\n" + prefSonic.getSummary());
    }
}
Also used : EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference)

Example 72 with Preference

use of android.preference.Preference 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 73 with Preference

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

the class SettingsActivity method fixSummaries.

@SuppressWarnings("deprecation")
private void fixSummaries() {
    int historyLength = KissApplication.getDataHandler(this).getHistoryLength();
    if (historyLength > 5) {
        findPreference("reset").setSummary(String.format(getString(R.string.items_title), historyLength));
    }
    // Only display the "rate the app" preference if the user has been using KISS long enough to enjoy it ;)
    Preference rateApp = findPreference("rate-app");
    if (historyLength < 300) {
        getPreferenceScreen().removePreference(rateApp);
    } else {
        rateApp.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("market://details?id=" + getApplicationContext().getPackageName()));
                startActivity(intent);
                return true;
            }
        });
    }
}
Also used : MultiSelectListPreference(android.preference.MultiSelectListPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Intent(android.content.Intent)

Example 74 with Preference

use of android.preference.Preference in project NetGuard by M66B.

the class ActivitySettings method onPostCreate.

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    final PreferenceScreen screen = getPreferenceScreen();
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    PreferenceGroup cat_options = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_options")).findPreference("category_options");
    PreferenceGroup cat_advanced = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_advanced_options")).findPreference("category_advanced_options");
    PreferenceGroup cat_stats = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_stats")).findPreference("category_stats");
    PreferenceGroup cat_backup = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_backup")).findPreference("category_backup");
    // Handle auto enable
    Preference pref_auto_enable = screen.findPreference("auto_enable");
    pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0")));
    // Handle screen delay
    Preference pref_screen_delay = screen.findPreference("screen_delay");
    pref_screen_delay.setTitle(getString(R.string.setting_delay, prefs.getString("screen_delay", "0")));
    // Handle theme
    Preference pref_screen_theme = screen.findPreference("theme");
    String theme = prefs.getString("theme", "teal");
    String[] themeNames = getResources().getStringArray(R.array.themeNames);
    String[] themeValues = getResources().getStringArray(R.array.themeValues);
    for (int i = 0; i < themeNames.length; i++) if (theme.equals(themeValues[i])) {
        pref_screen_theme.setTitle(getString(R.string.setting_theme, themeNames[i]));
        break;
    }
    // Wi-Fi home
    MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes");
    Set<String> ssids = prefs.getStringSet("wifi_homes", new HashSet<String>());
    if (ssids.size() > 0)
        pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssids)));
    else
        pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
    WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    List<CharSequence> listSSID = new ArrayList<>();
    List<WifiConfiguration> configs = wm.getConfiguredNetworks();
    if (configs != null)
        for (WifiConfiguration config : configs) listSSID.add(config.SSID == null ? "NULL" : config.SSID);
    for (String ssid : ssids) if (!listSSID.contains(ssid))
        listSSID.add(ssid);
    pref_wifi_homes.setEntries(listSSID.toArray(new CharSequence[0]));
    pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0]));
    Preference pref_reset_usage = screen.findPreference("reset_usage");
    pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() {

                @Override
                public void onSure() {
                    new AsyncTask<Object, Object, Throwable>() {

                        @Override
                        protected Throwable doInBackground(Object... objects) {
                            try {
                                DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1);
                                return null;
                            } catch (Throwable ex) {
                                return ex;
                            }
                        }

                        @Override
                        protected void onPostExecute(Throwable ex) {
                            if (ex == null)
                                Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show();
                            else
                                Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
                        }
                    }.execute();
                }
            });
            return false;
        }
    });
    // Handle port forwarding
    Preference pref_forwarding = screen.findPreference("forwarding");
    pref_forwarding.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class));
            return true;
        }
    });
    boolean can = Util.canFilter(this);
    TwoStatePreference pref_log_app = (TwoStatePreference) screen.findPreference("log_app");
    TwoStatePreference pref_filter = (TwoStatePreference) screen.findPreference("filter");
    pref_log_app.setEnabled(can);
    pref_filter.setEnabled(can);
    if (!can) {
        pref_log_app.setSummary(R.string.msg_unavailable);
        pref_filter.setSummary(R.string.msg_unavailable);
    }
    // VPN parameters
    screen.findPreference("vpn4").setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1")));
    screen.findPreference("vpn6").setTitle(getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")));
    EditTextPreference pref_dns1 = (EditTextPreference) screen.findPreference("dns");
    EditTextPreference pref_dns2 = (EditTextPreference) screen.findPreference("dns2");
    EditTextPreference pref_ttl = (EditTextPreference) screen.findPreference("ttl");
    List<String> def_dns = Util.getDefaultDNS(this);
    pref_dns1.getEditText().setHint(def_dns.get(0));
    pref_dns2.getEditText().setHint(def_dns.get(1));
    pref_dns1.setTitle(getString(R.string.setting_dns, prefs.getString("dns", def_dns.get(0))));
    pref_dns2.setTitle(getString(R.string.setting_dns, prefs.getString("dns2", def_dns.get(1))));
    pref_ttl.setTitle(getString(R.string.setting_ttl, prefs.getString("ttl", "259200")));
    // SOCKS5 parameters
    screen.findPreference("socks5_addr").setTitle(getString(R.string.setting_socks5_addr, prefs.getString("socks5_addr", "-")));
    screen.findPreference("socks5_port").setTitle(getString(R.string.setting_socks5_port, prefs.getString("socks5_port", "-")));
    screen.findPreference("socks5_username").setTitle(getString(R.string.setting_socks5_username, prefs.getString("socks5_username", "-")));
    screen.findPreference("socks5_password").setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString("socks5_username", "")) ? "-" : "*****"));
    // PCAP parameters
    screen.findPreference("pcap_record_size").setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64")));
    screen.findPreference("pcap_file_size").setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2")));
    // Watchdog
    screen.findPreference("watchdog").setTitle(getString(R.string.setting_watchdog, prefs.getString("watchdog", "0")));
    // Show resolved
    Preference pref_show_resolved = screen.findPreference("show_resolved");
    if (Util.isPlayStoreInstall(this))
        cat_advanced.removePreference(pref_show_resolved);
    else
        pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                startActivity(new Intent(ActivitySettings.this, ActivityDns.class));
                return true;
            }
        });
    // Handle stats
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        cat_stats.removePreference(screen.findPreference("show_top"));
    EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency");
    EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples");
    pref_stats_frequency.setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000")));
    pref_stats_samples.setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90")));
    // Handle export
    Preference pref_export = screen.findPreference("export");
    pref_export.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null);
    pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivityForResult(getIntentCreateExport(), ActivitySettings.REQUEST_EXPORT);
            return true;
        }
    });
    // Handle import
    Preference pref_import = screen.findPreference("import");
    pref_import.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null);
    pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startActivityForResult(getIntentOpenExport(), ActivitySettings.REQUEST_IMPORT);
            return true;
        }
    });
    // Hosts file settings
    Preference pref_block_domains = screen.findPreference("use_hosts");
    EditTextPreference pref_rcode = (EditTextPreference) screen.findPreference("rcode");
    Preference pref_hosts_import = screen.findPreference("hosts_import");
    EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url");
    final Preference pref_hosts_download = screen.findPreference("hosts_download");
    pref_rcode.setTitle(getString(R.string.setting_rcode, prefs.getString("rcode", "3")));
    if (Util.isPlayStoreInstall(this)) {
        Log.i(TAG, "Play store install");
        cat_options.removePreference(screen.findPreference("update_check"));
        cat_advanced.removePreference(pref_block_domains);
        cat_advanced.removePreference(pref_rcode);
        cat_advanced.removePreference(pref_forwarding);
        cat_backup.removePreference(pref_hosts_import);
        cat_backup.removePreference(pref_hosts_url);
        cat_backup.removePreference(pref_hosts_download);
    } else {
        String last_import = prefs.getString("hosts_last_import", null);
        String last_download = prefs.getString("hosts_last_download", null);
        if (last_import != null)
            pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import));
        if (last_download != null)
            pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download));
        // Handle hosts import
        // https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources
        pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null);
        pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS);
                return true;
            }
        });
        // Handle hosts file download
        pref_hosts_url.setSummary(pref_hosts_url.getText());
        pref_hosts_download.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                final File tmp = new File(getFilesDir(), "hosts.tmp");
                final File hosts = new File(getFilesDir(), "hosts.txt");
                EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url");
                try {
                    new DownloadTask(ActivitySettings.this, new URL(pref_hosts_url.getText()), tmp, new DownloadTask.Listener() {

                        @Override
                        public void onCompleted() {
                            if (hosts.exists())
                                hosts.delete();
                            tmp.renameTo(hosts);
                            String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime());
                            prefs.edit().putString("hosts_last_download", last).apply();
                            if (running) {
                                pref_hosts_download.setSummary(getString(R.string.msg_download_last, last));
                                Toast.makeText(ActivitySettings.this, R.string.msg_downloaded, Toast.LENGTH_LONG).show();
                            }
                            ServiceSinkhole.reload("hosts file download", ActivitySettings.this);
                        }

                        @Override
                        public void onCancelled() {
                            if (tmp.exists())
                                tmp.delete();
                        }

                        @Override
                        public void onException(Throwable ex) {
                            if (tmp.exists())
                                tmp.delete();
                            if (running)
                                Toast.makeText(ActivitySettings.this, ex.getMessage(), Toast.LENGTH_LONG).show();
                        }
                    }).execute();
                } catch (MalformedURLException ex) {
                    Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
                }
                return true;
            }
        });
    }
    // Development
    if (!Util.isDebuggable(this))
        screen.removePreference(screen.findPreference("screen_development"));
    // Handle technical info
    Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            updateTechnicalInfo();
            return true;
        }
    };
    // Technical info
    Preference pref_technical_info = screen.findPreference("technical_info");
    Preference pref_technical_network = screen.findPreference("technical_network");
    Preference pref_technical_subscription = screen.findPreference("technical_subscription");
    pref_technical_info.setEnabled(INTENT_VPN_SETTINGS.resolveActivity(this.getPackageManager()) != null);
    pref_technical_info.setIntent(INTENT_VPN_SETTINGS);
    pref_technical_info.setOnPreferenceClickListener(listener);
    pref_technical_network.setOnPreferenceClickListener(listener);
    pref_technical_subscription.setOnPreferenceClickListener(listener);
    updateTechnicalInfo();
    markPro(screen.findPreference("theme"), ActivityPro.SKU_THEME);
    markPro(screen.findPreference("install"), ActivityPro.SKU_NOTIFY);
    markPro(screen.findPreference("show_stats"), ActivityPro.SKU_SPEED);
}
Also used : WifiManager(android.net.wifi.WifiManager) MalformedURLException(java.net.MalformedURLException) PreferenceScreen(android.preference.PreferenceScreen) WifiConfiguration(android.net.wifi.WifiConfiguration) ArrayList(java.util.ArrayList) MultiSelectListPreference(android.preference.MultiSelectListPreference) URL(java.net.URL) TwoStatePreference(android.preference.TwoStatePreference) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) EditTextPreference(android.preference.EditTextPreference) Date(java.util.Date) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) MultiSelectListPreference(android.preference.MultiSelectListPreference) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference) PreferenceGroup(android.preference.PreferenceGroup) File(java.io.File)

Example 75 with Preference

use of android.preference.Preference in project NetGuard by M66B.

the class ActivitySettings method updateTechnicalInfo.

private void updateTechnicalInfo() {
    PreferenceScreen screen = getPreferenceScreen();
    Preference pref_technical_info = screen.findPreference("technical_info");
    Preference pref_technical_network = screen.findPreference("technical_network");
    Preference pref_technical_subscription = screen.findPreference("technical_subscription");
    pref_technical_info.setSummary(Util.getGeneralInfo(this));
    pref_technical_network.setSummary(Util.getNetworkInfo(this));
    pref_technical_subscription.setSummary(Util.getSubscriptionInfo(this));
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) MultiSelectListPreference(android.preference.MultiSelectListPreference) TwoStatePreference(android.preference.TwoStatePreference) Preference(android.preference.Preference)

Aggregations

Preference (android.preference.Preference)183 CheckBoxPreference (android.preference.CheckBoxPreference)54 ListPreference (android.preference.ListPreference)54 PreferenceScreen (android.preference.PreferenceScreen)37 Intent (android.content.Intent)33 EditTextPreference (android.preference.EditTextPreference)29 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)23 PreferenceCategory (android.preference.PreferenceCategory)23 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)21 SharedPreferences (android.content.SharedPreferences)19 ChromeSwitchPreference (org.chromium.chrome.browser.preferences.ChromeSwitchPreference)16 PreferenceGroup (android.preference.PreferenceGroup)15 Test (org.junit.Test)15 Uri (android.net.Uri)12 Bundle (android.os.Bundle)12 ArrayList (java.util.ArrayList)11 Resources (android.content.res.Resources)10 SwitchPreference (android.preference.SwitchPreference)10 View (android.view.View)10 ChromeBasePreference (org.chromium.chrome.browser.preferences.ChromeBasePreference)10