| | |
| | | |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.lang.reflect.Method; |
| | | import java.lang.reflect.Type; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import android.content.Context; |
| | | import android.content.SharedPreferences; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | |
| | | import safeluck.drive.evaluation.bean.BaseDataUIBean; |
| | | import safeluck.drive.evaluation.bean.MapInfoHead; |
| | | |
| | | public class SPUtils |
| | | { |
| | |
| | | public static final String Coach_SIGN_STATUS = "coach_sign_"; |
| | | public static final String SIGN_MODE = "sign_mode"; |
| | | public static final String EXAM_ID = "exam_id"; |
| | | //将 HashMap 用sp存储起来 |
| | | public static void saveHashMap(HashMap<BaseDataUIBean.TYPE_,MapInfoHead> map, Context context){ |
| | | |
| | | Gson gson = new Gson(); |
| | | String json = gson.toJson(map); |
| | | |
| | | //步骤1:创建一个SharedPreferences对象 |
| | | SharedPreferences sharedPreferences= context.getSharedPreferences("config", Context.MODE_PRIVATE); |
| | | //步骤2: 实例化SharedPreferences.Editor对象 |
| | | SharedPreferences.Editor editor = sharedPreferences.edit(); |
| | | //步骤3:将获取过来的值放入文件 |
| | | editor.putString("config",json); |
| | | editor.commit(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | //将json格式的字符串从sp中取出来转化为hashMap |
| | | public static HashMap<BaseDataUIBean.TYPE_, MapInfoHead> getHashMap(Context context){ |
| | | |
| | | SharedPreferences sharedPreferences=context. getSharedPreferences("config", Context .MODE_PRIVATE); |
| | | String json =sharedPreferences.getString("config",""); |
| | | HashMap<BaseDataUIBean.TYPE_,MapInfoHead> map = null; |
| | | |
| | | Type type = new TypeToken<HashMap<BaseDataUIBean.TYPE_, MapInfoHead>>(){}.getType(); |
| | | Gson gson = new Gson(); |
| | | map = gson.fromJson(json, type); |
| | | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | | * 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法 |