package me.liuyun.bjutlgn;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import butterknife.Bind;

public class SettingsActivity extends AppCompatActivity {
    @Bind(R.id.settings_toolbar)
    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prefs);
        getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
        setSupportActionBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        //toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        //    @Override
        //    public void onClick(View v) {
        //        onBackPressed();
        //    }
        //});

    }

    private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object value) {
            String stringValue = value.toString();
            if (preference instanceof ListPreference) {
                ListPreference listPreference = (ListPreference) preference;
                int index = listPreference.findIndexOfValue(stringValue);
                preference.setSummary(
                        index >= 0
                                ? listPreference.getEntries()[index]
                                : null);
            } else if (preference.getKey().equals("password")) {
                preference.setSummary("********");
            } else {
                preference.setSummary(stringValue);
            }
            return true;
        }
    };

    private static void bindPreferenceSummaryToValue(Preference preference) {
        preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
        sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    }

    public static class SettingsFragment extends PreferenceFragment {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.settings);
            bindPreferenceSummaryToValue(findPreference("account"));
            bindPreferenceSummaryToValue(findPreference("password"));
            bindPreferenceSummaryToValue(findPreference("package"));
            findPreference("version").setSummary(BuildConfig.VERSION_NAME);
            findPreference("licenses").setSummary(R.string.licenses);
        }
    }
}

@@ -354,32 +354,90 @@
 ar;%0A
-%0Aimport butterknife.Bind
+import android.view.View;%0A%0Aimport butterknife.Bind;%0Aimport butterknife.ButterKnife
 ;%0A%0Ap
@@ -812,24 +812,56 @@
 ).commit();%0A
+        ButterKnife.bind(this);%0A
         setS
@@ -947,18 +947,16 @@
         
-//
 toolbar.
@@ -1017,26 +1017,24 @@
 ) %7B%0A        
-//
     @Overrid
@@ -1039,26 +1039,24 @@
 ide%0A        
-//
     public v
@@ -1081,26 +1081,24 @@
 ) %7B%0A        
-//
         onBa
@@ -1118,18 +1118,16 @@
         
-//
     %7D%0A  
@@ -1136,15 +1136,12 @@
     
-//
 %7D);%0A
-%0A
     

Fix binding