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:ac.robinson.mediaphone.MediaPhoneActivity.java

private void loadAllPreferences() {
    SharedPreferences mediaPhoneSettings = PreferenceManager
            .getDefaultSharedPreferences(MediaPhoneActivity.this);
    Resources res = getResources();

    // bluetooth observer
    configureBluetoothObserver(mediaPhoneSettings, res);

    // importing confirmation
    boolean confirmImporting = res.getBoolean(R.bool.default_confirm_importing);
    try {/*  w  w  w .  j a v a 2s.com*/
        confirmImporting = mediaPhoneSettings.getBoolean(getString(R.string.key_confirm_importing),
                confirmImporting);
    } catch (Exception e) {
        confirmImporting = res.getBoolean(R.bool.default_confirm_importing);
    }
    MediaPhone.IMPORT_CONFIRM_IMPORTING = confirmImporting;

    // delete after import
    boolean deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing);
    try {
        deleteAfterImport = mediaPhoneSettings.getBoolean(getString(R.string.key_delete_after_importing),
                deleteAfterImport);
    } catch (Exception e) {
        deleteAfterImport = res.getBoolean(R.bool.default_delete_after_importing);
    }
    MediaPhone.IMPORT_DELETE_AFTER_IMPORTING = deleteAfterImport;

    // minimum frame duration
    TypedValue resourceValue = new TypedValue();
    res.getValue(R.attr.default_minimum_frame_duration, resourceValue, true);
    float minimumFrameDuration;
    try {
        minimumFrameDuration = mediaPhoneSettings.getFloat(getString(R.string.key_minimum_frame_duration),
                resourceValue.getFloat());
        if (minimumFrameDuration <= 0) {
            throw new NumberFormatException();
        }
    } catch (Exception e) {
        minimumFrameDuration = resourceValue.getFloat();
    }
    MediaPhone.PLAYBACK_EXPORT_MINIMUM_FRAME_DURATION = Math.round(minimumFrameDuration * 1000);

    // word duration
    res.getValue(R.attr.default_word_duration, resourceValue, true);
    float wordDuration;
    try {
        wordDuration = mediaPhoneSettings.getFloat(getString(R.string.key_word_duration),
                resourceValue.getFloat());
        if (wordDuration <= 0) {
            throw new NumberFormatException();
        }
    } catch (Exception e) {
        wordDuration = resourceValue.getFloat();
    }
    MediaPhone.PLAYBACK_EXPORT_WORD_DURATION = Math.round(wordDuration * 1000);

    // screen orientation
    int requestedOrientation = res.getInteger(R.integer.default_screen_orientation);
    try {
        String requestedOrientationString = mediaPhoneSettings
                .getString(getString(R.string.key_screen_orientation), null);
        requestedOrientation = Integer.valueOf(requestedOrientationString);
    } catch (Exception e) {
        requestedOrientation = res.getInteger(R.integer.default_screen_orientation);
    }
    setRequestedOrientation(requestedOrientation);

    // other preferences
    loadPreferences(mediaPhoneSettings);
}

From source file:info.alni.comete.android.Comete.java

private void getPrefs() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    throttleArr = sharedPreferences.getString("throttleKey", getString(R.string.prop_throttle)).split("$d");

    mixtureArr = sharedPreferences.getString("mixtureKey", getString(R.string.prop_mixture)).split("$d");
    propellerArr = sharedPreferences.getString("propellerKey", getString(R.string.prop_propeller)).split("$d");
    magnetosArr = sharedPreferences.getString("magnetosKey", getString(R.string.prop_magnetos)).split("$d");
    starterArr = sharedPreferences.getString("starterKey", getString(R.string.prop_starter)).split("$d");
    startSwitchsArr = sharedPreferences.getString("starterSwitchKey", getString(R.string.prop_starter_switch))
            .split("$d");
    setReverserArr(sharedPreferences.getString("reverserKey", getString(R.string.prop_reverser)).split("$d"));

    flapPropKey = sharedPreferences.getString("flapKey", getString(R.string.prop_flap));
    rudderPropKey = sharedPreferences.getString("rudderKey", getString(R.string.prop_rudder));
    aileronPropKey = sharedPreferences.getString("aileronKey", getString(R.string.prop_aileron));
    elevatorPropKey = sharedPreferences.getString("elevatorKey", getString(R.string.prop_elevator));
    setBrakeLeftPropKey(sharedPreferences.getString("brakeLeftKey", getString(R.string.prop_brakeLeft)));
    setBrakeRightPropKey(sharedPreferences.getString("brakeRightKey", getString(R.string.prop_brakeRight)));
    starter2PropKey = sharedPreferences.getString("starter2Key", getString(R.string.prop_starter2));
    nav1FreqPropKey = sharedPreferences.getString("nav1FreqKey", getString(R.string.prop_nav1Freq));
    setNav1RadPropKey(sharedPreferences.getString("nav1RadKey", getString(R.string.prop_nav1Rad)));
    nav2FreqPropKey = sharedPreferences.getString("nav2FreqKey", getString(R.string.prop_nav2Freq));
    setNav2RadPropKey(sharedPreferences.getString("nav2RadKey", getString(R.string.prop_nav2Rad)));
    adf1FreqPropKey = sharedPreferences.getString("adf1FreqKey", getString(R.string.prop_adf1Freq));
    com1FreqPropKey = sharedPreferences.getString("com1FreqKey", getString(R.string.prop_com1Freq));
    fgViewPropKey = sharedPreferences.getString("fgViewKey", getString(R.string.prop_fgView));

    ((FGToggleButton) findViewById(R.id.gear2))
            .setFgProp(sharedPreferences.getString("gearDownKey", getString(R.string.prop_gearDown)));
    ((FGToggleButton) findViewById(R.id.autoCoordination)).setFgProp(
            sharedPreferences.getString("autoCoordinationKey", getString(R.string.prop_autoCoordination)));
    ((FGToggleButton) findViewById(R.id.parking_brake))
            .setFgProp(sharedPreferences.getString("parkingBrakeKey", getString(R.string.prop_parkingBrake)));
    // this will be (0 or 1) not (true or false)
    ((FGToggleButton) findViewById(R.id.parking_brake)).setBoolean(false);

    try {/*from  w w w .j a v a  2s .  c  om*/
        aileronMoltDefault = sharedPreferences.getFloat("aileronMoltDefaultKey",
                Float.parseFloat(getString(R.string.aileronMoltDefault)));
        elevatorMoltDefault = sharedPreferences.getFloat("elevatorMoltDefaultKey",
                Float.parseFloat(getString(R.string.elevatorMoltDefault)));
        elevatorSubDefault = sharedPreferences.getFloat("elevatorSubDefaultKey",
                Float.parseFloat(getString(R.string.elevatorSubDefault)));
        rudderMoltDefault = sharedPreferences.getFloat("rudderMoltDefaultKey",
                Float.parseFloat(getString(R.string.rudderMoltDefault)));
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (sharedPreferences.getBoolean("orientationLandscape", false)) {

        /* First, get the Display from the WindowManager */
        Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

        /* Now we can retrieve all display-related infos */
        // int width = display.getWidth();
        // int height = display.getHeight();
        int orientation = display.getOrientation();

        if (orientation != Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }

    thrGetAirspeed.getProp().clear();
    thrGetAirspeed.addProp(sharedPreferences.getString("airspeedKey", getString(R.string.prop_airspeed)),
            getString(R.string.prop_airspeed_format));
    thrGetAirspeed.addProp(sharedPreferences.getString("directionKey", getString(R.string.prop_direction)),
            getString(R.string.prop_direction_format));

    thrGetAirspeed.addProp(sharedPreferences.getString("nav1FreqKey", getString(R.string.prop_nav1Freq)),
            getString(R.string.prop_nav1Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav1RadKey", getString(R.string.prop_nav1Rad)),
            getString(R.string.prop_nav1Rad_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav2FreqKey", getString(R.string.prop_nav2Freq)),
            getString(R.string.prop_nav2Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("nav2RadKey", getString(R.string.prop_nav2Rad)),
            getString(R.string.prop_nav2Rad_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("adf1FreqKey", getString(R.string.prop_adf1Freq)),
            getString(R.string.prop_adf1Freq_format), true);
    thrGetAirspeed.addProp(sharedPreferences.getString("com1FreqKey", getString(R.string.prop_com1Freq)),
            getString(R.string.prop_com1Freq_format), true);

    thrGetAirspeed.setEnabled(sharedPreferences.getBoolean("enableGetting", true));

    // }

}

From source file:com.androzic.MapActivity.java

/** Called when the activity is first created. */
@SuppressLint("ShowToast")
@Override//w w w  .  j  a va2  s  .  c o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Log.e(TAG, "onCreate()");

    ready = false;
    isFullscreen = false;

    backToast = Toast.makeText(this, R.string.backQuit, Toast.LENGTH_SHORT);
    finishHandler = new FinishHandler(this);

    application = (Androzic) getApplication();

    // FIXME Should find a better place for this
    application.mapObjectsOverlay = new MapObjectsOverlay(this);

    // check if called after crash
    if (!application.mapsInited) {
        restarting = true;
        startActivity(new Intent(this, Splash.class)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtras(getIntent()));
        finish();
        return;
    }

    application.setMapActivity(this);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    setRequestedOrientation(Integer.parseInt(settings.getString(getString(R.string.pref_orientation), "-1")));
    settings.registerOnSharedPreferenceChangeListener(this);
    Resources resources = getResources();

    if (settings.getBoolean(getString(R.string.pref_hideactionbar),
            resources.getBoolean(R.bool.def_hideactionbar))) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    panelActions = getResources().getStringArray(R.array.panel_action_values);

    setContentView(R.layout.act_main);
    coordinates = (TextView) findViewById(R.id.coordinates);
    satInfo = (TextView) findViewById(R.id.sats);
    currentFile = (TextView) findViewById(R.id.currentfile);
    mapZoom = (TextView) findViewById(R.id.currentzoom);
    waypointName = (TextView) findViewById(R.id.waypointname);
    waypointExtra = (TextView) findViewById(R.id.waypointextra);
    routeName = (TextView) findViewById(R.id.routename);
    routeExtra = (TextView) findViewById(R.id.routeextra);
    speedValue = (TextView) findViewById(R.id.speed);
    speedUnit = (TextView) findViewById(R.id.speedunit);
    trackValue = (TextView) findViewById(R.id.track);
    trackUnit = (TextView) findViewById(R.id.trackunit);
    elevationValue = (TextView) findViewById(R.id.elevation);
    elevationUnit = (TextView) findViewById(R.id.elevationunit);
    distanceValue = (TextView) findViewById(R.id.distance);
    distanceUnit = (TextView) findViewById(R.id.distanceunit);
    xtkValue = (TextView) findViewById(R.id.xtk);
    xtkUnit = (TextView) findViewById(R.id.xtkunit);
    bearingValue = (TextView) findViewById(R.id.bearing);
    bearingUnit = (TextView) findViewById(R.id.bearingunit);
    turnValue = (TextView) findViewById(R.id.turn);
    trackBar = (SeekBar) findViewById(R.id.trackbar);
    waitBar = (TextView) findViewById(R.id.waitbar);
    map = (MapView) findViewById(R.id.mapview);

    // set button actions
    findViewById(R.id.zoomin).setOnClickListener(this);
    findViewById(R.id.zoomout).setOnClickListener(this);
    findViewById(R.id.nextmap).setOnClickListener(this);
    findViewById(R.id.prevmap).setOnClickListener(this);
    findViewById(R.id.maps).setOnClickListener(this);
    findViewById(R.id.waypoints).setOnClickListener(this);
    findViewById(R.id.info).setOnClickListener(this);
    findViewById(R.id.follow).setOnClickListener(this);
    findViewById(R.id.locate).setOnClickListener(this);
    findViewById(R.id.tracking).setOnClickListener(this);
    findViewById(R.id.expand).setOnClickListener(this);
    findViewById(R.id.finishedit).setOnClickListener(this);
    findViewById(R.id.addpoint).setOnClickListener(this);
    findViewById(R.id.insertpoint).setOnClickListener(this);
    findViewById(R.id.removepoint).setOnClickListener(this);
    findViewById(R.id.orderpoints).setOnClickListener(this);
    findViewById(R.id.finishtrackedit).setOnClickListener(this);
    findViewById(R.id.cutafter).setOnClickListener(this);
    findViewById(R.id.cutbefore).setOnClickListener(this);

    Panel panel = (Panel) findViewById(R.id.panel);
    panel.setOnPanelListener(this);
    panel.setInterpolator(new ExpoInterpolator(Type.OUT));

    wptQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    wptQuickAction.addActionItem(new ActionItem(qaAddWaypointToRoute, getString(R.string.menu_addtoroute),
            resources.getDrawable(R.drawable.ic_action_add)));
    wptQuickAction.setOnActionItemClickListener(waypointActionItemClickListener);

    rteQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    rteQuickAction.addActionItem(new ActionItem(qaNavigateToWaypoint, getString(R.string.menu_thisnavpoint),
            resources.getDrawable(R.drawable.ic_action_directions)));
    rteQuickAction.setOnActionItemClickListener(routeActionItemClickListener);

    mobQuickAction = new QuickAction3D(this, QuickAction3D.VERTICAL);
    mobQuickAction.addActionItem(new ActionItem(qaNavigateToMapObject, getString(R.string.menu_navigate),
            resources.getDrawable(R.drawable.ic_action_directions)));
    mobQuickAction.setOnActionItemClickListener(mapObjectActionItemClickListener);

    trackBar.setOnSeekBarChangeListener(this);

    map.initialize(application);

    dimView = new RelativeLayout(this);

    String navWpt = settings.getString(getString(R.string.nav_wpt), "");
    if (!"".equals(navWpt) && savedInstanceState == null) {
        Intent intent = new Intent(getApplicationContext(), NavigationService.class)
                .setAction(NavigationService.NAVIGATE_MAPOBJECT);
        intent.putExtra(NavigationService.EXTRA_NAME, navWpt);
        intent.putExtra(NavigationService.EXTRA_LATITUDE,
                (double) settings.getFloat(getString(R.string.nav_wpt_lat), 0));
        intent.putExtra(NavigationService.EXTRA_LONGITUDE,
                (double) settings.getFloat(getString(R.string.nav_wpt_lon), 0));
        intent.putExtra(NavigationService.EXTRA_PROXIMITY, settings.getInt(getString(R.string.nav_wpt_prx), 0));
        startService(intent);
    }

    String navRoute = settings.getString(getString(R.string.nav_route), "");
    if (!"".equals(navRoute) && settings.getBoolean(getString(R.string.pref_navigation_loadlast),
            getResources().getBoolean(R.bool.def_navigation_loadlast)) && savedInstanceState == null) {
        int ndir = settings.getInt(getString(R.string.nav_route_dir), 0);
        int nwpt = settings.getInt(getString(R.string.nav_route_wpt), -1);
        try {
            int rt = -1;
            Route route = application.getRouteByFile(navRoute);
            if (route != null) {
                route.show = true;
                rt = application.getRouteIndex(route);
            } else {
                File rtf = new File(navRoute);
                // FIXME It's bad - it can be not a first route in a file
                route = OziExplorerFiles.loadRoutesFromFile(rtf, application.charset).get(0);
                rt = application.addRoute(route);
            }
            RouteOverlay newRoute = new RouteOverlay(this, route);
            application.routeOverlays.add(newRoute);
            startService(new Intent(this, NavigationService.class).setAction(NavigationService.NAVIGATE_ROUTE)
                    .putExtra(NavigationService.EXTRA_ROUTE_INDEX, rt)
                    .putExtra(NavigationService.EXTRA_ROUTE_DIRECTION, ndir)
                    .putExtra(NavigationService.EXTRA_ROUTE_START, nwpt));
        } catch (Exception e) {
            Log.e(TAG, "Failed to start navigation", e);
        }
    }

    // set activity preferences
    onSharedPreferenceChanged(settings, getString(R.string.pref_exit));
    onSharedPreferenceChanged(settings, getString(R.string.pref_unitprecision));
    // set map preferences
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapadjacent));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapcropborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_mapdrawborder));
    onSharedPreferenceChanged(settings, getString(R.string.pref_cursorcolor));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_mapshow));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_usershow));
    onSharedPreferenceChanged(settings, getString(R.string.pref_grid_preference));
    onSharedPreferenceChanged(settings, getString(R.string.pref_panelactions));

    if (getIntent().getExtras() != null)
        onNewIntent(getIntent());

    ready = true;
}