Cherish:HW Keys customization support [1/2]
Based on DUI jhenrique09 edits: make it DUI independent Original commit message: Same robust action library as used on software navigation. Supports single tap, double tap, and long press. As a precautionary measure, single tap back and single tap home are fixed and can not be changed. Camera button actions are not supported at this time. We will bring in wake key support at a later time. Also includes: DUI: Initial checkin for Oreo [4/7] Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cherish.settings.fragments;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
@@ -34,68 +33,160 @@ import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.util.hwkeys.ActionConstants;
|
||||
import com.android.internal.util.hwkeys.ActionUtils;
|
||||
|
||||
import com.cherish.settings.preferences.CustomSeekBarPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
|
||||
public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
Preference.OnPreferenceChangeListener{
|
||||
import com.cherish.settings.preferences.ActionFragment;
|
||||
public class ButtonSettings extends ActionFragment implements 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";
|
||||
|
||||
// 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;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
addPreferencesFromResource(R.xml.cherish_settings_button);
|
||||
|
||||
final Resources res = getResources();
|
||||
final ContentResolver resolver = getActivity().getContentResolver();
|
||||
final PreferenceScreen prefScreen = getPreferenceScreen();
|
||||
|
||||
final boolean variableBrightness = getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
|
||||
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);
|
||||
|
||||
mBacklightTimeout =
|
||||
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
|
||||
mButtonBrightness =
|
||||
(CustomSeekBarPreference) findPreference(KEY_BUTTON_BRIGHTNESS);
|
||||
mButtonBrightness_sw =
|
||||
(SwitchPreference) findPreference(KEY_BUTTON_BRIGHTNESS_SW);
|
||||
final boolean variableBrightness = getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_deviceHasVariableButtonBrightness);
|
||||
|
||||
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());
|
||||
}
|
||||
mBacklightTimeout =
|
||||
(ListPreference) findPreference(KEY_BACKLIGHT_TIMEOUT);
|
||||
|
||||
if (variableBrightness) {
|
||||
prefScreen.removePreference(mButtonBrightness_sw);
|
||||
if (mButtonBrightness != null) {
|
||||
int ButtonBrightness = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 255);
|
||||
mButtonBrightness.setValue(ButtonBrightness / 1);
|
||||
mButtonBrightness.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
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) {
|
||||
int ButtonBrightness = Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 255);
|
||||
mButtonBrightness.setValue(ButtonBrightness / 1);
|
||||
mButtonBrightness.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
} else {
|
||||
hwkeyCat.removePreference(mButtonBrightness);
|
||||
if (mButtonBrightness_sw != null) {
|
||||
mButtonBrightness_sw.setChecked((Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 1) == 1));
|
||||
mButtonBrightness_sw.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
prefScreen.removePreference(mButtonBrightness);
|
||||
if (mButtonBrightness_sw != null) {
|
||||
mButtonBrightness_sw.setChecked((Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, 1) == 1));
|
||||
mButtonBrightness_sw.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
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) {
|
||||
@@ -120,10 +211,21 @@ public class ButtonSettings extends SettingsPreferenceFragment implements
|
||||
Settings.System.putInt(getActivity().getContentResolver(),
|
||||
Settings.System.BUTTON_BRIGHTNESS, value ? 1 : 0);
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean usesExtendedActionsList() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||
|
||||
Reference in New Issue
Block a user