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:org.kiwix.kiwixmobile.views.KiwixWebView.java

public void loadPrefs() {
    disableZoomControls();/*  w  w w  . j a  v  a 2s  .c om*/

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    boolean zoomEnabled = sharedPreferences.getBoolean(PREF_ZOOM_ENABLED, false);

    if (zoomEnabled) {
        int zoomScale = (int) sharedPreferences.getFloat(PREF_ZOOM, 100.0f);
        setInitialScale(zoomScale);
    } else {
        setInitialScale(0);
    }
}

From source file:org.oscim.android.MapActivity.java

/**
 * This method is called once by each MapView during its setup process.
 * //from   w  w w. j a  v  a2s  .co m
 * @param mapView
 *            the calling MapView.
 */
public final void registerMapView(MapView mapView) {
    mMapView = mapView;
    mMap = mapView.map();

    SharedPreferences sharedPreferences = getSharedPreferences(PREFERENCES_FILE, MODE_PRIVATE);

    if (containsViewport(sharedPreferences)) {
        // get and set the map position and zoom level
        int latitudeE6 = sharedPreferences.getInt(KEY_LATITUDE, 0);
        int longitudeE6 = sharedPreferences.getInt(KEY_LONGITUDE, 0);
        float scale = sharedPreferences.getFloat(KEY_MAP_SCALE, 1);

        MapPosition mapPosition = new MapPosition();
        mapPosition.setPosition(latitudeE6 / 1E6, longitudeE6 / 1E6);
        mapPosition.setScale(scale);

        mMap.setMapPosition(mapPosition);
    }
}

From source file:com.alley.android.ppi.app.OverviewFragment.java

private void readCameraSettingsFromPreferences() {
    Activity activity = getActivity();//from w ww  . j a va 2s  . c o  m
    if (latitude == 0 && longitude == 0 && zoom == 0 && activity != null) {
        SharedPreferences settings = activity.getSharedPreferences("MAP_SETTINGS", 0);
        latitude = settings.getFloat("latitude", (float) 0);
        longitude = settings.getFloat("longitude", (float) 0);
        zoom = settings.getFloat("zoom", 0);
        //Log.i(LOG_TAG, "readCameraSettingsFromPreferences read from preferences latitude:" + latitude + " longtitude:" + longitude + " zoom:" + zoom);
    }
}

From source file:uk.co.jarofgreen.cityoutdoors.UI.BrowseMapActivity.java

/**
 * This is where we can add markers or lines, add listeners or move the camera.
 * <p>//from   w w w  .  j  av  a  2s.  c  o  m
 * This should only be called once and when we are sure that {@link #mMap} is not null.
 */
private void setUpMap() {
    // first, do we start at a certain point or do we start at the default bounds?
    boolean zoomed = false;
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        Float lat = extras.getFloat("lat");
        Float lng = extras.getFloat("lng");
        Log.d("LOADMAP", Float.toString(lat));
        Log.d("LOADMAP", Float.toString(lng));
        if (lat != 0.0 && lng != 0.0) {
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lng), 18));
            zoomed = true;
        }
    }

    if (!zoomed) {
        // We can't call newLatLngBounds at this point, the map isn't sized and app crashes.
        // So first we set the map to our hard coded range so it's at least sensible.
        map.moveCamera(
                CameraUpdateFactory.newLatLngZoom(new LatLng(STARTING_LAT, STARTING_LNG), STARTING_ZOOM));

        // now set up a handler to zoom to correct place a second later. This feels like a bad hack.
        Handler handler = new Handler();
        final Runnable r = new Runnable() {
            public void run() {
                SharedPreferences settings = PreferenceManager
                        .getDefaultSharedPreferences(BrowseMapActivity.this);
                float startingBoundsMaxLat = settings.getFloat("startingBoundsMaxLat", 0);
                float startingBoundsMinLat = settings.getFloat("startingBoundsMinLat", 0);
                float startingBoundsMaxLng = settings.getFloat("startingBoundsMaxLng", 0);
                float startingBoundsMinLng = settings.getFloat("startingBoundsMinLng", 0);

                if (!(startingBoundsMaxLat == 0 && startingBoundsMinLat == 0 && startingBoundsMaxLng == 0
                        && startingBoundsMinLng == 0)) {
                    LatLng southwest = new LatLng(startingBoundsMinLat, startingBoundsMinLng);
                    LatLng northeast = new LatLng(startingBoundsMaxLat, startingBoundsMaxLng);
                    try {
                        map.moveCamera(CameraUpdateFactory
                                .newLatLngBounds(new LatLngBounds(southwest, northeast), 10));
                    } catch (Exception e) {
                        // this feels like a bad hack, so if it crashes just ignore it. We will still be zoomed to sensible bounds.
                    }
                }
            }
        };
        handler.postDelayed(r, 250);
    }

    // icons

    Storage s = ((OurApplication) getApplication()).getStorage();
    for (Collection collection : s.getCollections()) {
        // normal icon
        BitmapDescriptor icon = null;
        if (collection.getIconURL() != null) {
            if (collection.getIconURL().contains("park")) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_park);
            } else if (collection.getIconURL().contains("tree")) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_tree);
            } else if (collection.getIconURL().contains("monument")) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_monument);
            } else if (collection.getIconURL().contains("wc")) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_wc);
            } else if (collection.getIconURL().contains("play")) {
                icon = BitmapDescriptorFactory.fromResource(R.drawable.marker_playground);
            }
        }
        if (icon != null) {
            collectionIcons.put(collection.getId(), icon);
        }
        // question icon
        BitmapDescriptor questionIcon = null;
        if (collection.getQuestionIconURL() != null) {
            if (collection.getQuestionIconURL().contains("park")) {
                questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_park_question);
            } else if (collection.getQuestionIconURL().contains("tree")) {
                questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_tree_question);
            } else if (collection.getQuestionIconURL().contains("monument")) {
                questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_monument_question);
            } else if (collection.getQuestionIconURL().contains("play")) {
                questionIcon = BitmapDescriptorFactory.fromResource(R.drawable.marker_playground_question);
            }
        }
        if (questionIcon != null) {
            collectionQuestionIcons.put(collection.getId(), questionIcon);
        } else if (icon != null) {
            // if we don't have a question icon but we have a normal icon, just reuse that.
            collectionQuestionIcons.put(collection.getId(), icon);
        }
    }

    // markers
    map.setOnCameraChangeListener(new OnCameraChangeListener() {
        public void onCameraChange(CameraPosition position) {
            LatLngBounds bounds = BrowseMapActivity.this.map.getProjection().getVisibleRegion().latLngBounds;
            new MarkerTask(bounds.northeast.latitude, bounds.southwest.latitude, bounds.southwest.longitude,
                    bounds.northeast.longitude).execute(true);
        }
    });
    map.setOnInfoWindowClickListener(this);

}

From source file:fr.digitbooks.android.examples.chapitre08.RateDigitbooksActivity.java

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

    // Changer le texte pour voter pour le livre digitbooks
    ((TextView) findViewById(R.id.notice)).setText(R.string.leave_your_digitbooks_comment);

    // On vrifie que l'on peut voter plusieurs fois
    mRateOnce = getIntent().getBooleanExtra(RATE_ONCE, false);
    if (mRateOnce) {
        boolean restoreBackup = false;

        // Mode prfrence local  l'activit
        SharedPreferences localPreferences = getPreferences(Context.MODE_PRIVATE);
        boolean rateSent = localPreferences.getBoolean(PREFERENCE_RATE_SENT, false);
        if (rateSent) {
            String comment = localPreferences.getString(PREFERENCE_COMMENT, "");
            float rating = localPreferences.getFloat(PREFERENCE_RATING, 0.0f);
            mRatingBar.setRating(rating);
            mEditText.setText(comment);/*from w w  w.  j av a2  s.  co m*/
            restoreBackup = true;
        }

        // Ce mode crase le prcdent
        // Mode data backup; les prfrences sont accessible  toute l'application
        // pour ?tre vue par le backup agent
        if (Config.USE_APPLICATIONS_PREFERENCES) {
            SharedPreferences preferences = getSharedPreferences(Config.PREFERENCES, Context.MODE_PRIVATE);
            rateSent = preferences.getBoolean(Config.PREFERENCE_RATE_SENT, false);
            if (rateSent) {
                String comment = preferences.getString(Config.PREFERENCE_COMMENT, "");
                float rating = preferences.getFloat(Config.PREFERENCE_RATING, 0.0f);
                mRatingBar.setRating(rating);
                mEditText.setText(comment);
                restoreBackup = true;
            }
        }

        if (restoreBackup) {
            mRatingBar.setEnabled(false);
            mRatingBar.setFocusable(false);
            mEditText.setEnabled(false);
            mEditText.setFocusable(false);
            mButton.setEnabled(false);
            mButton.setFocusable(false);
            ((TextView) findViewById(R.id.notice)).setText(R.string.rate_sent);
        }
    }

    mButton.setOnClickListener(this);
}

From source file:au.id.tedp.mapdroid.Picker.java

private MapLocation getInitialLocation(Bundle savedState) {
    double newLat, newLong;
    int newZoom;//  w  ww .  ja  va2 s .  com

    // Default location: Germany, from a high zoom level.
    // OpenStreetMap is big in Germany.
    newLat = 52.5;
    newLong = 13.4;
    newZoom = 2;

    SharedPreferences settings = getPreferences(MODE_PRIVATE);

    if (savedState != null) {
        newLat = savedState.getFloat(SAVED_LATITUDE_KEY, (float) newLat);
        newLong = savedState.getFloat(SAVED_LONGITUDE_KEY, (float) newLong);
        newZoom = savedState.getInt(SAVED_ZOOM_KEY, newZoom);
    } else if (settings != null) {
        newLat = settings.getFloat(SAVED_LATITUDE_KEY, (float) newLat);
        newLong = settings.getFloat(SAVED_LONGITUDE_KEY, (float) newLong);
        newZoom = settings.getInt(SAVED_ZOOM_KEY, newZoom);
    }

    MapLocation l = new MapLocation(new Location("default"), newZoom);
    l.setLatitude(newLat);
    l.setLongitude(newLong);
    return l;
}

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

private void saveCoordinatesInPreferences(float latitudeSP, float longitudeSP, int radiusSP, String address) {
    SharedPreferences prefs = this.getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    for (int i = 5; i > 1; i--) {
        prefsEditor.putFloat(POINT_LATITUDE_KEY + i, prefs.getFloat(POINT_LATITUDE_KEY + (i - 1), 0));
        prefsEditor.putFloat(POINT_LONGITUDE_KEY + i, prefs.getFloat(POINT_LONGITUDE_KEY + (i - 1), 0));
        prefsEditor.putInt(POINT_RADIUS_KEY + i, prefs.getInt(POINT_RADIUS_KEY + (i - 1), 0));
        prefsEditor.putString(POINT_ADDRESS_KEY + i, prefs.getString(POINT_ADDRESS_KEY + (i - 1), ""));
    }//from  w ww.j a  v  a2 s  . c  o  m
    prefsEditor.putFloat(POINT_LATITUDE_KEY + 1, latitudeSP);
    prefsEditor.putFloat(POINT_LONGITUDE_KEY + 1, longitudeSP);
    prefsEditor.putInt(POINT_RADIUS_KEY + 1, radiusSP);
    prefsEditor.putString(POINT_ADDRESS_KEY + 1, address);
    prefsEditor.commit();
}

From source file:com.adithya321.sharesanalysis.fragments.DetailFragment.java

private void setShareHoldings(View view) {
    TextView percentageChangeTV = (TextView) view.findViewById(R.id.detail__percent_change);
    TextView noOfDaysTV = (TextView) view.findViewById(R.id.detail_no_of_days);
    TextView totalProfitTV = (TextView) view.findViewById(R.id.detail_total_profit);
    TextView currentNoOfSharesTV = (TextView) view.findViewById(R.id.detail_currents_no_of_shares);
    TextView currentStockValueTV = (TextView) view.findViewById(R.id.detail_current_value);
    TextView targetTotalProfitTV = (TextView) view.findViewById(R.id.detail_target_total_profit);
    TextView rewardTV = (TextView) view.findViewById(detail_reward);

    int totalSharesPurchased = 0;
    int totalSharesSold = 0;
    double totalValuePurchased = 0;
    double totalValueSold = 0;
    double averageShareValue = 0;
    double percentageChange = 0;
    double totalProfit = 0;
    double targetTotalProfit = 0;
    double reward = 0;
    double currentStockValue = 0;

    RealmList<Purchase> purchases = share.getPurchases();
    for (Purchase purchase : purchases) {
        if (purchase.getType().equals("buy")) {
            totalSharesPurchased += purchase.getQuantity();
            totalValuePurchased += (purchase.getQuantity() * purchase.getPrice());
        } else if (purchase.getType().equals("sell")) {
            totalSharesSold += purchase.getQuantity();
            totalValueSold += (purchase.getQuantity() * purchase.getPrice());
        }// w  w  w. j  a  v  a  2  s.co  m
    }
    if (totalSharesPurchased != 0)
        averageShareValue = totalValuePurchased / totalSharesPurchased;

    if (averageShareValue != 0)
        percentageChange = ((share.getCurrentShareValue() - averageShareValue) / averageShareValue) * 100;
    Date today = new Date();
    Date start = share.getDateOfInitialPurchase();
    long noOfDays = DateUtils.getDateDiff(start, today, TimeUnit.DAYS);

    SharedPreferences sharedPreferences = getActivity().getSharedPreferences("prefs", 0);

    int currentNoOfShares = totalSharesPurchased - totalSharesSold;
    totalProfit = totalValueSold - totalValuePurchased;
    currentStockValue = currentNoOfShares * share.getCurrentShareValue();
    double target = sharedPreferences.getFloat("target", 0);
    targetTotalProfit = (target / 100) * totalValuePurchased * ((double) noOfDays / 365);
    reward = totalProfit - targetTotalProfit;
    if (reward < 0)
        rewardTV.setTextColor(getResources().getColor((android.R.color.holo_red_dark)));
    else
        rewardTV.setTextColor(getResources().getColor((R.color.colorPrimary)));

    currentNoOfSharesTV.setText(String.valueOf(currentNoOfShares));
    percentageChangeTV.setText(String.valueOf(NumberUtils.round(percentageChange, 2)));
    noOfDaysTV.setText(String.valueOf(noOfDays));
    totalProfitTV.setText(String.valueOf(NumberUtils.round(totalProfit, 2)));
    currentStockValueTV.setText(String.valueOf(NumberUtils.round(currentStockValue, 2)));
    targetTotalProfitTV.setText(String.valueOf(NumberUtils.round(targetTotalProfit, 2)));
    rewardTV.setText(String.valueOf(NumberUtils.round(reward, 2)));
}

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

private Location retrieveRecent(int index) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    Location location = new Location("POINT_LOCATION");
    location.setLatitude(0);//from   www .j a  v  a  2 s  .  co  m
    location.setLongitude(0);
    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));
    }
    return location;
}

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

private Location retrieveSaved(int index) {
    SharedPreferences prefs = getActivity().getSharedPreferences("AreWeThereYet", Context.MODE_WORLD_WRITEABLE);
    Location location = new Location("POINT_LOCATION");
    location.setLatitude(0);/*from  w  ww.ja v a2 s .  com*/
    location.setLongitude(0);
    if (prefs.contains(SAVED_LATITUDE_KEY + index)) {
        location.setLatitude(prefs.getFloat(SAVED_LATITUDE_KEY + index, 0));
    }
    if (prefs.contains(SAVED_LONGITUDE_KEY + index)) {
        location.setLongitude(prefs.getFloat(SAVED_LONGITUDE_KEY + index, 0));
    }
    return location;
}