ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:34:48 2017 +0800
Revision:
45:2aa9f933c8d2
?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TMBOY 45:2aa9f933c8d2 1 /*
TMBOY 45:2aa9f933c8d2 2 * Copyright (c) 2017 Baidu, Inc. All Rights Reserved.
TMBOY 45:2aa9f933c8d2 3 *
TMBOY 45:2aa9f933c8d2 4 * Licensed under the Apache License, Version 2.0 (the "License");
TMBOY 45:2aa9f933c8d2 5 * you may not use this file except in compliance with the License.
TMBOY 45:2aa9f933c8d2 6 * You may obtain a copy of the License at
TMBOY 45:2aa9f933c8d2 7 *
TMBOY 45:2aa9f933c8d2 8 * http://www.apache.org/licenses/LICENSE-2.0
TMBOY 45:2aa9f933c8d2 9 *
TMBOY 45:2aa9f933c8d2 10 * Unless required by applicable law or agreed to in writing, software
TMBOY 45:2aa9f933c8d2 11 * distributed under the License is distributed on an "AS IS" BASIS,
TMBOY 45:2aa9f933c8d2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
TMBOY 45:2aa9f933c8d2 13 * See the License for the specific language governing permissions and
TMBOY 45:2aa9f933c8d2 14 * limitations under the License.
TMBOY 45:2aa9f933c8d2 15 */
TMBOY 45:2aa9f933c8d2 16 package com.baidu.duer.dcs.oauth.api;
TMBOY 45:2aa9f933c8d2 17
TMBOY 45:2aa9f933c8d2 18 import android.content.Context;
TMBOY 45:2aa9f933c8d2 19
TMBOY 45:2aa9f933c8d2 20 import com.baidu.duer.dcs.util.PreferenceUtil;
TMBOY 45:2aa9f933c8d2 21
TMBOY 45:2aa9f933c8d2 22 /**
TMBOY 45:2aa9f933c8d2 23 * 用户认证保存Preference工具类
TMBOY 45:2aa9f933c8d2 24 * <p>
TMBOY 45:2aa9f933c8d2 25 * Created by zhangyan42@baidu.com on 2017/6/3.
TMBOY 45:2aa9f933c8d2 26 */
TMBOY 45:2aa9f933c8d2 27 public class OauthPreferenceUtil extends PreferenceUtil {
TMBOY 45:2aa9f933c8d2 28 public static final String BAIDU_OAUTH_CONFIG = "baidu_oauth_config";
TMBOY 45:2aa9f933c8d2 29
TMBOY 45:2aa9f933c8d2 30 /**
TMBOY 45:2aa9f933c8d2 31 * 保存数据的方法,拿到保存数据的具体类型,然后根据类型调用不同的保存方法
TMBOY 45:2aa9f933c8d2 32 *
TMBOY 45:2aa9f933c8d2 33 * @param context 上下文
TMBOY 45:2aa9f933c8d2 34 * @param key key
TMBOY 45:2aa9f933c8d2 35 * @param object value
TMBOY 45:2aa9f933c8d2 36 */
TMBOY 45:2aa9f933c8d2 37 public static void put(Context context, String key, Object object) {
TMBOY 45:2aa9f933c8d2 38 put(context, BAIDU_OAUTH_CONFIG, key, object);
TMBOY 45:2aa9f933c8d2 39 }
TMBOY 45:2aa9f933c8d2 40
TMBOY 45:2aa9f933c8d2 41 /**
TMBOY 45:2aa9f933c8d2 42 * 得到保存数据的方法,
TMBOY 45:2aa9f933c8d2 43 * 根据默认值得到保存的数据的具体类型,
TMBOY 45:2aa9f933c8d2 44 * 然后调用相对于的方法获取值
TMBOY 45:2aa9f933c8d2 45 *
TMBOY 45:2aa9f933c8d2 46 * @param context 上下文
TMBOY 45:2aa9f933c8d2 47 * @param key key
TMBOY 45:2aa9f933c8d2 48 * @param defaultObject default-value
TMBOY 45:2aa9f933c8d2 49 */
TMBOY 45:2aa9f933c8d2 50 public static Object get(Context context, String key, Object defaultObject) {
TMBOY 45:2aa9f933c8d2 51 return get(context, BAIDU_OAUTH_CONFIG, key, defaultObject);
TMBOY 45:2aa9f933c8d2 52 }
TMBOY 45:2aa9f933c8d2 53
TMBOY 45:2aa9f933c8d2 54 public static void clear(Context context) {
TMBOY 45:2aa9f933c8d2 55 clear(context, BAIDU_OAUTH_CONFIG);
TMBOY 45:2aa9f933c8d2 56 }
TMBOY 45:2aa9f933c8d2 57
TMBOY 45:2aa9f933c8d2 58 public static void setAccessToken(Context context, String value) {
TMBOY 45:2aa9f933c8d2 59 put(context, OauthConfig.PrefenenceKey.SP_ACCESS_TOKEN, value);
TMBOY 45:2aa9f933c8d2 60 }
TMBOY 45:2aa9f933c8d2 61
TMBOY 45:2aa9f933c8d2 62 public static String getAccessToken(Context context) {
TMBOY 45:2aa9f933c8d2 63 return (String) get(context, OauthConfig.PrefenenceKey.SP_ACCESS_TOKEN, "");
TMBOY 45:2aa9f933c8d2 64 }
TMBOY 45:2aa9f933c8d2 65
TMBOY 45:2aa9f933c8d2 66 public static void setExpires(Context context, long value) {
TMBOY 45:2aa9f933c8d2 67 put(context, OauthConfig.PrefenenceKey.SP_EXPIRE_SECONDS, value);
TMBOY 45:2aa9f933c8d2 68 }
TMBOY 45:2aa9f933c8d2 69
TMBOY 45:2aa9f933c8d2 70 public static long getExpires(Context context) {
TMBOY 45:2aa9f933c8d2 71 return (long) get(context, OauthConfig.PrefenenceKey.SP_EXPIRE_SECONDS, 0L);
TMBOY 45:2aa9f933c8d2 72 }
TMBOY 45:2aa9f933c8d2 73
TMBOY 45:2aa9f933c8d2 74 public static void setCreateTime(Context context, long value) {
TMBOY 45:2aa9f933c8d2 75 put(context, OauthConfig.PrefenenceKey.SP_CREATE_TIME, value);
TMBOY 45:2aa9f933c8d2 76 }
TMBOY 45:2aa9f933c8d2 77
TMBOY 45:2aa9f933c8d2 78 public static long getCreateTime(Context context) {
TMBOY 45:2aa9f933c8d2 79 return (long) get(context, OauthConfig.PrefenenceKey.SP_CREATE_TIME, 0L);
TMBOY 45:2aa9f933c8d2 80 }
TMBOY 45:2aa9f933c8d2 81
TMBOY 45:2aa9f933c8d2 82 public static void clearAllOauth(Context context) {
TMBOY 45:2aa9f933c8d2 83 clear(context);
TMBOY 45:2aa9f933c8d2 84 }
TMBOY 45:2aa9f933c8d2 85 }