List of usage examples for android.content SharedPreferences getAll
Map<String, ?> getAll();
From source file:com.umeng.comm.ui.fragments.BaseFeedsFragment.java
/** * feed?,Feed??ListView?.feedSharedPreferences?. */// w w w.j ava 2 s . com private void removeDeletedFeeds() { SharedPreferences deletedSharedPref = SharePrefUtils.getSharePrefEdit(getActivity(), Constants.DELETED_FEEDS_PREF); // all deleted feeds iterator. Iterator<String> deletedIterator = deletedSharedPref.getAll().keySet().iterator(); // ???feed while (deletedIterator.hasNext()) { String feedId = deletedIterator.next(); // Iterator<FeedItem> feedIterator = mFeedLvAdapter.getDataSource().iterator(); // find the target feed while (feedIterator.hasNext()) { FeedItem feedItem = feedIterator.next(); if (feedItem.id.equals(feedId)) { feedIterator.remove(); break; } } // end of second while } // first while mFeedLvAdapter.notifyDataSetChanged(); deletedSharedPref.edit().clear(); }
From source file:me.piebridge.bible.Bible.java
private Bible(Context context) { Log.d(TAG, "init bible"); mContext = context;// w w w . ja v a2s. c om SharedPreferences preferences = mContext.getSharedPreferences(HUMAN_PREFERENCE, Context.MODE_MULTI_PROCESS); for (Entry<String, ?> entry : preferences.getAll().entrySet()) { allhuman.put(entry.getKey(), String.valueOf(entry.getValue())); } try { versionName = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName; } catch (NameNotFoundException e) { } checkLocale(); setDefaultVersion(); }
From source file:dev.ukanth.ufirewall.Api.java
/** * Cleansup the uninstalled packages from the cache - will have slight performance * @param ctx/*from w w w . ja v a 2s. c o m*/ */ @Deprecated public static void removeAllUnusedCacheLabel(Context ctx) { final SharedPreferences prefs = ctx.getSharedPreferences("AFWallPrefs", Context.MODE_PRIVATE); final String cacheLabel = "cache.label."; String pkgName; String cacheKey; PackageManager pm = ctx.getPackageManager(); Map<String, ?> keys = prefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { if (entry.getKey().startsWith(cacheLabel)) { cacheKey = entry.getKey(); pkgName = entry.getKey().replace(cacheLabel, ""); if (prefs.getString(cacheKey, "").length() > 0 && !isPackageExists(pm, pkgName)) { prefs.edit().remove(cacheKey).commit(); } } } }
From source file:dev.ukanth.ufirewall.Api.java
/** * Cleanup the cache from profiles - Improve performance. * @param ctx/*from w ww . jav a2 s.c om*/ */ @Deprecated public static void removeAllProfileCacheLabel(Context ctx) { SharedPreferences prefs; final String cacheLabel = "cache.label."; String cacheKey; for (String profileName : G.profiles) { prefs = ctx.getSharedPreferences(profileName, Context.MODE_PRIVATE); if (prefs != null) { Map<String, ?> keys = prefs.getAll(); for (Map.Entry<String, ?> entry : keys.entrySet()) { if (entry.getKey().startsWith(cacheLabel)) { cacheKey = entry.getKey(); prefs.edit().remove(cacheKey).commit(); } } } } }
From source file:com.aware.Aware.java
@Override public void onCreate() { super.onCreate(); awareContext = getApplicationContext(); aware_preferences = getSharedPreferences("aware_core_prefs", MODE_PRIVATE); if (aware_preferences.getAll().isEmpty()) { SharedPreferences.Editor editor = aware_preferences.edit(); editor.putInt(PREF_FREQUENCY_WATCHDOG, CONST_FREQUENCY_WATCHDOG); editor.putLong(PREF_LAST_SYNC, 0); editor.putLong(PREF_LAST_UPDATE, 0); editor.commit();//from www .j a v a 2s. co m } IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_MEDIA_MOUNTED); filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED); filter.addDataScheme("file"); awareContext.registerReceiver(storage_BR, filter); filter = new IntentFilter(); filter.addAction(Aware.ACTION_AWARE_CLEAR_DATA); filter.addAction(Aware.ACTION_AWARE_REFRESH); filter.addAction(Aware.ACTION_AWARE_SYNC_DATA); filter.addAction(DownloadManager.ACTION_DOWNLOAD_COMPLETE); awareContext.registerReceiver(aware_BR, filter); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); awareStatusMonitor = new Intent(getApplicationContext(), Aware.class); repeatingIntent = PendingIntent.getService(getApplicationContext(), 0, awareStatusMonitor, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 1000, aware_preferences.getInt(PREF_FREQUENCY_WATCHDOG, 300) * 1000, repeatingIntent); Intent synchronise = new Intent(Aware.ACTION_AWARE_SYNC_DATA); webserviceUploadIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, synchronise, 0); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { stopSelf(); } else { SharedPreferences prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE); if (prefs.getAll().isEmpty() && Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) { PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences, true); prefs.edit().commit(); //commit changes } else { PreferenceManager.setDefaultValues(getApplicationContext(), getPackageName(), Context.MODE_PRIVATE, R.xml.aware_preferences, false); } Map<String, ?> defaults = prefs.getAll(); for (Map.Entry<String, ?> entry : defaults.entrySet()) { if (Aware.getSetting(getApplicationContext(), entry.getKey()).length() == 0) { Aware.setSetting(getApplicationContext(), entry.getKey(), entry.getValue()); } } if (Aware.getSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID).length() == 0) { UUID uuid = UUID.randomUUID(); Aware.setSetting(getApplicationContext(), Aware_Preferences.DEVICE_ID, uuid.toString()); } DEBUG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_FLAG).equals("true"); TAG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG) : TAG; get_device_info(); if (Aware.DEBUG) Log.d(TAG, "AWARE framework is created!"); //Fixed: only the client application does a ping to AWARE's server if (getPackageName().equals("com.aware")) { new AsyncPing().execute(); } } }
From source file:tv.piratemedia.lightcontroler.controller.java
private void newDeviceFound(final String IP, final String Mac) { final SharedPreferences Devices = this.getSharedPreferences("devices", MODE_PRIVATE); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override//from w ww.j av a 2s .com public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: Devices.edit().putBoolean(Mac + "-known", true).commit(); prefs.edit().putString("pref_light_controller_ip", IP).commit(); Devices.edit().putString(Mac + "-online", Utils.getWifiName()); gotDevice = true; DeviceMac = Mac; break; case DialogInterface.BUTTON_NEGATIVE: Devices.edit().putBoolean(Mac + "-known", false).commit(); break; } } }; if (Devices.getAll().size() < 1) { prefs.edit().putString("pref_light_controller_ip", IP).commit(); Devices.edit().putBoolean(Mac + "-known", true); Devices.edit().putString(Mac + "-online", Utils.getWifiName()); gotDevice = true; DeviceMac = Mac; } else { if (!Devices.contains(Mac + "-known")) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("A new Light Control device has been found, Would you like to save/control it?") .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener) .show(); } else { if (Devices.getBoolean(Mac + "-known", false)) { gotDevice = true; prefs.edit().putString("pref_light_controller_ip", IP).commit(); DeviceMac = Mac; } } } }
From source file:eu.faircode.adblocker.ActivitySettings.java
@Override @TargetApi(Build.VERSION_CODES.M)//from w ww. j a v a 2 s . co 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 ("show_stats".equals(name)) { if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) { prefs.edit().putBoolean(name, false).apply(); ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); startActivity(new Intent(this, ActivityPro.class)); return; } } Object value = prefs.getAll().get(name); if (value instanceof String && "".equals(value)) prefs.edit().remove(name).apply(); // Dependencies if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_other".equals(name) || "screen_other".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_INTERNATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } 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 ("tethering".equals(name)) ServiceSinkhole.reload("changed " + name, this); 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); } else if ("use_metered".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else { if ("unmetered_2g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2); else if ("unmetered_3g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3); else if ("unmetered_4g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4); } } else ServiceSinkhole.reload("changed " + name, this); } else if ("national_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_NATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } 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); } else if ("log_app".equals(name)) { Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset); } else if ("filter".equals(name)) { ServiceSinkhole.reload("changed " + name, this); // Show dialog if (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 ("use_hosts".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("vpn4".equals(name)) { String vpn4 = prefs.getString("vpn4", null); try { checkAddress(vpn4); } catch (Throwable ex) { prefs.edit().remove("vpn4").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn4)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); } else if ("vpn6".equals(name)) { String vpn6 = prefs.getString("vpn6", null); try { checkAddress(vpn6); } catch (Throwable ex) { prefs.edit().remove("vpn6").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(vpn6)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name).setTitle( getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); } else if ("dns".equals(name)) { String dns = prefs.getString("dns", null); try { checkAddress(dns); } catch (Throwable ex) { prefs.edit().remove("dns").apply(); ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); if (!TextUtils.isEmpty(dns)) Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); } ServiceSinkhole.reload("changed " + name, this); getPreferenceScreen().findPreference(name).setTitle( getString(R.string.setting_dns, prefs.getString("dns", Util.getDefaultDNS(this).get(0)))); } 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(getCacheDir(), "adblocker.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 ("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.adblocker.me/hosts")); else if ("loglevel".equals(name)) ServiceSinkhole.reload("changed " + name, this); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
@Override @TargetApi(Build.VERSION_CODES.M)// w w w . j a v a 2 s . c o m public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { // Pro features if ("theme".equals(name)) { if (!"teal".equals(prefs.getString(name, "teal"))) { prefs.edit().putString(name, "teal").apply(); ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal"); return; } } else if ("install".equals(name)) { if (prefs.getBoolean(name, false)) { prefs.edit().putBoolean(name, false).apply(); ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); return; } } else if ("show_stats".equals(name)) { if (prefs.getBoolean(name, false)) { prefs.edit().putBoolean(name, false).apply(); 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); else if ("whitelist_wifi".equals(name) || "screen_wifi".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_other".equals(name) || "screen_other".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("whitelist_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_INTERNATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } 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); else if ("tethering".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("lan".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("ip6".equals(name)) ServiceSinkhole.reload("changed " + name, this); 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); } else if ("use_metered".equals(name)) ServiceSinkhole.reload("changed " + name, this); else if ("unmetered_2g".equals(name) || "unmetered_3g".equals(name) || "unmetered_4g".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else { if ("unmetered_2g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED2); else if ("unmetered_3g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED3); else if ("unmetered_4g".equals(name)) requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_METERED4); } } else ServiceSinkhole.reload("changed " + name, this); } else if ("national_roaming".equals(name)) { if (prefs.getBoolean(name, false)) { if (Util.hasPhoneStatePermission(this)) ServiceSinkhole.reload("changed " + name, this); else requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, REQUEST_ROAMING_NATIONAL); } else ServiceSinkhole.reload("changed " + name, this); } else if ("manage_system".equals(name)) { boolean manage = prefs.getBoolean(name, true); if (!manage) prefs.edit().putBoolean("show_user", true).apply(); prefs.edit().putBoolean("show_system", manage).apply(); ServiceSinkhole.reload("changed " + name, this); } else if ("log_app".equals(name)) { Intent ruleset = new Intent(MainActivity.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); } else if ("use_hosts".equals(name)) ServiceSinkhole.reload("changed " + name, this); 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); } 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); } 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); } 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); } else if ("socks5_enabled".equals(name)) ServiceSinkhole.reload("changed " + name, this); 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); } else if ("socks5_port".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-"))); ServiceSinkhole.reload("changed " + name, this); } else if ("socks5_username".equals(name)) { getPreferenceScreen().findPreference(name) .setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-"))); ServiceSinkhole.reload("changed " + name, this); } 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); } 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); } 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); }
From source file:com.jtschohl.androidfirewall.MainActivity.java
private void LoadDefaultProfile() { SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE, Context.MODE_PRIVATE); final Editor editRules = prefs.edit(); editRules.clear();//from w ww. j av a2 s . c om for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; showOrLoadApplications(); refreshHeader(); toggleVPNbutton(getApplicationContext()); toggleRoambutton(getApplicationContext()); toggleLANbutton(getApplicationContext()); toggleInputWifiButton(getApplicationContext()); toggleUserSettings(getApplicationContext()); if (Api.isEnabled(getApplicationContext())) { Api.applyIptablesRules(getApplicationContext(), true); if (abs_menu != null) { final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4); final MenuItem item_apply = abs_menu.findItem(R.id.applyrules); item_apply.setTitle(R.string.applyrules); item_onoff.setChecked(true); } } else { Api.saveRules(getApplicationContext()); if (abs_menu != null) { final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4); final MenuItem item_apply = abs_menu.findItem(R.id.applyrules); item_apply.setTitle(R.string.saverules); item_onoff.setChecked(false); } } }
From source file:com.jtschohl.androidfirewall.MainActivity.java
private void LoadProfile1() { SharedPreferences prefs = getSharedPreferences(Api.PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences prefs2 = getSharedPreferences(Api.PREF_PROFILE1, Context.MODE_PRIVATE); final Editor editRules = prefs.edit(); editRules.clear();//from w ww. ja v a 2 s.c o m for (Entry<String, ?> entry : prefs2.getAll().entrySet()) { Object rule = entry.getValue(); String keys = entry.getKey(); if (rule instanceof Boolean) editRules.putBoolean(keys, ((Boolean) rule).booleanValue()); else if (rule instanceof Float) editRules.putFloat(keys, ((Float) rule).floatValue()); else if (rule instanceof String) editRules.putString(keys, ((String) rule)); else if (rule instanceof Long) editRules.putLong(keys, ((Long) rule).longValue()); else if (rule instanceof Integer) editRules.putInt(keys, ((Integer) rule).intValue()); } editRules.commit(); Api.applications = null; showOrLoadApplications(); refreshHeader(); toggleVPNbutton(getApplicationContext()); toggleRoambutton(getApplicationContext()); toggleLANbutton(getApplicationContext()); toggleInputWifiButton(getApplicationContext()); toggleUserSettings(getApplicationContext()); if (Api.isEnabled(getApplicationContext())) { Api.applyIptablesRules(getApplicationContext(), true); if (abs_menu != null) { final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4); final MenuItem item_apply = abs_menu.findItem(R.id.applyrules); item_apply.setTitle(R.string.applyrules); item_onoff.setChecked(true); } } else { Api.saveRules(getApplicationContext()); if (abs_menu != null) { final MenuItem item_onoff = abs_menu.findItem(R.id.enableipv4); final MenuItem item_apply = abs_menu.findItem(R.id.applyrules); item_apply.setTitle(R.string.saverules); item_onoff.setChecked(false); } } }