1 package com.yuji.em.utility;
3 import android.content.Context;
4 import android.content.SharedPreferences;
5 import android.content.SharedPreferences.Editor;
6 import android.content.pm.PackageManager.NameNotFoundException;
8 public class PrefUtilImpl implements PrefUtil {
9 private static final String EVER_CLIP_ACTIVITY = "EverMemoActivity";
10 private static final String PACKAGE_COM_YUJI_EM = "com.yuji.em";
11 private Context context;
13 public PrefUtilImpl(Context context) {
14 this.context = context;
18 public SharedPreferences getSharedPreferences(){
19 SharedPreferences pref = null;
21 Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
22 Context.CONTEXT_RESTRICTED);
23 pref = ctxt.getSharedPreferences(EVER_CLIP_ACTIVITY,
24 Context.MODE_PRIVATE);
25 } catch (NameNotFoundException e) {
26 Debug.d(this, null, e);
32 public void put(String key, String value) {
34 SharedPreferences pref = getSharedPreferences();
39 Editor e = pref.edit();
40 e.putString(key, value);
46 public void put(String key, int value) {
47 put(key, String.valueOf(value));
51 public void put(String key, long value) {
52 put(key, String.valueOf(value));
56 public String get(String key) {
60 SharedPreferences pref = getSharedPreferences();
65 val = pref.getString(key, null);
72 public int getInt(String key) {
73 return Integer.parseInt(get(key));
77 public long getLong(String key) {
78 return Long.parseLong(get(key));
82 public String get(String key, String initValue) {
83 String value = get(key);
92 public int getInt(String key, int initValue) {
93 return Integer.valueOf(get(key, String.valueOf(initValue)));
97 public long getLong(String key, long initValue) {
98 return Long.valueOf(get(key, String.valueOf(initValue)));
102 public void copy(String srcKey, String dstKey){
103 String value = get(srcKey);
108 public void remove(String key) {