Merge "Revert "Revert "Add sensitivity configuration to long press power dialog""" into sc-qpr1-dev am: 8351a9a504
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15640673 Change-Id: Ib92603ae0210aaa025f722d0d734b11e6030386c
This commit is contained in:
@@ -37,9 +37,18 @@
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?android:attr/textColorSecondary" />
|
||||
|
||||
<SeekBar
|
||||
android:id="@*android:id/seekbar"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_below="@android:id/summary"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
|
@@ -13225,6 +13225,15 @@
|
||||
<!-- Power menu explanation where to find prevent ringing option. [CHAR LIMIT=NONE] -->
|
||||
<string name="power_menu_power_prevent_ringing_hint">Prevent ringing:\nShortcut available in the volume menu.</string>
|
||||
|
||||
<!-- Power menu title of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
|
||||
<string name="power_menu_long_press_for_assist_sensitivity_title">Press & hold duration</string>
|
||||
<!-- Power menu summary of the seekbar setting controlling duration of how long the power button must be held to invoke assistant. [CHAR LIMIT=NONE]-->
|
||||
<string name="power_menu_long_press_for_assist_sensitivity_summary">Adjust sensitivity by choosing how long to press & hold the power button</string>
|
||||
<!-- Label at the lowest end of duration slider for long press power invocation of assistant. [CHAR LIMIT=30] -->
|
||||
<string name="power_menu_long_press_for_assist_sensitivity_low_label">Short</string>
|
||||
<!-- Label at the highest end of duration slider for long press power invocation of assistant. [CHAR LIMIT=30] -->
|
||||
<string name="power_menu_long_press_for_assist_sensitivity_high_label">Long</string>
|
||||
|
||||
<!-- Wallet (formerly Cards and passes) toggle name [CHAR LIMIT=60] -->
|
||||
<string name="lockscreen_privacy_wallet_setting_toggle">Show wallet</string>
|
||||
<!-- Wallet (formerly Cards and passes) summary [CHAR LIMIT=NONE] -->
|
||||
|
@@ -22,11 +22,21 @@
|
||||
android:title="@string/power_menu_long_press_for_assist"
|
||||
android:summary="@string/power_menu_long_press_for_assist_summary"
|
||||
settings:controller="com.android.settings.gestures.LongPressPowerButtonPreferenceController"
|
||||
/>
|
||||
/>
|
||||
|
||||
<com.android.settings.widget.LabeledSeekBarPreference
|
||||
android:key="gesture_power_menu_long_press_for_assist_sensitivity"
|
||||
android:title="@string/power_menu_long_press_for_assist_sensitivity_title"
|
||||
android:summary="@string/power_menu_long_press_for_assist_sensitivity_summary"
|
||||
android:selectable="true"
|
||||
settings:textStart="@string/power_menu_long_press_for_assist_sensitivity_low_label"
|
||||
settings:textEnd="@string/power_menu_long_press_for_assist_sensitivity_high_label"
|
||||
settings:controller="com.android.settings.gestures.LongPressPowerSensitivityPreferenceController"
|
||||
/>
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="power_menu_power_volume_up_hint"
|
||||
android:title="@string/power_menu_power_volume_up_hint"
|
||||
android:selectable="false"
|
||||
settings:searchable="false" />
|
||||
settings:searchable="false"/>
|
||||
</PreferenceScreen>
|
||||
|
@@ -16,6 +16,11 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -33,27 +38,12 @@ 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.
|
||||
*
|
||||
@@ -67,15 +57,6 @@ 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;
|
||||
|
||||
@@ -101,7 +82,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final int powerButtonValue = getPowerButtonValue();
|
||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext);
|
||||
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) {
|
||||
@@ -122,7 +103,7 @@ public class LongPressPowerButtonPreferenceController extends TogglePreferenceCo
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return getPowerButtonValue() == LONG_PRESS_POWER_ASSISTANT_VALUE;
|
||||
return PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,12 +140,6 @@ 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,
|
||||
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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,30 +16,23 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
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 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 = getPowerButtonLongPressValue(mContext);
|
||||
final int powerButtonValue = PowerMenuSettingsUtils.getPowerButtonSettingValue(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) {
|
||||
@@ -60,11 +53,4 @@ 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));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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,9 +20,11 @@ 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;
|
||||
|
||||
@@ -35,6 +37,8 @@ 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) {
|
||||
@@ -52,6 +56,7 @@ 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();
|
||||
}
|
||||
|
||||
@@ -76,6 +81,15 @@ 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) {
|
||||
@@ -90,5 +104,24 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -24,9 +26,12 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.widget.LabeledSeekBarPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -41,7 +46,9 @@ import org.robolectric.RuntimeEnvironment;
|
||||
public class LabeledSeekBarPreferenceTest {
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceViewHolder mViewHolder;
|
||||
private SeekBar mSeekBar;
|
||||
private TextView mSummary;
|
||||
private LabeledSeekBarPreference mSeekBarPreference;
|
||||
|
||||
@Mock
|
||||
@@ -57,7 +64,9 @@ public class LabeledSeekBarPreferenceTest {
|
||||
final View view =
|
||||
inflater.inflate(mSeekBarPreference.getLayoutResource(),
|
||||
new LinearLayout(mContext), false);
|
||||
mSeekBar = view.findViewById(com.android.internal.R.id.seekbar);
|
||||
mViewHolder = PreferenceViewHolder.createInstanceForTests(view);
|
||||
mSeekBar = (SeekBar) mViewHolder.findViewById(R.id.seekbar);
|
||||
mSummary = (TextView) mViewHolder.findViewById(R.id.summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,4 +78,23 @@ public class LabeledSeekBarPreferenceTest {
|
||||
|
||||
verify(mListener, times(1)).onPreferenceChange(mSeekBarPreference, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekBarPreferenceSummarySet_returnsValue() {
|
||||
final String summary = "this is a summary";
|
||||
mSeekBarPreference.setSummary(summary);
|
||||
mSeekBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
assertThat(mSeekBarPreference.getSummary()).isEqualTo(summary);
|
||||
assertThat(mSummary.getText()).isEqualTo(summary);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void seekBarPreferenceSummaryNull_hidesView() {
|
||||
mSeekBarPreference.setSummary(null);
|
||||
mSeekBarPreference.onBindViewHolder(mViewHolder);
|
||||
|
||||
assertThat(mSummary.getText()).isEqualTo("");
|
||||
assertThat(mSummary.getVisibility()).isEqualTo(View.GONE);
|
||||
}
|
||||
}
|
||||
|
@@ -137,7 +137,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_keyChordPowerVolumeUp))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
|
||||
verify(mController.mFooterHint).setVisible(false);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class LongPressPowerButtonPreferenceControllerTest {
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_GLOBAL_ACTIONS);
|
||||
@@ -162,19 +162,19 @@ public class LongPressPowerButtonPreferenceControllerTest {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
verify(mController.mAssistSwitch).setSummary(
|
||||
getString(
|
||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
||||
R.string.power_menu_summary_long_press_for_assist_disabled_with_power_menu));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,13 +203,13 @@ public class LongPressPowerButtonPreferenceControllerTest {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
|
||||
mController.onPreferenceChange(null, false);
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_GLOBAL_ACTIONS);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.KEY_CHORD_POWER_VOLUME_UP, -1)).isEqualTo(
|
||||
LongPressPowerButtonPreferenceController.KEY_CHORD_POWER_VOLUME_UP_NO_ACTION);
|
||||
|
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LongPressPowerSensitivityPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_LONG_PRESS_SENSITIVITY =
|
||||
"gesture_power_menu_long_press_for_assist_sensitivity";
|
||||
|
||||
private static final int[] SENSITIVITY_VALUES = {250, 350, 500, 750, 850};
|
||||
|
||||
private Application mContext;
|
||||
private Resources mResources;
|
||||
private LongPressPowerSensitivityPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(SENSITIVITY_VALUES);
|
||||
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliderPosition_returnsDefaultValue() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerDurationMs))
|
||||
.thenReturn(750);
|
||||
assertThat(mController.getSliderPosition()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSliderPosition_returnsSetValue() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 350);
|
||||
assertThat(mController.getSliderPosition()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSliderPosition_setsValue() {
|
||||
mController.setSliderPosition(4);
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS_DURATION_MS, 0)).isEqualTo(850);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSliderPositionOutOfBounds_returnsFalse() {
|
||||
assertThat(mController.setSliderPosition(-1)).isFalse();
|
||||
assertThat(mController.setSliderPosition(10)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMin_isZero() {
|
||||
assertThat(mController.getMin()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMax_isEqualToLastValueIndex() {
|
||||
assertThat(mController.getMax()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressForAssistEnabled_isAvailable() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_ASSISTANT_VALUE);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressForAssistDisabled_isNotAvailableDueToDependentSetting() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS,
|
||||
PowerMenuSettingsUtils.LONG_PRESS_POWER_NO_ACTION);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitivityValuesAreNull_notAvailable() {
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(null);
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensitivityValuesArrayTooShort_notAvailable() {
|
||||
when(mResources.getIntArray(
|
||||
com.android.internal.R.array.config_longPressOnPowerDurationSettings))
|
||||
.thenReturn(new int[]{200});
|
||||
mController = new LongPressPowerSensitivityPreferenceController(mContext,
|
||||
KEY_LONG_PRESS_SENSITIVITY);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
LongPressPowerSensitivityPreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PowerMenuSettingsUtilsTest {
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValuePresent_returnsValue() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(0);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 1);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueNotPresent_returnsDefault() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(2);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.getPowerButtonSettingValue(mContext)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueSetToAssistant_isAssistEnabledReturnsTrue() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 5);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourValueNotSetToAssistant_isAssistEnabledReturnsFalse() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.POWER_BUTTON_LONG_PRESS, 3);
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void longPressBehaviourDefaultSetToAssistant_isAssistEnabledReturnsFalse() {
|
||||
when(mResources.getInteger(
|
||||
com.android.internal.R.integer.config_longPressOnPowerBehavior))
|
||||
.thenReturn(3);
|
||||
|
||||
assertThat(PowerMenuSettingsUtils.isLongPressPowerForAssistEnabled(mContext)).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user