Java Code Examples for android.content.SharedPreferences.Editor#putInt()
The following examples show how to use
android.content.SharedPreferences.Editor#putInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SharedPreferencesUtils.java From fitness_Android with Apache License 2.0 | 6 votes |
/** * 保存用户名密码 * * @param context * @param user * @return */ public static boolean saveUserInfo(Context context, User user) { try { //1.通过Context对象创建一个SharedPreference对象 //name:sharedpreference文件的名称 mode:文件的操作模式 SharedPreferences sharedPreferences = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE); //2.通过sharedPreferences对象获取一个Editor对象 Editor editor = sharedPreferences.edit(); //3.往Editor中添加数据 editor.putInt("userId", user.getUserId()); editor.putString("username", user.getUsername()); editor.putString("password", user.getPassword()); editor.putString("sex", user.getSex()); editor.putString("height", user.getHeight() + ""); editor.putString("weight", user.getWeight() + ""); //4.提交Editor对象 editor.commit(); return true; } catch (Exception e) { e.printStackTrace(); } return false; }
Example 2
Source File: SharedPreferencesUtils.java From school_shop with MIT License | 6 votes |
/** * * @author zhoufeng * @createtime 2015-3-30 下午2:59:33 * @Decription 向SharedPreferences添加信息 * * @param context 上下文 * @param SharedPreferName SharedPreferences的名称 * @param type 数据的类型 * @param key 数据的名称 * @param value 数据的值 */ public static void saveSharedPreferInfo(Context context, String SharedPreferName, String type, String key, Object value) { SharedPreferences userPreferences; userPreferences = context.getSharedPreferences(SharedPreferName, Context.MODE_PRIVATE); Editor editor = userPreferences.edit(); if ("String".equals(type)) { editor.putString(key, (String) value); } else if ("Integer".equals(type)) { editor.putInt(key, (Integer) value); } else if ("Boolean".equals(type)) { editor.putBoolean(key, (Boolean) value); } else if ("Float".equals(type)) { editor.putFloat(key, (Float) value); } else if ("Long".equals(type)) { editor.putLong(key, (Long) value); } editor.commit(); }
Example 3
Source File: af.java From letv with Apache License 2.0 | 5 votes |
public static void a(Context context, String str, int i) { if (a(context)) { b(context); Editor edit = a.edit(); edit.putInt(str, i); edit.apply(); return; } z.d(); }
Example 4
Source File: SharedPreUtils.java From JianDan_OkHttpWithVolley with Apache License 2.0 | 5 votes |
public static void setInteger(Context context, String key, int value) { SharedPreferences sp = context.getSharedPreferences( SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putInt(key, value); editor.commit(); }
Example 5
Source File: Prefs.java From PS4-Payload-Sender-Android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param key The name of the preference to modify. * @param value The new value for the preference. * @see Editor#putStringSet(String, Set) */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) public static void putStringSet(final String key, final Set<String> value) { final Editor editor = getPreferences().edit(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { editor.putStringSet(key, value); } else { // Workaround for pre-HC's lack of StringSets int stringSetLength = 0; if (mPrefs.contains(key + LENGTH)) { // First read what the value was stringSetLength = mPrefs.getInt(key + LENGTH, -1); } editor.putInt(key + LENGTH, value.size()); int i = 0; for (String aValue : value) { editor.putString(key + "[" + i + "]", aValue); i++; } for (; i < stringSetLength; i++) { // Remove any remaining values editor.remove(key + "[" + i + "]"); } } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) { editor.commit(); } else { editor.apply(); } }
Example 6
Source File: MediaManager.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
/** * Save current audio mode in order to be able to restore it once done */ @SuppressWarnings("deprecation") private synchronized void saveAudioState() { if( prefs.getBoolean("isSavedAudioState", false) ) { //If we have already set, do not set it again !!! return; } ContentResolver ctntResolver = service.getContentResolver(); Editor ed = prefs.edit(); // ed.putInt("savedVibrateRing", audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)); // ed.putInt("savedVibradeNotif", audioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_NOTIFICATION)); // ed.putInt("savedRingerMode", audioManager.getRingerMode()); ed.putInt("savedWifiPolicy" , Compatibility.getWifiSleepPolicy(ctntResolver)); int inCallStream = Compatibility.getInCallStream(userWantBluetooth); ed.putInt("savedVolume", audioManager.getStreamVolume(inCallStream)); int targetMode = getAudioTargetMode(); if(service.getPrefs().useRoutingApi()) { ed.putInt("savedRoute", audioManager.getRouting(targetMode)); }else { ed.putBoolean("savedSpeakerPhone", audioManager.isSpeakerphoneOn()); } ed.putInt("savedMode", audioManager.getMode()); ed.putBoolean("isSavedAudioState", true); ed.commit(); }
Example 7
Source File: Preference.java From product-emm with Apache License 2.0 | 5 votes |
/** * Put integer data to shared preferences in private mode. * @param context - The context of activity which is requesting to put data. * @param key - Used to identify the value. * @param value - The actual value to be saved. */ public static void putInt(Context context, String key, int value) { SharedPreferences mainPref = context.getSharedPreferences(context.getResources() .getString(R.string.shared_pref_package), Context.MODE_PRIVATE ); Editor editor = mainPref.edit(); editor.putInt(key, value); editor.commit(); }
Example 8
Source File: Preference.java From product-emm with Apache License 2.0 | 5 votes |
/** * Put integer data to shared preferences in private mode. * @param context - The context of activity which is requesting to put data. * @param key - Used to identify the value. * @param value - The actual value to be saved. */ public static void putInt(Context context, String key, int value) { SharedPreferences mainPref = context.getSharedPreferences(context.getResources() .getString(R.string.shared_pref_package), Context.MODE_PRIVATE ); Editor editor = mainPref.edit(); editor.putInt(key, value); editor.commit(); }
Example 9
Source File: SpUtils.java From Last-Launcher with GNU General Public License v3.0 | 5 votes |
SpUtils putIntCommit(String key, int value) { if (mPref != null) { Editor editor = mPref.edit(); editor.putInt(key, value); editor.commit(); return this; } else throw new RuntimeException("First Initialize context"); }
Example 10
Source File: Preference.java From product-emm with Apache License 2.0 | 5 votes |
/** * Put integer data to shared preferences in private mode. * @param context - The context of activity which is requesting to put data. * @param key - Used to identify the value. * @param value - The actual value to be saved. */ public static void putInt(Context context, String key, int value) { SharedPreferences mainPref = context.getSharedPreferences(context.getResources() .getString(R.string.shared_pref_package), Context.MODE_PRIVATE ); Editor editor = mainPref.edit(); editor.putInt(key, value); editor.commit(); }
Example 11
Source File: ProfileManager.java From SimpleOpenVpn-Android with Apache License 2.0 | 5 votes |
public void saveProfileList(Context context) { SharedPreferences sharedprefs = context.getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE); Editor editor = sharedprefs.edit(); editor.putStringSet("vpnlist", profiles.keySet()); // For reasing I do not understand at all // Android saves my prefs file only one time // if I remove the debug code below :( int counter = sharedprefs.getInt("counter", 0); editor.putInt("counter", counter + 1); editor.apply(); }
Example 12
Source File: SPHelper.java From JianDanRxJava with Apache License 2.0 | 5 votes |
public static void setInteger(String key, int value) { SharedPreferences sp = mContext.getSharedPreferences( SHARED_PREFERANCE_NAME, Context.MODE_PRIVATE); Editor editor = sp.edit(); editor.putInt(key, value); editor.apply(); }
Example 13
Source File: PreferencesUtil.java From ViewDebugHelper with BSD 3-Clause "New" or "Revised" License | 5 votes |
/**有些时候MarketApplication.getInstance()是为null的,比如升级数据库的时候*/ public static boolean setIntValue(Context context,String key, int value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = prefs.edit(); editor.putInt(key, value); return editor.commit(); }
Example 14
Source File: PreferenceUtils.java From BmapLite with GNU General Public License v3.0 | 4 votes |
public void setIntPreference(String key, int value) { Editor ed = preference.edit(); ed.putInt(key, value); ed.apply(); }
Example 15
Source File: SPStoreManager.java From FimiX8-RE with MIT License | 4 votes |
public void saveInt(String key, int value) { Editor edit = this.settings.edit(); edit.putInt(key, value); edit.commit(); }
Example 16
Source File: PreferenceUtil.java From RetroMusicPlayer with GNU General Public License v3.0 | 4 votes |
public void setLastSleepTimerValue(final int value) { final Editor editor = mPreferences.edit(); editor.putInt(LAST_SLEEP_TIMER_VALUE, value); editor.apply(); }
Example 17
Source File: PreferencesManager.java From letv with Apache License 2.0 | 4 votes |
public void setContinuePayDateTime(String datetime) { Editor editor = context.getSharedPreferences(SETTINGS, 4).edit(); editor.putString("continue_pay_datetime", datetime); editor.putInt("expire_days", -101); editor.commit(); }
Example 18
Source File: PageApp.java From TvLauncher with Apache License 2.0 | 4 votes |
public void saveAppMoveStatus() { SharedPreferences mSharedPreferences = thisActivity.getSharedPreferences("app_order", Context.MODE_PRIVATE); Editor editor = mSharedPreferences.edit(); editor.clear(); for (int i = 0; i < mAppInfos.size(); i++) { editor.putInt(mAppInfos.get(i).mAppName, i); } editor.apply(); }
Example 19
Source File: SettingsActivity.java From PowerFileExplorer with GNU General Public License v3.0 | 4 votes |
public void colorChanged(int fg, int bg) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); Editor editor = sp.edit(); editor.putInt( KEY_UNDERLINE_COLOR, fg ); editor.commit(); }
Example 20
Source File: PreferencesManager.java From letv with Apache License 2.0 | 4 votes |
public void setExpireDays(int expireDays) { Editor editor = context.getSharedPreferences(SETTINGS, 4).edit(); editor.putInt("expire_days", expireDays); editor.commit(); }