use of android.preference.TwoStatePreference in project OpenCamera by ageback.
the class MyPreferenceFragment method onSharedPreferenceChanged.
/* So that manual changes to the checkbox/switch preferences, while the preferences are showing, show up;
* in particular, needed for preference_using_saf, when the user cancels the SAF dialog (see
* MainActivity.onActivityResult).
* Also programmatically sets summary (see setSummary).
*/
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (MyDebug.LOG)
Log.d(TAG, "onSharedPreferenceChanged");
Preference pref = findPreference(key);
if (pref instanceof TwoStatePreference) {
TwoStatePreference twoStatePref = (TwoStatePreference) pref;
twoStatePref.setChecked(prefs.getBoolean(key, true));
}
setSummary(key);
}
use of android.preference.TwoStatePreference in project NetGuard by M66B.
the class ActivitySettings method onSharedPreferenceChanged.
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
// Pro features
if ("theme".equals(name)) {
if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) {
prefs.edit().putString(name, "teal").apply();
((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal");
startActivity(new Intent(this, ActivityPro.class));
return;
}
} else if ("install".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) {
prefs.edit().putBoolean(name, false).apply();
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false);
startActivity(new Intent(this, ActivityPro.class));
return;
}
} else if ("show_stats".equals(name)) {
if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) {
prefs.edit().putBoolean(name, false).apply();
startActivity(new Intent(this, ActivityPro.class));
return;
}
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false));
}
Object value = prefs.getAll().get(name);
if (value instanceof String && "".equals(value))
prefs.edit().remove(name).apply();
// Dependencies
if ("screen_on".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_other".equals(name) || "screen_other".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("whitelist_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("auto_enable".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_auto, prefs.getString(name, "0")));
else if ("screen_delay".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_delay, prefs.getString(name, "0")));
else if ("theme".equals(name) || "dark_theme".equals(name))
recreate();
else if ("subnet".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("tethering".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("lan".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("ip6".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("wifi_homes".equals(name)) {
MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen().findPreference(name);
Set<String> ssid = prefs.getStringSet(name, new HashSet<String>());
if (ssid.size() > 0)
pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid)));
else
pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-"));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("use_metered".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("national_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("eu_roaming".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("disable_on_call".equals(name)) {
if (prefs.getBoolean(name, false)) {
if (checkPermissions(name))
ServiceSinkhole.reload("changed " + name, this, false);
} else
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("manage_system".equals(name)) {
boolean manage = prefs.getBoolean(name, false);
if (!manage)
prefs.edit().putBoolean("show_user", true).apply();
prefs.edit().putBoolean("show_system", manage).apply();
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("log_app".equals(name)) {
Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED);
LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset);
} else if ("filter".equals(name)) {
// Show dialog
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) {
LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this);
View view = inflater.inflate(R.layout.filter, null, false);
dialogFilter = new AlertDialog.Builder(ActivitySettings.this).setView(view).setCancelable(false).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
}).setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialogInterface) {
dialogFilter = null;
}
}).create();
dialogFilter.show();
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) {
prefs.edit().putBoolean(name, true).apply();
Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show();
}
((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("use_hosts".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("vpn4".equals(name)) {
String vpn4 = prefs.getString(name, null);
try {
checkAddress(vpn4);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(vpn4))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("vpn6".equals(name)) {
String vpn6 = prefs.getString(name, null);
try {
checkAddress(vpn6);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(vpn6))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("dns".equals(name) || "dns2".equals(name)) {
String dns = prefs.getString(name, null);
try {
checkAddress(dns);
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(dns))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_dns, prefs.getString(name, Util.getDefaultDNS(this).get("dns".equals(name) ? 0 : 1))));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("ttl".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_ttl, prefs.getString(name, "259200")));
else if ("rcode".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_rcode, prefs.getString(name, "3")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_enabled".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
else if ("socks5_addr".equals(name)) {
String socks5_addr = prefs.getString(name, null);
try {
if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr))
throw new IllegalArgumentException("Bad address");
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
if (!TextUtils.isEmpty(socks5_addr))
Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show();
}
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_addr, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_port".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_username".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("socks5_password".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****"));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) {
if ("pcap_record_size".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64")));
else
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2")));
ServiceSinkhole.setPcap(false, this);
File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");
if (pcap_file.exists() && !pcap_file.delete())
Log.w(TAG, "Delete PCAP failed");
if (prefs.getBoolean("pcap", false))
ServiceSinkhole.setPcap(true, this);
} else if ("watchdog".equals(name)) {
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0")));
ServiceSinkhole.reload("changed " + name, this, false);
} else if ("show_stats".equals(name))
ServiceSinkhole.reloadStats("changed " + name, this);
else if ("stats_frequency".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000")));
else if ("stats_samples".equals(name))
getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90")));
else if ("hosts_url".equals(name))
getPreferenceScreen().findPreference(name).setSummary(prefs.getString(name, "http://www.netguard.me/hosts"));
else if ("loglevel".equals(name))
ServiceSinkhole.reload("changed " + name, this, false);
}
use of android.preference.TwoStatePreference 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();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
return false;
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
TwoStatePreference pref_reload_onconnectivity = (TwoStatePreference) screen.findPreference("reload_onconnectivity");
pref_reload_onconnectivity.setChecked(true);
pref_reload_onconnectivity.setEnabled(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, false);
}
@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();
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} 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");
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);
updateTechnicalInfo();
markPro(screen.findPreference("theme"), ActivityPro.SKU_THEME);
markPro(screen.findPreference("install"), ActivityPro.SKU_NOTIFY);
markPro(screen.findPreference("show_stats"), ActivityPro.SKU_SPEED);
}
use of android.preference.TwoStatePreference in project PhoneProfilesPlus by henrichg.
the class PhoneProfilesPreferencesNestedFragment method setSummary.
/*
private void setTitleStyle(Preference preference, boolean bold, boolean underline)
{
CharSequence title = preference.getTitle();
Spannable sbt = new SpannableString(title);
Object spansToRemove[] = sbt.getSpans(0, title.length(), Object.class);
for(Object span: spansToRemove){
if(span instanceof CharacterStyle)
sbt.removeSpan(span);
}
if (bold || underline)
{
if (bold)
sbt.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, sbt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (underline)
sbt.setSpan(new UnderlineSpan(), 0, sbt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
preference.setTitle(sbt);
}
else
{
preference.setTitle(sbt);
}
}
*/
void setSummary(String key) {
Preference preference = prefMng.findPreference(key);
if (preference == null)
return;
PreferenceScreen preferenceCategoryNotifications = (PreferenceScreen) findPreference("categoryNotifications");
if (Build.VERSION.SDK_INT < 26) {
boolean notificationStatusBar = preferences.getBoolean(ApplicationPreferences.PREF_NOTIFICATION_STATUS_BAR, true);
boolean notificationStatusBarPermanent = preferences.getBoolean(ApplicationPreferences.PREF_NOTIFICATION_STATUS_BAR_PERMANENT, true);
if (!(notificationStatusBar && notificationStatusBarPermanent)) {
GlobalGUIRoutines.setPreferenceTitleStyle(preferenceCategoryNotifications, true, false, true, false);
if (preferenceCategoryNotifications != null)
preferenceCategoryNotifications.setSummary(getString(R.string.phone_profiles_pref_notificationStatusBarNotEnabled_summary) + " " + getString(R.string.phone_profiles_pref_notificationStatusBarRequired));
} else {
GlobalGUIRoutines.setPreferenceTitleStyle(preferenceCategoryNotifications, false, false, false, false);
if (preferenceCategoryNotifications != null)
preferenceCategoryNotifications.setSummary(R.string.empty_string);
}
if (key.equals(ApplicationPreferences.PREF_NOTIFICATION_STATUS_BAR)) {
GlobalGUIRoutines.setPreferenceTitleStyle(preference, !notificationStatusBar, false, !notificationStatusBar, false);
}
if (key.equals(ApplicationPreferences.PREF_NOTIFICATION_STATUS_BAR_PERMANENT)) {
GlobalGUIRoutines.setPreferenceTitleStyle(preference, !notificationStatusBarPermanent, false, !notificationStatusBarPermanent, false);
}
}
if ((android.os.Build.VERSION.SDK_INT >= 21) && (android.os.Build.VERSION.SDK_INT < 26)) {
if (key.equals(ApplicationPreferences.PREF_NOTIFICATION_SHOW_IN_STATUS_BAR)) {
boolean show = preferences.getBoolean(key, true);
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_NOTIFICATION_HIDE_IN_LOCKSCREEN);
if (_preference != null)
_preference.setEnabled(show);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_BACKGROUND_TYPE)) {
if (preferences.getBoolean(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_BACKGROUND_TYPE, false)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(true);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(false);
} else {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(false);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(true);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_BACKGROUND_TYPE)) {
if (preferences.getBoolean(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_BACKGROUND_TYPE, false)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(true);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(false);
} else {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(false);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(true);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_BACKGROUND_TYPE)) {
if (preferences.getBoolean(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_BACKGROUND_TYPE, false)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(true);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(false);
} else {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_BACKGROUND_COLOR);
if (_preference != null)
_preference.setEnabled(false);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_LIGHTNESS_B);
if (_preference != null)
_preference.setEnabled(true);
}
}
// Do not bind toggles.
if (preference instanceof CheckBoxPreference || preference instanceof TwoStatePreference) {
return;
}
String stringValue = preferences.getString(key, "");
if (key.equals(ApplicationPreferences.PREF_APPLICATION_BACKGROUND_PROFILE)) {
long lProfileId;
try {
lProfileId = Long.parseLong(stringValue);
} catch (Exception e) {
lProfileId = 0;
}
ProfilePreference profilePreference = (ProfilePreference) preference;
profilePreference.setSummary(lProfileId);
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_BACKGROUND_PROFILE_NOTIFICATION_SOUND);
if (_preference != null)
_preference.setEnabled(lProfileId != Profile.PROFILE_NO_ACTIVATE);
_preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_BACKGROUND_PROFILE_NOTIFICATION_VIBRATE);
if (_preference != null)
_preference.setEnabled(lProfileId != Profile.PROFILE_NO_ACTIVATE);
} else if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
// the preference's 'entries' list.
ListPreference listPreference = (ListPreference) preference;
int index = listPreference.findIndexOfValue(stringValue);
// Set the summary to reflect the new value.
// added support for "%" in list items
CharSequence summary = (index >= 0) ? listPreference.getEntries()[index] : null;
if (summary != null) {
String sSummary = summary.toString();
sSummary = sSummary.replace("%", "%%");
preference.setSummary(sSummary);
} else
preference.setSummary(null);
// if (key.equals(PPApplication.PREF_APPLICATION_LANGUAGE))
// setTitleStyle(preference, true, false);
} else // noinspection StatementWithEmptyBody
if (preference instanceof RingtonePreference) {
// keep summary from preference
} else {
// For all other preferences, set the summary to the value's
// simple string representation.
// preference.setSummary(preference.toString());
preference.setSummary(stringValue);
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_FORCE_SET_MERGE_RINGER_NOTIFICATION_VOLUMES)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_UNLINK_RINGER_NOTIFICATION_VOLUMES);
if (_preference != null) {
boolean enabled;
String value = preferences.getString(key, "0");
if (!value.equals("0"))
enabled = value.equals("1");
else
enabled = ActivateProfileHelper.getMergedRingNotificationVolumes(getActivity().getApplicationContext());
// Log.d("PhoneProfilesPreferencesNestedFragment.setSummary","enabled="+enabled);
_preference.setEnabled(enabled);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_COLOR)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_ICON_LIGHTNESS);
if (_preference != null) {
boolean colorful = preferences.getString(key, "0").equals("1");
_preference.setEnabled(colorful);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_ICON_COLOR)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_WIDGET_LIST_ICON_LIGHTNESS);
if (_preference != null) {
boolean colorful = preferences.getString(key, "0").equals("1");
_preference.setEnabled(colorful);
}
}
if (key.equals(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_ICON_COLOR)) {
Preference _preference = prefMng.findPreference(ApplicationPreferences.PREF_APPLICATION_SAMSUNG_EDGE_ICON_LIGHTNESS);
if (_preference != null) {
boolean colorful = preferences.getString(key, "0").equals("1");
_preference.setEnabled(colorful);
}
}
}
use of android.preference.TwoStatePreference in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class AccountsSettingsFragment method onCreate.
@Override
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_accounts);
mAccountSwitcher = findPreference(PREF_ACCCOUNT_SWITCHER);
mEnableSyncPreference = (TwoStatePreference) findPreference(PREF_ENABLE_SYNC_NOW);
mSyncNowPreference = findPreference(PREF_SYNC_NOW);
mClearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
if (ProductionFlags.IS_METRICS_LOGGING_SUPPORTED) {
final Preference enableMetricsLogging = findPreference(Settings.PREF_ENABLE_METRICS_LOGGING);
final Resources res = getResources();
if (enableMetricsLogging != null) {
final String enableMetricsLoggingTitle = res.getString(R.string.enable_metrics_logging, getApplicationName());
enableMetricsLogging.setTitle(enableMetricsLoggingTitle);
}
} else {
removePreference(Settings.PREF_ENABLE_METRICS_LOGGING);
}
if (!ProductionFlags.ENABLE_USER_HISTORY_DICTIONARY_SYNC) {
removeSyncPreferences();
} else {
// Disable by default till we are sure we can enable this.
disableSyncPreferences();
new ManagedProfileCheckerTask(this).execute();
}
}
Aggregations