Example usage for android.content SharedPreferences getInt

List of usage examples for android.content SharedPreferences getInt

Introduction

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

Prototype

int getInt(String key, int defValue);

Source Link

Document

Retrieve an int value from the preferences.

Usage

From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java

private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString,
        final Exception exception) {
    Log.i("Ringdroid", "handleFatalError");

    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0);
    final SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1);
    prefsEditor.commit();/*from  w  ww . j  a  v a  2s .  c o m*/

    // Check if we already have a pref for whether or not we can
    // contact the server.
    int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN);

    if (serverAllowed == SERVER_ALLOWED_NO) {
        Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO");

        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    if (serverAllowed == SERVER_ALLOWED_YES) {
        Log.i("Ringdroid", "SERVER_ALLOWED_YES");

        new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure)
                .setMessage(errorString)
                .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        finish();
                        return;
                    }
                }).setCancelable(false).show();
        return;
    }

    // The number of times the user must have had a failure before
    // we'll ask them.  Defaults to 1, and each time they click "Later"
    // we double and add 1.
    final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1);
    if (failureCount < allowServerCheckIndex) {
        Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex);
        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    final SpannableString message = new SpannableString(
            errorString + ". " + getResources().getText(R.string.error_server_prompt));
    Linkify.addLinks(message, Linkify.ALL);

    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure)
            .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();
                    finish();
                    return;
                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2);
                    Log.i("Ringdroid",
                            "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors.");
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();

    // Make links clicky
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:br.com.rescue_bots_android.bluetooth.MainActivity.java

@Override
protected void onResume() {

    SharedPreferences settings = this.getSharedPreferences(ConfigActivity.PREFS_NAME, 0);
    robottype = settings.getString(ConfigActivity.PARAM_BOTTYPE, "");
    if (robottype != null && robottype.equalsIgnoreCase("FLAREGUN")) {
        routeController.selectAll(coordinates);
    } else if (robottype != null && robottype.equalsIgnoreCase("SAVIOUR")) {
        selectRouteFromServices(coordinates);
    }/*from w  w w.j a  v  a 2  s . co m*/
    accuraccy = settings.getInt(ConfigActivity.PARAM_ACCURACCY, 10);

    Log.d(TAG, "Resumed");
    super.onResume();

    // for the system's orientation sensor registered listeners
    mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_GAME);

    if (mBTSocket == null || !mIsBluetoothConnected) {
        new ConnectBT().execute();
    }

}

From source file:de.alosdev.android.customerschoice.CustomersChoice.java

public void setLifeTime(Context context, LifeTime lifeTime) {
    final SharedPreferences preferences = getPreferences(context);
    final Set<String> foundVariants;
    switch (lifeTime) {
    case Session: {
        Editor editor = preferences.edit();
        foundVariants = preferences.getStringSet(getPreferencesKey(FIELD_VARIANTS, ""), null);
        if ((null != foundVariants) && !foundVariants.isEmpty()) {
            for (String variantName : foundVariants) {
                editor.remove(getPreferencesKey(FIELD_VARIANTS, variantName));
            }// w w w .ja  v a  2  s.c  o m
            editor.remove(getPreferencesKey(FIELD_VARIANTS, ""));
            editor.commit();
        }
        log.d(TAG, "cleared persisted Variant");
        break;
    }

    case Persistent: {
        foundVariants = preferences.getStringSet(getPreferencesKey(FIELD_VARIANTS, ""), null);
        if ((null != foundVariants) && !foundVariants.isEmpty()) {
            for (String variantName : foundVariants) {
                forceVariant(context, variantName,
                        preferences.getInt(getPreferencesKey(FIELD_VARIANTS, variantName), 0));
            }
        }
        log.d(TAG, "read persisted Variant");
        break;
    }

    default: {
        throw new IllegalArgumentException("Unknown LifeTime: " + lifeTime);
    }
    }
    this.lifeTime = lifeTime;
}

From source file:org.openplans.rcavl.RCAVL.java

private void switchToLogin() {
    setContentView(R.layout.login);/*from   w w  w .ja  v  a  2s  .c  o  m*/

    SharedPreferences preferences = getPreferences(MODE_PRIVATE);
    String emails = preferences.getString("emails", "");

    String[] past_emails = emails.split(",");
    if (past_emails == null) {
        past_emails = new String[0];
    }

    emailField = (AutoCompleteTextView) findViewById(R.id.emailField);
    passwordField = (TextView) findViewById(R.id.passwordField);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, past_emails);
    emailField.setAdapter(adapter);
    spinner = (ProgressBar) findViewById(R.id.loginProgressBar);

    View loginButton = findViewById(R.id.loginButton);
    loginButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            spinner.setIndeterminate(true);
            spinner.setVisibility(View.VISIBLE);
            new LoginTask().execute();
        }
    });

    View configButton = findViewById(R.id.configButton);
    configButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            ConfigDialog dialog = new ConfigDialog(RCAVL.this);
            dialog.setConfigured(RCAVL.this);
            dialog.show();
        }
    });

    apiRequestUrl = preferences.getString("apiRequestUrl", apiRequestUrl);
    pingInterval = preferences.getInt("pingInterval", pingInterval);

}

From source file:net.phase.wallet.Currency.java

private void loadPreferences() {
    SharedPreferences pref = getPreferences(MODE_PRIVATE);
    setActiveCurrency(pref.getString("currency", "USD"));
    maxlength = pref.getInt("maxlength", 40);
    decimalpoints = pref.getInt("decimal", 2);
}

From source file:com.ringdroid.RingdroidEditActivity.java

private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString,
        final Exception exception) {
    Log.i("Ringdroid", "handleFatalError");

    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0);
    final SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1);
    prefsEditor.commit();/*from  w  w w  .j av a  2s  . co m*/

    // Check if we already have a pref for whether or not we can
    // contact the server.
    int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN);

    if (serverAllowed == SERVER_ALLOWED_NO) {
        Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO");

        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    if (serverAllowed == SERVER_ALLOWED_YES) {
        Log.i("Ringdroid", "SERVER_ALLOWED_YES");

        new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure)
                .setMessage(errorString)
                .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        return;
                    }
                }).setCancelable(false).show();
        return;
    }

    // The number of times the user must have had a failure before
    // we'll ask them. Defaults to 1, and each time they click "Later"
    // we double and add 1.
    final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1);
    if (failureCount < allowServerCheckIndex) {
        Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex);
        // Just show a simple "write error" message
        showFinalAlert(exception, errorString);
        return;
    }

    new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure)
            .setMessage(errorString + ". " + getResources().getText(R.string.error_server_prompt))
            .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES);
                    prefsEditor.commit();

                }
            }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2);
                    Log.i("Ringdroid",
                            "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors.");
                    prefsEditor.commit();
                    finish();
                }
            }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO);
                    prefsEditor.commit();
                    finish();
                }
            }).setCancelable(false).show();
}

From source file:com.ringdroid.RingdroidEditActivity.java

private void afterSavingRingtone(CharSequence title, String outPath, File outFile, int duration) {
    long length = outFile.length();
    if (length <= 512) {
        outFile.delete();//w w w  . jav a2 s. c o  m
        new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure)
                .setMessage(R.string.too_small_error).setPositiveButton(R.string.alert_ok_button, null)
                .setCancelable(false).show();
        return;
    }

    // Create the database record, pointing to the existing file path

    long fileSize = outFile.length();
    String mimeType = "audio/mpeg";

    String artist = "" + getResources().getText(R.string.artist_name);

    ContentValues values = new ContentValues();
    values.put(MediaStore.MediaColumns.DATA, outPath);
    values.put(MediaStore.MediaColumns.TITLE, title.toString());
    values.put(MediaStore.MediaColumns.SIZE, fileSize);
    values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);

    values.put(MediaStore.Audio.Media.ARTIST, artist);
    values.put(MediaStore.Audio.Media.DURATION, duration);

    values.put(MediaStore.Audio.Media.IS_RINGTONE, mNewFileKind == FileSaveDialog.FILE_KIND_RINGTONE);
    values.put(MediaStore.Audio.Media.IS_NOTIFICATION, mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION);
    values.put(MediaStore.Audio.Media.IS_ALARM, mNewFileKind == FileSaveDialog.FILE_KIND_ALARM);
    values.put(MediaStore.Audio.Media.IS_MUSIC, mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC);

    // Insert it into the database
    Uri uri = MediaStore.Audio.Media.getContentUriForPath(outPath);
    final Uri newUri = getContentResolver().insert(uri, values);
    setResult(RESULT_OK, new Intent().setData(newUri));

    // Update a preference that counts how many times we've
    // successfully saved a ringtone or other audio
    SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
    int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0);
    SharedPreferences.Editor prefsEditor = prefs.edit();
    prefsEditor.putInt(PREF_SUCCESS_COUNT, successCount + 1);
    prefsEditor.commit();

    // If Ringdroid was launched to get content, just return
    if (mWasGetContentIntent) {
        // sendStatsToServerIfAllowedAndFinish();
        return;
    }

    // There's nothing more to do with music or an alarm. Show a
    // success message and then quit.
    if (mNewFileKind == FileSaveDialog.FILE_KIND_MUSIC || mNewFileKind == FileSaveDialog.FILE_KIND_ALARM) {
        Toast.makeText(this, R.string.save_success_message, Toast.LENGTH_SHORT).show();
        // sendStatsToServerIfAllowedAndFinish();
        return;
    }

    // If it's a notification, give the user the option of making
    // this their default notification. If they say no, we're finished.
    if (mNewFileKind == FileSaveDialog.FILE_KIND_NOTIFICATION) {
        new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_success)
                .setMessage(R.string.set_default_notification)
                .setPositiveButton(R.string.alert_yes_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this,
                                RingtoneManager.TYPE_NOTIFICATION, newUri);
                        // sendStatsToServerIfAllowedAndFinish();
                    }
                }).setNegativeButton(R.string.alert_no_button, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // sendStatsToServerIfAllowedAndFinish();
                    }
                }).setCancelable(false).show();
        return;
    }

    // If we get here, that means the type is a ringtone. There are
    // three choices: make this your default ringtone, assign it to a
    // contact, or do nothing.

    final Handler handler = new Handler() {
        public void handleMessage(Message response) {
            int actionId = response.arg1;
            switch (actionId) {
            case R.id.button_make_default:
                RingtoneManager.setActualDefaultRingtoneUri(RingdroidEditActivity.this,
                        RingtoneManager.TYPE_RINGTONE, newUri);
                Toast.makeText(RingdroidEditActivity.this, R.string.default_ringtone_success_message,
                        Toast.LENGTH_SHORT).show();
                // sendStatsToServerIfAllowedAndFinish();
                break;
            case R.id.button_choose_contact:
                chooseContactForRingtone(newUri);
                break;
            default:
            case R.id.button_do_nothing:
                // sendStatsToServerIfAllowedAndFinish();
                break;
            }
        }
    };
    Message message = Message.obtain(handler);
    AfterSaveActionDialog dlog = new AfterSaveActionDialog(this, message);
    dlog.show();
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public void refreshList() {
    SharedPreferences repeater_prefs = PreferenceManager.getDefaultSharedPreferences(this);

    excludeLink = repeater_prefs.getBoolean("excludeLinkRepeater", false);

    m_deviceid = repeater_prefs.getString("deviceid", this.generateCallsign());
    m_callsign = repeater_prefs.getString("callsign", "9W2-" + this.generateCallsign());
    m_handle = repeater_prefs.getString("handle", "Newbie (" + this.generateCallsign().substring(0, 4) + ")");
    m_status = repeater_prefs.getString("status", "no status");
    m_qsx = Double.parseDouble(repeater_prefs.getString("qsx", "145.00"));
    m_phoneno = repeater_prefs.getString("phoneno", "+60120000");
    try {/*from  w  w  w  .jav a 2s  . com*/
        m_passcode = Integer.parseInt(repeater_prefs.getString("passcode", "0"));

    } catch (NumberFormatException nfe) {

        m_passcode = 0;
    } catch (Exception ex) {

        m_passcode = 0;
    }

    local_distance = repeater_prefs.getInt("range", 100);

    adapter = new RepeaterAdapter(this, rl, xlocation, local_distance, excludeLink, excludeDirection);
    mrefresh = false;

    lv.setAdapter(adapter);

}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

/**
 * Retrieve application persistent data.
 *//*from  ww w.  j a v  a  2  s  .  c  o m*/
private void loadAntState() {
    // Restore preferences
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    mAntManager.setDeviceNumberHRM((short) settings.getInt("DeviceNumberHRM", ANT_WILDCARD));
    mAntManager.setDeviceNumberSDM((short) settings.getInt("DeviceNumberSDM", ANT_WILDCARD));
    mAntManager.setDeviceNumberWGT((short) settings.getInt("DeviceNumberWGT", ANT_WILDCARD));
    mAntManager.setProximityThreshold((byte) settings.getInt("ProximityThreshold", ANT_DEFAULT_BIN));
    mAntManager.setBufferThreshold((short) settings.getInt("BufferThreshold", ANT_DEFAULT_BUFFER_THRESHOLD));
}

From source file:net.kidlogger.kidlogger.KLService.java

private int getIntPref(String key) {
    SharedPreferences pref = this.getSharedPreferences(PREF_NAME, 0);
    return pref.getInt(key, 0);
}