Blame view

src/com/ectrip/cyt/utils/PreferenceUtils.java 2.66 KB
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  package com.ectrip.cyt.utils;
  
  
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  
  /**
   * Created by Administrator on 2016/2/17.
   */
  public class PreferenceUtils {
  
      private static SharedPreferences mPreferences;
      private static String NAME = "MachineType";
  
      private static SharedPreferences getpreferences(Context context) {
          if (mPreferences == null) {
              mPreferences = context.getSharedPreferences(NAME, 0);
              return mPreferences;
          }
          return mPreferences;
      }
  
      public static boolean getBoolean(Context context, String key) {
          return getBoolean(context, key, false);
      }
  
      public static boolean getBoolean(Context context, String key, boolean b) {
          SharedPreferences sp = getpreferences(context);
  
          return sp.getBoolean(key, b);
      }
  
      public static String getString(Context context, String key) {
          return getString(context, key, null);
      }
  
      public static String getString(Context context, String key, String defValue) {
          SharedPreferences sp = getpreferences(context);
          return sp.getString(key, defValue);
      }
  
      public static void putString(Context context, String key, String value) {
          SharedPreferences sp = getpreferences(context);
          Editor editor = sp.edit();
          editor.putString(key, value);
          editor.commit();
      }
  
      public static void putBoolean(Context context, String key, boolean value) {
          SharedPreferences sp = getpreferences(context);
          Editor editor = sp.edit();
          editor.putBoolean(key, value);
          editor.commit();
      }
  
  
  
      public static long getLong(Context context, String key) {
          return getLong(context, key, -1);
      }
  
      public static long getLong(Context context, String key, long defValue) {
          SharedPreferences sp = getpreferences(context);
          return sp.getLong(key, defValue);
      }
  
      public static void putLong(Context context, String key, long value) {
          SharedPreferences sp = getpreferences(context);
          Editor editor = sp.edit();
          editor.putLong(key, value);
          editor.commit();
      }
      public static int getInt(Context context, String key) {
          return getInt(context, key, -1);
      }
  
      public static int getInt(Context context, String key, int defValue) {
          SharedPreferences sp = getpreferences(context);
          return sp.getInt(key, defValue);
      }
  
      public static void putInt(Context context, String key, int value) {
          SharedPreferences sp = getpreferences(context);
          Editor editor = sp.edit();
          editor.putInt(key, value);
          editor.commit();
      }
  }