/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.android.sunshine.app;

import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;

/**
 * A {@link PreferenceActivity} that presents a set of application settings.
 * <p>
 * See <a href="http://developer.android.com/design/patterns/settings.html">
 * Android Design: Settings</a> for design guidelines and the <a
 * href="http://developer.android.com/guide/topics/ui/settings.html">Settings
 * API Guide</a> for more information on developing a Settings UI.
 */
public class SettingsActivity extends PreferenceActivity
        implements Preference.OnPreferenceChangeListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Add 'general' preferences, defined in the XML file
        addPreferencesFromResource(R.xml.pref_general);

        // For all preferences, attach an OnPreferenceChangeListener so the UI summary can be
        // updated when the preference changes.
        bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_key)));
        bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_units_key)));
    }

    /**
     * Attaches a listener so the summary is always updated with the preference value.
     * Also fires the listener once, to initialize the summary (so it shows up before the value
     * is changed.)
     */
    private void bindPreferenceSummaryToValue(Preference preference) {
        // Set the listener to watch for value changes.
        preference.setOnPreferenceChangeListener(this);

        // Trigger the listener immediately with the preference's
        // current value.
        onPreferenceChange(preference,
                PreferenceManager
                        .getDefaultSharedPreferences(preference.getContext())
                        .getString(preference.getKey(), ""));
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object value) {
        String stringValue = value.toString();

        if (preference instanceof ListPreference) {
            // For list preferences, look up the correct display value in
            // the preference's 'entries' list (since they have separate labels/values).
            ListPreference listPreference = (ListPreference) preference;
            int prefIndex = listPreference.findIndexOfValue(stringValue);
            if (prefIndex >= 0) {
                preference.setSummary(listPreference.getEntries()[prefIndex]);
            }
        } else {
            // For other preferences, set the summary to the value's simple string representation.
            preference.setSummary(stringValue);
        }
        return true;
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
    @Override
    public Intent getParentActivityIntent() {
        return super.getParentActivityIntent().addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    }
}
@@ -1,1336 +1,339 @@
-/*%0A * Copyright (C) 2014 The Android Open Source Project%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.example.android.sunshine.app;%0A%0Aimport android.annotation.TargetApi;%0Aimport android.content.Intent;%0Aimport android.os.Build;%0Aimport android.os.Bundle;%0Aimport android.preference.ListPreference;%0Aimport android.preference.Preference;%0Aimport android.preference.PreferenceActivity;%0Aimport android.preference.PreferenceManager;%0A%0A/**%0A * A %7B@link PreferenceActivity%7D that presents a set of application settings.%0A * %3Cp%3E%0A * See %3Ca href=%22http://developer.android.com/design/patterns/settings.html%22%3E%0A * Android Design: Settings%3C/a%3E for design guidelines and the %3Ca%0A * href=%22http://developer.android.com/guide/topics/ui/settings.html%22%3ESettings%0A * API Guide%3C/a%3E for more information on developing a Settings UI.%0A */
+%0Apackage com.example.android.sunshine.app;%0A%0Aimport android.annotation.TargetApi;%0Aimport android.content.Intent;%0Aimport android.os.Build;%0Aimport android.os.Bundle;%0Aimport android.preference.ListPreference;%0Aimport android.preference.Preference;%0Aimport android.preference.PreferenceActivity;%0Aimport android.preference.PreferenceManager;%0A%0A
 %0Apub
@@ -1017,222 +1017,8 @@
     
-/**%0A     * Attaches a listener so the summary is always updated with the preference value.%0A     * Also fires the listener once, to initialize the summary (so it shows up before the value%0A     * is changed.)%0A     */
 %0A   
@@ -1202,100 +1202,8 @@
 );%0A%0A
-        // Trigger the listener immediately with the preference's%0A        // current value.%0A
     
@@ -1622,161 +1622,8 @@
     
-   // For list preferences, look up the correct display value in%0A            // the preference's 'entries' list (since they have separate labels/values).
 %0A   
@@ -2298,8 +2298,9 @@
 %0A    %7D%0A%7D
+%0A

Update SettingsActivity.java