List of usage examples for android.content.res Resources getBoolean
public boolean getBoolean(@BoolRes int id) throws NotFoundException
From source file:org.distantshoresmedia.keyboard.LatinIME.java
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Log.i("PCKeyboard", "onSharedPreferenceChanged()"); boolean needReload = false; Resources res = getResources(); // Apply globally handled shared prefs sKeyboardSettings.sharedPreferenceChanged(sharedPreferences, key); if (sKeyboardSettings.hasFlag(GlobalKeyboardSettings.FLAG_PREF_NEED_RELOAD)) { needReload = true;/*from w ww. j ava 2 s. c om*/ } if (sKeyboardSettings.hasFlag(GlobalKeyboardSettings.FLAG_PREF_NEW_PUNC_LIST)) { initSuggestPuncList(); } if (sKeyboardSettings.hasFlag(GlobalKeyboardSettings.FLAG_PREF_RECREATE_INPUT_VIEW)) { mKeyboardSwitcher.recreateInputView(); } if (sKeyboardSettings.hasFlag(GlobalKeyboardSettings.FLAG_PREF_RESET_MODE_OVERRIDE)) { mKeyboardModeOverrideLandscape = 0; mKeyboardModeOverridePortrait = 0; } if (sKeyboardSettings.hasFlag(GlobalKeyboardSettings.FLAG_PREF_RESET_KEYBOARDS)) { toggleLanguage(true, true); } int unhandledFlags = sKeyboardSettings.unhandledFlags(); if (unhandledFlags != GlobalKeyboardSettings.FLAG_PREF_NONE) { Log.w(TAG, "Not all flag settings handled, remaining=" + unhandledFlags); } if (PREF_SELECTED_LANGUAGES.equals(key)) { mLanguageSwitcher.loadLocales(sharedPreferences); mRefreshKeyboardRequired = true; } else if (PREF_RECORRECTION_ENABLED.equals(key)) { mReCorrectionEnabled = sharedPreferences.getBoolean(PREF_RECORRECTION_ENABLED, res.getBoolean(R.bool.default_recorrection_enabled)); if (mReCorrectionEnabled) { // It doesn't work right on pre-Gingerbread phones. Toast.makeText(getApplicationContext(), res.getString(R.string.recorrect_warning), Toast.LENGTH_LONG).show(); } } else if (PREF_CONNECTBOT_TAB_HACK.equals(key)) { mConnectbotTabHack = sharedPreferences.getBoolean(PREF_CONNECTBOT_TAB_HACK, res.getBoolean(R.bool.default_connectbot_tab_hack)); } else if (PREF_FULLSCREEN_OVERRIDE.equals(key)) { mFullscreenOverride = sharedPreferences.getBoolean(PREF_FULLSCREEN_OVERRIDE, res.getBoolean(R.bool.default_fullscreen_override)); needReload = true; } else if (PREF_FORCE_KEYBOARD_ON.equals(key)) { mForceKeyboardOn = sharedPreferences.getBoolean(PREF_FORCE_KEYBOARD_ON, res.getBoolean(R.bool.default_force_keyboard_on)); needReload = true; } else if (PREF_KEYBOARD_NOTIFICATION.equals(key)) { mKeyboardNotification = sharedPreferences.getBoolean(PREF_KEYBOARD_NOTIFICATION, res.getBoolean(R.bool.default_keyboard_notification)); setNotification(mKeyboardNotification); } else if (PREF_SUGGESTIONS_IN_LANDSCAPE.equals(key)) { mSuggestionsInLandscape = sharedPreferences.getBoolean(PREF_SUGGESTIONS_IN_LANDSCAPE, res.getBoolean(R.bool.default_suggestions_in_landscape)); // Respect the suggestion settings in legacy Gingerbread mode, // in portrait mode, or if suggestions in landscape enabled. mSuggestionForceOff = false; mSuggestionForceOn = false; setCandidatesViewShown(isPredictionOn()); } else if (PREF_SHOW_SUGGESTIONS.equals(key)) { mShowSuggestions = sharedPreferences.getBoolean(PREF_SHOW_SUGGESTIONS, res.getBoolean(R.bool.default_suggestions)); mSuggestionForceOff = false; mSuggestionForceOn = false; needReload = true; } else if (PREF_HEIGHT_PORTRAIT.equals(key)) { mHeightPortrait = getHeight(sharedPreferences, PREF_HEIGHT_PORTRAIT, res.getString(R.string.default_height_portrait)); needReload = true; } else if (PREF_HEIGHT_LANDSCAPE.equals(key)) { mHeightLandscape = getHeight(sharedPreferences, PREF_HEIGHT_LANDSCAPE, res.getString(R.string.default_height_landscape)); needReload = true; } else if (PREF_HINT_MODE.equals(key)) { LatinIME.sKeyboardSettings.hintMode = Integer.parseInt( sharedPreferences.getString(PREF_HINT_MODE, res.getString(R.string.default_hint_mode))); needReload = true; } else if (PREF_LONGPRESS_TIMEOUT.equals(key)) { LatinIME.sKeyboardSettings.longpressTimeout = getPrefInt(sharedPreferences, PREF_LONGPRESS_TIMEOUT, res.getString(R.string.default_long_press_duration)); } else if (PREF_RENDER_MODE.equals(key)) { LatinIME.sKeyboardSettings.renderMode = getPrefInt(sharedPreferences, PREF_RENDER_MODE, res.getString(R.string.default_render_mode)); needReload = true; } else if (PREF_SWIPE_UP.equals(key)) { mSwipeUpAction = sharedPreferences.getString(PREF_SWIPE_UP, res.getString(R.string.default_swipe_up)); } else if (PREF_SWIPE_DOWN.equals(key)) { mSwipeDownAction = sharedPreferences.getString(PREF_SWIPE_DOWN, res.getString(R.string.default_swipe_down)); } else if (PREF_SWIPE_LEFT.equals(key)) { mSwipeLeftAction = sharedPreferences.getString(PREF_SWIPE_LEFT, res.getString(R.string.default_swipe_left)); } else if (PREF_SWIPE_RIGHT.equals(key)) { mSwipeRightAction = sharedPreferences.getString(PREF_SWIPE_RIGHT, res.getString(R.string.default_swipe_right)); } else if (PREF_VOL_UP.equals(key)) { mVolUpAction = sharedPreferences.getString(PREF_VOL_UP, res.getString(R.string.default_vol_up)); } else if (PREF_VOL_DOWN.equals(key)) { mVolDownAction = sharedPreferences.getString(PREF_VOL_DOWN, res.getString(R.string.default_vol_down)); } else if (PREF_VIBRATE_LEN.equals(key)) { mVibrateLen = getPrefInt(sharedPreferences, PREF_VIBRATE_LEN, getResources().getString(R.string.vibrate_duration_ms)); } updateKeyboardOptions(); if (needReload) { mKeyboardSwitcher.makeKeyboards(true); } }
From source file:com.androzic.Androzic.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Resources resources = getResources(); if (getString(R.string.pref_folder_data).equals(key)) { setDataPath(Androzic.PATH_DATA,// w w w .j a v a2 s . com sharedPreferences.getString(key, resources.getString(R.string.def_folder_data))); } else if (getString(R.string.pref_folder_icon).equals(key)) { setDataPath(Androzic.PATH_ICONS, sharedPreferences.getString(key, resources.getString(R.string.def_folder_icon))); } else if (getString(R.string.pref_unitcoordinate).equals(key)) { StringFormatter.coordinateFormat = Integer.parseInt(sharedPreferences.getString(key, "0")); } else if (getString(R.string.pref_unitdistance).equals(key)) { int distanceIdx = Integer.parseInt(sharedPreferences.getString(key, "0")); StringFormatter.distanceFactor = Double .parseDouble(resources.getStringArray(R.array.distance_factors)[distanceIdx]); StringFormatter.distanceAbbr = resources.getStringArray(R.array.distance_abbrs)[distanceIdx]; StringFormatter.distanceShortFactor = Double .parseDouble(resources.getStringArray(R.array.distance_factors_short)[distanceIdx]); StringFormatter.distanceShortAbbr = resources.getStringArray(R.array.distance_abbrs_short)[distanceIdx]; } else if (getString(R.string.pref_unitspeed).equals(key)) { int speedIdx = Integer.parseInt(sharedPreferences.getString(key, "0")); StringFormatter.speedFactor = Double .parseDouble(resources.getStringArray(R.array.speed_factors)[speedIdx]); StringFormatter.speedAbbr = resources.getStringArray(R.array.speed_abbrs)[speedIdx]; } else if (getString(R.string.pref_unitelevation).equals(key)) { int elevationIdx = Integer.parseInt(sharedPreferences.getString(key, "0")); StringFormatter.elevationFactor = Double .parseDouble(resources.getStringArray(R.array.elevation_factors)[elevationIdx]); StringFormatter.elevationAbbr = resources.getStringArray(R.array.elevation_abbrs)[elevationIdx]; } else if (getString(R.string.pref_unitangle).equals(key)) { int angleIdx = Integer.parseInt(sharedPreferences.getString(key, "0")); StringFormatter.angleFactor = Double .parseDouble(resources.getStringArray(R.array.angle_factors)[angleIdx]); StringFormatter.angleAbbr = resources.getStringArray(R.array.angle_abbrs)[angleIdx]; } else if (getString(R.string.pref_unitanglemagnetic).equals(key)) { angleMagnetic = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitanglemagnetic)); } else if (getString(R.string.pref_unitsunrise).equals(key)) { sunriseType = Integer.parseInt(sharedPreferences.getString(key, "0")); } else if (getString(R.string.pref_unitprecision).equals(key)) { boolean precision = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_unitprecision)); StringFormatter.precisionFormat = precision ? "%.1f" : "%.0f"; } else if (getString(R.string.pref_grid_mapshow).equals(key)) { overlayManager.mapGrid = sharedPreferences.getBoolean(key, false); if (currentMap instanceof OzfMap) overlayManager.initGrids((OzfMap) currentMap); } else if (getString(R.string.pref_grid_usershow).equals(key)) { overlayManager.userGrid = sharedPreferences.getBoolean(key, false); if (currentMap instanceof OzfMap) overlayManager.initGrids((OzfMap) currentMap); } else if (getString(R.string.pref_grid_preference).equals(key)) { overlayManager.gridPrefer = Integer.parseInt(sharedPreferences.getString(key, "0")); if (currentMap instanceof OzfMap) overlayManager.initGrids((OzfMap) currentMap); } else if (getString(R.string.pref_grid_userscale).equals(key) || getString(R.string.pref_grid_userunit).equals(key) || getString(R.string.pref_grid_usermpp).equals(key)) { if (currentMap instanceof OzfMap) overlayManager.initGrids((OzfMap) currentMap); } else if (getString(R.string.pref_vectormap_theme).equals(key) || getString(R.string.pref_vectormap_poi).equals(key)) { initializeRenderTheme(); ForgeMap.onRenderThemeChanged(); } else if (getString(R.string.pref_vectormap_textscale).equals(key)) { ForgeMap.textScale = Float .parseFloat(sharedPreferences.getString(getString(R.string.pref_vectormap_textscale), "1.0")); ForgeMap.onRenderThemeChanged(); } else if (getString(R.string.pref_onlinemap).equals(key) || getString(R.string.pref_onlinemapscale).equals(key)) { setOnlineMaps(sharedPreferences.getString(getString(R.string.pref_onlinemap), resources.getString(R.string.def_onlinemap))); } else if (getString(R.string.pref_mapadjacent).equals(key)) { adjacentMaps = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapadjacent)); } else if (getString(R.string.pref_onlinemapprescalefactor).equals(key)) { onlineMapPrescaleFactor = sharedPreferences.getInt(key, resources.getInteger(R.integer.def_onlinemapprescalefactor)); if (maps != null) for (BaseMap map : maps.getMaps()) if (map instanceof OnlineMap) ((OnlineMap) map).setPrescaleFactor(onlineMapPrescaleFactor); // Hack to recalculate cache and mpp if (currentMap != null && currentMap instanceof OnlineMap) currentMap.setZoom(currentMap.getZoom()); } else if (getString(R.string.pref_onlinemapexpiration).equals(key)) { // in weeks onlineMapTileExpiration = sharedPreferences.getInt(key, resources.getInteger(R.integer.def_onlinemapexpiration)); // in milliseconds onlineMapTileExpiration *= 1000 * 3600 * 24 * 7; if (onlineMaps != null) { for (TileProvider provider : onlineMaps) provider.tileExpiration = onlineMapTileExpiration; } } else if (getString(R.string.pref_mapcropborder).equals(key)) { cropMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapcropborder)); } else if (getString(R.string.pref_mapdrawborder).equals(key)) { drawMapBorder = sharedPreferences.getBoolean(key, resources.getBoolean(R.bool.def_mapdrawborder)); } else if (getString(R.string.pref_showwaypoints).equals(key)) { overlayManager.setWaypointsOverlayEnabled(sharedPreferences.getBoolean(key, true)); } else if (getString(R.string.pref_showcurrenttrack).equals(key)) { overlayManager.setCurrentTrackOverlayEnabled(sharedPreferences.getBoolean(key, true)); } else if (getString(R.string.pref_showaccuracy).equals(key)) { overlayManager.setAccuracyOverlayEnabled(sharedPreferences.getBoolean(key, true)); } else if (getString(R.string.pref_showdistance_int).equals(key)) { int showDistance = Integer .parseInt(sharedPreferences.getString(key, getString(R.string.def_showdistance))); overlayManager.setDistanceOverlayEnabled(showDistance > 0); } overlayManager.onPreferencesChanged(sharedPreferences); if (mapHolder != null) mapHolder.refreshMap(); }
From source file:org.adblockplus.android.ProxyService.java
@SuppressLint("NewApi") @Override/*ww w .j a va2 s . co m*/ public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { // Proxy is running in separate thread, it's just some resolution request during initialization. // Not worth spawning a separate thread for this. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build(); StrictMode.setThreadPolicy(policy); } // Get port for local proxy SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Resources resources = getResources(); // Try to read user proxy settings String proxyHost = null; String proxyPort = null; String proxyExcl = null; String proxyUser = null; String proxyPass = null; if (NATIVE_PROXY_SUPPORTED) { // Read system settings proxyHost = System.getProperty("http.proxyHost"); proxyPort = System.getProperty("http.proxyPort"); proxyExcl = System.getProperty("http.nonProxyHosts"); Log.d(TAG, "PRX: " + proxyHost + ":" + proxyPort + "(" + proxyExcl + ")"); // not used but left for future reference String[] px = ProxySettings.getUserProxy(getApplicationContext()); if (px != null) Log.d(TAG, "PRX: " + px[0] + ":" + px[1] + "(" + px[2] + ")"); } else { // Read application settings proxyHost = prefs.getString(getString(R.string.pref_proxyhost), null); proxyPort = prefs.getString(getString(R.string.pref_proxyport), null); proxyUser = prefs.getString(getString(R.string.pref_proxyuser), null); proxyPass = prefs.getString(getString(R.string.pref_proxypass), null); } // Check for root privileges and try to install transparent proxy if (RootTools.isAccessGiven()) { try { initIptables(); StringBuffer cmd = new StringBuffer(); int uid = getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.uid; cmd.append(iptables); cmd.append(IPTABLES_RETURN.replace("{{UID}}", String.valueOf(uid))); String rules = cmd.toString(); RootTools.sendShell(rules, DEFAULT_TIMEOUT); transparent = true; } catch (FileNotFoundException e) { // ignore - this is "normal" case } catch (NameNotFoundException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (IOException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (RootToolsException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (TimeoutException e) { Log.e(TAG, "Failed to initialize iptables", e); } } if (!transparent) { // Try to set native proxy nativeProxyAutoConfigured = ProxySettings.setConnectionProxy(getApplicationContext(), LOCALHOST, port, ""); if (NATIVE_PROXY_SUPPORTED) { registerReceiver(connectionReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); registerReceiver(connectionReceiver, new IntentFilter(Proxy.PROXY_CHANGE_ACTION)); } } // Save current native proxy situation. The service is always started on the first run so // we will always have a correct value from the box SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(getString(R.string.pref_proxyautoconfigured), transparent || nativeProxyAutoConfigured); editor.commit(); registerReceiver(proxyReceiver, new IntentFilter(ProxyService.BROADCAST_PROXY_FAILED)); registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTERING_CHANGE)); registerReceiver(filterReceiver, new IntentFilter(AdblockPlus.BROADCAST_FILTER_MATCHES)); // Start proxy if (proxy == null) { // Select available port and bind to it, use previously selected port by default portVariants[0] = prefs.getInt(getString(R.string.pref_lastport), -1); ServerSocket listen = null; String msg = null; for (int p : portVariants) { if (p < 0) continue; try { listen = new ServerSocket(p, 1024); port = p; break; } catch (IOException e) { Log.e(TAG, null, e); msg = e.getMessage(); } } if (listen == null) { sendBroadcast(new Intent(BROADCAST_PROXY_FAILED).putExtra("msg", msg)); return; } // Save selected port editor.putInt(getString(R.string.pref_lastport), port); editor.commit(); // Initialize proxy proxyConfiguration.put("handler", "main"); proxyConfiguration.put("main.prefix", ""); proxyConfiguration.put("main.class", "sunlabs.brazil.server.ChainHandler"); if (transparent) { proxyConfiguration.put("main.handlers", "urlmodifier adblock"); proxyConfiguration.put("urlmodifier.class", "org.adblockplus.brazil.TransparentProxyHandler"); } else { proxyConfiguration.put("main.handlers", "https adblock"); proxyConfiguration.put("https.class", "org.adblockplus.brazil.SSLConnectionHandler"); } proxyConfiguration.put("adblock.class", "org.adblockplus.brazil.RequestHandler"); if (logRequests) proxyConfiguration.put("adblock.proxylog", "yes"); configureUserProxy(proxyConfiguration, proxyHost, proxyPort, proxyExcl, proxyUser, proxyPass); proxy = new ProxyServer(); proxy.logLevel = Server.LOG_DIAGNOSTIC; proxy.setup(listen, proxyConfiguration.getProperty("handler"), proxyConfiguration); proxy.start(); } if (transparent) { // Redirect traffic via iptables try { StringBuffer cmd = new StringBuffer(); cmd.append(iptables); cmd.append(IPTABLES_ADD_HTTP.replace("{{PORT}}", String.valueOf(port))); String rules = cmd.toString(); RootTools.sendShell(rules, DEFAULT_TIMEOUT); } catch (FileNotFoundException e) { // ignore - this is "normal" case } catch (IOException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (RootToolsException e) { Log.e(TAG, "Failed to initialize iptables", e); } catch (TimeoutException e) { Log.e(TAG, "Failed to initialize iptables", e); } } prefs.registerOnSharedPreferenceChangeListener(this); // Lock service hideIcon = prefs.getBoolean(getString(R.string.pref_hideicon), resources.getBoolean(R.bool.def_hideicon)); startForeground(ONGOING_NOTIFICATION_ID, getNotification()); // If automatic setting of proxy was blocked, check if user has set it manually boolean manual = isManual(); if (manual && NATIVE_PROXY_SUPPORTED) { ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService( Context.CONNECTIVITY_SERVICE); updateNoTrafficCheck(connectivityManager); } sendStateChangedBroadcast(); Log.i(TAG, "Service started"); }