package jp.co.se.android.androidbook2.chapter0313;

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

/**
 * preferences֘ÃNXł
 * @author canu
 *
 */
public class MyPreferences {
	
	public static final String PREF_NAME 		= "jp.ne.alij.test";
	public static final String PREF_NAME_RESULT = "result";
	public static final String DELIMIT 			= ",";

	public static SharedPreferences getMyPrefs(Context context){
			return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
	}
	
	/* ʂǉ */
	public static void addResult(Context context, String val){
		SharedPreferences sp = getMyPrefs(context);
		String result = sp.getString(PREF_NAME_RESULT, "");
		String newResult = (result.equals("")) ? val : result + DELIMIT + val;
		
		//Preferencesɒǉ
		SharedPreferences.Editor prefEditor = sp.edit();
		prefEditor.putString(PREF_NAME_RESULT, newResult);
		prefEditor.commit();
	}
	
	/*@ʈꗗ擾@*/
	public static String[] getResult(Context context){
		SharedPreferences sp = getMyPrefs(context);
		String result = sp.getString(PREF_NAME_RESULT, "");
		return result.split(",");
	}
	
	/*ʍ폜*/
	public static void deleteResult(Context context){
		SharedPreferences sp = getMyPrefs(context);
		SharedPreferences.Editor prefEditor = sp.edit();
		prefEditor.putString(PREF_NAME_RESULT, "");
		prefEditor.commit();
	}
	
	
	

	
}

@@ -118,16 +118,61 @@
 erences;
+%0Aimport android.preference.PreferenceManager;
 %0A%0A/**%0A *
@@ -248,69 +248,8 @@
 %7B%0A%09%0A
-%09public static final String PREF_NAME %09%09= %22jp.ne.alij.test%22;%0A
 %09pub
@@ -348,16 +348,40 @@
 = %22,%22;%0A%0A
+%09/* ftHgpreferences%E6%93%BE */%0A
 %09public 
@@ -448,68 +448,61 @@
 urn 
-context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE
+PreferenceManager.getDefaultSharedPreferences(context
 );%0A%09

change preferences to default preferences