public static float getFloat(String key, float defaultValue, boolean isPublic) { if (isPublic) { return mSharedPreference.getFloat(key, defaultValue); } else { return mSharedPreference.getFloat(userId() + key, defaultValue); } }
/** * Returns a stored geofence by its id, or returns {@code null} if it's not found. * * @param id The ID of a stored geofence * @return A geofence defined by its center and radius. See {@link SimpleGeofence} */ public SimpleGeofence getGeofence(String id) { /* * Get the latitude for the geofence identified by id, or GeofenceUtils.INVALID_VALUE * if it doesn't exist */ double lat = mPrefs.getFloat( getGeofenceFieldKey(id, GeofenceUtils.KEY_LATITUDE), GeofenceUtils.INVALID_FLOAT_VALUE); /* * Get the longitude for the geofence identified by id, or * -999 if it doesn't exist */ double lng = mPrefs.getFloat( getGeofenceFieldKey(id, GeofenceUtils.KEY_LONGITUDE), GeofenceUtils.INVALID_FLOAT_VALUE); /* * Get the radius for the geofence identified by id, or GeofenceUtils.INVALID_VALUE * if it doesn't exist */ float radius = mPrefs.getFloat( getGeofenceFieldKey(id, GeofenceUtils.KEY_RADIUS), GeofenceUtils.INVALID_FLOAT_VALUE); /* * Get the expiration duration for the geofence identified by * id, or GeofenceUtils.INVALID_VALUE if it doesn't exist */ long expirationDuration = mPrefs.getLong( getGeofenceFieldKey(id, GeofenceUtils.KEY_EXPIRATION_DURATION), GeofenceUtils.INVALID_LONG_VALUE); /* * Get the transition type for the geofence identified by * id, or GeofenceUtils.INVALID_VALUE if it doesn't exist */ int transitionType = mPrefs.getInt( getGeofenceFieldKey(id, GeofenceUtils.KEY_TRANSITION_TYPE), GeofenceUtils.INVALID_INT_VALUE); // If none of the values is incorrect, return the object if (lat != GeofenceUtils.INVALID_FLOAT_VALUE && lng != GeofenceUtils.INVALID_FLOAT_VALUE && radius != GeofenceUtils.INVALID_FLOAT_VALUE && expirationDuration != GeofenceUtils.INVALID_LONG_VALUE && transitionType != GeofenceUtils.INVALID_INT_VALUE) { // Return a true Geofence object return new SimpleGeofence(id, lat, lng, radius, expirationDuration, transitionType); // Otherwise, return null. } else { return null; } }
public void Load(View v) { // Get from the SharedPreferences SharedPreferences settings = getApplicationContext().getSharedPreferences(DATA, 0); iPixels = settings.getFloat("Pixels", 0); Pixels = (TextView) findViewById(R.id.pixelsValue); String s = String.format("%s", Float.toString(iPixels)); Pixels.setText(s); fPhoneHeightToCamera = settings.getFloat("Phone Height to Camera", 0); PhoneHeightToCamera = (EditText) findViewById(R.id.PhoneHeightToCamera); s = String.format("%s", Float.toString(fPhoneHeightToCamera)); PhoneHeightToCamera.setText(s); fPhoneHeight = settings.getFloat("Phone Height", 0); PhoneHeight = (EditText) findViewById(R.id.PhoneHeight); s = String.format("%s", Float.toString(fPhoneHeight)); PhoneHeight.setText(s); fShoulderHeight = settings.getFloat("Shoulder Height", 0); ShoulderHeight = (EditText) findViewById(R.id.ShoulderHeight); s = String.format("%s", Float.toString(fShoulderHeight)); ShoulderHeight.setText(s); }
/** * Загружает состояние акселерометра из настроек, или возвращает нулевой вектор (не ссылку на null * !) */ public static float[] getAcellPosition() { float[] pos = new float[] {0, 0, 0}; pos[0] = settings.getFloat(ACCELX, 0); pos[1] = settings.getFloat(ACCELY, 0); pos[2] = settings.getFloat(ACCELZ, 0); return pos; }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.achieved); SharedPreferences settings = getSharedPreferences("RUNWITHME_ACHIEVEMENTS", 0); // setText(R.id.tvTopSpeed, String.format("%.1f km/h", settings.getFloat("TopSpeed", 0))); setText(R.id.tvTopDist, String.format("%.2f km", settings.getFloat("TopDist", 0))); setText(R.id.tvTopAvg, String.format("%.1f km/h", settings.getFloat("TopAvg", 0))); setText(R.id.tvTopTime, Helper.formatTime(settings.getFloat("TopTime", 0))); }
@Override public void onCreate() { LoginScreen.appendLog(TAG, "[SERVICE] onCreate"); super.onCreate(); // Load settings mSettings = PreferenceManager.getDefaultSharedPreferences(this); mPedometerSettings = new PedometerSettings(mSettings); mState = getSharedPreferences("state", 0); mUtils = Utils.getInstance(); mUtils.setService(this); acquireWakeLock(); // Start detecting mStepDetector = new StepDetector(); mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE); registerDetector(); // Register our receiver for the ACTION_SCREEN_OFF action. This will make our receiver // code be called whenever the phone enters standby mode. IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(mReceiver, filter); mStepDisplayer = new StepDisplayer(mPedometerSettings, mUtils); mStepDisplayer.setSteps(mSteps = mState.getInt("steps", 0)); mStepDisplayer.addListener(mStepListener); mStepDetector.addStepListener(mStepDisplayer); mPaceNotifier = new PaceNotifier(mPedometerSettings, mUtils); mPaceNotifier.setPace(mPace = mState.getInt("pace", 0)); mPaceNotifier.addListener(mPaceListener); mStepDetector.addStepListener(mPaceNotifier); mDistanceNotifier = new DistanceNotifier(mDistanceListener, mPedometerSettings, mUtils); mDistanceNotifier.setDistance(mDistance = mState.getFloat("distance", 0)); mStepDetector.addStepListener(mDistanceNotifier); mSpeedNotifier = new SpeedNotifier(mSpeedListener, mPedometerSettings, mUtils); mSpeedNotifier.setSpeed(mSpeed = mState.getFloat("speed", 0)); mPaceNotifier.addListener(mSpeedNotifier); mCaloriesNotifier = new CaloriesNotifier(mCaloriesListener, mPedometerSettings, mUtils); mCaloriesNotifier.setCalories(mCalories = mState.getFloat("calories", 0)); mStepDetector.addStepListener(mCaloriesNotifier); // Start voice reloadSettings(); // Tell the user we started. // Toast.makeText(this, "we started pedometer service bruh", Toast.LENGTH_SHORT).show(); }
// this method fills the user data from the shared preferences information public void fillUserFromPrefs() { this.name = sharedPreferences.getString("name", null); this.weight = sharedPreferences.getFloat("weight", 0); this.height = sharedPreferences.getFloat("height", 0); this.BMI = sharedPreferences.getFloat("BMI", 0); this.BMR = sharedPreferences.getFloat("BMR", 0); this.start_weight = sharedPreferences.getFloat("Starting_Weight", 0); this.start_lvl = sharedPreferences.getInt("Start_LVL", 0); this.cal_needs = sharedPreferences.getFloat("Cal_Needs", 0); this.cur_weight = sharedPreferences.getFloat("Current_Weight", 0); this.cur_lvl = sharedPreferences.getInt("Cur_Lvl", 0); this.email = sharedPreferences.getString("Email", null); this.phone = sharedPreferences.getString("Phone", null); }
// return last camera position public CameraPosition getSavedCameraPosition() { double latitude = mapStatePrefs.getFloat(LATITUDE, 0); if (latitude == 0) { return null; } double longitude = mapStatePrefs.getFloat(LONGITUDE, 0); LatLng target = new LatLng(latitude, longitude); float zoom = mapStatePrefs.getFloat(ZOOM, 0); float bearing = mapStatePrefs.getFloat(BEARING, 0); float tilt = mapStatePrefs.getFloat(TILT, 0); CameraPosition position = new CameraPosition(target, zoom, tilt, bearing); return position; }
public void loadSettings() { // if does not exist load default SharedPreferences settings = getActivity().getSharedPreferences(PREF_TITLE, 0); StringBuilder sb = new StringBuilder(); et_serv.setText(settings.getString(PREF_URL, DEFAULT_URL)); et_user.setText(settings.getString(PREF_USER, DEFAULT_USER)); et_pass.setText(settings.getString(PREF_PASS, DEFAULT_PASS)); et_thread.setText(sb.append(settings.getInt(PREF_THREAD, DEFAULT_THREAD)).toString()); sb.setLength(0); sb_throttle.setProgress((int) (settings.getFloat(PREF_THROTTLE, DEFAULT_THROTTLE) * 100)); et_scanTime.setText(sb.append(settings.getLong(PREF_SCANTIME, DEFAULT_SCANTIME)).toString()); sb.setLength(0); et_retryPause.setText( sb.append(settings.getLong(PREF_RETRYPAUSE, DEFAULT_RETRYPAUSE)).toString()); cb_service.setChecked(settings.getBoolean(PREF_BACKGROUND, DEFAULT_BACKGROUND)); cb_donate.setChecked(settings.getBoolean(PREF_DONATE, DEFAULT_DONATE)); if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.MIN_PRIORITY) { spn_priority.setSelection(0); } if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.NORM_PRIORITY) { spn_priority.setSelection(1); } if (settings.getInt(PREF_PRIORITY, DEFAULT_PRIORITY) == Thread.MAX_PRIORITY) { spn_priority.setSelection(2); } Toast.makeText(getActivity(), "Settings Loaded", Toast.LENGTH_SHORT).show(); }
public static float[] loadBaseValueArray(String arrayName, Context mContext) { SharedPreferences prefs = mContext.getSharedPreferences("bases", 0); int size = prefs.getInt(arrayName + "_size", 0); float array[] = new float[size]; for (int i = 0; i < size; i++) array[i] = prefs.getFloat(arrayName + "_" + i, 0); return array; }
/** * Initializes an {@link InputOverlayDrawableJoystick} * * @param context The current {@link Context} * @param resOuter Resource ID for the outer image of the joystick (the static image that shows * the circular bounds). * @param resInner Resource ID for the inner image of the joystick (the one you actually move * around). * @param joystick Identifier for which joystick this is. * @return the initialized {@link InputOverlayDrawableJoystick}. */ private static InputOverlayDrawableJoystick initializeOverlayJoystick( Context context, int resOuter, int resInner, int joystick) { // Resources handle for fetching the initial Drawable resource. final Resources res = context.getResources(); // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); // Initialize the InputOverlayDrawableJoystick. final Bitmap bitmapOuter = resizeBitmap(context, BitmapFactory.decodeResource(res, resOuter), 0.30f); final Bitmap bitmapInner = BitmapFactory.decodeResource(res, resInner); // String ID of the Drawable. This is what is passed into SharedPreferences // to check whether or not a value has been set. final String drawableId = res.getResourceEntryName(resOuter); // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. // These were set in the input overlay configuration menu. int drawableX = (int) sPrefs.getFloat(drawableId + "-X", 0f); int drawableY = (int) sPrefs.getFloat(drawableId + "-Y", 0f); // Now set the bounds for the InputOverlayDrawableJoystick. // This will dictate where on the screen (and the what the size) the // InputOverlayDrawableJoystick will be. int outerSize = bitmapOuter.getWidth(); Rect outerRect = new Rect(drawableX, drawableY, drawableX + outerSize, drawableY + outerSize); Rect innerRect = new Rect(0, 0, outerSize / 4, outerSize / 4); final InputOverlayDrawableJoystick overlayDrawable = new InputOverlayDrawableJoystick( res, bitmapOuter, bitmapInner, outerRect, innerRect, joystick); return overlayDrawable; }
private void read_prefs() { SharedPreferences lPrefs = getSharedPreferences("DatLogPrefs", MODE_PRIVATE); CLocProvStates lLPStates = mLPStates; CSensorStates lSenNames = mSenStates; float mindist; long mintime; boolean val; int rate; // Read the sensor preferences for (int i = 0; i < lSenNames.getNum(); i++) { val = lPrefs.getBoolean(lSenNames.getName(i), false); lSenNames.setActive(i, val); rate = lPrefs.getInt(lSenNames.getName(i) + "_rate", SensorManager.SENSOR_DELAY_FASTEST); lSenNames.setRate(i, rate); } // Read the location provider preferences for (int i = 0; i < lLPStates.getNum(); i++) { val = lPrefs.getBoolean(lLPStates.getName(i), false); lLPStates.setActive(i, val); mindist = lPrefs.getFloat(lLPStates.getName(i) + "_mindist", 0); mintime = lPrefs.getLong(lLPStates.getName(i) + "_mintime", 0); lLPStates.setCriterion(i, mindist, mintime); } // Read the GPS Status preference val = lPrefs.getBoolean("gps_status", false); }
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); findPreference("about").setOnPreferenceClickListener(this); Preference account = findPreference("account"); account.setOnPreferenceClickListener(this); if (((MainActivity) getActivity()).getGC().isConnected()) { account.setSummary( getString( R.string.signed_in, ((MainActivity) getActivity()).getGC().getCurrentPlayer().getDisplayName())); } final SharedPreferences prefs = getPreferenceManager().getSharedPreferences(); Preference goal = findPreference("goal"); goal.setOnPreferenceClickListener(this); goal.setSummary(getString(R.string.goal_summary, prefs.getInt("goal", DEFAULT_GOAL))); Preference stepsize = findPreference("stepsize"); stepsize.setOnPreferenceClickListener(this); stepsize.setSummary( getString( R.string.step_size_summary, prefs.getFloat("stepsize_value", DEFAULT_STEP_SIZE), prefs.getString("stepsize_unit", DEFAULT_STEP_UNIT))); setHasOptionsMenu(true); }
@SuppressWarnings("unchecked") private T load() { if (type == String.class) { return (T) sp.getString(name, (String) defValue); } else if (type == Integer.class) { return (T) Integer.valueOf(sp.getInt(name, (Integer) defValue)); } else if (type == Float.class) { return (T) Float.valueOf(sp.getFloat(name, (Float) defValue)); } else if (type == Long.class) { return (T) Long.valueOf(sp.getLong(name, (Long) defValue)); } else if (type == Boolean.class) { return (T) Boolean.valueOf(sp.getBoolean(name, (Boolean) defValue)); } return null; }
public void initResource() { /* * Load MapObject property */ for (EObjectType objectType : EObjectType.values()) { objectType.setColor( new float[] { mPreferences.getFloat(objectType.R_KEY, objectType.getDefaultColor()[0]), mPreferences.getFloat(objectType.G_KEY, objectType.getDefaultColor()[1]), mPreferences.getFloat(objectType.B_KEY, objectType.getDefaultColor()[2]), mPreferences.getFloat(objectType.ALPHA_KEY, objectType.getDefaultColor()[3]) }); objectType.setVisibile(mPreferences.getBoolean(objectType.name(), true)); } }
private float getDistanceFromPreferences() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); float prefDist = prefs.getFloat(PrefKey.LIST_DISTANCE, QUERY_DISTANCE_DEFAULT); return prefDist; }
/** Loads all settings from the storage. Should be called on the begin of app's lifecycle. */ public final void load(@NonNull Context context) { synchronized (this) { Resources res = context.getResources(); SharedPreferences prefs = getSharedPreferences(context); for (Option option : getMap().values()) { // Get the current value. Object value = option.getDefault(res); if (boolean.class.isAssignableFrom(option.clazz)) { value = prefs.getBoolean(option.key, (Boolean) value); } else if (int.class.isAssignableFrom(option.clazz)) { value = prefs.getInt(option.key, (Integer) value); } else if (float.class.isAssignableFrom(option.clazz)) { value = prefs.getFloat(option.key, (Float) value); } else if (String.class.isAssignableFrom(option.clazz)) { value = prefs.getString(option.key, (String) value); } else if (long.class.isAssignableFrom(option.clazz)) { value = prefs.getLong(option.key, (Long) value); } else throw new IllegalArgumentException("Unknown option\'s type."); Log.d(TAG, "Init option=" + option.key + " with " + value); // Set the current value. option.setValue(value); } } }
@Override public boolean exportValue(JSONObject json, String key, SharedPreferences preferences) { final Preference preference = supportedMap.get(key); if (preference == null || !preference.exportable()) return false; try { switch (preference.type()) { case BOOLEAN: json.put(key, preferences.getBoolean(key, preference.defaultBoolean())); break; case INT: json.put(key, preferences.getInt(key, preference.defaultInt())); break; case LONG: json.put(key, preferences.getLong(key, preference.defaultLong())); break; case FLOAT: json.put(key, preferences.getFloat(key, preference.defaultFloat())); break; case STRING: json.put(key, preferences.getString(key, preference.defaultString())); break; default: break; } } catch (JSONException e) { return false; } return true; }
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { Log.i("TAG", "onActivityCreated"); super.onActivityCreated(savedInstanceState); btn_steps = new Button[4]; btn_steps[0] = (Button) getActivity().findViewById(R.id.step0); btn_steps[1] = (Button) getActivity().findViewById(R.id.step1); btn_steps[2] = (Button) getActivity().findViewById(R.id.step2); btn_steps[3] = (Button) getActivity().findViewById(R.id.step3); mMapManeger = new MapManager(); mapLayout = new MapLayout(getActivity()); mMapView = mapLayout.getMapView(); mMapView.setDaumMapApiKey("c7e2c768ceb283cba77acced06e1203b"); mMapView.setMapViewEventListener(this); mMapView.setPOIItemEventListener(this); mMapView.setMapType(MapView.MapType.Standard); ViewGroup mapViewContainer = (ViewGroup) getActivity().findViewById(R.id.map_view); mapViewContainer.addView(mapLayout); SharedPreferences sharedPreferences = getActivity().getSharedPreferences("GnBang", getContext().MODE_PRIVATE); CurrentZoomLevel = sharedPreferences.getInt("Zoomlevel", DEFAULT_ZOOM_LEVEL); CurrentLat = sharedPreferences.getFloat("Lat", (float) DEFAULT_LAT); CurrentLon = sharedPreferences.getFloat("Lon", (float) DEFAULT_LON); CurrentSelect = sharedPreferences.getInt("Select", DEFAULT_SELECT); mMapView.setMapCenterPointAndZoomLevel( MapPoint.mapPointWithGeoCoord(CurrentLat, CurrentLon), CurrentZoomLevel, true); mMapView = mMapManeger.CreateMarker(mMapView, CurrentZoomLevel); btn_steps = mMapManeger.SelectCity(CurrentSelect, btn_steps); }
private RequestThrottler(Context context, int uid) { mSharedPreferences = context.getSharedPreferences(PREFERENCES_NAME, 0); mUid = uid; mScore = mSharedPreferences.getFloat(SCORE + uid, MAX_SCORE); mLastPrerenderRequestMs = mSharedPreferences.getLong(LAST_REQUEST + uid, 0); mBannedUntilMs = mSharedPreferences.getLong(BANNED_UNTIL + uid, 0); }
public static IGeoPoint getCenter( final Context context, final IGeoPoint priorityCenter, final Location previousLocation) { IGeoPoint centerPoint = DEFAULT_POINT; final Location location = ListActivity.lameStatic.location; final SharedPreferences prefs = context.getSharedPreferences(ListActivity.SHARED_PREFS, 0); if (priorityCenter != null) { centerPoint = priorityCenter; } else if (location != null) { centerPoint = new GeoPoint(location); } else if (previousLocation != null) { centerPoint = new GeoPoint(previousLocation); } else { final Location gpsLocation = safelyGetLast(context, LocationManager.GPS_PROVIDER); final Location networkLocation = safelyGetLast(context, LocationManager.NETWORK_PROVIDER); if (gpsLocation != null) { centerPoint = new GeoPoint(gpsLocation); } else if (networkLocation != null) { centerPoint = new GeoPoint(networkLocation); } else { // ok, try the saved prefs float lat = prefs.getFloat(ListActivity.PREF_PREV_LAT, Float.MIN_VALUE); float lon = prefs.getFloat(ListActivity.PREF_PREV_LON, Float.MIN_VALUE); if (lat != Float.MIN_VALUE && lon != Float.MIN_VALUE) { centerPoint = new GeoPoint(lat, lon); } } } return centerPoint; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_setting); timeOut = (TextView) findViewById(R.id.editTimeOut); sharedPref = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE); timeOut.setText(String.format("%.2f", sharedPref.getFloat(FILENAME, 1f))); }
protected void restoreTextState() { EditTextScaleRotateView.TextState state = new EditTextScaleRotateView.TextState(); String STORE_NAME = "TextStateInfo"; SharedPreferences settings = getSharedPreferences(STORE_NAME, MODE_PRIVATE); state.mOutlineEllipse = settings.getInt("mOutlineEllipse", 12); state.mOutlineStrokeColor = settings.getInt("mOutlineStrokeColor", 0xff00FF00); state.mPadding = settings.getInt("mPadding", 15); state.mTextColor = settings.getInt("mTextColor", 0xffff0000); state.mDegree = settings.getFloat("mDegree", 0); state.mRectCenterX = settings.getFloat("mRectCenterX", 400); state.mRectCenterY = settings.getFloat("mRectCenterY", 200); state.mStrokeWidth = settings.getFloat("mStrokeWidth", 5); state.mTextSize = settings.getFloat("mTextSize", 24); state.mText = settings.getString("mText", ""); mTextView.initBy(state); }
/** * Equivalent to {@code getFloat(key, defaultValue)} on the internal SharedPreferences instance. * If the given key is null, {@code defaultValue} is returned. */ @Override public float getFloat(String key, float defaultValue) { if (key == null) { return defaultValue; } return prefs.getFloat(key, defaultValue); }
public LatLon getPointToNavigate() { float lat = globalPreferences.getFloat(POINT_NAVIGATE_LAT, 0); float lon = globalPreferences.getFloat(POINT_NAVIGATE_LON, 0); if (lat == 0 && lon == 0) { return null; } return new LatLon(lat, lon); }
public static Double getDouble(Context context, String key) { double isi; SharedPreferences sharedPreferences = context.getSharedPreferences("Zelory", Context.MODE_PRIVATE); switch (key) { case "lat": isi = sharedPreferences.getFloat(key, -7.7521492f); break; case "lon": isi = sharedPreferences.getFloat(key, 110.377659f); break; default: isi = sharedPreferences.getFloat(key, 0); } return isi; }
private Feedback readFromPreference() { SharedPreferences sharedPreferences = getSharedPreferences("TarotAppFeedback", Context.MODE_PRIVATE); Feedback feedback = new Feedback(); feedback.setFeedback(sharedPreferences.getString("feedback", "")); feedback.setRating(sharedPreferences.getFloat("rating", 0.0f)); feedback.setObjectId(sharedPreferences.getString("objectID", "")); return feedback; }
public float getFloatData(String key) { float resp = 0; try { resp = sharedPreferences.getFloat(key, 0); } catch (Exception e) { } return resp; }