Guest User

Untitled

a guest
Jul 16th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package info.mores.mackpharmademo.helper;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5. import android.content.SharedPreferences.Editor;
  6.  
  7. public class SharedPreferenceManager {
  8. private static final String PREFS_NAME = "wowfeedback";
  9. private Context context;
  10. private SharedPreferences prefs;
  11. private Editor editor;
  12.  
  13. public SharedPreferenceManager() {
  14. }
  15.  
  16. public SharedPreferenceManager(Context context) {
  17. this.context = context;
  18. }
  19.  
  20. public void connectDB() {
  21. prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
  22. editor = prefs.edit();
  23. }
  24.  
  25. public void clearSingle(String key)
  26. {
  27. editor.remove (key);
  28. }
  29.  
  30. public void closeDB()
  31.  
  32. {
  33. editor.commit();
  34. }
  35.  
  36. public void clear() {
  37. editor.clear();
  38. }
  39.  
  40. public void setInt(String key, int value)
  41.  
  42. {
  43. editor.putInt(key, value);
  44. }
  45.  
  46. public int getInt(String key)
  47.  
  48. {
  49. return prefs.getInt(key, 1);
  50. }
  51.  
  52. public void setFloat(String key, float value) {
  53. editor.putFloat(key, value);
  54. }
  55.  
  56. public float getFloat(String key) {
  57. return prefs.getFloat(key, 0);
  58. }
  59.  
  60. public void setBoolean(String key, boolean value) {
  61. editor.putBoolean(key, value);
  62. }
  63.  
  64. public boolean getBoolean(String key) {
  65. return prefs.getBoolean(key, false);
  66. }
  67.  
  68. public void setString(String key, String value) {
  69. editor.putString(key, value);
  70. }
  71.  
  72. public String getString(String key) {
  73. return prefs.getString(key, "");
  74. }
  75.  
  76.  
  77. }
Add Comment
Please, Sign In to add comment