package com.tofly.ghrq_route.common.util.sharedPreference;

import android.content.Context;
import android.content.SharedPreferences;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.module.plan.domain.ChildPlanCountBean;
import com.tofly.ghrq_route.module.user.domain.UserBean;
import com.tofly.ghrq_route.common.util.date.DateUtils;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * SharePreference的工具类
 * Created by li on 2016/8/5.
 */
public class SharePreUtil {
    private static final String QUERY_NAME = "config";
    private static final String USER_ACCOUNT = "user_account";
    private static final String DEVICE_INFO = "device_info";
    private static final String USER_MAP_CONFIG = "user_map_config";
    public static final String ONLINE_MAP = "online_map";
    public static final String LOCALTILEDLAYER = "localTiledLayer";//基础图层的key
    public static final String GEODATABASE = "geodatabase";//管线的key
    public static final String SATELLITE = "satellite";//的key
    public static final String POILAYER = "poiLayer";//管线的key
    public static final String LAST_SIGN_SATE = "last_sign_state";
    public static final String APP_FORCE_RESTART = "app_force_restart";
    public static final String SIGN_LAYER = "signLayer";
    public static final String CAR_MODE = "car_mode";
    public static final String CAR_NO = "car_no";
    public static final String BIG_FONT = "big_font";
    public static final String GPS_NOTIFY = "gps_notify";
    public static final String GPS_VIBRATE = "gps_vibrate";
    public static final String GPS_VIBRATE_PERIOD = "gps_vibrate_period";
    public static final String SCREEN_ON_MODE = "keep_screen_on";
    public static final String SCREEN_WAKEUP_MODE = "keep_screen_wakeup";
    public static final String SCREEN_WAKEUP_TIME = "kepp_screen_wakeup_time";
    public static final String SET_OLD_PORT_V_1_3_8_1 = "set_old_port_v1.3.8.1";
    public static final String SIGN_SECTION = "sign_section";
    public static final String APK_PKG_REMOVE = "remove_apk_package";
    public static final String APK_PKG_PATH = "apk_package_path";
    public static final String PLAN_LINE_RENDER_ALL = "plan_line_render_all";
    public static final String PLAN_POINT_TODAY_PLAN = "plan_point_today_plan";
    public static final String PLAN_POINT_DOWN_ERR_TIMES = "plan_point_down_err_times";
    public static final String PLAN_POINT_PLAN_DOWN_TIMES = "plan_point_plan_down_times";
    private static final String CUSTOM_THEME_TAG = "custom_theme_tag";
    private static final String BACUP_SEVER_OPENED  = "backup_server_opened";
    public static final String IMEI = "imei";
    public static final String DEVICE_BIND = "device_bind";
    public static final String GIS_TOKEN = "gis_token";

    //设置已登录过
    public static void setIsLogined(Context context, boolean isLogin) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("isLogined", isLogin);
        editor.commit();
    }

    //获取是否需要重新登录
    public static boolean getIsNeedReLogin(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean("isNeedReLogin", false);
    }

    //设置是否需要重新登陆
    public static void setIsNeedReLogin(Context context, boolean need) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("isNeedReLogin", need);
        editor.commit();
    }

    //获取是否登录过
    public static boolean getIsLogined(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean("isLogined", false);
    }

    //保存用户登录信息
    public static String getLoginPassword(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(USER_ACCOUNT, Context.MODE_PRIVATE);
        return  preferences.getString("password", "");
    }

    //保存用户登录信息
    public static void saveLoginInfo(Context context, String username, String userid) {
        SharedPreferences preferences = context.getSharedPreferences(USER_ACCOUNT, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("username", username);
        editor.putString("userid", userid);
        editor.commit();
    }

    //保存用户登录信息
    public static void saveLoginInfo(Context context, String username, String userid, String password) {
        SharedPreferences preferences = context.getSharedPreferences(USER_ACCOUNT, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("username", username);
        editor.putString("userid", userid);
        editor.putString("password", password);
        editor.commit();
    }

    //获取之前保存的用户登录信息
    public static UserBean getLoginInfo(Context context) {
        UserBean user = null;
        SharedPreferences preferences = context.getSharedPreferences(USER_ACCOUNT, Context.MODE_PRIVATE);
        if (preferences != null) {
            user = new UserBean();
            user.setUsername(preferences.getString("username", ""));
            user.setPassword(preferences.getString("password", ""));
            user.setUserid(preferences.getString("userid", ""));
        }
        return user;
    }

    //设置是否为备用机
    public static void setDeviceIsStandBy(Context context, boolean isStandBy) {
        SharedPreferences preferences = context.getSharedPreferences(DEVICE_INFO, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean("stand_by", isStandBy);
        editor.commit();
    }

    //是否为备用机
    public static boolean getDeviceIsStandBy(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(DEVICE_INFO, Context.MODE_PRIVATE);
        return  preferences.getBoolean("stand_by", false);
    }

    /**
     * 设置是否使用在线地图
     * @param context
     */
    public static void setOnlineMap(Context context, boolean online) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(ONLINE_MAP, online);
        editor.commit();
    }

    /**
     * 查询是否使用在线地图
     * @param context
     * @return
     */
    public static boolean getIsOnlineMap(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(ONLINE_MAP, true);
    }

    /**
     * 设置是否显示了某图层
     *
     * @param context
     * @param which      图层名
     * @param isLayoutOn
     */
    public static void setIsLayoutOn(Context context, String which, boolean isLayoutOn) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(which, isLayoutOn);
        editor.commit();
    }

    /**
     * 查询某图层是否显示
     *
     * @param context
     * @param which
     * @return
     */
    public static boolean getIsLayoutOn(Context context, String which) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        boolean defValue = (which == LOCALTILEDLAYER || which == GEODATABASE ? true : false);
        return preferences.getBoolean(which, defValue);
    }

    /**
     * 设置是否为车载模式
     *
     * @param context
     */
    public static void setLastSignState(Context context, int state) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(LAST_SIGN_SATE, state);
        editor.commit();
    }

    /**
     * 获取是否为车载模式
     */
    public static int getLastSignState(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getInt(LAST_SIGN_SATE, -1);
    }

    /**
     * 设置是否为车载模式
     *
     * @param context
     */
    public static void setAppForceRestart(Context context, boolean isOn) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(APP_FORCE_RESTART, isOn);
        editor.commit();
    }

    /**
     * 获取是否为车载模式
     */
    public static boolean getAppForceRestart(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(APP_FORCE_RESTART, false);
    }

    /**
     * 设置是否为车载模式
     *
     * @param context
     */
    public static void setCarMode(Context context, boolean isOn) {

        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(CAR_MODE, isOn);
        editor.commit();
    }

    /**
     * 获取是否为车载模式
     */
    public static boolean getCarMode(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(CAR_MODE, false);
    }

    /**
     * 设置车巡绑定车牌号码
     *
     * @param context
     */
    public static void setCarNo(Context context, String carno) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(CAR_NO, carno);
        editor.commit();
    }

    /**
     * 获取车牌号码
     */
    public static String getCarNo(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getString(CAR_NO, "");
    }

    /**
     * 设置是否为车载模式
     *
     * @param context
     */
    public static void setBigFont(Context context, boolean isOn) {

        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(BIG_FONT, isOn);
        editor.commit();
    }

    /**
     * 获取是否为车载模式
     */
    public static boolean getBigFont(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(BIG_FONT, false);
    }

    /**
     * 设置是否为轨迹提醒
     *
     * @param context
     */
    public static void setGpsNotifyOpen(Context context, boolean isOn) {

        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(GPS_NOTIFY, isOn);
        editor.commit();
    }

    /**
     * 获取是否为开启轨迹震动
     */
    public static boolean getGpsVibrateOn(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(GPS_VIBRATE, false);
    }

    /**
     * 获取是轨迹震动间隔次数
     */
    public static int getGpsVibratePeriod(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getInt(GPS_VIBRATE_PERIOD, 10);
    }

    /**
     * 设置是否为轨迹震动
     *
     * @param context
     */
    public static void setGpsVibrateOn(Context context, boolean isOn, int times) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(GPS_VIBRATE, isOn);
        if (isOn){
            editor.putInt(GPS_VIBRATE_PERIOD, times);
        }
        editor.commit();
    }

    /**
     * 获取是否为开启轨迹提醒
     */
    public static boolean getGpsNotifyOpen(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(GPS_NOTIFY, false);
    }

    /**
     * 设置是否开启常亮屏模式
     *
     * @param context
     */
    public static void setKeepScreenOnMode(Context context, boolean isOn) {

        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(SCREEN_ON_MODE, isOn);
        editor.commit();
    }

    /**
     * 获取是否为开启常亮屏模式,默认为开启
     */
    public static boolean getKeepScreenOnMode(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(SCREEN_ON_MODE, true);
    }

    /**
     * 设置是否开启屏幕唤醒模式
     *
     * @param context
     */
    public static void setKeepScreenWakeupMode(Context context, boolean isOn, int time) {

        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(SCREEN_WAKEUP_MODE, isOn);
        if (isOn){
            editor.putInt(SCREEN_WAKEUP_TIME, time);
        }
        editor.commit();
    }

    /**
     * 获取是否为开启屏幕唤醒模式,默认为不开启
     */
    public static boolean getKeepScreenWakeupMode(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(SCREEN_WAKEUP_MODE, false);
    }

    /**
     * 获取是否为开启屏幕唤醒模式,默认为不开启
     */
    public static int getKeepScreenWakeupTime(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getInt(SCREEN_WAKEUP_TIME, 120);
    }

    /**
     * 设置是否开启常亮屏模式
     *
     * @param context
     */
    public static void setUserMapConfigSaved(Context context, boolean isSaved) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(USER_MAP_CONFIG, isSaved);
        editor.commit();
    }

    /**
     * 获取是否为开启常亮屏模式,默认为开启
     */
    public static boolean getUserMapConfigSaved(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(USER_MAP_CONFIG, true);
    }

    /**
     * 获取是否强制设置端口号为旧的8180/xjapi，针对v1.3.8.1
     */
    public static boolean getForceSetOldPortV1381(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        boolean isSet = preferences.getBoolean(SET_OLD_PORT_V_1_3_8_1, true);

        if (isSet){
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean(SET_OLD_PORT_V_1_3_8_1, false);
            editor.commit();
        }

        return isSet;
    }

    /**
     * 设置当日 section
     */
    public static void setSignSection(String date, long section) {

        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(SIGN_SECTION, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(date, section);
        editor.commit();
    }

    // 当前 section
    public static long getSignSection(String date) {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(SIGN_SECTION, Context.MODE_PRIVATE);
        return preferences.getLong(date, 1);
    }

    public static void setSignSectionToday(long section){
        String today = DateUtils.getYMD();
        setSignSection(today, section);
    }

    // 当前 section
    public static long getSignSectionToday() {
        String today = DateUtils.getYMD();
        return getSignSection(today);
    }

    /**
     * 设置服务器获取到当日所需要下载的计划
     */
    public static <T> void setPlanPointTodayPlan(List<T> dataList) {
        String date = DateUtils.getYMD();

        setListData(PLAN_POINT_TODAY_PLAN, date, dataList);
    }

    // 服务器获取到当日所需要下载的计划
    public static List getPlanPointTodayPlan() {
        String date = DateUtils.getYMD();

        Type type = new TypeToken<List<ChildPlanCountBean>>(){}.getType();

        return getListData(type, PLAN_POINT_TODAY_PLAN, date);
    }

    /**
     * 设置当日下载离线点错误的次数
     */
    public static void setPlanPointDownErrTimes(long err_times) {
        String date = DateUtils.getYMD();

        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(PLAN_POINT_DOWN_ERR_TIMES, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(date, err_times);
        editor.commit();
    }

    // 当日下载离线点错误的次数
    public static long getPlanPointDownErrTimes() {
        String date = DateUtils.getYMD();
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(PLAN_POINT_DOWN_ERR_TIMES, Context.MODE_PRIVATE);
        return preferences.getLong(date, 0);
    }

    /**
     * 设置某个巡检计划的离线点下载次数
     */
    public static void setPlanPointPlanDownTimes(String planId, long err_times) {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(PLAN_POINT_PLAN_DOWN_TIMES, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putLong(planId, err_times);
        editor.commit();
    }

    // 获取某个巡检计划的离线点下载次数
    public static long getPlanPointPlanDownTimes(String planId) {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(PLAN_POINT_PLAN_DOWN_TIMES, Context.MODE_PRIVATE);
        return preferences.getLong(planId, 0);
    }


    /**
     * 设置是否删除之前下载的安装包
     *
     * @param context
     */
    public static void setRemoveApkPackage(Context context, boolean remove) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(APK_PKG_REMOVE, remove);
        editor.commit();
    }

    /**
     * 获取是否删除之前下载的安装包
     */
    public static boolean getRemoveApkPackage(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(APK_PKG_REMOVE, false);
    }

    /**
     * 设置之前下载的安装包路径
     *
     * @param context
     */
    public static void setApkPackagePath(Context context, String path) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(APK_PKG_PATH, path);
        editor.commit();
    }

    /**
     * 获取之前下载的安装包路径
     */
    public static String getApkPackagePath(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getString(APK_PKG_PATH, "");
    }

    /**
     * 设置是否巡检线显示所有(是：包括已到位和未到位 否：只显示未到位)
     *
     * @param context
     */
    public static void setPlanLineRenderAll(Context context, boolean isAll) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(PLAN_LINE_RENDER_ALL, isAll);
        editor.commit();
    }

    /**
     * 获取是否巡检线显示所有
     */
    public static boolean getPlanLineRenderAll(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(PLAN_LINE_RENDER_ALL, true);
    }

    public static <T> void setListData(String pref_name, String tag, List<T> dataList){
        if (null == dataList || dataList.size() <= 0)
            return;

        Gson gson = new Gson();
        String strJson = gson.toJson(dataList);

        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(pref_name, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(tag, strJson);
        editor.commit();
    }

    public static <T> List<T> getListData(Type type, String pref_name, String tag){
        List<T> dataList = new ArrayList<>();

        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(pref_name, Context.MODE_PRIVATE);
        String strJson = preferences.getString(tag, null);
        if (strJson == null)
            return dataList;

        Gson gson = new Gson();
        dataList = gson.fromJson(strJson, type);
        return dataList;
    }

    /**
     * */
    public static int getThemeTag() {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getInt(CUSTOM_THEME_TAG, 1);
    }

    /**
     * */
    public static void setThemeTag(int tag) {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = preferences.edit();
        edit.putInt(CUSTOM_THEME_TAG, tag);
        edit.commit();
    }

    /**
     * */
    public static boolean isBackupServerOpened() {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(BACUP_SEVER_OPENED, false);
    }

    /**
     * */
    public static void setBackupServerOpened(boolean open) {
        SharedPreferences preferences = BaseApp.getInstance().getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor edit = preferences.edit();
        edit.putBoolean(BACUP_SEVER_OPENED, open);
        edit.commit();
    }

    /**
     * 保存IMEI号码
     *
     * @param context
     */
    public static void setIMEI(Context context, String imei) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(IMEI, imei);
        editor.commit();
    }

    /**
     * 获取保存的IMEI号码
     */
    public static String getIMEI(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getString(IMEI, "");
    }

    /**
     * 设置设备是否和账户绑定
     * @param context
     */
    public static void setDeviceBinded(Context context, boolean bind) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(DEVICE_BIND, bind);
        editor.commit();
    }

    /**
     * 获取设备是否和账户绑定状态
     */
    public static Boolean getDeviceBinded(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getBoolean(DEVICE_BIND, false);
    }


    /**
     * 保存IMEI号码
     *
     * @param context
     */
    public static void setGisToken(Context context, String gisToken) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(GIS_TOKEN, gisToken);
        editor.commit();
    }

    /**
     * 获取保存的IMEI号码
     */
    public static String getGisToken(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(QUERY_NAME, Context.MODE_PRIVATE);
        return preferences.getString(GIS_TOKEN, "");
    }
}
