Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. package com.yundin.styleruhw2;
  2.  
  3. import android.content.Context;
  4. import android.content.SharedPreferences;
  5.  
  6. public final class SharedPreferencesHelper {
  7.  
  8. private static final String SP_NAME = "my_app_sp";
  9. private static final String NAME_KEY = "sp_name";
  10. private static final String SURNAME_KEY = "sp_lastname";
  11. private static final String GROUP_KEY = "sp_group";
  12. private static final String EDIT_KEY = null;
  13. private static SharedPreferences sharedPreferences;
  14.  
  15. public static SharedPreferences getSharedPreferences() {
  16. return sharedPreferences;
  17. }
  18.  
  19. public static void init(Context context) {
  20. sharedPreferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
  21. }
  22.  
  23. public static String getName() {
  24. return sharedPreferences.getString(NAME_KEY, null);
  25. }
  26.  
  27. public static String getSurname() {
  28. return sharedPreferences.getString(SURNAME_KEY, null);
  29. }
  30.  
  31. public static String getGroup() {
  32. return sharedPreferences.getString(GROUP_KEY, null);
  33. }
  34.  
  35. public static String getEdit() {
  36. return sharedPreferences.getString(EDIT_KEY, null);
  37. }
  38.  
  39. public static void setName(String name) {
  40. sharedPreferences.edit()
  41. .putString(NAME_KEY, name)
  42. .apply();
  43. }
  44.  
  45. public static void setSurname(String surname) {
  46. sharedPreferences.edit()
  47. .putString(SURNAME_KEY, surname)
  48. .apply();
  49. }
  50.  
  51. public static void setGroup(String group) {
  52. sharedPreferences.edit()
  53. .putString(GROUP_KEY, group)
  54. .apply();
  55. }
  56.  
  57. public static void setEdit(String edit) {
  58. sharedPreferences.edit()
  59. .putString(EDIT_KEY, edit)
  60. .apply();
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement