List of usage examples for android.content SharedPreferences getInt
int getInt(String key, int defValue);
From source file:com.secretparty.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences prefs = this.getPreferences(MODE_PRIVATE); thematicRepo = ((SecretPartyApplication) getApplication()).getThematicRepository(); api = ((SecretPartyApplication) getApplication()).getApiService(); //TODO : check if thematics are in the database. If so, launch a ThematicFragment. Otherwise, download them, save them to the db and launch TheamticFragment int userId = prefs.getInt(getString(R.string.SP_user_id), -1); int partyId = prefs.getInt(getString(R.string.SP_party_id), -1); long partyEnd = prefs.getLong(getString(R.string.SP_date_party_end), -1); Log.v("creation", new Date(partyEnd).toLocaleString() + ""); api.listThematics(new OnReceivedThematics()); if (userId == -1) { DialogFragment df = new UserCreationDialog(); df.setCancelable(false);/* w w w.ja v a 2 s. c o m*/ df.show(getSupportFragmentManager(), "dialog"); } }
From source file:com.bellman.bible.service.device.speak.SpeakTextProvider.java
/** * restore state to allow long pauses//from ww w. j av a 2s. co m * * @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:edu.gatech.ppl.cycleatlanta.TripUploader.java
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)); }/*from w w w . j a va 2 s.c o m*/ 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()); return user; }
From source file:com.afollestad.polar.ui.MainActivity.java
public void showChangelogIfNecessary(boolean licenseAllowed) { if (!Config.get().changelogEnabled()) { retryLicenseCheck();/*w w w .j ava 2 s . c o m*/ } else if (licenseAllowed || retryLicenseCheck()) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final int currentVersion = BuildConfig.VERSION_CODE; if (currentVersion != prefs.getInt("changelog_version", -1)) { prefs.edit().putInt("changelog_version", currentVersion).apply(); ChangelogDialog.show(this); } } }
From source file:a.dev.mobile.thread.MainActivity.java
private int loadIntFromFile() { SharedPreferences sharedPreferences; int i = 1;/*from ww w. ja v a 2s . c o m*/ sharedPreferences = getSharedPreferences(AppConst.SHARED_PREFERENCES, Context.MODE_PRIVATE); if (sharedPreferences.contains(AppConst.PREF_ISO_OR_UN)) { i = sharedPreferences.getInt(AppConst.PREF_ISO_OR_UN, i); } return i; }
From source file:com.example.clientapplication.MainActivity.java
/** * Gets the current registration ID for application on GCM service, if there is one. * <p>/* w ww.j a v a2 s . co m*/ * If result is empty, the app needs to register. * * @return registration ID, or empty string if there is no existing * registration ID. */ private String getRegistrationId(Context context) { final SharedPreferences prefs = getGcmPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.equals("")) { Log.i(TAG, "Registration not found."); return ""; } // 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:com.intel.xdk.camera.Camera.java
void cameraActivityResult(int resultCode, Intent intent) { if (resultCode == Activity.RESULT_OK) { //get info from shared prefs SharedPreferences prefs = activity.getSharedPreferences(cameraPrefsKey, 0); String outputFile = prefs.getString(cameraPrefsFileName, ""); boolean isPNG = prefs.getBoolean(cameraPrefsIsPNG, false); int quality = prefs.getInt(cameraPrefsQuality, 100); savePicture(outputFile, quality, isPNG); } else {/*from w w w . j ava 2 s. c om*/ pictureCancelled(); } }
From source file:com.abhijitvalluri.android.fitnotifications.setup.AppIntroActivity.java
private void addDemoSlide() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean dismissPlaceholderNotif = preferences .getBoolean(getString(R.string.dismiss_placeholder_notif_key), false); final int placeholderNotifDismissDelayMillis = preferences .getInt(getString(R.string.placeholder_dismiss_delay_key), Constants.DEFAULT_DELAY_SECONDS) * 1000; final Handler handler = new Handler(); // Demo/*from w ww . ja v a2 s . c o m*/ addSlide(new SimpleSlide.Builder().layout(R.layout.fragment_intro).title(R.string.intro_done_title) .description(R.string.intro_done_desc).image(R.drawable.intro_done).background(R.color.colorAccent) .backgroundDark(R.color.colorAccentDark).buttonCtaLabel(R.string.test_notification) .buttonCtaClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle newExtra = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(AppIntroActivity.this); String notificationText = "Sample notification subject"; String notificationBigText = "Sample notification body. This is where the details of the notification will be shown."; StringBuilder sb = new StringBuilder(); sb.append("[").append("example").append("] "); sb.append(notificationText); if (notificationBigText.length() > 0) { sb.append(" -- ").append(notificationBigText); } RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); contentView.setTextViewText(R.id.customNotificationText, getString(R.string.placeholder_notification_text)); builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString()) .setExtras(newExtra).setContentTitle("Sample Notification Title") .setContent(contentView); // Creates an explicit intent for the SettingsActivity in the app Intent settingsIntent = new Intent(AppIntroActivity.this, SettingsActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // the application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(AppIntroActivity.this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(settingsIntent); PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(settingsPendingIntent).setAutoCancel(true); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, builder.build()); Toast.makeText(AppIntroActivity.this, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show(); if (dismissPlaceholderNotif) { handler.postDelayed(new Runnable() { @Override public void run() { ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(NOTIFICATION_ID); } }, placeholderNotifDismissDelayMillis); } } }).build()); }
From source file:org.jboss.aerogear.android.unifiedpush.gcm.AeroGearGCMPushRegistrar.java
/** * Gets the current registration id for application on GCM service. * <p>//www .j a va2 s . co m * If result is empty, the registration has failed. * * @param context the application context * * @return registration id, or empty string if the registration is not * complete. */ public String getRegistrationId(Context context) { final SharedPreferences prefs = getGCMPreferences(context); String registrationId = prefs.getString(PROPERTY_REG_ID, ""); if (registrationId.length() == 0) { Log.v(TAG, "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(context)) { Log.v(TAG, "App version changed or registration expired."); return ""; } return registrationId; }