SpUtils.java 1.05 KB
package com.polysoft.nafmii.utils;

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

public class SpUtils {

    private static final String SP_NAME = "NAFMII";

    // 首次运行
    public static final String KEY_FIRST_RUN = "FIRST_RUN";
    // H5版本
    public static final String KEY_H5_VERSION = "H5_VERSION";

    public static void putBoolean(String key, boolean val) {
        SharedPreferences.Editor edit = getSpMgr().edit();
        edit.putBoolean(key, val).commit();
    }

    public static boolean getBoolean(String key, boolean def) {
        return getSpMgr().getBoolean(key, def);
    }

    public static void putString(String key, String val) {
        SharedPreferences.Editor edit = getSpMgr().edit();
        edit.putString(key, val).commit();
    }

    public static String getString(String key, String def) {
        return getSpMgr().getString(key, def);
    }


    private static SharedPreferences getSpMgr() {
        return CtxUtils.getApplication().getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    }
}