mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-13 21:36:58 -08:00
Apparently, I thought a theme was a good idea...
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
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.preference.PreferenceScreen;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
public class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener{
|
||||
private CheckBoxPreference quickTilePreference;
|
||||
private ListPreference themePreference;
|
||||
private SharedPreferences.OnSharedPreferenceChangeListener listener;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -30,6 +38,15 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getActivity().setTitle("Settings");
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,9 +54,11 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
ButterKnife.bind(this, view);
|
||||
quickTilePreference = (CheckBoxPreference) findPreference("enable_quicktile");
|
||||
themePreference = (ListPreference) findPreference("theme");
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(this);
|
||||
CheckBoxPreference keepRootOffPreference = (CheckBoxPreference) findPreference("keep_root_off");
|
||||
CheckBoxPreference hideRootNotificationPreference = (CheckBoxPreference) findPreference("hide_root_notification");
|
||||
|
||||
themePreference.setSummary(themePreference.getValue());
|
||||
if (Utils.magiskVersion == -1) {
|
||||
quickTilePreference.setEnabled(false);
|
||||
keepRootOffPreference.setEnabled(false);
|
||||
@@ -50,6 +69,7 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
hideRootNotificationPreference.setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
Preference.OnPreferenceClickListener preferenceClickListener = preference -> {
|
||||
if (preference == quickTilePreference) {
|
||||
boolean isChecked = quickTilePreference.isChecked();
|
||||
@@ -64,6 +84,10 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
quickTilePreference.setOnPreferenceClickListener(preferenceClickListener);
|
||||
// calculate margins
|
||||
int horizontalMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
|
||||
@@ -78,5 +102,36 @@ public class SettingsFragment extends PreferenceFragment {
|
||||
|
||||
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Logger.dh("Settings: NewValue is " + key);
|
||||
|
||||
if (key.equals("theme")) {
|
||||
String pref = sharedPreferences.getString(key,"");
|
||||
|
||||
themePreference.setSummary(pref);
|
||||
if (pref.equals("Dark")) {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme_dh);
|
||||
} else {
|
||||
getActivity().getApplication().setTheme(R.style.AppTheme);
|
||||
}
|
||||
Intent intent = new Intent(getActivity(), MainActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.putExtra("Relaunch","Settings");
|
||||
startActivity(intent);
|
||||
|
||||
|
||||
Logger.dh("SettingsFragment: theme is " + pref);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user