Revert "Add sensitivity configuration to long press power dialog"
This reverts commit de2f00df41
.
Reason for revert: This CL will cause build break, b/197290948
Change-Id: Ibee2d4bc5e445e863585c291b4b2741bcb4b4c81
This commit is contained in:
@@ -16,11 +16,6 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE;
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
@@ -38,12 +33,27 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
*/
|
||||
public class LongPressPowerButtonPreferenceController extends TogglePreferenceController {
|
||||
|
||||
private static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||
private static final String KEY_CHORD_POWER_VOLUME_UP_SETTING =
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP;
|
||||
|
||||
private static final String FOOTER_HINT_KEY = "power_menu_power_volume_up_hint";
|
||||
private static final String ASSIST_SWITCH_KEY = "gesture_power_menu_long_press_for_assist";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_NO_ACTION = 0;
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5; // Settings.Secure.ASSISTANT
|
||||
|
||||
/**
|
||||
* Values used for volume key chord behaviour when Assist setting is enabled.
|
||||
*
|
||||
@@ -57,6 +67,15 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
@VisibleForTesting
|
||||
static final int KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS = 2;
|
||||
|
||||
/**
|
||||
* Value used for long press power button behaviour when the Assist setting is disabled.
|
||||
*
|
||||
* If this value matches Assist setting, then it falls back to Global Actions panel or
|
||||
* power menu, depending on their respective settings.
|
||||
*/
|
||||
private static final int POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE =
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior;
|
||||
|
||||
private static final int KEY_CHORD_POWER_VOLUME_UP_DEFAULT_VALUE_RESOURCE =
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp;
|
||||
|
||||
@@ -82,7 +101,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
|
||||
final int powerButtonValue = getPowerButtonValue();
|
||||
if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
||||
return mContext.getString(R.string.power_menu_summary_long_press_for_assist_enabled);
|
||||
} else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
|
||||
@@ -103,7 +122,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext);
|
||||
return getPowerButtonValue() == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,6 +159,12 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
}
|
||||
}
|
||||
|
||||
private int getPowerButtonValue() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
mContext.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
||||
}
|
||||
|
||||
private static boolean isPowerMenuKeyChordEnabled(Context context) {
|
||||
return Settings.Global.getInt(context.getContentResolver(),
|
||||
KEY_CHORD_POWER_VOLUME_UP_SETTING,
|
||||
|
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/** Handles changes to the long press power button sensitivity slider. */
|
||||
public class LongPressPowerSensitivityPreferenceController extends
|
||||
SliderPreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private final ContentObserver mPowerButtonObserver = new ContentObserver(Handler.getMain()) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
if (mPreference != null) {
|
||||
updateState(mPreference);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
private final int[] mSensitivityValues;
|
||||
|
||||
@Nullable
|
||||
private LabeledSeekBarPreference mPreference;
|
||||
|
||||
public LongPressPowerSensitivityPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mSensitivityValues = context.getResources().getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
Settings.Global.getUriFor(PowerMenuSettingsUtils.POWER_BUTTON_LONG_PRESS_SETTING),
|
||||
false, mPowerButtonObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mContext.getContentResolver().unregisterContentObserver(mPowerButtonObserver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
if (mPreference != null) {
|
||||
mPreference.setContinuousUpdates(false);
|
||||
mPreference.setHapticFeedbackMode(
|
||||
LabeledSeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
|
||||
mPreference.setMin(getMin());
|
||||
mPreference.setMax(getMax());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final LabeledSeekBarPreference pref = (LabeledSeekBarPreference) preference;
|
||||
pref.setEnabled(
|
||||
isAvailable() && PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext));
|
||||
pref.setProgress(getSliderPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mSensitivityValues == null || mSensitivityValues.length < 2) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
if (!PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)) {
|
||||
return DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliderPosition() {
|
||||
return mSensitivityValues == null ? 0 : closestValueIndex(mSensitivityValues,
|
||||
getCurrentSensitivityValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSliderPosition(int position) {
|
||||
if (mSensitivityValues == null || position < 0 || position >= mSensitivityValues.length) {
|
||||
return false;
|
||||
}
|
||||
return Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS,
|
||||
mSensitivityValues[position]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMax() {
|
||||
if (mSensitivityValues == null || mSensitivityValues.length == 0) {
|
||||
return 0;
|
||||
}
|
||||
return mSensitivityValues.length - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getCurrentSensitivityValue() {
|
||||
return Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS,
|
||||
mContext.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerDurationMs));
|
||||
}
|
||||
|
||||
private static int closestValueIndex(int[] values, int needle) {
|
||||
int minDistance = Integer.MAX_VALUE;
|
||||
int valueIndex = 0;
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int diff = Math.abs(values[i] - needle);
|
||||
if (diff < minDistance) {
|
||||
minDistance = diff;
|
||||
valueIndex = i;
|
||||
}
|
||||
}
|
||||
return valueIndex;
|
||||
}
|
||||
}
|
@@ -16,23 +16,30 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
import static com.android.settings.gestures.PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String POWER_BUTTON_LONG_PRESS_SETTING =
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
|
||||
@VisibleForTesting
|
||||
static final int LONG_PRESS_POWER_ASSISTANT_VALUE = 5;
|
||||
|
||||
public PowerMenuPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
|
||||
final int powerButtonValue = getPowerButtonLongPressValue(mContext);
|
||||
if (powerButtonValue == LONG_PRESS_POWER_ASSISTANT_VALUE) {
|
||||
return mContext.getText(R.string.power_menu_summary_long_press_for_assist_enabled);
|
||||
} else if (powerButtonValue == LONG_PRESS_POWER_GLOBAL_ACTIONS) {
|
||||
@@ -53,4 +60,11 @@ public class PowerMenuPreferenceController extends BasePreferenceController {
|
||||
return mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable);
|
||||
}
|
||||
|
||||
private static int getPowerButtonLongPressValue(Context context) {
|
||||
return Settings.Global.getInt(context.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
context.getResources().getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior));
|
||||
}
|
||||
}
|
||||
|
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
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 =
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS;
|
||||
|
||||
/**
|
||||
* Value used for long press power button behaviour when the Assist setting is disabled.
|
||||
*
|
||||
* If this value matches Assist setting, then it falls back to Global Actions panel or
|
||||
* power menu, depending on their respective settings.
|
||||
*/
|
||||
public 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.
|
||||
*/
|
||||
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
|
||||
|
||||
/**
|
||||
* @return current value of power button behaviour.
|
||||
*/
|
||||
public static int getPowerButtonSettingValue(Context context) {
|
||||
return Settings.Global.getInt(context.getContentResolver(),
|
||||
POWER_BUTTON_LONG_PRESS_SETTING,
|
||||
context.getResources().getInteger(POWER_BUTTON_LONG_PRESS_DEFAULT_VALUE_RESOURCE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if long press power for assist is currently enabled.
|
||||
*/
|
||||
public static boolean isLongPressPowerForAssistEnabled(Context context) {
|
||||
return getPowerButtonSettingValue(context) == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
}
|
||||
|
||||
private PowerMenuSettingsUtils() {
|
||||
}
|
||||
}
|
@@ -20,11 +20,9 @@ import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
@@ -37,8 +35,6 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||
private final int mTextEndId;
|
||||
private final int mTickMarkId;
|
||||
private OnPreferenceChangeListener mStopListener;
|
||||
@Nullable
|
||||
private CharSequence mSummary;
|
||||
|
||||
public LabeledSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
@@ -56,7 +52,6 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||
R.string.summary_placeholder);
|
||||
mTickMarkId = styledAttrs.getResourceId(
|
||||
R.styleable.LabeledSeekBarPreference_tickMark, /* defValue= */ 0);
|
||||
mSummary = styledAttrs.getText(R.styleable.Preference_android_summary);
|
||||
styledAttrs.recycle();
|
||||
}
|
||||
|
||||
@@ -81,15 +76,6 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||
com.android.internal.R.id.seekbar);
|
||||
seekBar.setTickMark(tickMark);
|
||||
}
|
||||
|
||||
final TextView summary = (TextView) holder.findViewById(android.R.id.summary);
|
||||
if (mSummary != null) {
|
||||
summary.setText(mSummary);
|
||||
summary.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
summary.setText(null);
|
||||
summary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnPreferenceChangeStopListener(OnPreferenceChangeListener listener) {
|
||||
@@ -104,24 +90,5 @@ public class LabeledSeekBarPreference extends SeekBarPreference {
|
||||
mStopListener.onPreferenceChange(this, seekBar.getProgress());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(CharSequence summary) {
|
||||
super.setSummary(summary);
|
||||
mSummary = summary;
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSummary(int summaryResId) {
|
||||
super.setSummary(summaryResId);
|
||||
mSummary = getContext().getText(summaryResId);
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mSummary;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user