當前位置: 首頁>>代碼示例>>Java>>正文


Java SharedPreferences.getFloat方法代碼示例

本文整理匯總了Java中android.content.SharedPreferences.getFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java SharedPreferences.getFloat方法的具體用法?Java SharedPreferences.getFloat怎麽用?Java SharedPreferences.getFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.SharedPreferences的用法示例。


在下文中一共展示了SharedPreferences.getFloat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Pedometer

import android.content.SharedPreferences; //導入方法依賴的package包/類
/** Constructor. */
public Pedometer(ComponentContainer container) {
  super(container.$form());
  context = container.$context();
  // some initialization
  winPos = 0;
  startPeaking = false;
  numStepsWithFilter = 0;
  numStepsRaw = 0;

  foundValley = true;
  lastValley = 0;

  sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

  // Restore preferences
  SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
  strideLength = settings.getFloat("Pedometer.stridelength", STRIDE_LENGTH);
  totalDistance = settings.getFloat("Pedometer.distance", 0);
  numStepsRaw = settings.getInt("Pedometer.prevStepCount", 0);
  prevStopClockTime = settings.getLong("Pedometer.clockTime", 0);
  numStepsWithFilter = numStepsRaw;
  startTime = System.currentTimeMillis();
  Log.d(TAG, "Pedometer Created");
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:26,代碼來源:Pedometer.java

示例2: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 得到保存數據的方法,我們根據默認值得到保存的數據的具體類型,然後調用相對於的方法獲取值
 *
 * @param context
 * @param key
 * @param defaultObject
 * @return
 */
public static Object get(Context context, String key, Object defaultObject)
{
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String)
    {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer)
    {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean)
    {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float)
    {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long)
    {
        return sp.getLong(key, (Long) defaultObject);
    }

    return null;
}
 
開發者ID:xiaobaima520gyj,項目名稱:imooc-imi-app,代碼行數:33,代碼來源:SPUtils.java

示例3: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static Object get(String fileName, Context context, String key, Object defaultObject) {
    SharedPreferences sp = SharedPreferencesImpl.getSharedPreferences(context, getFileName(fileName),
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    } else if (null == defaultObject) {
        return sp.getString(key, null);
    }

    return null;
}
 
開發者ID:miLLlulei,項目名稱:Accessibility,代碼行數:21,代碼來源:SPUtils.java

示例4: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 得到保存數據的方法,我們根據默認值得到保存的數據的具體類型,然後調用相對於的方法獲取值
 *
 * @param context
 * @param key
 * @param defaultObject
 * @return
 */
public static Object get(Context context, String key, Object defaultObject) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
            Context.MODE_PRIVATE);

    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }

    return null;
}
 
開發者ID:li-yu,項目名稱:FakeWeather,代碼行數:27,代碼來源:SPUtil.java

示例5: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 獲取存放object
 * @param context
 * @param fileName
 * @param key
 * @param def
 * @return
 */
public static Object get(Context context, String fileName, String key, Object def) {
    SharedPreferences sp = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    if (def instanceof String) {
        return sp.getString(key, def.toString());
    } else if (def instanceof Integer) {
        return sp.getInt(key, ((Integer) def).intValue());
    } else if (def instanceof Boolean) {
        return sp.getBoolean(key, ((Boolean) def).booleanValue());
    } else if (def instanceof Float) {
        return sp.getFloat(key, ((Float) def).floatValue());
    } else if (def instanceof Long) {
        return sp.getLong(key, ((Long) def).longValue());
    } else if (def instanceof Set) {
        return sp.getStringSet(key, (Set<String>) def);
    }
    return def;
}
 
開發者ID:AriesHoo,項目名稱:FastLib,代碼行數:26,代碼來源:SPUtil.java

示例6: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 得到保存數據的方法,我們根據默認值得到保存的數據的具體類型,然後調用相對於的方法獲取值
 *
 * @param key
 * @param defaultObject
 * @return
 */
public static Object get(String key, Object defaultObject) {
        SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
                Context.MODE_PRIVATE);

        if (defaultObject instanceof String) {
                return sp.getString(key, (String) defaultObject);
        } else if (defaultObject instanceof Integer) {
                return sp.getInt(key, (Integer) defaultObject);
        } else if (defaultObject instanceof Boolean) {
                return sp.getBoolean(key, (Boolean) defaultObject);
        } else if (defaultObject instanceof Float) {
                return sp.getFloat(key, (Float) defaultObject);
        } else if (defaultObject instanceof Long) {
                return sp.getLong(key, (Long) defaultObject);
        }

        return null;
}
 
開發者ID:HelloChenJinJun,項目名稱:TestChat,代碼行數:26,代碼來源:SPUtils.java

示例7: STLView

import android.content.SharedPreferences; //導入方法依賴的package包/類
public STLView(Context context, STLObject stlObject) {
	super(context);


	SharedPreferences colorConfig = context.getSharedPreferences("colors", Activity.MODE_PRIVATE);
	STLRenderer.red = colorConfig.getFloat("red", 0.75f);
	STLRenderer.green = colorConfig.getFloat("green", 0.75f);
	STLRenderer.blue = colorConfig.getFloat("blue", 0.75f);
	STLRenderer.alpha = colorConfig.getFloat("alpha", 0.5f);

	// render: stlObject as null
	stlRenderer = new STLRenderer(stlObject);
	setRenderer(stlRenderer);
	stlRenderer.requestRedraw();
}
 
開發者ID:xhd-Git,項目名稱:3DPrint-Controller,代碼行數:16,代碼來源:STLView.java

示例8: getFloat

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static float getFloat(String name, float defaultValue) {
    SharedPreferences sp = getSP(name);
    if (sp == null) {
        ContentResolver cr = mContext.getContentResolver();
        Uri uri = Uri.parse(CONTENT_URI + SEPARATOR + TYPE_FLOAT + SEPARATOR + name);
        String rtn = cr.getType(uri);
        if (rtn == null || rtn.equals(NULL_STRING)) {
            return defaultValue;
        }
        return Float.parseFloat(rtn);
    } else {
        return sp.getFloat(name, defaultValue);
    }
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:15,代碼來源:SPHelper.java

示例9: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static Object get(String key, Object defaultObject) {
    SharedPreferences sp = CommonApp.getInstance().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    if (defaultObject instanceof String) {
        return sp.getString(key, (String) defaultObject);
    } else if (defaultObject instanceof Integer) {
        return sp.getInt(key, (Integer) defaultObject);
    } else if (defaultObject instanceof Boolean) {
        return sp.getBoolean(key, (Boolean) defaultObject);
    } else if (defaultObject instanceof Float) {
        return sp.getFloat(key, (Float) defaultObject);
    } else if (defaultObject instanceof Long) {
        return sp.getLong(key, (Long) defaultObject);
    }
    return null;
}
 
開發者ID:vsona,項目名稱:RxJava2RetrofitDemo,代碼行數:16,代碼來源:SPUtils.java

示例10: RestoreState

import android.content.SharedPreferences; //導入方法依賴的package包/類
private void RestoreState() {
    try {
        SharedPreferences mPrefs = getActivity().getPreferences(Activity.MODE_PRIVATE);

        ActNewFlight.fPaused = mPrefs.getBoolean(m_KeysIsPaused, false);
        ActNewFlight.dtPauseTime = mPrefs.getLong(m_KeysPausedTime, 0);
        ActNewFlight.dtTimeOfLastPause = mPrefs.getLong(m_KeysTimeOfLastPause, 0);
        ActNewFlight.accumulatedNight = (double) mPrefs.getFloat(m_KeysAccumulatedNight, (float) 0.0);
    } catch (Exception e) {
        Log.e(MFBConstants.LOG_TAG, Log.getStackTraceString(e));
    }
}
 
開發者ID:ericberman,項目名稱:MyFlightbookAndroid,代碼行數:13,代碼來源:ActNewFlight.java

示例11: getFloat

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * 獲取float的value
 */
public static float getFloat(String key, Float defValue) {
    SharedPreferences sharedPreference = getSharedPreference(CONFIG);
    return sharedPreference.getFloat(key, defValue);
}
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:8,代碼來源:SPUtils.java

示例12: getLocationLatitude

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static float getLocationLatitude(Context context) {
    SharedPreferences prefs
            = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getFloat(context.getString(R.string.pref_location_latitude),
            DEFAULT_LATLONG);
}
 
開發者ID:changja88,項目名稱:Udacity_Sunshine,代碼行數:7,代碼來源:Utility.java

示例13: get

import android.content.SharedPreferences; //導入方法依賴的package包/類
public static float get(SharedPreferences prefs, @NonNull String key, float defaultValue) {
    return prefs.getFloat(key, defaultValue);
}
 
開發者ID:hisaichi5518,項目名稱:konohana,代碼行數:4,代碼來源:FloatPrefsAdapter.java

示例14: getParam

import android.content.SharedPreferences; //導入方法依賴的package包/類
public float getParam(String key, float defValue) {
    SharedPreferences spf = getSharedPreferences(context);
    return spf.getFloat(key, defValue);
}
 
開發者ID:abook23,項目名稱:godlibrary,代碼行數:5,代碼來源:Preference.java

示例15: getFloat

import android.content.SharedPreferences; //導入方法依賴的package包/類
/**
 * get float preferences
 *
 * @param context
 * @param key          The name of the preference to retrieve
 * @param defaultValue Value to return if this preference does not exist
 * @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with
 * this name that is not a float
 */
public static float getFloat(Context context, String key, float defaultValue) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    return settings.getFloat(key, defaultValue);
}
 
開發者ID:harrylefit,項目名稱:eazycore,代碼行數:14,代碼來源:PreferencesUtils.java


注:本文中的android.content.SharedPreferences.getFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。