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

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

源代码1 项目: HaoReader   文件: SharedPreferencesUtil.java
/**
 * 保存数据到文件
 *
 * @param context
 * @param key
 * @param data
 */
public static void saveData(Context context, String key, Object data) {

    SharedPreferences sharedPreferences = context
            .getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    Editor editor = sharedPreferences.edit();

    if (data instanceof Integer) {
        editor.putInt(key, (Integer) data);
    } else if (data instanceof Boolean) {
        editor.putBoolean(key, (Boolean) data);
    } else if (data instanceof String) {
        editor.putString(key, (String) data);
    } else if (data instanceof Float) {
        editor.putFloat(key, (Float) data);
    } else if(data instanceof Double) {
        editor.putFloat(key, Float.valueOf(data + ""));
    }else if (data instanceof Long) {
        editor.putLong(key, (Long) data);
    }

    editor.apply();
}
 
源代码2 项目: BaseProject   文件: PreferVisitor.java
@SuppressLint("NewApi")
private void editorPutValues(Editor editor, String preferKey, Object valueData) {
    if (editor == null) {
        return;
    }
    if (valueData == null) {
        editor.putString(preferKey, null);
    } else {
        if (valueData instanceof String) {
            editor.putString(preferKey, (String) valueData);
        } else if (valueData instanceof Integer) {
            editor.putInt(preferKey, (Integer) valueData);
        } else if (valueData instanceof Boolean) {
            editor.putBoolean(preferKey, (Boolean) valueData);
        } else if (valueData instanceof Float) {
            editor.putFloat(preferKey, (Float) valueData);
        } else if (valueData instanceof Set) {
            if (Util.isCompateApi(11))
                editor.putStringSet(preferKey, (Set<String>) valueData);
        } else if (valueData instanceof Long) {
            editor.putLong(preferKey, (Long) valueData);
        }
    }
}
 
源代码3 项目: letv   文件: e.java
private static void a(String str, Object obj) {
    Editor edit = c.edit();
    if (obj.getClass() == Boolean.class) {
        edit.putBoolean(str, ((Boolean) obj).booleanValue());
    }
    if (obj.getClass() == String.class) {
        edit.putString(str, (String) obj);
    }
    if (obj.getClass() == Integer.class) {
        edit.putInt(str, ((Integer) obj).intValue());
    }
    if (obj.getClass() == Float.class) {
        edit.putFloat(str, (float) ((Float) obj).intValue());
    }
    if (obj.getClass() == Long.class) {
        edit.putLong(str, (long) ((Long) obj).intValue());
    }
    edit.commit();
}
 
@Override
public void onStop() {
    super.onStop();
    // Store threshold values
    Editor editor = prefs.edit();
    editor.putFloat("faceThreshold", faceThreshold);
    editor.putFloat("distanceThreshold", distanceThreshold);
    editor.putInt("maximumImages", maximumImages);
    editor.putBoolean("useEigenfaces", useEigenfaces);
    editor.putInt("mCameraIndex", mOpenCvCameraView.mCameraIndex);
    editor.apply();

    // Store ArrayLists containing the images and labels
    if (images != null && imagesLabels != null) {
        tinydb.putListMat("images", images);
        tinydb.putListString("imagesLabels", imagesLabels);
    }
}
 
源代码5 项目: 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();
}
 
源代码6 项目: Cotable   文件: BaseApplication.java
/**
 * Save the display size of Activity.
 *
 * @param activity an activity
 */
public static void saveDisplaySize(Activity activity) {
    DisplayMetrics displaymetrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay()
            .getMetrics(displaymetrics);
    Editor editor = getPreferences().edit();
    editor.putInt("screen_width", displaymetrics.widthPixels);
    editor.putInt("screen_height", displaymetrics.heightPixels);
    editor.putFloat("density", displaymetrics.density);
    apply(editor);
    TLog.log("", "Resolution:" + displaymetrics.widthPixels + " x "
            + displaymetrics.heightPixels + " DisplayMetrics:" + displaymetrics.density
            + " " + displaymetrics.densityDpi);
}
 
源代码7 项目: EasySettings   文件: SettingsObject.java
/**
 * convenience method for setting the given value to this {@link SettingsObject}
 * and also saving the value in the apps' settings.<br><br/>
 * VERY IMPORTANT!!! <br><br/>
 * this method does NOT perform validity checks on the given "value" and
 * assumes that it is a valid value to be saved as a setting!
 * for example, if this method is called from {@link SeekBarSettingsObject},
 * it is assumed that "value" is between {@link SeekBarSettingsObject#getMinValue()}
 * and {@link SeekBarSettingsObject#getMaxValue()}
 * @param context the context to be used to get the app settings
 * @param value the VALID value to be saved in the apps' settings
 * @throws IllegalArgumentException if the given value is of a type which cannot be saved
 *                                  to SharedPreferences
 */
public void setValueAndSaveSetting(Context context, V value)
		throws IllegalArgumentException
{
	setValue(value);
	Editor editor = EasySettings.retrieveSettingsSharedPrefs(context).edit();

	switch (getType())
	{
		case VOID:
			//no actual value to save
			break;
		case BOOLEAN:
			editor.putBoolean(getKey(), (Boolean) value);
			break;
		case FLOAT:
			editor.putFloat(getKey(), (Float) value);
			break;
		case INTEGER:
			editor.putInt(getKey(), (Integer) value);
			break;
		case LONG:
			editor.putLong(getKey(), (Long) value);
			break;
		case STRING:
			editor.putString(getKey(), (String) value);
			break;
		case STRING_SET:
			editor.putStringSet(getKey(), getStringSetToSave((Set<?>) value));
			break;
		default:
			throw new IllegalArgumentException("parameter \"value\" must be of a type that " +
											   "can be saved in SharedPreferences. given type was "
											   + value.getClass().getName());
	}

	editor.apply();
}
 
源代码8 项目: 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#putFloat(String, float)
 */
public static void putFloat(final String key, final float value) {
    final Editor editor = getPreferences().edit();
    editor.putFloat(key, value);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        editor.commit();
    } else {
        editor.apply();
    }
}
 
源代码9 项目: Aria   文件: SharePreUtil.java
/**
 * 保存Float数据到配置文件
 */
public static Boolean putFloat(String preName, Context context, String key, float value) {
  SharedPreferences pre = context.getSharedPreferences(preName, Context.MODE_PRIVATE);
  Editor editor = pre.edit();
  editor.putFloat(key, value);
  return editor.commit();
}
 
源代码10 项目: CSipSimple   文件: PreferencesWrapper.java
/**
 * Set a preference float value
 * @param key the preference key to set
 * @param value the value for this key
 */
public void setPreferenceFloatValue(String key, float value) {
    if(sharedEditor == null) {
   		Editor editor = prefs.edit();
   		editor.putFloat(key, value);
   		editor.commit();
    }else {
        sharedEditor.putFloat(key, value);
    }
}
 
源代码11 项目: product-emm   文件: Preference.java
/**
 * Put float 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 putFloat(Context context, String key, float value) {
	SharedPreferences mainPref =
			context.getSharedPreferences(context.getResources()
			                                    .getString(R.string.shared_pref_package),
			                             Context.MODE_PRIVATE
			);
	Editor editor = mainPref.edit();
	editor.putFloat(key, value);
	editor.commit();
}
 
源代码12 项目: BaseProject   文件: PreferVisitor.java
/**
 * 存储一条数据到首选项文件中
 * @param preferFileName 要保存的SharedPreference 文件名
 * @param key
 * @param value
 */
@SuppressLint("NewApi")
public boolean saveValue(String preferFileName, String key, Object value) {
    if (Util.isEmpty(preferFileName)) {
        return false;
    }
    Editor mEditor = getSpByName(preferFileName).edit();
    if (value == null) {
        mEditor.putString(key, null);
    }
    else{
        String valueType = value.getClass().getSimpleName();
        if ("String".equals(valueType)) {
            mEditor.putString(key, (String) value);
        } else if ("Integer".equals(valueType)) {
            mEditor.putInt(key, (Integer) value);
        } else if ("Boolean".equals(valueType)) {
            mEditor.putBoolean(key, (Boolean) value);
        } else if ("Float".equals(valueType)) {
            mEditor.putFloat(key, (Float) value);
        } else if ("Long".equals(valueType)) {
            mEditor.putLong(key, (Long) value);
        } else if ("Set".equals(valueType)) {
            if (Util.isCompateApi(11)) {
                mEditor.putStringSet(key, (Set<String>) value);
            }
        }
    }
    return mEditor.commit();
}
 
源代码13 项目: mytracks   文件: PreferencesUtils.java
/**
 * Sets a float preference value.
 * 
 * @param context the context
 * @param keyId the key id
 * @param value the value
 */
@SuppressLint("CommitPrefEdits")
public static void setFloat(Context context, int keyId, float value) {
  SharedPreferences sharedPreferences = context.getSharedPreferences(
      Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
  Editor editor = sharedPreferences.edit();
  editor.putFloat(getKey(context, keyId), value);
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);
}
 
源代码14 项目: mytracks   文件: PreferenceBackupHelperTest.java
public void testExportImportPreferences() throws Exception {
  // Populate with some initial values
  Editor editor = preferences.edit();
  editor.clear();
  editor.putBoolean("bool1", true);
  editor.putBoolean("bool2", false);
  editor.putFloat("flt1", 3.14f);
  editor.putInt("int1", 42);
  editor.putLong("long1", 123456789L);
  editor.putString("str1", "lolcat");
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);

  // Export it
  byte[] exported = preferenceBackupHelper.exportPreferences(preferences);

  // Mess with the previous values
  editor = preferences.edit();
  editor.clear();
  editor.putString("str2", "Shouldn't be there after restore");
  editor.putBoolean("bool2", true);
  ApiAdapterFactory.getApiAdapter().applyPreferenceChanges(editor);

  // Import it back
  preferenceBackupHelper.importPreferences(exported, preferences);

  assertFalse(preferences.contains("str2"));
  assertTrue(preferences.getBoolean("bool1", false));
  assertFalse(preferences.getBoolean("bool2", true));
  assertEquals(3.14f, preferences.getFloat("flt1", 0.0f));
  assertEquals(42, preferences.getInt("int1", 0));
  assertEquals(123456789L, preferences.getLong("long1", 0));
  assertEquals("lolcat", preferences.getString("str1", ""));
}
 
源代码15 项目: BmapLite   文件: PreferenceUtils.java
public void setFloatPreference(String key, float value) {
    Editor ed = preference.edit();
    ed.putFloat(key, value);
    ed.apply();

}
 
源代码16 项目: BmapLite   文件: PreferenceUtils.java
public void setFloatPreference(String key, float value) {
    Editor ed = preference.edit();
    ed.putFloat(key, value);
    ed.apply();

}
 
源代码17 项目: android-project-wo2b   文件: SdkPreference.java
public static boolean putFloatTemp(String key, float value)
{
	Editor editor = editTemp();
	editor.putFloat(key, value);
	return editor.commit();
}
 
源代码18 项目: android-project-wo2b   文件: SdkPreference.java
public static boolean putFloat(String key, float value)
{
	Editor editor = edit();
	editor.putFloat(key, value);
	return editor.commit();
}
 
源代码19 项目: BaseProject   文件: PreferVisitor.java
/**
 * 批量存储数据 参数的长度一定要一致 并且keys中的key 与 values中同序号的元素要一一对应,以保证数据存储的正确性
 * @param preferFileName
 * @param keys
 * @param vTypes keys中键key要存储的对应的 values中的元素的数据类型 eg.: keys[0]= "name"; vTypes[0] = V_TYPE_STR;values[0]="ZhangSan"
 * @param values 要存储的值
 */
@Deprecated
@SuppressLint("NewApi")
public boolean saveValue(String preferFileName, String[] keys, byte[] vTypes, Object... values) {
    if (keys == null || vTypes == null || values == null) {
        return false;
    }
    int keysLen = keys.length;
    if (keysLen == 0)
        return false;
    int vTypesLen = vTypes.length;
    int valuesLen = values.length;
    if (vTypesLen == 0 || valuesLen == 0) {
        return false;
    }
    //三者长度取最小的,以保证任何一个数组中不出现异常
    int canOptLen = Math.min(keysLen, Math.min(vTypesLen,valuesLen));
    Editor mEditor = getSpByName(preferFileName).edit();
    for (int i = 0; i < canOptLen; i++) {
        byte vType = vTypes[i];
        String key = keys[i];
        Object v = values[i];
        switch (vType) {
            case V_TYPE_STR:
                mEditor.putString(key, (String) v);
                break;
            case V_TYPE_INT:
                mEditor.putInt(key, (Integer) v);
                break;
            case V_TYPE_BOOL:
                mEditor.putBoolean(key, (Boolean) v);
                break;
            case V_TYPE_LONG:
                mEditor.putLong(key, (Long) v);
                break;
            case V_TYPE_FLOAT:
                mEditor.putFloat(key, (Float) v);
                break;
            case V_TYPE_SET_STR:
                if (Util.isCompateApi(11)) {
                    mEditor.putStringSet(key, (Set<String>) v);
                }
                break;
        }
    }
    return mEditor.commit();
}
 
源代码20 项目: mobile-manager-tool   文件: SharedPreferenceUtil.java
/**
 * 设置Float类型值
 * 
 * @param key
 * @param value
 */
public void putFloat(String key, float value) {
	Editor editor = sharedPreferences.edit();
	editor.putFloat(key, value);
	editor.commit();
}