Improve the UI of Press & hold power button settings
The following changes has been made:
- The on/off toggle for Assistant now becomes two radio selectors ("Power Menu" and "Digital Assistant"). This is to make things clearer that Press & hold power button can be configured to power menu.
- The corresponding power menu animation will be shown when "Power Menu" is selected.
- The Assistant specific sensitivity settings and the foot notes are hidden when "Power Menu" is selected.
- Some minor wording updates according to the requests from Assistant / Settings UXW.
Bug: 229722937
Test: robotest, manual
Change-Id: Ib356fba861ad8c4a2626a0e0bd8cf3e4d90ce9a6
This commit is contained in:
@@ -16,53 +16,163 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
|
||||
/** Common code for long press power settings shared between controllers. */
|
||||
final class PowerMenuSettingsUtils {
|
||||
|
||||
/**
|
||||
* Setting storing the current behaviour of long press power.
|
||||
*/
|
||||
public static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||
/** Setting storing the current behaviour of long press power. */
|
||||
private static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||
|
||||
/** Setting storing the current behaviour of key chord power + volume up. */
|
||||
private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
|
||||
|
||||
/**
|
||||
* Value used for long press power button behaviour when the Assist setting is disabled.
|
||||
* Value used for long press power button behaviour when long press power for Assistant is
|
||||
* disabled.
|
||||
*
|
||||
* If this value matches Assist setting, then it falls back to Global Actions panel or
|
||||
* power menu, depending on their respective settings.
|
||||
* <p>If this value matches long press power for Assistant, then it falls back to Global Actions
|
||||
* panel (i.e., the Power Menu), depending on their respective settings.
|
||||
*/
|
||||
public static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
||||
private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior;
|
||||
|
||||
/**
|
||||
* Values used for long press power button behaviour when Assist setting is enabled.
|
||||
*
|
||||
* {@link com.android.server.policy.PhoneWindowManager#LONG_PRESS_POWER_GLOBAL_ACTIONS} for
|
||||
* source of the value.
|
||||
* Value used for key chord power + volume up behaviour when long press power for Assistant is
|
||||
* disabled.
|
||||
*/
|
||||
static final int LONG_PRESS_POWER_NO_ACTION = 0;
|
||||
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
|
||||
static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
||||
private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp;
|
||||
|
||||
private static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; // a.k.a., Power Menu
|
||||
private static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
||||
|
||||
private static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
|
||||
|
||||
private static final Uri POWER_BUTTON_LONG_PRESS_URI =
|
||||
Settings.Global.getUriFor(POWER_BUTTON_LONG_PRESS_SETTING);
|
||||
|
||||
/**
|
||||
* @return current value of power button behaviour.
|
||||
* @return true if long press power for assistant is currently enabled.
|
||||
*/
|
||||
public static int getPowerButtonSettingValue(Context context) {
|
||||
return Settings.Global.getInt(context.getContentResolver(),
|
||||
public static boolean isLongPressPowerForAssistantEnabled(Context context) {
|
||||
int longPressPowerSettingValue = Settings.Global.getInt(
|
||||
context.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
||||
return longPressPowerSettingValue == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if long press power for assist is currently enabled.
|
||||
* @return true if long press power for assistant setting is available on the device.
|
||||
*/
|
||||
public static boolean isLongPressPowerForAssistEnabled(Context context) {
|
||||
return getPowerButtonSettingValue(context) == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
public static boolean isLongPressPowerSettingAvailable(Context context) {
|
||||
if (!context.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int defaultLongPressPowerSettingValue =
|
||||
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE);
|
||||
switch (defaultLongPressPowerSettingValue) {
|
||||
case LONG_PRESS_POWER_GLOBAL_ACTIONS:
|
||||
case LONG_PRESS_POWER_ASSISTANT_VALUE:
|
||||
// We support switching between Power Menu and Digital Assistant.
|
||||
return true;
|
||||
default:
|
||||
// All other combinations are not supported.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private PowerMenuSettingsUtils() {
|
||||
public static boolean setLongPressPowerForAssistant(Context context) {
|
||||
if (Settings.Global.putInt(
|
||||
context.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
LONG_PRESS_POWER_ASSISTANT_VALUE)) {
|
||||
// Make power + volume up buttons to open the power menu
|
||||
Settings.Global.putInt(
|
||||
context.getContentResolver(),
|
||||
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
||||
KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean setLongPressPowerForPowerMenu(Context context) {
|
||||
if (Settings.Global.putInt(
|
||||
context.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
LONG_PRESS_POWER_GLOBAL_ACTIONS)) {
|
||||
// We restore power + volume up buttons to the default action.
|
||||
int keyChordDefaultValue =
|
||||
context.getResources()
|
||||
.getInteger(KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE);
|
||||
Settings.Global.putInt(
|
||||
context.getContentResolver(),
|
||||
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
||||
keyChordDefaultValue);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
private final SettingsObserver mSettingsObserver;
|
||||
|
||||
PowerMenuSettingsUtils(Context context) {
|
||||
mContext = context;
|
||||
mSettingsObserver = new SettingsObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers callback for observing SettingsProvider state.
|
||||
*
|
||||
* @param callback for state changes
|
||||
*/
|
||||
public void registerObserver(SettingsStateCallback callback) {
|
||||
mSettingsObserver.setCallback(callback);
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
resolver.registerContentObserver(POWER_BUTTON_LONG_PRESS_URI, true, mSettingsObserver);
|
||||
}
|
||||
|
||||
/** Unregisters callback for observing SettingsProvider state. */
|
||||
public void unregisterObserver() {
|
||||
final ContentResolver resolver = mContext.getContentResolver();
|
||||
resolver.unregisterContentObserver(mSettingsObserver);
|
||||
}
|
||||
|
||||
/** An interface for when SettingsProvider key state changes. */
|
||||
public interface SettingsStateCallback {
|
||||
/** Callback method for SettingsProvider key state changes. */
|
||||
void onChange(Uri uri);
|
||||
}
|
||||
|
||||
private static final class SettingsObserver extends ContentObserver {
|
||||
private SettingsStateCallback mCallback;
|
||||
|
||||
SettingsObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
private void setCallback(SettingsStateCallback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onChange(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user