List of usage examples for android.content SharedPreferences getFloat
float getFloat(String key, float defValue);
From source file:aarddict.android.ArticleViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) { applyTextZoomPref();/* ww w . j ava 2s . c o m*/ } else { SharedPreferences prefs = getPreferences(MODE_PRIVATE); float scale = prefs.getFloat("articleView.scale", 1.0f); int initialScale = Math.round(scale * 100); Log.d(TAG, "Setting initial article view scale to " + initialScale); articleView.setInitialScale(initialScale); } if (android.os.Build.VERSION.SDK_INT >= 11) { try { Method getActionBar = getClass().getMethod("getActionBar"); Object actionBar = getActionBar.invoke(this); Method setDisplayHomeAsUpEnabled = actionBar.getClass().getMethod("setDisplayHomeAsUpEnabled", boolean.class); setDisplayHomeAsUpEnabled.invoke(actionBar, true); } catch (Exception e) { } } }
From source file:gr.scify.newsum.ui.ViewActivity.java
protected void updateTextSize() { final TextView tx = (TextView) findViewById(R.id.textView1); float defSize = tx.getTextSize(); SharedPreferences usersize = ViewActivity.this.getSharedPreferences("textS", 0); float newSize = usersize.getFloat("size", defSize); tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize); }
From source file:com.first.akashshrivastava.showernow.ShowerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_shower_activity); /*Launching BootReceiver to test Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class); startActivity(playIntent);/* w w w . j a v a2 s. c o m*/ */ //Mobile ads initialization....The long number is the AdID, can be found on AdMob - ca-app-pub-8782530512283806/2988799979 MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979"); AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); //Facebook SDK initialization... FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); shareDialog = new ShareDialog(this); mDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAuth = FirebaseAuth.getInstance(); final ImageView genderImage = (ImageView) findViewById(R.id.imageGender); guyText = (TextView) findViewById(R.id.guyText); topText = (TextView) findViewById(R.id.textView2); SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); extraAge = prefs.getInt("age", 0); extraFluffiness = prefs.getString("fluffiness", ""); extraGender = prefs.getString("gender", ""); extraOldTime = prefs.getLong("time", 0); extraSteps = prefs.getFloat("stepsBoot", 0); switch (extraGender) { case "male": genderImage.setImageResource(R.drawable.male_white_outline); break; case "female": genderImage.setImageResource(R.drawable.female_white_outline); break; case "other": genderImage.setImageResource(R.drawable.other_white_outline); break; } genderImage.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //set alarm //Swith ccase switch (event.getAction()) { case MotionEvent.ACTION_UP: // PRESSED ..PRESSED if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline); } //Resets the wave after shower..this is not getting called for some reason.... waveProgressbar.setCurrent(0, ""); guyText.setText("0 %"); waveProgressbar.setVisibility(View.INVISIBLE); topText.setText("You have showered! \n When the wave hits 100% its time for your next shower "); if (fluffiness != null && gotSteps) { Calendar cal = Calendar.getInstance(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); activate.putExtra("age", age); activate.putExtra("fluffiness", fluffiness); activate.putExtra("gender", gender); activate.putExtra("steps", steps); activate.putExtra("time", System.currentTimeMillis()); AlarmManager alarms; PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60, alarmIntent);//sets the alarm mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Steps").setValue(steps);//sets old steps oldSteps = steps; mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Time").setValue(System.currentTimeMillis()); oldTime = System.currentTimeMillis(); newUser = false; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", age); editor.putString("fluffiness", fluffiness); editor.putString("gender", gender); editor.putFloat("steps", steps); editor.putLong("time", System.currentTimeMillis()); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", true); editor.apply(); } else if (!gotSteps) { Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show(); } return true; // if you want to handle the touch event case MotionEvent.ACTION_DOWN: // RELEASED..RELEASED.. if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.female_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.female_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.male_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.male_white_outline_pressed); } else if (genderImage.getDrawable().getConstantState() == getResources() .getDrawable(R.drawable.other_white_outline).getConstantState()) { genderImage.setImageResource(R.drawable.other_white_outline_pressed); } return true; // if you want to handle the touch event } //Switch case end bracket return false; } }); createWave(); setMenuColor(); setupStepcount(); setWaveHeight(); FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity editDetails.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* Fragment fragment = new Fragment(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(ShowerActivity.java); transaction.addToBackStack(ShowerActivity.java); transaction.commit(); */ //Fragment B at pos 2 should open when edit details is pressed.. Intent i = new Intent(ShowerActivity.this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); } }); FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account); fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog(); } }); FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item); fabMenuItem1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);?? PackageManager pm = ShowerActivity.this.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/ //mFirebaseAuth.getCurrentUser().getUid() =null; SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("age", 0); editor.putString("fluffiness", ""); editor.putString("gender", ""); editor.putFloat("steps", 0); editor.putLong("time", 0); editor.putFloat("stepsBoot", 0); editor.putBoolean("bootStart", false); editor.apply(); Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class); PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate, FLAG_CANCEL_CURRENT); AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE); alarms.cancel(alarmIntent); stopService(new Intent(ShowerActivity.this, StepCountService.class)); mFirebaseAuth.getInstance().signOut(); Intent i = new Intent(ShowerActivity.this, LoginActivity.class); startActivity(i); } }); final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton); shareButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n"; String shareSubString = "An app that tells you when you should shower and apparently keeps you clean"; shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString); shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody); startActivity(Intent.createChooser(shareIntent, " Share using the following")); } }); mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snap) { try { if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty())) && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("female")) { genderImage.setImageResource(R.drawable.female_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("male")) { genderImage.setImageResource(R.drawable.male_white_outline); } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString().equalsIgnoreCase("other")) { genderImage.setImageResource(R.drawable.other_white_outline); } } catch (Exception e) { e.printStackTrace(); } age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()) .child("Age").getValue().toString());//gotta get int fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender") .getValue().toString(); if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) { oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time") .getValue(Long.class); oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps") .getValue(float.class); } else { newUser = true; } } @Override public void onCancelled(DatabaseError databaseError) { } }); }
From source file:com.nextgis.woody.fragment.MapFragment.java
@Override public void onResume() { super.onResume(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (null != mMap && !mShowSelectLocation) { if (prefs.getBoolean(SettingsConstants.KEY_PREF_MAP_FIRST_VIEW, true)) { // Zoom to trees extent MapDrawable md = mMap.getMap(); ILayer layer = md.getLayerByName(Constants.KEY_MAIN); if (layer instanceof VectorLayer) { VectorLayer vectorLayer = (VectorLayer) layer; mMap.zoomToExtent(vectorLayer.getExtents()); }/*from w w w.ja v a 2s . c o m*/ final SharedPreferences.Editor edit = prefs.edit(); edit.putBoolean(SettingsConstants.KEY_PREF_MAP_FIRST_VIEW, false); edit.commit(); } else { float mMapZoom; try { mMapZoom = prefs.getFloat(SettingsConstants.KEY_PREF_ZOOM_LEVEL, mMap.getMinZoom()); } catch (ClassCastException e) { mMapZoom = mMap.getMinZoom(); } double mMapScrollX; double mMapScrollY; try { mMapScrollX = Double.longBitsToDouble(prefs.getLong(SettingsConstants.KEY_PREF_SCROLL_X, 0)); mMapScrollY = Double.longBitsToDouble(prefs.getLong(SettingsConstants.KEY_PREF_SCROLL_Y, 0)); } catch (ClassCastException e) { mMapScrollX = 0; mMapScrollY = 0; } mMap.setZoomAndCenter(mMapZoom, new GeoPoint(mMapScrollX, mMapScrollY)); } mMap.addListener(this); } resumeGps(); mCurrentCenter = null; }
From source file:com.coincide.alphafitness.ui.Fragment_Main.java
/** * Updates the pie graph to show todays steps/distance as well as the * yesterday and total values. Should be called when switching from step * count to distance./*from w w w . j av a2 s . co m*/ */ private void updatePie() { if (BuildConfig.DEBUG) Logger.log("UI - update steps: " + since_boot); // todayOffset might still be Integer.MIN_VALUE on first start int steps_today = Math.max(todayOffset + since_boot, 0); /* sliceCurrent.setValue(steps_today); if (goal - steps_today > 0) { // goal not reached yet if (pg.getData().size() == 1) { // can happen if the goal value was changed: old goal value was // reached but now there are some steps missing for the new goal pg.addPieSlice(sliceGoal); } sliceGoal.setValue(goal - steps_today); } else { // goal reached pg.clearChart(); pg.addPieSlice(sliceCurrent); } pg.update();*/ if (showSteps) { // stepsView.setText(formatter.format(steps_today)); totalView.setText(formatter.format(total_start + steps_today)); // averageView.setText(formatter.format((total_start + steps_today) / total_days)); } else { // update only every 10 steps when displaying distance SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE); float stepsize = prefs.getFloat("stepsize_value", Fragment_Settings.DEFAULT_STEP_SIZE); float distance_today = steps_today * stepsize; float distance_total = (total_start + steps_today) * stepsize; if (prefs.getString("stepsize_unit", Fragment_Settings.DEFAULT_STEP_UNIT).equals("cm")) { distance_today /= 100000; distance_total /= 100000; } else { distance_today /= 5280; distance_total /= 5280; } // stepsView.setText(formatter.format(distance_today)); totalView.setText(formatter.format(distance_today)); // averageView.setText(formatter.format(distance_total / total_days)); // avg_distance=formatter.format(distance_total / total_days); avg_distance = distance_total / 7; all_distance = distance_total; all_calories = (float) (mBodyWeight * (METRIC_WALKING_FACTOR)) * distance_total; avg_calories = (float) (mBodyWeight * (METRIC_WALKING_FACTOR)) * distance_total / 7; // Distance: // * mStepLength // centimeters // / 100000.0; // centimeters/kilometer today_distance = distance_today; today_calories = (float) (mBodyWeight * (METRIC_WALKING_FACTOR)) * distance_total; } }
From source file:com.coincide.alphafitness.ui.Fragment_Main.java
/** * Updates the bar graph to show the steps/distance of the last week. Should * be called when switching from step count to distance. *///from w w w . ja va 2 s. com private void updateBars() { SimpleDateFormat df = new SimpleDateFormat("E", Locale.getDefault()); BarChart barChart = (BarChart) getView().findViewById(R.id.bargraph); if (barChart.getData().size() > 0) barChart.clearChart(); int steps; float distance = 0, stepsize = Fragment_Settings.DEFAULT_STEP_SIZE; boolean stepsize_cm = true; if (!showSteps) { // load some more settings if distance is needed SharedPreferences prefs = getActivity().getSharedPreferences("pedometer", Context.MODE_PRIVATE); stepsize = prefs.getFloat("stepsize_value", Fragment_Settings.DEFAULT_STEP_SIZE); stepsize_cm = prefs.getString("stepsize_unit", Fragment_Settings.DEFAULT_STEP_UNIT).equals("cm"); } barChart.setShowDecimal(!showSteps); // show decimal in distance view only BarModel bm; Database db = Database.getInstance(getActivity()); // List<Pair<Long, Integer>> last = db.getLastEntries(8); List<Pair<Float, Integer>> last = db.getWorkouts(8); db.close(); for (int i = last.size() - 1; i > 0; i--) { // Pair<Long, Integer> current = last.get(i); Pair<Float, Integer> current = last.get(i); steps = current.second; if (steps > 0) { // bm = new BarModel(df.format(new Date(current.first)), 0, // steps > goal ? Color.parseColor("#99CC00") : Color.parseColor("#0099cc")); bm = new BarModel("Calories Burnt", 0, Color.parseColor("#0099cc")); /*if (showSteps) { bm.setValue(steps); } else { distance = steps * stepsize; if (stepsize_cm) { distance /= 100000; } else { distance /= 5280; } distance = Math.round(distance * 1000) / 1000f; // 3 decimals bm.setValue(distance); }*/ bm.setValue(current.first); barChart.addBar(bm); } } /* bm=new BarModel("Calories Burnt",0,Color.parseColor("#0099cc")); bm.setValue(2.5f); barChart.addBar(bm); bm=new BarModel("Calories Burnt",0,Color.parseColor("#0099cc")); bm.setValue(1.5f); barChart.addBar(bm); bm=new BarModel("Calories Burnt",0,Color.parseColor("#0099cc")); bm.setValue(1.0f); barChart.addBar(bm); */ if (barChart.getData().size() > 0) { barChart.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { // Dialog_Statistics.getDialog(getActivity(), since_boot).show(); } }); barChart.startAnimation(); } else { barChart.setVisibility(View.VISIBLE); } // Database db = Database.getInstance(getActivity()); try { long avgDistance = db.getAVGDistance(); long avgTime = db.getAVGTime(); long millis = avgTime * 100; // obtained from StopWatch long minutes = (millis / 1000) / 60; long avg = minutes / avgDistance; tv_avg.setText(TimeFormatUtil.toDisplayString((int) avg)); avgDistance = db.getMAXDistance(); avgTime = db.getMAXTime(); millis = avgTime * 100; // obtained from StopWatch minutes = (millis / 1000) / 60; avg = minutes / avgDistance; tv_max.setText(TimeFormatUtil.toDisplayString((int) avg)); avgDistance = db.getMINDistance(); avgTime = db.getMINTime(); millis = avgTime * 100; // obtained from StopWatch minutes = (millis / 1000) / 60; avg = minutes / avgDistance; tv_min.setText(TimeFormatUtil.toDisplayString((int) avg)); } catch (Exception e) { } }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Read in the current user preferences. *///from w w w. j a v a 2 s . c o m private void readPrefs() { SharedPreferences prefs = this.getSharedPreferences(PrefUtils.FILTER_PREFS, Activity.MODE_PRIVATE); this.lpfActive = prefs.getBoolean(PrefUtils.LPF_ACTIVE_PREF, false); this.meanFilterActive = prefs.getBoolean(PrefUtils.MEAN_FILTER_ACTIVE_PREF, false); this.invertAxisActive = prefs.getBoolean(PrefUtils.INVERT_AXIS_ACTIVE, false); this.lpfTimeConstant = prefs.getFloat(PrefUtils.LPF_TIME_CONSTANT, 1); this.meanFilterTimeConstant = prefs.getFloat(PrefUtils.MEAN_FILTER_TIME_CONSTANT, 1); }
From source file:com.bullmobi.base.content.ConfigBase.java
protected void initInternal(@NonNull Context context) { try {/*from w ww . ja va 2s.com*/ 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 {//from w w w.j a v a2 s . 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.openatk.fieldnotebook.MainActivity.java
private void setUpMapIfNeeded() { if (map == null) { map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); }// w ww. j a v a 2 s. co m // markerHandler = new MarkerHandler(map, this, mCurrentRockSelected); // slideMenu.setMarkerHandler(markerHandler); if (map != null) { mapSettings = map.getUiSettings(); mapSettings.setZoomControlsEnabled(false); mapSettings.setMyLocationButtonEnabled(false); mapSettings.setTiltGesturesEnabled(false); map.setOnMapClickListener(this); map.setOnMarkerClickListener(this); map.setOnMarkerDragListener(this); map.setMapType(GoogleMap.MAP_TYPE_HYBRID); map.setMyLocationEnabled(true); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Float startLat = prefs.getFloat("StartupLat", START_LAT); Float startLng = prefs.getFloat("StartupLng", START_LNG); Float startZoom = prefs.getFloat("StartupZoom", START_ZOOM); map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(startLat, startLng), startZoom)); } drawMap(); }