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.amaze.filemanager.utils.files.FileUtils.java

public static void openFile(final File f, final MainActivity m, SharedPreferences sharedPrefs) {
    boolean useNewStack = sharedPrefs.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
    boolean defaultHandler = isSelfDefault(f, m);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(m);
    final Toast[] studioCount = { null };

    if (f.getName().toLowerCase().endsWith(".apk")) {
        GeneralDialogCreation.showPackageDialog(f, m);
    } else if (defaultHandler && CompressedHelper.isFileExtractable(f.getPath())) {
        GeneralDialogCreation.showArchiveDialog(f, m);
    } else if (defaultHandler && f.getName().toLowerCase().endsWith(".db")) {
        Intent intent = new Intent(m, DatabaseViewerActivity.class);
        intent.putExtra("path", f.getPath());
        m.startActivity(intent);/*from ww w .j a  v  a  2  s .  c om*/
    } else if (Icons.getTypeOfFile(f.getPath(), f.isDirectory()) == Icons.AUDIO) {
        final int studio_count = sharedPreferences.getInt("studio", 0);
        Uri uri = Uri.fromFile(f);
        final Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.setDataAndType(uri, "audio/*");

        // Behold! It's the  legendary easter egg!
        if (studio_count != 0) {
            new CountDownTimer(studio_count, 1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    int sec = (int) millisUntilFinished / 1000;
                    if (studioCount[0] != null)
                        studioCount[0].cancel();
                    studioCount[0] = Toast.makeText(m, sec + "", Toast.LENGTH_LONG);
                    studioCount[0].show();
                }

                @Override
                public void onFinish() {
                    if (studioCount[0] != null)
                        studioCount[0].cancel();
                    studioCount[0] = Toast.makeText(m, m.getString(R.string.opening), Toast.LENGTH_LONG);
                    studioCount[0].show();
                    m.startActivity(intent);
                }
            }.start();
        } else
            m.startActivity(intent);
    } else {
        try {
            openunknown(f, m, false, useNewStack);
        } catch (Exception e) {
            Toast.makeText(m, m.getString(R.string.noappfound), Toast.LENGTH_LONG).show();
            openWith(f, m, useNewStack);
        }
    }
}

From source file:org.hfoss.posit.android.sync.Communicator.java

/**
 * Returns a list of guIds for server finds that need syncing.
 * /*  w  w w.ja va  2  s. c  o m*/
 * @return
 */
public static String getServerFindsNeedingSync(Context context, String authKey) {
    String response = "";
    String url = "";

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String server = prefs.getString(SERVER_PREF, "");
    int projectId = prefs.getInt(PROJECT_PREF, 0);

    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();

    url = server + "/api/getDeltaFindsIds?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId;
    Log.i(TAG, "getDeltaFindsIds URL=" + url);

    try {
        response = doHTTPGET(url);
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
    }
    Log.i(TAG, "serverFindsNeedingSync = " + response);

    return response;
}

From source file:org.hfoss.posit.android.sync.Communicator.java

public static boolean recordSync(Context context, String authKey) {
    // Record the synchronization in the server's sync_history table

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    String server = prefs.getString(SERVER_PREF, "");
    int projectId = prefs.getInt(context.getString(R.string.projectPref), 0);

    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String imei = telephonyManager.getDeviceId();

    String url = server + "/api/recordSync?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId;
    Log.i(TAG, "recordSync URL=" + url);
    String responseString = "";

    try {//from   w  ww.j a va 2 s.c o m
        responseString = doHTTPGET(url);
    } catch (Exception e) {
        Log.i(TAG, e.getMessage());
        e.printStackTrace();
        return false;
    }
    Log.i(TAG, "HTTPGet recordSync response = " + responseString);
    return true;
}

From source file:com.mozilla.simplepush.simplepushdemoapp.MainActivity.java

private String getRegistrationId(Context context) {
    final SharedPreferences prefs = getGcmPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId == null || registrationId.isEmpty()) {
        Log.i(TAG, "Registration not found.");
        return "";
    }//  www  . j av  a 2s . c om
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion) {
        Log.i(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

From source file:com.albertcbraun.cms50fw.alert.MainUIFragment.java

private void setUpSeekBar(SharedPreferences defaultSettingsPreference, SeekBar seekBar,
        TextView correspondingTextView, Integer correspondingInteger,
        @SuppressWarnings("SameParameterValue") String maxValueSharedPrefsKeyName, int defaultMaxValue,
        String currentValueSharedPrefsKeyName, int defaultCurrValue) {

    SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBarChangeListener(getActivity(),
            correspondingTextView, correspondingInteger, currentValueSharedPrefsKeyName);

    seekBar.setMax(defaultSettingsPreference.getInt(maxValueSharedPrefsKeyName, defaultMaxValue));
    int currValue = defaultSettingsPreference.getInt(currentValueSharedPrefsKeyName, defaultCurrValue);
    correspondingTextView.setText(String.valueOf(currValue));
    seekBar.setProgress(currValue);/* ww w  .  j  a  v a  2  s  .c  o  m*/
    seekBar.setOnSeekBarChangeListener(seekBarChangeListener);
}

From source file:com.example.Android.LoginActivity.java

private String getRegistrationId(Context context) {
    final SharedPreferences prefs = getGcmPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.isEmpty()) {
        Log.i(TAG, "Registration not found.");
        return "";
    }/* w  w  w . j av  a2  s  . co  m*/
    // Check if app was updated; if so, it must clear the registration ID
    // since the existing regID is not guaranteed to work with the new
    // app version.
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion) {
        Log.i(TAG, "App version changed.");
        return "";
    }
    return registrationId;
}

From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java

/******************************************************************************************
 * Gets all of the information the user filled out on the settings tab
 ******************************************************************************************
 * @return Returns the JSONObject form of the info the user filled out
 * @throws JSONException//from   ww w. j ava  2s .  c o m
 ******************************************************************************************/
private JSONObject getUserJSON() throws JSONException {
    JSONObject user = new JSONObject();
    Map<String, Integer> fieldMap = new HashMap<String, Integer>();

    fieldMap.put(USER_EMAIL, Integer.valueOf(FragmentUserInfo.PREF_EMAIL));

    fieldMap.put(USER_ZIP_HOME, Integer.valueOf(FragmentUserInfo.PREF_ZIPHOME));
    fieldMap.put(USER_ZIP_WORK, Integer.valueOf(FragmentUserInfo.PREF_ZIPWORK));
    fieldMap.put(USER_ZIP_SCHOOL, Integer.valueOf(FragmentUserInfo.PREF_ZIPSCHOOL));

    SharedPreferences settings = this.mCtx.getSharedPreferences("PREFS", 0);
    for (Entry<String, Integer> entry : fieldMap.entrySet()) {
        user.put(entry.getKey(), settings.getString(entry.getValue().toString(), null));
    }
    user.put(USER_AGE, settings.getInt("" + FragmentUserInfo.PREF_AGE, 0));
    user.put(USER_GENDER, settings.getInt("" + FragmentUserInfo.PREF_GENDER, 0));
    user.put(USER_CYCLING_FREQUENCY, settings.getInt("" + FragmentUserInfo.PREF_GENDER, 0) / 100);
    // Integer.parseInt(settings.getString(""+UserInfoActivity.PREF_CYCLEFREQ,
    // "0"))
    user.put(USER_ETHNICITY, settings.getInt("" + FragmentUserInfo.PREF_ETHNICITY, 0));
    user.put(USER_INCOME, settings.getInt("" + FragmentUserInfo.PREF_INCOME, 0));
    user.put(USER_RIDERTYPE, settings.getInt("" + FragmentUserInfo.PREF_RIDERTYPE, 0));
    user.put(USER_RIDERHISTORY, settings.getInt("" + FragmentUserInfo.PREF_RIDERHISTORY, 0));

    user.put(APP_VERSION, getAppVersion());
    user.put(USER_AGREE, getUserAgreement());

    return user;
}

From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java

public static boolean isDbOutOfDate(Context ctx) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
    File f = new File(DB_PATH, DB_NAME);
    int dbVersion = preferences.getInt("databaseVersion", -1);
    if (!f.exists() || f.length() < 1048576 || dbVersion < CardDbAdapter.DATABASE_VERSION) {
        return true;
    }//w w  w  .  j  a  v a  2  s.co  m
    return false;
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if ((getResources().getConfiguration().screenLayout
            & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_NORMAL
            & (getResources().getConfiguration().screenLayout
                    & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_SMALL) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    }//from   ww  w  .  j a va2s  .com
    SharedPreferences usertheme = getSharedPreferences("theme", 0);
    int newTheme = usertheme.getInt("theme", 2);
    Utils.onActivityCreateSetTheme(this, newTheme);

    SharedPreferences userlang = getSharedPreferences("lang", 0);
    String newlang = userlang.getString("lang", Locale.getDefault().getLanguage());
    Setlanguage.updateLanguage(getApplicationContext(), newlang);

    GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
    View inflate = getLayoutInflater().inflate(R.layout.view, null);
    gestureOverlayView.addView(inflate);
    gestureOverlayView.addOnGesturePerformedListener(this);
    gestureOverlayView.setGestureColor(Color.TRANSPARENT);
    gestureOverlayView.setUncertainGestureColor(Color.TRANSPARENT);
    gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
    if (!gestureLib.load()) {
        finish();
    }
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(gestureOverlayView);
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

    ImageView title_image = (ImageView) findViewById(R.id.title_image);
    title_image.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(getResources().getString(R.string.scify)));
            startActivity(browse);
        }

    });

    // setContentView(R.layout.view);
    // TODO: Add Loading dialog

    SharedPreferences setvmassage = getSharedPreferences("dialog", 0);
    boolean dialogShown = setvmassage.getBoolean("dialogShown", false);

    if (!dialogShown) {
        // prepare the alert box
        AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        alertbox.setMessage(R.string.view_massage);
        alertbox.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface arg0, int arg1) {

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

        SharedPreferences.Editor editor = setvmassage.edit();
        editor.putBoolean("dialogShown", true);
        editor.commit();
    }

    // Init waiting dialog
    showWaitingDialog();

    initLayoutAndControls();

}

From source file:com.sakisds.icymonitor.activities.ConnectionActivity.java

/**
 * Gets the current registration id for application on GCM service.
 * <p/>//  w  ww .ja  v  a 2s  .  co m
 * If result is empty, the registration has failed.
 *
 * @return registration id, or empty string if the registration is not
 * complete.
 */
private String getRegistrationId(Context context) {
    final SharedPreferences prefs = getGCMPreferences(context);
    String registrationId = prefs.getString(PROPERTY_REG_ID, "");
    if (registrationId.length() == 0) {
        Log.v("gcm", "Registration not found.");
        return "";
    }
    // check if app was updated; if so, it must clear registration id to
    // avoid a race condition if GCM sends a message
    int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
    int currentVersion = getAppVersion(context);
    if (registeredVersion != currentVersion || isRegistrationExpired()) {
        Log.v("gcm", "App version changed or registration expired.");
        return "";
    }
    return registrationId;
}