Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. SharedPreferences pref; // Shared Preferences reference
  2.     Editor editor;  // Editor reference for Shared preferences
  3.     Context _context;   // Context
  4.     int PRIVATE_MODE = 0;   // Shared preferences mode
  5.     public static final String PREFER_NAME = "Session"; // Shared preferences file name
  6.     public static final String IS_USER_LOGIN = "IsUserLoggedIn";    // Shared Preferences Keys
  7.     public static final String KEY_USER = "User";   // Username
  8.     public static final String KEY_PASS = "Pass";    // Password
  9.     public static final String KEY_SIZE = "FontSize";    // Shared Preferences Keys
  10.     public static final String KEY_COLOUR = "Colour";   // Username
  11.  
  12.     // Constructor
  13.     public UserSession(Context context){
  14.         this._context = context;
  15.         pref = _context.getSharedPreferences(PREFER_NAME, PRIVATE_MODE);
  16.         editor = pref.edit();
  17.     }
  18.  
  19.     //Create login
  20.     public void createLogin(String uName, String uPass){
  21.  
  22.         editor.putBoolean(IS_USER_LOGIN, true); // Storing login value as TRUE
  23.  
  24.         editor.putString(KEY_USER, uName);
  25.         editor.putString(KEY_PASS, uPass);
  26.  
  27.         // commit changes
  28.         editor.commit();
  29.     }
  30.  
  31.     //Create login
  32.     public void createUserSettings(String uSize, String uColour){
  33.  
  34.         editor.putString(KEY_SIZE, uSize);
  35.         editor.putString(KEY_COLOUR, uColour);
  36.  
  37.         // commit changes
  38.         editor.commit();
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement