// Path: app/src/main/java/com/kong/app/news/utils/SettingsUtil.java
// public class SettingsUtil {
// 
//     public static int getThemeIndex() {
//         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppRun.get().getApplicationContext());
//         return prefs.getInt("ThemeIndex", 0);
//     }
// 
//     public static void setThemeIndex(int index) {
//         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppRun.get().getApplicationContext());
//         prefs.edit().putInt("ThemeIndex", index).apply();
//     }
// }


import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import com.kong.R;
import com.kong.app.news.utils.SettingsUtil;
package com.kong.app.news.fragment;



/**
 * Created by CaoPengfei on 17/6/17.
 */

public class SettingFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {

    private Preference mPreferenceTheme;
    private Preference mCleanCache;

    public static SettingFragment newInstance() {
        Bundle args = new Bundle();
        SettingFragment fragment = new SettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.setting);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

        mCleanCache = findPreference("clean_cache");
        mCleanCache.setOnPreferenceClickListener(this);
        mCleanCache.setSummary("0MB");

        mPreferenceTheme = findPreference("keyTheme");
        mPreferenceTheme.setOnPreferenceClickListener(this);
        String[] colorNames = getActivity().getResources().getStringArray(R.array.SettingColorNames);
// Path: app/src/main/java/com/kong/app/news/utils/SettingsUtil.java
// public class SettingsUtil {
// 
//     public static int getThemeIndex() {
//         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppRun.get().getApplicationContext());
//         return prefs.getInt("ThemeIndex", 0);
//     }
// 
//     public static void setThemeIndex(int index) {
//         SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(AppRun.get().getApplicationContext());
//         prefs.edit().putInt("ThemeIndex", index).apply();
//     }
// }


// Path: app/src/main/java/com/kong/app/news/fragment/SettingFragment.java
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import com.kong.R;
import com.kong.app.news.utils.SettingsUtil;

package com.kong.app.news.fragment;



/**
 * Created by CaoPengfei on 17/6/17.
 */

public class SettingFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {

    private Preference mPreferenceTheme;
    private Preference mCleanCache;

    public static SettingFragment newInstance() {
        Bundle args = new Bundle();
        SettingFragment fragment = new SettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.setting);
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

        mCleanCache = findPreference("clean_cache");
        mCleanCache.setOnPreferenceClickListener(this);
        mCleanCache.setSummary("0MB");

        mPreferenceTheme = findPreference("keyTheme");
        mPreferenceTheme.setOnPreferenceClickListener(this);
        String[] colorNames = getActivity().getResources().getStringArray(R.array.SettingColorNames);
        int currentThemeIndex = SettingsUtil.getThemeIndex();