384bdae401ceabf54b42ee28aa38a7009b2ceadd.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.example.myapplication.utils;
  2. import android.text.TextUtils;
  3. import com.example.myapplication.MyApplication;
  4. public class SharePreferHelper {
  5. /**
  6. * 获取sessionId
  7. *
  8. * @return sessionId
  9. */
  10. public static String getSessionId() {
  11. return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID, "");
  12. }
  13. /**
  14. * 清除 sessionId
  15. */
  16. public static void clearSessionId() {
  17. SPUtils.remove(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID);
  18. }
  19. /**
  20. * 保存sessionId
  21. *
  22. * @param sessionId
  23. */
  24. public static void setSessionId(String sessionId) {
  25. if (TextUtils.isEmpty(sessionId)) {
  26. return;
  27. }
  28. SPUtils.put(MyApplication.getInstance(), Constants.SP_USER_SESSION_ID, Constants.SP_KEY_USER_SESSION_ID, sessionId);
  29. }
  30. /**
  31. * 保存用户手机号码
  32. *
  33. * @param phoneNumber
  34. */
  35. public static void setUserPhoneNumber(String phoneNumber) {
  36. if (TextUtils.isEmpty(phoneNumber)) {
  37. return;
  38. }
  39. SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_NAME, phoneNumber);
  40. }
  41. /**
  42. * 获取用户手机号码
  43. *
  44. * @return phoneNumber
  45. */
  46. public static String getUserPhoneNumber() {
  47. return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_NAME, "");
  48. }
  49. /**
  50. * 保存用户密码
  51. *
  52. * @param password
  53. */
  54. public static void setPassword(String password) {
  55. if (TextUtils.isEmpty(password)) {
  56. return;
  57. }
  58. SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD, password);
  59. }
  60. /**
  61. * 获取用户密码
  62. *
  63. * @return password
  64. */
  65. public static String getPassword() {
  66. return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD, "");
  67. }
  68. /**
  69. * 保存用户邮箱地址
  70. *
  71. * @param mailAddress 地址
  72. */
  73. public static void setUserMail(String mailAddress) {
  74. if (TextUtils.isEmpty(mailAddress)) {
  75. return;
  76. }
  77. SPUtils.put(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_MAIL, mailAddress);
  78. }
  79. /**
  80. * 获取用户邮箱地址
  81. *
  82. * @return mailAddress
  83. */
  84. public static String getUserMail() {
  85. return (String) SPUtils.get(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_MAIL, "");
  86. }
  87. /**
  88. * 清除 password
  89. */
  90. public static void clearPassword() {
  91. SPUtils.remove(MyApplication.getInstance(), Constants.SP_FILE_NAME_LOCAL_USER_ENTITY, Constants.SP_KEY_USER_PASSWORD);
  92. }
  93. /**
  94. * 退出登录
  95. */
  96. public static void loginOut() {
  97. clearSessionId();
  98. clearPassword();
  99. }
  100. }