public int setCustom(int time, int increment) { // is this custom a duplicate? for (int i = 0; i < times.size(); i++) { if (times.get(i) == time && increments.get(i) == increment) return i; } // check if there is an old custom to remove for (int i = 0; i < times.size(); i++) { if (times.get(i) == customTime && increments.get(i) == customIncrement) { times.remove(i); increments.remove(i); } } // save the new custom customTime = time; customIncrement = increment; SharedPreferences.Editor editor = preferences.edit(); editor.putInt(Common.PREF_CUSTOM_TIME, time); editor.putInt(Common.PREF_CUSTOM_INCREMENT, increment); editor.commit(); for (int i = 0; i < times.size(); i++) { if (times.get(i) >= time) { times.add(i, time); increments.add(i, increment); return i; } } times.add(time); increments.add(increment); return times.size() - 1; }
public void onRadioButtonClicked(View view) { // Log that onRadioButtonClicked was called Log.d(LOG, "WidgetConfigureActivity.onRadioButtonClicked called."); // load up the preferences list SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editPreferences = preferences.edit(); // Is the button now checked? boolean checked = ((RadioButton) view).isChecked(); // Check which radio button was clicked switch (view.getId()) { case R.id.widget_configure_activity_setting_background_radio_dark: if (checked) { // We've selected a Dark widget background Log.d(LOG, "WidgetConfigureActivity.onRadioButtonClicked - Dark Widget"); editPreferences.putInt(WidgetProvider.WIDGET_BACKGROUND_VALUE + "_" + widgetId, 0); preview.setImageResource(R.drawable.preview_dark); } break; case R.id.widget_configure_activity_setting_background_radio_light: if (checked) { // We've selected a Light widget background Log.d(LOG, "WidgetConfigureActivity.onRadioButtonClicked - Light Widget"); editPreferences.putInt(WidgetProvider.WIDGET_BACKGROUND_VALUE + "_" + widgetId, 1); preview.setImageResource(R.drawable.preview_light); } break; } // close and save our preferences now we're done with them editPreferences.commit(); }
private void writeToSharedPref(SharedPreferences prefs) { SharedPreferences.Editor editor = prefs.edit(); editor.putLong(Stopwatches.PREF_START_TIME, mStartTime); editor.putLong(Stopwatches.PREF_ACCUM_TIME, mAccumulatedTime); editor.putInt(Stopwatches.PREF_STATE, mState); if (mLapsAdapter != null) { long[] laps = mLapsAdapter.getLapTimes(); if (laps != null) { editor.putInt(Stopwatches.PREF_LAP_NUM, laps.length); for (int i = 0; i < laps.length; i++) { String key = Stopwatches.PREF_LAP_TIME + Integer.toString(laps.length - i); editor.putLong(key, laps[i]); } } } if (mState == Stopwatches.STOPWATCH_RUNNING) { editor.putLong(Stopwatches.NOTIF_CLOCK_BASE, mStartTime - mAccumulatedTime); editor.putLong(Stopwatches.NOTIF_CLOCK_ELAPSED, -1); editor.putBoolean(Stopwatches.NOTIF_CLOCK_RUNNING, true); } else if (mState == Stopwatches.STOPWATCH_STOPPED) { editor.putLong(Stopwatches.NOTIF_CLOCK_ELAPSED, mAccumulatedTime); editor.putLong(Stopwatches.NOTIF_CLOCK_BASE, -1); editor.putBoolean(Stopwatches.NOTIF_CLOCK_RUNNING, false); } else if (mState == Stopwatches.STOPWATCH_RESET) { editor.remove(Stopwatches.NOTIF_CLOCK_BASE); editor.remove(Stopwatches.NOTIF_CLOCK_RUNNING); editor.remove(Stopwatches.NOTIF_CLOCK_ELAPSED); } editor.putBoolean(Stopwatches.PREF_UPDATE_CIRCLE, false); editor.apply(); }
@Override public void onReceive(Context context, Intent intent) { SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_PREF_KEY, Activity.MODE_PRIVATE); int serviceCount = sp.getInt(INVOKER_SERVICE_COUNT, 0); SharedPreferences.Editor editor = sp.edit(); Log.d(TAG, "OnReceive with serviceCount " + serviceCount); if (intent.getAction().equals("com.windroilla.invoker.blockservice.start")) { if (serviceCount == 0) { Intent i = new Intent(context.getApplicationContext(), TouchBlockService.class); context.getApplicationContext().startService(i); Log.d(TAG, "OnReceive start TouchBlockService"); } serviceCount++; editor.putInt(INVOKER_SERVICE_COUNT, serviceCount); } else if (intent.getAction().equals("com.windroilla.invoker.blockservice.stop")) { if (serviceCount == 1) { Intent i = new Intent(context.getApplicationContext(), TouchBlockService.class); context.getApplicationContext().stopService(i); Log.d(TAG, "OnReceive stop TouchBlockService"); } serviceCount--; editor.putInt(INVOKER_SERVICE_COUNT, serviceCount); } else if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { Intent i = new Intent(context.getApplicationContext(), OnBootService.class); context.getApplicationContext().startService(i); Log.d(TAG, "OnReceive BOOT_COMPLETE"); } Log.d(TAG, "OnReceive with new serviceCount " + serviceCount); editor.commit(); }
private void resetValues(boolean updateDisplay) { if (mService != null && mIsRunning) { mService.resetValues(); } else { TextView timer = (TextView) findViewById(R.id.textView); // timer.setText("00:00"); finalTime = 0; timeSwap = 0; timeInMillies = 0; mStepValueView.setText("0"); mPaceValueView.setText("0"); mDistanceValueView.setText("0"); mSpeedValueView.setText("0"); mCaloriesValueView.setText("0"); mTimeValueView.setText("00:00"); SharedPreferences state = getSharedPreferences("state", 0); SharedPreferences.Editor stateEditor = state.edit(); if (updateDisplay) { stateEditor.putInt("steps", 0); stateEditor.putInt("pace", 0); stateEditor.putFloat("distance", 0); stateEditor.putFloat("speed", 0); stateEditor.putFloat("calories", 0); stateEditor.putLong("time", 0); stateEditor.commit(); } } Toast.makeText(getApplicationContext(), "Pedometer Reset!", Toast.LENGTH_LONG).show(); }
@Override public void onReceive(Context context, Intent intent) { PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, AppTags.UFRGS_MOBILE); // Acquire the lock wl.acquire(); prefs = context.getSharedPreferences(AppTags.LIBRARY_LOGIN_PREF, Context.MODE_PRIVATE); editor = prefs.edit(); int value = prefs.getInt(AppTags.ALARM_COUNTER, 0); value = value + 1; editor.putInt(AppTags.ALARM_COUNTER, value); editor.commit(); LibraryLoader loader = new LibraryLoader(context); loader.renewBooks(null, true); if (value == DAILY_RETRIES) { launchNotification( context, context.getString(R.string.we_tried_to_renew_your_items_notification_title), context.getString(R.string.verify_return_date_notification_message)); editor.putInt(AppTags.ALARM_COUNTER, 0); editor.commit(); } wl.release(); }
public void setScreenResolution(int width, int height) { SharedPreferences.Editor editor = getPreference().edit(); editor.putInt(SCREEN_WIDTH, width); editor.putInt(SCREEN_HEIGHT, height); editor.commit(); }
void saveToSharedPreferences(android.content.SharedPreferences.Editor ed, int index) { String si = Integer.toString(index); if (executionCount > 0) { ed.putInt(IntentExtra.EXTRA_EXECUTION_COUNT.key + si, executionCount); } ed.putInt(IntentExtra.EXTRA_RETRIES_LEFT.key + si, retriesLeft); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.callOk: edit.putInt(Properties.PREF_CALL_ON_LENGTH_VALUE, onProgress); edit.putInt(Properties.PREF_CALL_OFF_LENGTH_VALUE, offProgress); edit.commit(); this.dismiss(); break; case R.id.callCancel: this.dismiss(); break; case R.id.callTest: if (isEnable) { utils.flickFlash(500, 500); isEnable = false; } else { utils.setFlashEnable(false); isEnable = true; } break; default: break; } }
public static void saveGameResults(int scores, int levelNumber, Context context) { // Log.e(tag, "saveGameResults"); SharedPreferences settings = context.getSharedPreferences(Config.Preferences.NAME, 0); final SharedPreferences.Editor editor = settings.edit(); int mScores = settings.getInt(Preferences.LEVEL_SCORE[levelNumber], -1); if (scores > mScores) { editor.putInt(Preferences.LEVEL_SCORE[levelNumber], scores); } int mPackNumber = (levelNumber / 4); int mCurrentRank = settings.getInt(Preferences.LEVEL_RANK[levelNumber], -1); int mNewRank = LevelCompleteScene.getRankByScores(scores); int mCurrentStarsEarned = settings.getInt(Preferences.STARS_EARNED[mPackNumber], 0); if (mNewRank > mCurrentRank) { editor.putInt(Preferences.LEVEL_RANK[levelNumber], mNewRank); if (mCurrentRank < Config.RANK_FOR_GETTING_STAR && mNewRank >= Config.RANK_FOR_GETTING_STAR) { editor.putBoolean(Preferences.STARS_EARNED_NEW[mPackNumber], true); editor.putInt(Preferences.STARS_EARNED[mPackNumber], mCurrentStarsEarned + 1); } } editor.commit(); }
// @TODO this is a sample to get through the database public void buildDummy(SQLiteDatabase db) { // set query to execute String query = "SELECT * FROM Users;"; // set a cursor to run the query Cursor c = db.rawQuery(query, null); // move to the first row c.moveToFirst(); // clear the shared preferences editor.clear(); // set both the shared prefernces and the user elements... editor.putString("name", name = c.getString(1)); editor.putFloat("weight", weight = c.getFloat(2)); editor.putFloat("height", height = c.getFloat(3)); editor.putFloat("BMI", BMI = c.getFloat(4)); editor.putFloat("BMR", BMR = c.getFloat(5)); editor.putFloat("Starting_Weight", start_weight = c.getFloat(6)); editor.putInt("Start_LVL", start_lvl = c.getInt(7)); editor.putFloat("Cal_Needs", cal_needs = c.getFloat(8)); editor.putFloat("Current_Weight", cur_weight = c.getFloat(9)); editor.putInt("Cur_Lvl", cur_lvl = c.getInt(10)); editor.putString("Email", email = c.getString(11)); editor.putString("Phone", phone = c.getString(12)); // commit changes to shared preferences editor.commit(); }
@Override public void onDestroy() { LoginScreen.appendLog(TAG, "[SERVICE] onDestroy"); // Unregister our receiver. unregisterReceiver(mReceiver); unregisterDetector(); mStateEditor = mState.edit(); mStateEditor.putInt("steps", mSteps); mStateEditor.putInt("pace", mPace); mStateEditor.putFloat("distance", mDistance); mStateEditor.putFloat("speed", mSpeed); mStateEditor.putFloat("calories", mCalories); mStateEditor.commit(); wakeLock.release(); super.onDestroy(); // Stop detecting mSensorManager.unregisterListener(mStepDetector); // Tell the user we stopped. // Toast.makeText(this, "stopped pedometer service", Toast.LENGTH_SHORT).show(); }
@Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub switch (seekBar.getId()) { case R.id.seekBar_minLevel: spe.putInt(SEEKBAR_MIN_LEVEL, seekBar.getProgress()); while (!spe.commit()) {} mainFragment.rebuildSeekbar(); break; case R.id.seekBar_maxLevel: spe.putInt(SEEKBAR_MAX_LEVEL, seekBar.getProgress()); while (!spe.commit()) {} mainFragment.rebuildSeekbar(); break; case R.id.seekBar_safetyLevel: spe.putInt(SEEKBAR_SAFETY_LEVEL, seekBar.getProgress()); while (!spe.commit()) {} mainFragment.rebuildSeekbar(); break; case R.id.seekBar_VolumeButtonHack: spe.putInt(SEEKBAR_VOLUME_BUTTON_HACK, seekBar.getProgress()); while (!spe.commit()) {} Intent service = new Intent(this, MainService.class); service.putExtra(MainService.HEADSET_STATUS, MainActivity.TOGGLE_VOLUME_HACK); startService(service); break; } }
// Go Back to Title Screen @Override public void onBackPressed() { // Get New Values int theme = themeSpinner.getSelectedItemPosition(); int controls = controlsSpinner.getSelectedItemPosition(); int view = viewSpinner.getSelectedItemPosition(); int speed = speedSpinner.getSelectedItemPosition(); // Save in Settings // Speed Setting is Stored in a Different File Because It Should Not Be Synced Across Devices userPreferencesEditor = userPreferences.edit(); userPreferencesEditor.putInt("theme", theme); userPreferencesEditor.putInt("controls", controls); userPreferencesEditor.putInt("view", view); speedSettingEditor = speedSetting.edit(); speedSettingEditor.putInt("speed", speed); userPreferencesEditor.commit(); speedSettingEditor.commit(); // Call for Backup BackupManager backupManager = new BackupManager(this); backupManager.dataChanged(); // Go Home & Close Options Screen Intent intent = new Intent(this, TitleScreen.class); startActivity(intent); this.finish(); }
@Override protected void onPause() { Log.i(TAG, "[ACTIVITY] onPause"); if (mIsRunning) {} if (mQuitting) { // mPedometerSettings.saveServiceRunningWithNullTimestamp(mIsRunning); } else { // mPedometerSettings.saveServiceRunningWithTimestamp(mIsRunning); } super.onPause(); stateEditor.putInt("parentStepCountKey", mStepValue); stateEditor.putInt("parentCoinsKey", parentcoinsValue); stateEditor.putInt("childStepCountKey", childstepcount); stateEditor.putInt("childCoinsKey", childcoinValue); stateEditor.commit(); // savePaceSetting(); Log.i( "INSIDEONPAUSE", "VALUES ==> " + mStepValue + " " + parentcoinsValue + " " + childstepcount + " " + childcoinValue); // Dheera: Added to resolve the memory leak issue if (mDataLogReceiver != null) { unregisterReceiver(mDataLogReceiver); mDataLogReceiver = null; } }
@Override protected void onPause() { super.onPause(); SharedPreferences hints = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor hintchanger = hints.edit(); hintchanger.putInt("hints", hints.getInt("hints", 10)); hintchanger.commit(); SharedPreferences pref = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor editor = pref.edit(); editor.putInt("SoundNumber", pref.getInt("SoundNumber", 0)); editor.commit(); SharedPreferences pagenumber = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor changer = pagenumber.edit(); changer.putInt("PageNumber", pagenumber.getInt("PageNumber", 0)); changer.commit(); SharedPreferences correctcounter = getSharedPreferences("MyPref", Context.MODE_PRIVATE); SharedPreferences.Editor counterchanger = correctcounter.edit(); counterchanger.putInt("correctno", correctcounter.getInt("correctno", 0)); counterchanger.commit(); }
private void saveSetting() { for (int i = 0; i < achievements.size(); i++) { data.achieveValue.set(i, achievements.get(i).getValue()); } SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putBoolean("isLogin", isLogin); editor.putString("Username", data.getUser()); editor.commit(); SharedPreferences.Editor sPEditor = getPreferences(Context.MODE_PRIVATE).edit(); String dataJasonString = convertingDataKeeperToJSONString(data); sPEditor.putString("DATAs" + data.getUser(), dataJasonString); Log.e("JasonStringSaved", dataJasonString); sPEditor.putString("FOODLIST", foodListJson); sPEditor.putString("ACTIVITYLIST", activityListJson); Calendar calendar = Calendar.getInstance(); sPEditor.putInt("DAY", calendar.get(Calendar.DAY_OF_MONTH)); sPEditor.putInt("lvl", data.getlvl()); sPEditor.putInt("lvlexp", data.getLvlexp()); sPEditor.commit(); isLoad = false; }
public void putIndexes(HashMap<String, Integer> indexes) { SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putInt("index_fm", indexes.get("FM")); editor.putInt("index_am", indexes.get("AM")); editor.putInt("index_fav", indexes.get("FAV")); editor.commit(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.delete) { dbhelper.deleteMarkByID(ChalkmarkID); Context context = getApplicationContext(); AlertDialog.Builder alertbox = new AlertDialog.Builder(context); alertbox.setMessage("The Mark Was Deleted"); SharedPreferences.Editor editor = mPreferences.edit(); editor.putInt("DefaultTab", 1); editor.commit(); Intent intent = new Intent().setClass(MessageDetails.this, ChalkMarkTabHost.class); startActivity(intent); finish(); } else if (item.getItemId() == R.id.map) { Intent i = new Intent(MessageDetails.this, MarkInfoMap.class); c = dbhelper.getByID(ChalkmarkID); c.moveToFirst(); Double latitude = dbhelper.getLat(c); Double longitude = dbhelper.getLon(c); i.putExtra(MarkInfoMap.EXTRA_LATITUDE, latitude); i.putExtra(MarkInfoMap.EXTRA_LONGITUDE, longitude); i.putExtra(MarkInfoMap.EXTRA_NAME, dbhelper.getFromName(c)); i.putExtra(MarkInfoMap.EXTRA_SUBJECT, dbhelper.getSubject(c)); dbhelper.close(); startActivity(i); } else if (item.getItemId() == R.id.unread) { // Make the Chalkmark unread c = dbhelper.getByID(ChalkmarkID); c.moveToFirst(); dbhelper.updateStatus(ChalkmarkID, "unread"); } else if (item.getItemId() == R.id.unread) { // Make the Chalkmark unread c = dbhelper.getByID(ChalkmarkID); c.moveToFirst(); dbhelper.updateStatus(ChalkmarkID, "unread"); } else if (item.getItemId() == R.id.repost) { c = dbhelper.getByID(ChalkmarkID); c.moveToFirst(); SharedPreferences.Editor editor = mPreferences.edit(); editor.putString("SavedSubject", dbhelper.getSubject(c)); editor.putString("SavedBody", dbhelper.getBody(c)); editor.putInt("SavedExpiration", 25); editor.putInt("SavedRadius", 1000); editor.putBoolean("SavedImageFlag", imageflag); editor.putString("RandomString", dbhelper.getImagePair(c)); editor.putFloat("MarkLat", (float) dbhelper.getLat(c)); editor.putFloat("MarkLon", (float) dbhelper.getLon(c)); editor.commit(); Intent i = new Intent(MessageDetails.this, MakeMark.class); startActivity(i); finish(); } return (super.onOptionsItemSelected(item)); }
@Override protected void onPause() { super.onPause(); SharedPreferences.Editor editor = mSettings.edit(); editor.putInt(APP_PREFERENCES_COUNTER_CAT, mCountCat); editor.putInt(APP_PREFERENCES_COUNTER_CROWN, mCountCrown); editor.apply(); }
/** Save measurement statistics to persistent storage. */ private void saveStats() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences.Editor editor = prefs.edit(); editor.putInt(Config.PREF_KEY_COMPLETED_MEASUREMENTS, completedMeasurementCnt); editor.putInt(Config.PREF_KEY_FAILED_MEASUREMENTS, failedMeasurementCnt); editor.commit(); }
private void updatePreferences() { SharedPreferences.Editor editor = preferences.edit(); editor.putString("address", addressField.getText().toString()); editor.putInt("port", Integer.parseInt(portField.getText().toString())); editor.putInt("interval", Integer.parseInt(intervalField.getText().toString())); editor.commit(); }
public void setDate(int dateType, int dateValue) { SharedPreferences settings = getSharedPreferences(FILTER_PREFS, MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putInt(DATE_TYPE, dateType); editor.putInt(DATE_VALUE, dateValue); editor.commit(); }
@Override public boolean onPreferenceChange(Preference preference, Object o) { SharedPreferences.Editor e = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE).edit(); String key = preference.getKey(); // Вычитываем параметры // @todo: нужен рефакторинг повторных кусков кода if (key.equals(BACKGROUND_ENABLED_CHECKBOX_KEY)) { Boolean enabled = Boolean.parseBoolean(o.toString()); e.putBoolean(BACKGROUND_ENABLED_CHECKBOX_KEY, enabled); } else if (key.equals(H_ENABLED_CHECKBOX_KEY)) { Boolean enabled = Boolean.parseBoolean(o.toString()); e.putBoolean(H_ENABLED_CHECKBOX_KEY, enabled); } else if (key.equals(V_ENABLED_CHECKBOX_KEY)) { Boolean enabled = Boolean.parseBoolean(o.toString()); e.putBoolean(V_ENABLED_CHECKBOX_KEY, enabled); } else if (key.equals(VF_TOUCH_ENABLED_CHECKBOX_KEY)) { Boolean enabled = Boolean.parseBoolean(o.toString()); e.putBoolean(VF_TOUCH_ENABLED_CHECKBOX_KEY, enabled); } else if (key.equals(V_SCROLL_ENABLED_CHECKBOX_KEY)) { Boolean enabled = Boolean.parseBoolean(o.toString()); e.putBoolean(V_SCROLL_ENABLED_CHECKBOX_KEY, enabled); } else if (key.equals(VF_COUNT_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(VF_COUNT_LIST_KEY, id); } else if (key.equals(VB_COUNT_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(VB_COUNT_LIST_KEY, id); } else if (key.equals(HB_COUNT_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(HB_COUNT_LIST_KEY, id); } else if (key.equals(HF_COUNT_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(HF_COUNT_LIST_KEY, id); } else if (key.equals(BACKGROUND_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(BACKGROUND_SPEED_LIST_KEY, id); } else if (key.equals(HF_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(HF_SPEED_LIST_KEY, id); } else if (key.equals(HB_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(HB_SPEED_LIST_KEY, id); } else if (key.equals(VF_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(VF_SPEED_LIST_KEY, id); } else if (key.equals(VB_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(VB_SPEED_LIST_KEY, id); } else if (key.equals(V_SCROLL_SPEED_LIST_KEY)) { int id = Integer.parseInt(o.toString()); e.putInt(V_SCROLL_SPEED_LIST_KEY, id); } e.commit(); return true; }
public static void saveDisplaySize(Activity activity) { DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); SharedPreferences.Editor editor = getPreferences().edit(); editor.putInt("screen_width", displaymetrics.widthPixels); editor.putInt("screen_height", displaymetrics.heightPixels); editor.putFloat("density", displaymetrics.density); editor.commit(); }
/** * Saves the provided Color object to the SharedPreferences * * @param color */ public void setColor(ColorPref color) { SharedPreferences.Editor editor = this.prefs.edit(); editor.putInt("color.red", color.red); editor.putInt("color.blue", color.blue); editor.putInt("color.green", color.green); editor.commit(); }
public void saveSettings() { SharedPreferences settings = getActivity().getSharedPreferences(PREF_TITLE, 0); SharedPreferences.Editor editor = settings.edit(); StringBuilder sb = new StringBuilder(); if (verify() == true) { sb = new StringBuilder(); String url = sb.append(et_serv.getText()).toString(); sb.setLength(0); String user = sb.append(et_user.getText()).toString(); sb.setLength(0); String pass = sb.append(et_pass.getText()).toString(); sb.setLength(0); int threads = Integer.parseInt(sb.append(et_thread.getText()).toString()); sb.setLength(0); float throttle = (float) sb_throttle.getProgress() / 100; sb.setLength(0); long scantime = Long.parseLong(sb.append(et_scanTime.getText()).toString()); sb.setLength(0); long retrypause = Long.parseLong(sb.append(et_retryPause.getText()).toString()); settings = getActivity().getSharedPreferences(PREF_TITLE, 0); editor = settings.edit(); editor.putString(PREF_URL, url); editor.putString(PREF_USER, user); editor.putString(PREF_PASS, pass); editor.putInt(PREF_THREAD, threads); Log.i("LC", "Settings: Throttle: " + throttle); editor.putFloat(PREF_THROTTLE, throttle); editor.putLong(PREF_SCANTIME, scantime); editor.putLong(PREF_RETRYPAUSE, retrypause); editor.putBoolean(PREF_BACKGROUND, cb_service.isChecked()); editor.putBoolean(PREF_DONATE, cb_donate.isChecked()); Log.i("LC", "Settings: Pri " + (String) spn_priority.getSelectedItem()); if (spn_priority.getSelectedItemPosition() == 0) { editor.putInt(PREF_PRIORITY, Thread.MIN_PRIORITY); } if (spn_priority.getSelectedItemPosition() == 1) { editor.putInt(PREF_PRIORITY, Thread.NORM_PRIORITY); } if (spn_priority.getSelectedItemPosition() == 2) { editor.putInt(PREF_PRIORITY, Thread.MAX_PRIORITY); } Log.i("LC", "Settings: Settings saved"); editor.commit(); Toast.makeText(getActivity(), "Settings Saved", Toast.LENGTH_SHORT).show(); } else { Log.i("LC", "Settings: Invalid Input"); Toast.makeText(getActivity(), "Settings: Errors changed to red", Toast.LENGTH_SHORT).show(); } editor.commit(); }
public void storeStreak(boolean isSolved) { int solved_streak = stats.getInt("solvedstreak", 0); int longest_streak = stats.getInt("longeststreak", 0); SharedPreferences.Editor editor = stats.edit(); if (isSolved) { editor.putInt("solvedstreak", solved_streak + 1); if (solved_streak == longest_streak) editor.putInt("longeststreak", solved_streak + 1); } else editor.putInt("solvedstreak", 0); editor.commit(); }
public static void setInstanceId(Context context, PushRegistration registration) { int appVersion = getAppVersion(context); SharedPreferences preferences = context.getSharedPreferences(Constants.PREFS_FILE, Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString(Constants.PrefKeys.PUSH_REGISTRATION_INSTANCE_ID, registration.instanceId); editor.putString(Constants.PrefKeys.PUSH_REGISTRATION_SENDER_ID, registration.senderId); editor.putInt(Constants.PrefKeys.PROPERTY_APP_VERSION, appVersion); editor.putInt(Constants.PrefKeys.PROPERTY_OS_VERSION, Build.VERSION.SDK_INT); editor.apply(); }
private void savePreferences() { int updateIndex = updateFreqSpinner.getSelectedItemPosition(); int minMagIndex = magnitudeSpinner.getSelectedItemPosition(); boolean autoUpdateChecked = autoUpdate.isChecked(); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean(PREF_AUTO_UPDATE, autoUpdateChecked); editor.putInt(PREF_UPDATE_FREQ_INDEX, updateIndex); editor.putInt(PREF_MIN_MAG_INDEX, minMagIndex); editor.apply(); }