<commit_before>package com.huetoyou.chatexchange.ui.activity;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.widget.Toast;

import com.huetoyou.chatexchange.R;
import com.huetoyou.chatexchange.auth.AuthenticatorActivity;
import com.huetoyou.chatexchange.backend.BackendService;
import com.huetoyou.chatexchange.ui.misc.AppCompatPreferenceActivity;
import com.huetoyou.chatexchange.ui.misc.hue.ActionBarHue;
import com.huetoyou.chatexchange.ui.misc.hue.ThemeHue;
import com.jrummyapps.android.colorpicker.ColorPreference;

import java.util.ArrayList;

public class PreferencesActivity extends AppCompatPreferenceActivity
{
    private static SharedPreferences mSharedPrefs;
    private final ArrayList<CharSequence> mAccountNames = new ArrayList<>();
    private static ActionBarHue actionBarHue = null;
    private static ThemeHue themeHue = null;
    private static boolean darkThemePrevState;
    private static ColorPreference fabColorPreference;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        themeHue = new ThemeHue();
        actionBarHue = new ActionBarHue();
        ThemeHue.setTheme(PreferencesActivity.this);

        super.onCreate(null);
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();

        mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        ActionBarHue.setActionBarColorToSharedPrefsValue(this);

        AccountManager mAccountManager = AccountManager.get(this);
        if (mAccountManager.getAccounts().length > 0)
        {
            Account[] mAccounts = mAccountManager.getAccounts();

            for (Account a : mAccounts)
            {
                mAccountNames.add(a.name);
            }
        }
    }

    public static class MyPreferenceFragment extends PreferenceFragment
    {

        @Override
        public void onCreate(final Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
            mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

            /*
             * Default color preference
             */
            ColorPreference colorPreference = (ColorPreference) findPreference("default_color");
            colorPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
            {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue)
                {
                    ActionBarHue.setActionBarColorToSharedPrefsValue(((PreferencesActivity)getActivity()));
                    return true;
                }
            });

            /*
             * Dynamically change color based on chat room theme preference
             */<commit_msg>Add back button to Settings<commit_after>package com.huetoyou.chatexchange.ui.activity;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.view.MenuItem;
import android.widget.Toast;

import com.huetoyou.chatexchange.R;
import com.huetoyou.chatexchange.auth.AuthenticatorActivity;
import com.huetoyou.chatexchange.backend.BackendService;
import com.huetoyou.chatexchange.ui.misc.AppCompatPreferenceActivity;
import com.huetoyou.chatexchange.ui.misc.hue.ActionBarHue;
import com.huetoyou.chatexchange.ui.misc.hue.ThemeHue;
import com.jrummyapps.android.colorpicker.ColorPreference;

import java.util.ArrayList;

public class PreferencesActivity extends AppCompatPreferenceActivity
{
    private static SharedPreferences mSharedPrefs;
    private final ArrayList<CharSequence> mAccountNames = new ArrayList<>();
    private static ActionBarHue actionBarHue = null;
    private static ThemeHue themeHue = null;
    private static boolean darkThemePrevState;
    private static ColorPreference fabColorPreference;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        themeHue = new ThemeHue();
        actionBarHue = new ActionBarHue();
        ThemeHue.setTheme(PreferencesActivity.this);

        super.onCreate(null);
        getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();

        mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        ActionBarHue.setActionBarColorToSharedPrefsValue(this);

        AccountManager mAccountManager = AccountManager.get(this);
        if (mAccountManager.getAccounts().length > 0)
        {
            Account[] mAccounts = mAccountManager.getAccounts();

            for (Account a : mAccounts)
            {
                mAccountNames.add(a.name);
            }
        }

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    public static class MyPreferenceFragment extends PreferenceFragment
    {

        @Override
        public void onCreate(final Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
            mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

            /*
             * Default color preference
             */
            ColorPreference colorPreference = (ColorPreference) findPreference("default_color");
            colorPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
            {
                @Override
                public boolean onPreferenceChange(Preference preference, Object newValue)
                {
                    ActionBarHue.setActionBarColorToSharedPrefsValue(((PreferencesActivity)getActivity()));
                    return true;
                }
            });

            /*
             * Dynamically change color based on chat room theme preference
             */
{'fraction_non_alphanumeric': 0.07667402501839587, 'fraction_numerical': 0.00029433406916850625, 'mean_word_length': 3.076784643071386, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3959863', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1724, 'n_words': 320}