Created
July 14, 2015 00:34
-
-
Save jen6/733507c23a3ea415bf5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.jen6.tester; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.SharedPreferences; | |
/** | |
* Created by jen6 on 2015-07-13. | |
*/ | |
public class RbPreference { | |
private final String PREF_NAME = "com.example.jen6.tester"; | |
public final static String PREF_INTRO_USER_AGREEMENT = "PREF_USER_AGREEMENT"; | |
public final static String PREF_MAIN_VALUE = "PREF_MAIN_VALUE"; | |
static Context mContext; | |
public RbPreference(Context c) { | |
mContext = c; | |
} | |
public void put(String key, String value) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
SharedPreferences.Editor editor = pref.edit(); | |
editor.putString(key, value); | |
editor.commit(); | |
} | |
public void put(String key, boolean value) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
SharedPreferences.Editor editor = pref.edit(); | |
editor.putBoolean(key, value); | |
editor.commit(); | |
} | |
public void put(String key, int value) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
SharedPreferences.Editor editor = pref.edit(); | |
editor.putInt(key, value); | |
editor.commit(); | |
} | |
public String getValue(String key, String dftValue) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
try { | |
return pref.getString(key, dftValue); | |
} catch (Exception e) { | |
return dftValue; | |
} | |
} | |
public int getValue(String key, int dftValue) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
try { | |
return pref.getInt(key, dftValue); | |
} catch (Exception e) { | |
return dftValue; | |
} | |
} | |
public boolean getValue(String key, boolean dftValue) { | |
SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, | |
Activity.MODE_PRIVATE); | |
try { | |
return pref.getBoolean(key, dftValue); | |
} catch (Exception e) { | |
return dftValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment