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_MEMO_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;
17 public void put(String key, String value) {
19 SharedPreferences pref = null;
21 Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
22 Context.CONTEXT_RESTRICTED);
23 pref = ctxt.getSharedPreferences(EVER_MEMO_ACTIVITY,
24 Context.MODE_PRIVATE);
25 } catch (NameNotFoundException e) {
26 Debug.d(this, null, e);
30 Editor e = pref.edit();
31 e.putString(key, value);
36 public void put(String key, int value) {
37 put(key, String.valueOf(value));
40 public String get(String key) {
44 SharedPreferences pref = null;
46 Context ctxt = context.createPackageContext(PACKAGE_COM_YUJI_EM,
47 Context.CONTEXT_RESTRICTED);
48 pref = ctxt.getSharedPreferences(EVER_MEMO_ACTIVITY,
49 Context.MODE_WORLD_READABLE);
50 } catch (NameNotFoundException e) {
51 Debug.d(this, null, e);
54 val = pref.getString(key, null);
60 public int getInt(String key) {
61 return Integer.parseInt(get(key));
64 public String get(String key, String initValue) {
65 String value = get(key);
73 public int getInt(String key, int initValue) {
74 return Integer.valueOf(get(key, String.valueOf(initValue)));
77 public void remove(String key) {