Example usage for android.content SharedPreferences getFloat

List of usage examples for android.content SharedPreferences getFloat

Introduction

In this page you can find the example usage for android.content SharedPreferences getFloat.

Prototype

float getFloat(String key, float defValue);

Source Link

Document

Retrieve a float value from the preferences.

Usage

From source file:com.nextgis.ngm_clink_monitoring.fragments.MapFragment.java

@Override
public void onResume() {
    super.onResume();

    GISApplication app = (GISApplication) getActivity().getApplication();

    if (null != mGpsEventSource) {
        mGpsEventSource.addListener(this);
    }/* w  ww .ja va  2 s  . c  om*/

    mCurrentCenter = null;

    if (null != mMapView) {
        mMapView.addListener(this);

        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

        float mapZoom = prefs.getFloat(FoclSettingsConstantsUI.KEY_PREF_ZOOM_LEVEL, mMapView.getMinZoom());
        double mapScrollX = Double
                .longBitsToDouble(prefs.getLong(FoclSettingsConstantsUI.KEY_PREF_SCROLL_X, 0));
        double mapScrollY = Double
                .longBitsToDouble(prefs.getLong(FoclSettingsConstantsUI.KEY_PREF_SCROLL_Y, 0));
        mMapView.setZoomAndCenter(mapZoom, new GeoPoint(mapScrollX, mapScrollY));

        //change zoom controls visibility
        boolean showControls = prefs.getBoolean(FoclSettingsConstantsUI.KEY_PREF_SHOW_ZOOM_CONTROLS, false);

        if (showControls) {
            addMapButtons();
        } else {
            removeMapButtons();
        }

        if (null != mCurrentLocationOverlay) {
            mCurrentLocationOverlay.updateMode(app.getLocationOverlayMode());
            mCurrentLocationOverlay.startShowingCurrentLocation();
            mMapView.addOverlay(mCurrentLocationOverlay);
        }

        if (null != mGpsEventSource && onMenuMapClicked) {
            onMenuMapClicked = false;
            Location lastLocation = mGpsEventSource.getLastKnownLocation();
            setCurrentCenter(lastLocation);
            locateCurrentPositionAndZoom(false, lastLocation);
        }

        /// TODO: ???
        //             mMapView.drawMapDrawable();
    }
}

From source file:ngoc.com.pedometer.ui.Fragment_Overview.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./*w  w  w.  j av  a2s .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_total));
        averageView.setText(formatter.format(distance_total / total_days));
    }
}

From source file:ngoc.com.pedometer.ui.Fragment_Overview.java

/**
 * Updates the bar graph to show the steps/distance of the last week. Should
 * be called when switching from step count to distance.
 *///  w w w. j  a va  2s.co  m
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, 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);
    db.close();
    for (int i = last.size() - 1; i > 0; i--) {
        Pair<Long, 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"));
            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);
            }
            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.GONE);
    }
}

From source file:com.artemchep.horario.content.PreferenceStore.java

public void load(@NonNull Context context) {
    mMap = new HashMap<>();
    loadPreferencesMap(mMap);/*from w  ww.  j  av  a 2s .co  m*/
    String name = getPreferenceName();
    SharedPreferences sp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
    for (Preference pref : mMap.values()) {
        Object value = pref.value;
        if (boolean.class.isAssignableFrom(pref.clazz)) {
            value = sp.getBoolean(pref.key, (Boolean) value);
        } else if (int.class.isAssignableFrom(pref.clazz)) {
            value = sp.getInt(pref.key, (Integer) value);
        } else if (float.class.isAssignableFrom(pref.clazz)) {
            value = sp.getFloat(pref.key, (Float) value);
        } else if (String.class.isAssignableFrom(pref.clazz)) {
            value = sp.getString(pref.key, (String) value);
        } else if (long.class.isAssignableFrom(pref.clazz)) {
            value = sp.getLong(pref.key, (Long) value);
        } else
            throw new IllegalArgumentException("Unknown option\'s type.");
        pref.value = value;
    }
}

From source file:org.uoyabause.android.PadButton.java

private void init() {

    setOnTouchListener(this);

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
    base_scale = sharedPref.getFloat("pref_pad_scale", 0.5f);
    _transparent = sharedPref.getFloat("pref_pad_trans", 1.0f);

    buttons = new PadButton[PadEvent.BUTTON_LAST];
    buttons[PadEvent.BUTTON_UP] = new DPadButton();
    buttons[PadEvent.BUTTON_RIGHT] = new DPadButton();
    buttons[PadEvent.BUTTON_DOWN] = new DPadButton();
    buttons[PadEvent.BUTTON_LEFT] = new DPadButton();
    buttons[PadEvent.BUTTON_RIGHT_TRIGGER] = new DPadButton();
    buttons[PadEvent.BUTTON_LEFT_TRIGGER] = new DPadButton();
    buttons[PadEvent.BUTTON_START] = new StartButton();
    buttons[PadEvent.BUTTON_A] = new ActionButton((int) (100), "", 40);
    buttons[PadEvent.BUTTON_B] = new ActionButton((int) (100), "", 40);
    buttons[PadEvent.BUTTON_C] = new ActionButton((int) (100), "", 40);
    buttons[PadEvent.BUTTON_X] = new ActionButton((int) (72), "", 25);
    buttons[PadEvent.BUTTON_Y] = new ActionButton((int) (72), "", 25);
    buttons[PadEvent.BUTTON_Z] = new ActionButton((int) (72), "", 25);

    _analog_pad = new AnalogPad((int) (256), "", 40);

    active = new HashMap<Integer, Integer>();

}

From source file:de.grundid.plusrad.recording.RecordingService.java

private void resumeTracking() {
    Log.i(TAG, "restarting tracking...");
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    int testState = sharedPreferences.getInt(CURRENT_STATE, -1);
    long testTripId = sharedPreferences.getLong(CURRENT_TRIP_ID, -1);
    if (testState != -1 && testTripId != -1) {
        this.state = testState;
        TripData tripData = dbAdapter.getTrip(testTripId);
        float distanceTraveled = sharedPreferences.getFloat(DISTANCE_TRAVELED, 0);
        float maxSpeed = sharedPreferences.getFloat(MAX_SPEED, 0);
        float currentSpeed = sharedPreferences.getFloat(CURRENT_SPEED, 0);
        int points = sharedPreferences.getInt(POINTS, 0);
        long standingTime = sharedPreferences.getLong(STANDING_TIME, 0);
        long pauseTimestamp = sharedPreferences.getLong(PAUSE_TIMESTAMP, 0);
        boolean manualPause = sharedPreferences.getBoolean(MANUAL_PAUSE, false);
        trip = new CurrentTrip(tripData, distanceTraveled, maxSpeed, currentSpeed, points, standingTime,
                pauseTimestamp, manualPause);
        if (state == STATE_RECORDING) {
            startLocationUpdates();//from   w w  w . j  ava 2s . c  om
        }
    }
}

From source file:com.bellman.bible.service.device.speak.SpeakTextProvider.java

/**
 * restore state to allow long pauses//from   w  w w.j a va 2 s  . c om
 *
 * @return state restored
 */
public boolean restoreState() {
    boolean isRestored = false;
    SharedPreferences sharedPreferences = CommonUtils.getSharedPreferences();
    if (sharedPreferences.contains(PERSIST_SPEAK_TEXT)) {
        mTextToSpeak = new ArrayList<String>(Arrays.asList(
                sharedPreferences.getString(PERSIST_SPEAK_TEXT, "").split(PERSIST_SPEAK_TEXT_SEPARATOR)));
        nextTextToSpeak = sharedPreferences.getInt(PERSIST_NEXT_TEXT, 0);
        fractionOfNextSentenceSpoken = sharedPreferences.getFloat(PERSIST_FRACTION_SPOKEN, 0);
        clearPersistedState();
        isRestored = true;
    }

    return isRestored;
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void setSaved(int index) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    Location location = new Location("POINT_LOCATION");
    location.setLatitude(0);// w w  w.  jav a  2  s .  c  o  m
    location.setLongitude(0);
    int setRad = 0;
    String setAddress = "";
    if (prefs.contains(POINT_LATITUDE_KEY + index)) {
        location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + index, 0));
    }
    if (prefs.contains(POINT_LONGITUDE_KEY + index)) {
        location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + index, 0));
    }
    if (prefs.contains(POINT_RADIUS_KEY + index)) {
        setRad = prefs.getInt(POINT_RADIUS_KEY + index, 0);
    }
    if (prefs.contains(POINT_ADDRESS_KEY + index)) {
        setAddress = prefs.getString(POINT_ADDRESS_KEY + index, "");
    }

    touchSaveIndex(1);

    float setLat = (float) location.getLatitude();
    float setLong = (float) location.getLongitude();
    prefsEditor.putFloat(SAVED_LATITUDE_KEY + touchSaveIndex(0), setLat);
    prefsEditor.putFloat(SAVED_LONGITUDE_KEY + touchSaveIndex(0), setLong);
    prefsEditor.putInt(SAVED_RADIUS_KEY + touchSaveIndex(0), setRad);
    prefsEditor.putString(SAVED_ADDRESS_KEY + touchSaveIndex(0), setAddress);
    prefsEditor.commit();
}

From source file:com.geoffreybuttercrumbs.arewethereyet.DrawerFragment.java

private void recent() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);

    for (int i = 1; i <= 5; i++) {
        Location location = new Location("POINT_LOCATION");
        String address = prefs.getString(POINT_ADDRESS_KEY + i, "");
        location.setLatitude(0);/*from w  w  w. j a va 2  s .com*/
        location.setLongitude(0);
        if (prefs.contains(POINT_LATITUDE_KEY + i)) {
            location.setLatitude(prefs.getFloat(POINT_LATITUDE_KEY + i, 0));
        }
        if (prefs.contains(POINT_LONGITUDE_KEY + i)) {
            location.setLongitude(prefs.getFloat(POINT_LONGITUDE_KEY + i, 0));
        }

        LinearLayout RecentParent = (LinearLayout) V.findViewById(R.id.group_recent);
        View Recent = inflater.inflate(R.layout.saved_item, null);
        Recent.setOnClickListener(this);

        CharSequence name;
        if (!address.equals("")) {
            name = address;
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDDFFFFFF);
            ((CompoundButton) Recent.findViewById(R.id.saveCB)).setOnCheckedChangeListener(this);
        } else {
            name = "No Recent Alarms";
            ((TextView) Recent.findViewById(R.id.savedLabel)).setTextColor(0xDD999999);
            Recent.findViewById(R.id.saveCB).setEnabled(false);
        }

        ((TextView) Recent.findViewById(R.id.savedLabel)).setText(name);
        ((TextView) Recent.findViewById(R.id.savedLabel)).setTextSize(14);
        Recent.findViewById(R.id.saveCB).setTag(i);
        Recent.setId(i);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        RecentParent.setLayoutParams(params);
        RecentParent.addView(Recent);
    }
}

From source file:com.digitallizard.nicecompass.CompassActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // create the gui
    setContentView(R.layout.main);//from  ww w . ja  va2s. com

    // load in the settings
    SharedPreferences settings = this.getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE);
    boolean useTrueNorth = settings.getBoolean(PREFKEY_USE_TRUE_NORTH, DEFAULT_USE_TRUE_NORTH);

    // initialize variables
    compass = new CompassManager(this);
    surface = new CompassSurface(this, compass, useTrueNorth);
    surfaceContainer = (LinearLayout) findViewById(R.id.compassSurfaceContainer);

    // check if we need to enable manual declination
    if (settings.getBoolean(PREFKEY_USE_MANUAL_DECLINATION, false)) {
        surface.setManualDeclination(
                settings.getFloat(PREFKEY_MANUAL_DECLINATION_VALUE, DEFAULT_MANUAL_DECLINATION));
    }

    // prevent gradient banding
    surface.getHolder().setFormat(android.graphics.PixelFormat.TRANSPARENT);

    // add the compass
    surfaceContainer.addView(surface);
}