// Path: app/src/main/java/com/hexforhn/hex/fragment/SettingsFragment.java
// public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         addPreferencesFromResource(R.xml.preferences);
// 
//         getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
//     }
// 
//     @Override
//     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//         // Apply theme changes instantly by immediately re-creating the parent activity
//         if (key.equals(getString(R.string.enableDarkThemeSettingKey))) {
//             getActivity().recreate();
//         }
//     }
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/util/ThemeHelper.java
// public class ThemeHelper {
//     public static void applyTheme(Activity activity) {
//         if (shouldSetTheme(activity)) {
//             activity.setTheme(getDesiredTheme(activity));
//         }
//     }
// 
//     public static void updateTheme(Activity activity) {
//         if (shouldSetTheme(activity)) {
//             activity.recreate();
//         }
//     }
// 
//     private static boolean shouldSetTheme(Activity activity) {
//         return getCurrentTheme(activity) != getDesiredTheme(activity);
//     }
// 
//     private static int getDesiredTheme(Activity activity) {
//         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
//         boolean useDarkTheme = sharedPref.getBoolean(activity.getString(R.string.enableDarkThemeSettingKey), false);
// 
//         return useDarkTheme ? R.style.AppThemeDark : R.style.AppThemeLight;
//     }
// 
//     private static int getCurrentTheme(Activity activity) {
//         TypedValue outValue = new TypedValue();
//         activity.getTheme().resolveAttribute(R.attr.themeName, outValue, true);
// 
//         return outValue.string.toString().equals("AppThemeDark") ? R.style.AppThemeDark : R.style.AppThemeLight;
//     }
// }


import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.hexforhn.hex.R;
import com.hexforhn.hex.fragment.SettingsFragment;
import com.hexforhn.hex.util.ThemeHelper;
package com.hexforhn.hex.activity;


public class SettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
// Path: app/src/main/java/com/hexforhn/hex/fragment/SettingsFragment.java
// public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
//     @Override
//     public void onCreate(Bundle savedInstanceState) {
//         super.onCreate(savedInstanceState);
// 
//         addPreferencesFromResource(R.xml.preferences);
// 
//         getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
//     }
// 
//     @Override
//     public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
//         // Apply theme changes instantly by immediately re-creating the parent activity
//         if (key.equals(getString(R.string.enableDarkThemeSettingKey))) {
//             getActivity().recreate();
//         }
//     }
// }
// 
// Path: app/src/main/java/com/hexforhn/hex/util/ThemeHelper.java
// public class ThemeHelper {
//     public static void applyTheme(Activity activity) {
//         if (shouldSetTheme(activity)) {
//             activity.setTheme(getDesiredTheme(activity));
//         }
//     }
// 
//     public static void updateTheme(Activity activity) {
//         if (shouldSetTheme(activity)) {
//             activity.recreate();
//         }
//     }
// 
//     private static boolean shouldSetTheme(Activity activity) {
//         return getCurrentTheme(activity) != getDesiredTheme(activity);
//     }
// 
//     private static int getDesiredTheme(Activity activity) {
//         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(activity);
//         boolean useDarkTheme = sharedPref.getBoolean(activity.getString(R.string.enableDarkThemeSettingKey), false);
// 
//         return useDarkTheme ? R.style.AppThemeDark : R.style.AppThemeLight;
//     }
// 
//     private static int getCurrentTheme(Activity activity) {
//         TypedValue outValue = new TypedValue();
//         activity.getTheme().resolveAttribute(R.attr.themeName, outValue, true);
// 
//         return outValue.string.toString().equals("AppThemeDark") ? R.style.AppThemeDark : R.style.AppThemeLight;
//     }
// }


// Path: app/src/main/java/com/hexforhn/hex/activity/SettingsActivity.java
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.hexforhn.hex.R;
import com.hexforhn.hex.fragment.SettingsFragment;
import com.hexforhn.hex.util.ThemeHelper;

package com.hexforhn.hex.activity;


public class SettingsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeHelper.applyTheme(this);