List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.nextgis.firereporter.GetFiresService.java
protected void GetUserData(boolean bShowProgress) { Location currentLocation = null; String sLat = null, sLon = null; if (mLocManager != null) { currentLocation = mLocManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (currentLocation == null) { currentLocation = mLocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); }/*from w w w . j a va2s .c o m*/ if (currentLocation == null) { SendError(getString(R.string.noLocation)); return; } else { sLat = Double.toString(currentLocation.getLatitude()); sLon = Double.toString(currentLocation.getLongitude()); } } SharedPreferences prefs = getSharedPreferences(MainActivity.PREFERENCES, MODE_PRIVATE | MODE_MULTI_PROCESS); String sURL = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER, getResources().getString(R.string.stDefaultServer)); String sLogin = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER_USER, "firereporter"); String sPass = prefs.getString(SettingsActivity.KEY_PREF_SRV_USER_PASS, "8QdA4"); int nDayInterval = prefs.getInt(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL + "_int", 5); int fetchRows = prefs.getInt(SettingsActivity.KEY_PREF_ROW_COUNT + "_int", 15); int searchRadius = prefs.getInt(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS + "_int", 5) * 1000;//meters boolean searchByDate = prefs.getBoolean("search_current_date", false); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); long diff = 86400000L * nDayInterval;//1000 * 60 * 60 * 24 * 5;// 5 days date.setTime(date.getTime() - diff); String dt = dateFormat.format(date); String sFullURL = sURL + "?function=get_rows_user&user=" + sLogin + "&pass=" + sPass + "&limit=" + fetchRows + "&radius=" + searchRadius;// if (searchByDate) { sFullURL += "&date=" + dt; } if (sLat.length() > 0 && sLon.length() > 0) { sFullURL += "&lat=" + sLat + "&lon=" + sLon; } //SELECT * FROM (SELECT id, report_date, latitude, longitude, round(ST_Distance_Sphere(ST_PointFromText('POINT(37.506247479468584 55.536129316315055)', 4326), fires.geom)) AS dist FROM fires WHERE ST_Intersects(fires.geom, ST_GeomFromText('POLYGON((32.5062474795 60.5361293163, 42.5062474795 60.5361293163, 42.5062474795 50.5361293163, 32.5062474795 50.5361293163, 32.5062474795 60.5361293163))', 4326) ) AND CAST(report_date as date) >= '2013-09-27')t WHERE dist <= 5000 LIMIT 15 //String sRemoteData = "http://gis-lab.info/data/zp-gis/soft/fires.php?function=get_rows_nasa&user=fire_usr&pass=J59DY&limit=5"; new HttpGetter(this, 1, getResources().getString(R.string.stDownLoading), mFillDataHandler, bShowProgress) .execute(sFullURL); }
From source file:radu.pidroid.Controller.java
private void loadPreferences() { ////from w w w . j a v a 2s. c om SharedPreferences preferences = this.getPreferences(Context.MODE_PRIVATE); controlsID = preferences.getInt(EXTRA_CONTROLS_ID, TOUCH_CONTROLS); maxTiltAngle = preferences.getInt(EXTRA_MAX_TILT_ANGLE, 45); accelerationTime = preferences.getInt(EXTRA_ACCELERATION_TIME, 1500); decelerationTime = preferences.getInt(EXTRA_DECELERATION_TIME, 1000); touchResponsiveness = preferences.getInt(EXTRA_TOUCH_RESPONSIVENESS, 200); turnSensitivity = preferences.getInt(EXTRA_TURN_SENSITIVITY, 1); tutorialsOn = preferences.getBoolean(EXTRA_TUTORIALS_ON, true); cameraStabilisationOn = preferences.getBoolean(EXTRA_CAMERA_STABILISATION_ON, true); videoFeedMjpegView.setCameraStabilisation(cameraStabilisationOn); currentHudResource = preferences.getInt(EXTRA_HUD, 0); levelIndicatorImageView.setVisibility(preferences.getInt(EXTRA_LEVEL_INDICATOR, View.VISIBLE)); hudImageView.setImageResource(hudResources[currentHudResource]); setControls(controlsID); }
From source file:mobile.tiis.appv2.LoginActivity.java
/** * Gets the current registration ID for application on GCM service. * <p/>//from w w w . j a v a 2s .c o m * If result is empty, the appv2 needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ private String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.isEmpty()) { Log.i(TAG, "Registration not found."); return ""; } // Check if appv2 was updated; if so, it must clear the registration ID // since the existing regID is not guaranteed to work with the new // appv2 version. int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE); int currentVersion = getAppVersion(context); if (registeredVersion != currentVersion) { Log.i(TAG, "App version changed."); return ""; } return registrationId; }
From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java
/** * We want the help screen to be shown automatically the first time a new * version of the app is run. The easiest way to do this is to check * android:versionCode from the manifest, and compare it to a value stored * as a preference.//from w w w . j a v a2s . com */ private boolean showHelpOnFirstLaunch() { try { PackageInfo info = getPackageManager().getPackageInfo(PACKAGE_NAME, 0); int currentVersion = info.versionCode; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); int lastVersion = prefs.getInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN, 0); if (currentVersion > lastVersion) { prefs.edit().putInt(PreferencesActivity.KEY_HELP_VERSION_SHOWN, currentVersion).commit(); Intent intent = new Intent(this, HelpActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); // Show the default page on a clean install, and the what's new // page on an upgrade. String page = lastVersion == 0 ? HelpActivity.DEFAULT_PAGE : HelpActivity.WHATS_NEW_PAGE; intent.putExtra(HelpActivity.REQUESTED_PAGE_KEY, page); startActivity(intent); return true; } } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, e); } return false; }
From source file:com.acrutiapps.browser.ui.components.CustomWebView.java
@SuppressLint("SetJavaScriptEnabled") public void loadSettings() { WebSettings settings = getSettings(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); settings.setJavaScriptEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_JAVASCRIPT, true)); settings.setLoadsImagesAutomatically(prefs.getBoolean(Constants.PREFERENCE_ENABLE_IMAGES, true)); settings.setUseWideViewPort(prefs.getBoolean(Constants.PREFERENCE_USE_WIDE_VIEWPORT, true)); settings.setLoadWithOverviewMode(prefs.getBoolean(Constants.PREFERENCE_LOAD_WITH_OVERVIEW, false)); settings.setGeolocationEnabled(prefs.getBoolean(Constants.PREFERENCE_ENABLE_GEOLOCATION, true)); settings.setSaveFormData(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_FORM_DATA, true)); settings.setSavePassword(prefs.getBoolean(Constants.PREFERENCE_REMEMBER_PASSWORDS, true)); settings.setTextZoom(prefs.getInt(Constants.PREFERENCE_TEXT_SCALING, 100)); int minimumFontSize = prefs.getInt(Constants.PREFERENCE_MINIMUM_FONT_SIZE, 1); settings.setMinimumFontSize(minimumFontSize); settings.setMinimumLogicalFontSize(minimumFontSize); boolean useInvertedDisplay = prefs.getBoolean(Constants.PREFERENCE_INVERTED_DISPLAY, false); setWebSettingsProperty(settings, "inverted", useInvertedDisplay ? "true" : "false"); if (useInvertedDisplay) { setWebSettingsProperty(settings, "inverted_contrast", Float.toString(prefs.getInt(Constants.PREFERENCE_INVERTED_DISPLAY_CONTRAST, 100) / 100f)); }/*from ww w .ja va 2 s .c om*/ settings.setUserAgentString(prefs.getString(Constants.PREFERENCE_USER_AGENT, Constants.USER_AGENT_ANDROID)); settings.setPluginState(PluginState .valueOf(prefs.getString(Constants.PREFERENCE_PLUGINS, PluginState.ON_DEMAND.toString()))); CookieManager.getInstance().setAcceptCookie(prefs.getBoolean(Constants.PREFERENCE_ACCEPT_COOKIES, true)); settings.setSupportZoom(true); settings.setDisplayZoomControls(false); settings.setBuiltInZoomControls(true); settings.setSupportMultipleWindows(true); settings.setEnableSmoothTransition(true); if (mPrivateBrowsing) { settings.setGeolocationEnabled(false); settings.setSaveFormData(false); settings.setSavePassword(false); settings.setAppCacheEnabled(false); settings.setDatabaseEnabled(false); settings.setDomStorageEnabled(false); } else { // HTML5 API flags settings.setAppCacheEnabled(true); settings.setDatabaseEnabled(true); settings.setDomStorageEnabled(true); // HTML5 configuration settings. settings.setAppCacheMaxSize(3 * 1024 * 1024); settings.setAppCachePath(mContext.getDir("appcache", 0).getPath()); settings.setDatabasePath(mContext.getDir("databases", 0).getPath()); settings.setGeolocationDatabasePath(mContext.getDir("geolocation", 0).getPath()); } setLongClickable(true); setDownloadListener(this); }
From source file:com.bullmobi.base.content.ConfigBase.java
protected void initInternal(@NonNull Context context) { try {// ww w.j a v a 2s . c o m Resources res = context.getResources(); SharedPreferences prefs = getSharedPreferences(context); for (Map.Entry<String, Option> entry : getMap().entrySet()) { final String key = entry.getKey(); final Option option = entry.getValue(); // Get the current value. Object value = option.getDefault(res); if (boolean.class.isAssignableFrom(option.clazz)) { value = prefs.getBoolean(key, (Boolean) value); } else if (int.class.isAssignableFrom(option.clazz)) { value = prefs.getInt(key, (Integer) value); } else if (float.class.isAssignableFrom(option.clazz)) { value = prefs.getFloat(key, (Float) value); } else if (String.class.isAssignableFrom(option.clazz)) { value = prefs.getString(key, (String) value); } else throw new IllegalArgumentException("Unknown option\'s type."); // Set the current value. Field field = getClass().getDeclaredField(option.fieldName); field.setAccessible(true); field.set(this, value); } } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(); } }
From source file:com.achep.base.content.ConfigBase.java
protected void initInternal(@NonNull Context context) { try {/*ww w . ja v a2s . c o m*/ Resources res = context.getResources(); SharedPreferences prefs = getSharedPreferences(context); for (Map.Entry<String, Option> entry : getMap().entrySet()) { final String key = entry.getKey(); final Option option = entry.getValue(); // Get the current value. Object value = option.getDefault(res); if (boolean.class.isAssignableFrom(option.clazz)) { value = prefs.getBoolean(key, (Boolean) value); } else if (int.class.isAssignableFrom(option.clazz)) { value = prefs.getInt(key, (Integer) value); } else if (float.class.isAssignableFrom(option.clazz)) { value = prefs.getFloat(key, (Float) value); } else if (String.class.isAssignableFrom(option.clazz)) { value = prefs.getString(key, (String) value); } else throw new IllegalArgumentException("Unknown option\'s type."); // Set the current value. Field field = getClass().getDeclaredField(option.fieldName); field.setAccessible(true); field.set(this, value); } } catch (Exception e) { throw new RuntimeException(); } }
From source file:com.mainpanel.LifeApp_Map.java
public void showevents(View view) throws IOException { spinner.setVisibility(View.VISIBLE); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); double mLatitude = mLocationClient.getLastLocation().getLatitude(); double mLongitude = mLocationClient.getLastLocation().getLongitude(); event_type = sharedPrefs.getString("event_type", "workshop"); event_radius = sharedPrefs.getInt("event_radius", 1); String msg = "Searching " + event_type + " within " + event_radius + " radius."; Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show(); HandleXML obj;// ww w . j a v a 2 s . c om String finalUrl = "https://www.eventbrite.com/xml/event_search?app_key=B5KBKT5IZNBOOFXF2G&within=" + event_radius + "&longitude=" + mLongitude + "&latitude=" + mLatitude; obj = new HandleXML(finalUrl); obj.fetchXML(); while (obj.parsingComplete) ; String events_data = obj.getevent_details(); String[] event = events_data.split("eventend#"); for (int i = 0; i < event.length - 1; i++) { if (event_type.toLowerCase().equals("all")) { String[] each_event = event[i].split("lifeapp#"); String eTitle = "Event : " + each_event[0]; double eLat = Double.parseDouble(each_event[1].split("/")[0]); double eLong = Double.parseDouble(each_event[1].split("/")[1]); String eDesc = each_event[2] + "lifeapp#" + each_event[3] + "lifeapp#" + each_event[4] + "lifeapp#" + each_event[5]; // create marker MarkerOptions marker = new MarkerOptions().position(new LatLng(eLat, eLong)).title(eTitle) .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_eventmap)); marker.snippet(eDesc); // adding marker mMap.addMarker(marker); } else if (event[i].toLowerCase().contains(event_type.toLowerCase()) || event[i].toLowerCase().contains(event_type.toLowerCase())) { String[] each_event = event[i].split("lifeapp#"); String eTitle = "Event : " + each_event[0]; double eLat = Double.parseDouble(each_event[1].split("/")[0]); double eLong = Double.parseDouble(each_event[1].split("/")[1]); String eDesc = each_event[2] + "lifeapp#" + each_event[3] + "lifeapp#" + each_event[4] + "lifeapp#" + each_event[5]; // create marker MarkerOptions marker = new MarkerOptions().position(new LatLng(eLat, eLong)).title(eTitle) .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon_eventmap)); marker.snippet(eDesc); // adding marker mMap.addMarker(marker); } } spinner.setVisibility(View.GONE); }
From source file:com.horizondigital.delta.UpdateService.java
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PREF_AUTO_UPDATE_NETWORKS_NAME.equals(key)) { networkState.updateFlags(//from w w w. ja va2 s .c o m sharedPreferences.getInt(PREF_AUTO_UPDATE_NETWORKS_NAME, PREF_AUTO_UPDATE_NETWORKS_DEFAULT)); } }
From source file:it.scoppelletti.mobilepower.app.AbstractActivity.java
/** * Costruisce il testo delle note di rilascio. * //from w w w . j a va 2 s . c o m * @param resId Identificatore del vettore di stringhe che rappresenta le * note di release. * @return Testo. Può essere {@code null}. */ private String buildReleaseNotes(int resId) { int n; int ver, lastVer; String note, pkgName; StringBuilder buf; PackageInfo pkgInfo; PackageManager pkgMgr; SharedPreferences prefs; SharedPreferences.Editor editor; String[] notes; try { notes = getResources().getStringArray(resId); } catch (Resources.NotFoundException ex) { myLogger.debug("Release notes {} not found.", resId); return null; } if (ArrayUtils.isEmpty(notes)) { myLogger.warn("Release notes {} is empty.", resId); onNextAsyncInitializer(); return null; } pkgName = getPackageName(); pkgMgr = getPackageManager(); try { pkgInfo = pkgMgr.getPackageInfo(pkgName, 0); } catch (PackageManager.NameNotFoundException ex) { myLogger.error("Failed to get PackageInfo.", ex); pkgInfo = null; } if (pkgInfo == null) { myLogger.debug("No PackagerInfo set."); return null; } ver = pkgInfo.versionCode; prefs = PreferenceManager.getDefaultSharedPreferences(this); lastVer = prefs.getInt(AppUtils.PREF_LASTVER, 1); myLogger.debug("Version code={}, Last version code={}", ver, lastVer); editor = prefs.edit(); editor.putInt(AppUtils.PREF_LASTVER, ver); editor.apply(); if (ver == 1 || ver <= lastVer) { return null; } ver -= 2; lastVer = (lastVer > 0) ? lastVer - 2 : -1; buf = new StringBuilder(); for (n = notes.length - 1; ver > lastVer; ver--) { if (ver > n) { continue; } note = notes[ver]; if (StringUtils.isBlank(note)) { continue; } buf.append(note); } if (buf.length() == 0) { return null; } buf.insert(0, "</h1>"); buf.insert(0, getString(R.string.lbl_releaseNotes)); buf.insert(0, "<h1>"); return buf.toString(); }