<commit_before>package com.tzapps.tzpalette.ui;

import com.tzapps.tzpalette.R;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.util.Log;

public class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener
{
    private static final String TAG = "SettingsFragment";
    
    public static final String KEY_PREF_COLOR_TYPE = "pref_analysisColorType";
    public static final String KEY_PREF_COLOR_NUMBER = "pref_setColorNumber";
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
    {
        if (key.equals(KEY_PREF_COLOR_TYPE))
        {
            Preference colorTypePref = findPreference(key);
            String defaultColorType = getResources().getString(R.string.pref_analysisColorType_default);
            String colorType = sharedPreferences.getString(key, defaultColorType);
            colorTypePref.setSummary(colorType);
        }
        else if (key.equals(KEY_PREF_COLOR_NUMBER))
        {
            Preference colorNumberPref = findPreference(key);
            int defaultColorNumber = getResources().getInteger(R.integer.pref_setColorNumber_default);
            int colorNumber = sharedPreferences.getInt(key, defaultColorNumber);
            colorNumberPref.setSummary(colorNumber + "");
        }
    }
    
    @Override
    public void onResume()
    {
        super.onResume();
        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    }
    
    @Override<commit_msg>load the prefs when create the fragment<commit_after>package com.tzapps.tzpalette.ui;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;

import com.tzapps.tzpalette.R;

public class SettingsFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener
{
    private static final String TAG = "SettingsFragment";
    
    public static final String KEY_PREF_COLOR_TYPE = "pref_analysisColorType";
    public static final String KEY_PREF_COLOR_NUMBER = "pref_setColorNumber";
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.preferences);
        
        // Initialize the pref summary label
        loadPrefs();
    }
    
    private void loadPrefs()
    {
        SharedPreferences sp = getPreferenceScreen().getSharedPreferences();
        
        String colorType = sp.getString(KEY_PREF_COLOR_TYPE, getString(R.string.pref_analysisColorType_default));
        Preference colorTypePref = findPreference(KEY_PREF_COLOR_TYPE);
        colorTypePref.setSummary(colorType);
        
        int colurNumber = sp.getInt(KEY_PREF_COLOR_NUMBER, getResources().getInteger(R.integer.pref_setColorNumber_default));
        Preference colorNumberPref = findPreference(KEY_PREF_COLOR_NUMBER);
        colorNumberPref.setSummary(colurNumber+"");
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
    {
        if (key.equals(KEY_PREF_COLOR_TYPE))
        {
            Preference colorTypePref = findPreference(key);
            String colorType = sharedPreferences.getString(key, getString(R.string.pref_analysisColorType_default));
            colorTypePref.setSummary(colorType);
        }
        else if (key.equals(KEY_PREF_COLOR_NUMBER))
        {
            Preference colorNumberPref = findPreference(key);
            int defaultColorNumber = getResources().getInteger(R.integer.pref_setColorNumber_default);
            int colorNumber = sharedPreferences.getInt(key, defaultColorNumber);
            colorNumberPref.setSummary(colorNumber + "");
        }
    }
    
    @Override
    public void onResume()
    {
        super.onResume();
        getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    }
    
    @Override
{'fraction_non_alphanumeric': 0.07515840069914792, 'fraction_numerical': 0.0, 'mean_word_length': 3.461988304093567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5389263', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1179, 'n_words': 220}