android.content.SharedPreferences.Editor#putInt ( )源码实例Demo

下面列出了android.content.SharedPreferences.Editor#putInt ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: school_shop   文件: SharedPreferencesUtils.java
/**
 * 
 * @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();
}
 
源代码2 项目: fitness_Android   文件: SharedPreferencesUtils.java
/**
 * 保存用户名密码
 *
 * @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;
}
 
源代码3 项目: ViewDebugHelper   文件: PreferencesUtil.java
/**有些时候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();
}
 
源代码4 项目: JianDanRxJava   文件: SPHelper.java
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();
}
 
源代码5 项目: SimpleOpenVpn-Android   文件: ProfileManager.java
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();

}
 
源代码6 项目: product-emm   文件: Preference.java
/**
 * 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();
}
 
源代码7 项目: Last-Launcher   文件: SpUtils.java
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");
    }
 
源代码8 项目: product-emm   文件: Preference.java
/**
 * 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();
}
 
源代码9 项目: product-emm   文件: Preference.java
/**
 * 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();
}
 
源代码10 项目: letv   文件: af.java
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();
}
 
源代码11 项目: CSipSimple   文件: MediaManager.java
/**
	 * 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();
	}
 
源代码12 项目: PS4-Payload-Sender-Android   文件: Prefs.java
/**
 * @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();
    }
}
 
源代码13 项目: JianDan_OkHttpWithVolley   文件: SharedPreUtils.java
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();
}
 
源代码14 项目: FimiX8-RE   文件: SPStoreManager.java
public void saveInt(String key, int value) {
    Editor edit = this.settings.edit();
    edit.putInt(key, value);
    edit.commit();
}
 
源代码15 项目: BmapLite   文件: PreferenceUtils.java
public void setIntPreference(String key, int value) {
    Editor ed = preference.edit();
    ed.putInt(key, value);
    ed.apply();

}
 
源代码16 项目: RetroMusicPlayer   文件: PreferenceUtil.java
public void setLastSleepTimerValue(final int value) {
    final Editor editor = mPreferences.edit();
    editor.putInt(LAST_SLEEP_TIMER_VALUE, value);
    editor.apply();
}
 
源代码17 项目: letv   文件: PreferencesManager.java
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();
}
 
源代码18 项目: TvLauncher   文件: PageApp.java
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();

    }
 
源代码19 项目: PowerFileExplorer   文件: SettingsActivity.java
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();
}
 
源代码20 项目: letv   文件: PreferencesManager.java
public void setExpireDays(int expireDays) {
    Editor editor = context.getSharedPreferences(SETTINGS, 4).edit();
    editor.putInt("expire_days", expireDays);
    editor.commit();
}