Cherish:Cleanup for android 12

Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Hưng Phan
2021-10-24 20:56:46 +07:00
parent 2ee28134b0
commit 3c58bb7cd8
144 changed files with 12 additions and 63182 deletions

View File

@@ -45,54 +45,13 @@ import com.cherish.settings.preferences.ActionFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import android.provider.SearchIndexableResource;
import java.util.ArrayList;
import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ButtonSettings extends ActionFragment implements OnPreferenceChangeListener {
public class ButtonSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
//Keys
private static final String KEY_BUTTON_BRIGHTNESS = "button_brightness";
private static final String KEY_BUTTON_BRIGHTNESS_SW = "button_brightness_sw";
private static final String KEY_BACKLIGHT_TIMEOUT = "backlight_timeout";
private static final String HWKEY_DISABLE = "hardware_keys_disable";
private static final String PIXEL_ANIMATION_NAVIGATION = "pixel_nav_animation";
private static final String KEY_NAVIGATION_BAR_ARROWS = "navigation_bar_menu_arrow_keys";
private static final String INVERT_NAVIGATION = "sysui_nav_bar_inverse";
private static final String NAVBAR_VISIBILITY = "navigation_bar_show_new";
// category keys
private static final String CATEGORY_HWKEY = "hardware_keys";
private static final String CATEGORY_HOME = "home_key";
private static final String CATEGORY_MENU = "menu_key";
private static final String CATEGORY_BACK = "back_key";
private static final String CATEGORY_ASSIST = "assist_key";
private static final String CATEGORY_APPSWITCH = "app_switch_key";
// Masks for checking presence of hardware keys.
// Must match values in frameworks/base/core/res/res/values/config.xml
// Masks for checking presence of hardware keys.
// Must match values in frameworks/base/core/res/res/values/config.xml
public static final int KEY_MASK_HOME = 0x01;
public static final int KEY_MASK_BACK = 0x02;
public static final int KEY_MASK_MENU = 0x04;
public static final int KEY_MASK_ASSIST = 0x08;
public static final int KEY_MASK_APP_SWITCH = 0x10;
public static final int KEY_MASK_CAMERA = 0x20;
public static final int KEY_MASK_VOLUME = 0x40;
private ListPreference mBacklightTimeout;
private CustomSeekBarPreference mButtonBrightness;
private SwitchPreference mButtonBrightness_sw;
private SwitchPreference mHwKeyDisable;
private SystemSettingSwitchPreference mPixelAnimationNavigation;
private SecureSettingSwitchPreference mInvertNavigation;
private SwitchPreference mNavbarVisibility;
private boolean mIsNavSwitchingMode = false;
private Handler mHandler;
private SystemSettingSwitchPreference mNavigationArrowKeys;
@Override
public void onCreate(Bundle icicle) {
@@ -102,200 +61,12 @@ public class ButtonSettings extends ActionFragment implements OnPreferenceChange
final Resources res = getResources();
final ContentResolver resolver = getActivity().getContentResolver();
final PreferenceScreen prefScreen = getPreferenceScreen();
mNavbarVisibility = (SwitchPreference) findPreference(NAVBAR_VISIBILITY);
mNavigationArrowKeys = (SystemSettingSwitchPreference) findPreference(KEY_NAVIGATION_BAR_ARROWS);
boolean showing = Settings.System.getInt(getContentResolver(),
Settings.System.FORCE_SHOW_NAVBAR,
ActionUtils.hasNavbarByDefault(getActivity()) ? 1 : 0) != 0;
updateBarVisibleAndUpdatePrefs(showing);
mNavbarVisibility.setOnPreferenceChangeListener(this);
mHandler = new Handler();
mPixelAnimationNavigation = findPreference(PIXEL_ANIMATION_NAVIGATION);
mInvertNavigation = findPreference(INVERT_NAVIGATION);
// On three button nav
if (com.android.internal.util.cherish.CherishUtils.isThemeEnabled("com.android.internal.systemui.navbar.threebutton")) {
mPixelAnimationNavigation.setSummary(getString(R.string.pixel_navbar_anim_summary));
mInvertNavigation.setSummary(getString(R.string.navigation_bar_invert_layout_summary));
// On two button nav
} else if (com.android.internal.util.cherish.CherishUtils.isThemeEnabled("com.android.internal.systemui.navbar.twobutton")) {
mPixelAnimationNavigation.setSummary(getString(R.string.pixel_navbar_anim_summary));
mInvertNavigation.setSummary(getString(R.string.navigation_bar_invert_layout_summary));
// On gesture nav
} else {
mPixelAnimationNavigation.setSummary(getString(R.string.unsupported_gestures));
mInvertNavigation.setSummary(getString(R.string.unsupported_gestures));
mPixelAnimationNavigation.setEnabled(false);
mInvertNavigation.setEnabled(false);
}
final boolean needsNavbar = ActionUtils.hasNavbarByDefault(getActivity());
final PreferenceCategory hwkeyCat = (PreferenceCategory) prefScreen
.findPreference(CATEGORY_HWKEY);
int keysDisabled = 0;
if (!needsNavbar) {
mHwKeyDisable = (SwitchPreference) findPreference(HWKEY_DISABLE);
keysDisabled = Settings.Secure.getIntForUser(getContentResolver(),
Settings.Secure.HARDWARE_KEYS_DISABLE, 0,
UserHandle.USER_CURRENT);
mHwKeyDisable.setChecked(keysDisabled != 0);
mHwKeyDisable.setOnPreferenceChangeListener(this);
final boolean variableBrightness = getResources().getBoolean(
com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
mBacklightTimeout =
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
mButtonBrightness =
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
mButtonBrightness_sw =
(SwitchPreference) findPreference(KEY_BUTTON_BRIGHTNESS_SW);
if (mBacklightTimeout != null) {
mBacklightTimeout.setOnPreferenceChangeListener(this);
int BacklightTimeout = Settings.System.getInt(getContentResolver(),
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, 5000);
mBacklightTimeout.setValue(Integer.toString(BacklightTimeout));
mBacklightTimeout.setSummary(mBacklightTimeout.getEntry());
}
if (variableBrightness) {
hwkeyCat.removePreference(mButtonBrightness_sw);
if (mButtonBrightness != null) {
float ButtonBrightness = Settings.System.getFloat(getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, 1.0f);
mButtonBrightness.setValue((int)(ButtonBrightness * 100.0f));
mButtonBrightness.setOnPreferenceChangeListener(this);
}
} else {
hwkeyCat.removePreference(mButtonBrightness);
if (mButtonBrightness_sw != null) {
mButtonBrightness_sw.setChecked((Settings.System.getFloat(getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, 1.0f) == 1));
mButtonBrightness_sw.setOnPreferenceChangeListener(this);
}
}
} else {
prefScreen.removePreference(hwkeyCat);
}
// bits for hardware keys present on device
final int deviceKeys = getResources().getInteger(
com.android.internal.R.integer.config_deviceHardwareKeys);
// read bits for present hardware keys
final boolean hasHomeKey = (deviceKeys & KEY_MASK_HOME) != 0;
final boolean hasBackKey = (deviceKeys & KEY_MASK_BACK) != 0;
final boolean hasMenuKey = (deviceKeys & KEY_MASK_MENU) != 0;
final boolean hasAssistKey = (deviceKeys & KEY_MASK_ASSIST) != 0;
final boolean hasAppSwitchKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0;
// load categories and init/remove preferences based on device
// configuration
final PreferenceCategory backCategory =
(PreferenceCategory) prefScreen.findPreference(CATEGORY_BACK);
final PreferenceCategory homeCategory =
(PreferenceCategory) prefScreen.findPreference(CATEGORY_HOME);
final PreferenceCategory menuCategory =
(PreferenceCategory) prefScreen.findPreference(CATEGORY_MENU);
final PreferenceCategory assistCategory =
(PreferenceCategory) prefScreen.findPreference(CATEGORY_ASSIST);
final PreferenceCategory appSwitchCategory =
(PreferenceCategory) prefScreen.findPreference(CATEGORY_APPSWITCH);
// back key
if (!hasBackKey) {
prefScreen.removePreference(backCategory);
}
// home key
if (!hasHomeKey) {
prefScreen.removePreference(homeCategory);
}
// App switch key (recents)
if (!hasAppSwitchKey) {
prefScreen.removePreference(appSwitchCategory);
}
// menu key
if (!hasMenuKey) {
prefScreen.removePreference(menuCategory);
}
// search/assist key
if (!hasAssistKey) {
prefScreen.removePreference(assistCategory);
}
// let super know we can load ActionPreferences
onPreferenceScreenLoaded(ActionConstants.getDefaults(ActionConstants.HWKEYS));
// load preferences first
setActionPreferencesEnabled(keysDisabled == 0);
}
public boolean onPreferenceChange(Preference preference, Object newValue) {
ContentResolver resolver = getActivity().getContentResolver();
if (preference == mBacklightTimeout) {
String BacklightTimeout = (String) newValue;
int BacklightTimeoutValue = Integer.parseInt(BacklightTimeout);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.BUTTON_BACKLIGHT_TIMEOUT, BacklightTimeoutValue);
int BacklightTimeoutIndex = mBacklightTimeout
.findIndexOfValue(BacklightTimeout);
mBacklightTimeout
.setSummary(mBacklightTimeout.getEntries()[BacklightTimeoutIndex]);
return true;
} else if (preference == mButtonBrightness) {
float value = (Integer) newValue;
Settings.System.putFloat(getActivity().getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, value / 100.0f);
return true;
} else if (preference == mButtonBrightness_sw) {
boolean value = (Boolean) newValue;
Settings.System.putFloat(getActivity().getContentResolver(),
Settings.System.BUTTON_BRIGHTNESS, value ? 1.0f : -1.0f);
return true;
} else if (preference == mHwKeyDisable) {
boolean value = (Boolean) newValue;
Settings.Secure.putInt(getContentResolver(), Settings.Secure.HARDWARE_KEYS_DISABLE,
value ? 1 : 0);
setActionPreferencesEnabled(!value);
return true;
} else if (preference.equals(mNavbarVisibility)) {
if (mIsNavSwitchingMode) {
return false;
}
mIsNavSwitchingMode = true;
boolean showing = ((Boolean)newValue);
Settings.System.putInt(getContentResolver(), Settings.System.FORCE_SHOW_NAVBAR,
showing ? 1 : 0);
updateBarVisibleAndUpdatePrefs(showing);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
mIsNavSwitchingMode = false;
}
}, 1500);
return true;
}
return false;
}
private void updateBarVisibleAndUpdatePrefs(boolean showing) {
mNavbarVisibility.setChecked(showing);
}
@Override
protected boolean usesExtendedActionsList() {
return true;
}
@Override
public int getMetricsCategory() {