package com.example.hp.exercise10_sharepreference;

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

import com.google.gson.Gson;
/**
 * Created by hp on 12/31/2016.
 */

public class Pref {
    SharedPreferences preferences;
    SharedPreferences.Editor editor;
    Context mycontex;
    public static String SettingKey = "setting";
    private static String domain = "myapp";
    public Pref(Context context)
    {
        mycontex = context;
        preferences = mycontex.getSharedPreferences(domain,mycontex.MODE_PRIVATE);
        editor = preferences.edit();
    }
    public Setting getsetting()
    {
        Gson gson  = new Gson();
        Setting output;
        output = gson.fromJson(preferences.getString(SettingKey,""),Setting.class);
        return  output;
    }



}

@@ -799,13 +799,182 @@
 ;%0A    %7D%0A
+    public void setsetting(Setting input)%0A    %7B%0A        Gson gson  = new Gson();%0A        editor.putString(SettingKey,gson.toJson(input));%0A        editor.commit();%0A    %7D%0A
 %0A%0A%0A%7D%0A

create setsetting method for pref class