src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\AccountUtils.java

This commit is contained in:
zhangnaifu15 2018-05-12 08:19:48 +08:00
parent 5b8d278bfb
commit 305120744e
2 changed files with 143 additions and 0 deletions

View File

@ -0,0 +1,110 @@
package com.example.administrator.myapplication.utils;
import android.content.Context;
import android.text.TextUtils;
import com.example.administrator.myapplication.entity.User;
/**
* 用户信息管理类
*/
public class AccountUtils {
private static final String USER_NAME = "user_name";
private static final String USER_PWD = "user_pwd";
private static final String USER_ID = "user_id";
private static final String USER_EMAIL = "user_email";
private static final String USER_NICK_NAME = "user_nickname";
private static final String USER_NOTE_PWD = "user_note_pwd";
private static final String USER_SEX = "user_sex";
private static final String USER_HEAD_URL = "user_head_url";
/**
* 保存用户的所有信息
* @param context
* @param user
* @param user_pwd 用户的登录密码
*/
public static void saveUserInfos(Context context, User user, String user_pwd) {
saveUserName(context, user.getUsername());
saveUserPwd(context, user_pwd);
saveUserId(context, user.getObjectId());
saveUserNickName(context, user.getUserNickname());
saveUserEmail(context, user.getEmail());
saveUserDiaryPwd(context, user.getUserNotePwd());
saveUserSex(context, user.getUserSex());
saveUserHeadUrl(context, user.getUserHeadUrl());
}
public static String getUserName(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NAME, "");
}
public static void saveUserName(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NAME, str);
}
public static String getUserPwd(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_PWD, "");
}
public static void saveUserPwd(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_PWD, str);
}
public static String getUserId(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_ID, "");
}
public static void saveUserId(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_ID, str);
}
public static String getUserEmail(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_EMAIL, "");
}
public static void saveUserEmail(Context context, String str) {
if (!TextUtils.isEmpty(str)) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_EMAIL, str);
}
}
public static String getUserNickName(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NICK_NAME, "");
}
public static void saveUserNickName(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NICK_NAME, str);
}
public static String getUserDiaryPwd(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_NOTE_PWD, "");
}
public static void saveUserDiaryPwd(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_NOTE_PWD, str);
}
public static String getUserSex(Context context) {
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_SEX, "");
}
public static void saveUserSex(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_SEX, str);
}
public static String getUserHeadUrl(Context context){
return (String) com.example.administrator.myapplication.utils.SPUtils.get(context, USER_HEAD_URL, "");
}
public static void saveUserHeadUrl(Context context, String str) {
com.example.administrator.myapplication.utils.SPUtils.put(context, USER_HEAD_URL, str);
}
public static void clearAllInfos(Context context){
com.example.administrator.myapplication.utils.SPUtils.clear(context);
}
}

View File

@ -0,0 +1,33 @@
package com.example.administrator.myapplication.utils;
import android.annotation.SuppressLint;
import android.os.Environment;
@SuppressLint("SdCardPath")
public class BmobConstants {
/**
* <EFBFBD><EFBFBD>ŷ<EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD>Ŀ¼
*/
public static String BMOB_PICTURE_PATH = Environment.getExternalStorageDirectory() + "/bmobimdemo/image/";
/**
* <EFBFBD>ҵ<EFBFBD>ͷ<EFBFBD>񱣴<EFBFBD>Ŀ¼
*/
public static String MyAvatarDir = "/sdcard/soucang/avatar/";
/**
* <EFBFBD><EFBFBD><EFBFBD>ջص<EFBFBD>
*/
public static final int REQUESTCODE_UPLOADAVATAR_CAMERA = 1;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ͷ<EFBFBD><EFBFBD>
public static final int REQUESTCODE_UPLOADAVATAR_LOCATION = 2;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>ͷ<EFBFBD><EFBFBD>
public static final int REQUESTCODE_UPLOADAVATAR_CROP = 3;//ϵͳ<EFBFBD>ü<EFBFBD>ͷ<EFBFBD><EFBFBD>
public static final int REQUESTCODE_TAKE_CAMERA = 0x000001;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public static final int REQUESTCODE_TAKE_LOCAL = 0x000002;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ
public static final int REQUESTCODE_TAKE_LOCATION = 0x000003;//λ<EFBFBD><EFBFBD>
public static final String EXTRA_STRING = "extra_string";
public static final String ACTION_REGISTER_SUCCESS_FINISH ="register.success.finish";//ע<EFBFBD><EFBFBD>ɹ<EFBFBD>֮<EFBFBD><EFBFBD><EFBFBD>½ҳ<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>
}