Java Code Examples for android.content.ContextWrapper#getSharedPreferences()

The following examples show how to use android.content.ContextWrapper#getSharedPreferences() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public static UserInfo queryUserInfo(ContextWrapper contextWrapper) {
    if (contextWrapper == null) {
        return null;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_USER_INFO
            , 0);
    String headImg = sp.getString("headImg", "");
    String cover = sp.getString("cover", "");
    String nickname = sp.getString("nickname", "");

    UserInfo userInfo = new UserInfo();
    userInfo.setHeadImg(headImg);
    userInfo.setCover(cover);
    userInfo.setNickname(nickname);
    userInfo.setUsername(nickname);
    LoginResult loginResult = queryToken(contextWrapper);
    if (loginResult != null) {
        userInfo.setId(loginResult.getUserId());
    }
    return userInfo;
}
 
Example 2
public static void storeToken(ContextWrapper contextWrapper, LoginResult loginResult) {
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_PASSPORT, 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putLong("userId", loginResult.getUserId());
    editor.putString("mobile", loginResult.getUsername());
    editor.putString("token", loginResult.getToken());
    editor.commit();
    if (loginResult.getUserId() > 0) {
        MiPushClient.setAlias(MyApp.getInstance(), loginResult.getUserId() + "", null);
        Log.i(MY_TAG, "MiPushClient_setAlias:alias=" + loginResult.getUserId() + "");
    }
}
 
Example 3
public static LoginResult queryToken(ContextWrapper contextWrapper) {
    if (contextWrapper == null) {
        return null;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_PASSPORT, 0);
    long userId = sp.getLong("userId", 0);
    String mobile = sp.getString("mobile", null);
    String token = sp.getString("token", null);
    LoginResult loginResult = new LoginResult();
    loginResult.setUserId(userId);
    loginResult.setToken(token);
    loginResult.setUsername(mobile);
    return loginResult;
}
 
Example 4
/**
 * @param contextWrapper
 * @param headFilePath   头像图片本地文件的绝对路径
 */
public static void storeHead(ContextWrapper contextWrapper, String headFilePath) {
    if (contextWrapper == null) {
        return;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_STORAGE
            , 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString("headFilePath", headFilePath);
    editor.commit();
}
 
Example 5
public static String queryHead(ContextWrapper contextWrapper) {
    if (contextWrapper == null) {
        return null;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_STORAGE
            , 0);
    return sp.getString("headFilePath", null);
}
 
Example 6
public static void storeHeadVersion(ContextWrapper contextWrapper, long headVersion) {
    if (contextWrapper == null) {
        return;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_STORAGE
            , 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putLong("headVersion", headVersion);
    editor.commit();
}
 
Example 7
public static Long queryHeadVersion(ContextWrapper contextWrapper) {
    if (contextWrapper == null) {
        return null;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_STORAGE
            , 0);
    return sp.getLong("headVersion", 0);
}
 
Example 8
public static void storeUserInfo(ContextWrapper contextWrapper, UserInfo userInfo) {
    if (contextWrapper == null) {
        return;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_FILE_USER_INFO
            , 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString("headImg", userInfo.getHeadImg());
    editor.putString("cover", userInfo.getCover());
    editor.putString("nickname", userInfo.getNickname());
    editor.commit();
}
 
Example 9
public static void storeMiRegid(ContextWrapper contextWrapper, String regid) {
    if (contextWrapper == null) {
        return;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_MIPUSH
            , 0);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString("regid", regid);
    editor.commit();
}
 
Example 10
public static String queryMiRegid(ContextWrapper contextWrapper) {
    if (contextWrapper == null) {
        return null;
    }
    SharedPreferences sp = contextWrapper.getSharedPreferences(StorageConstant.SHARED_PREFERENCES_NAME_MIPUSH
            , 0);
    String regid = sp.getString("regid", "");
    return regid;
}
 
Example 11
Source Project: quickmark   File: CrashHandler.java    License: MIT License 5 votes vote down vote up
/**
 * ��ʼ��
 * 
 * @param context
 */
public void init(Context context) {
	mContext = context;
	ContextWrapper a = (ContextWrapper) mContext.getApplicationContext();
	SharedPreferences sp = a.getSharedPreferences("preferences",
			MODE_WORLD_READABLE);
	if (sp.getString("sendlog", "").equals("��")
			|| sp.getString("sendlog", "").equals("")) {
		mDefaultHandler = Thread.getDefaultUncaughtExceptionHandler();// ��ȡϵͳĬ�ϵ�UncaughtException������
		Thread.setDefaultUncaughtExceptionHandler(this);// ���ø�CrashHandlerΪ�����Ĭ�ϴ�����
	}
}