Merge "Adds haptic build-up during LPNH behind feature flag" into main

This commit is contained in:
Andreas Agvard authored and Android (Google) Code Review committed 2023-10-19 21:48:21 +00:00
commit 257f431da2
8 files changed
+144 -51

No files matched your search

@@ -24,6 +24,10 @@ import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static com.android.launcher3.LauncherPrefs.ALL_APPS_OVERVIEW_THRESHOLD;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_TIMEOUT_MS;
import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
@@ -118,9 +122,7 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
if (FeatureFlags.ENABLE_ALL_APPS_FROM_OVERVIEW.get()) {
addAllAppsFromOverviewCatergory();
}
if (FeatureFlags.CUSTOM_LPNH_THRESHOLDS.get()) {
addCustomLpnhCatergory();
}
addCustomLpnhCategory();
if (getActivity() != null) {
getActivity().setTitle("Developer Options");
@@ -423,13 +425,25 @@ public class DeveloperOptionsFragment extends PreferenceFragmentCompat {
105, 500, 100, ALL_APPS_OVERVIEW_THRESHOLD));
}
private void addCustomLpnhCatergory() {
private void addCustomLpnhCategory() {
PreferenceCategory category = newCategory("Long Press Nav Handle Config");
category.addPreference(createSeekBarPreference("Slop multiplier (applied to edge slop, "
+ "which is generally already 50% higher than touch slop)",
25, 200, 100, LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE));
category.addPreference(createSeekBarPreference("Trigger milliseconds",
100, 500, 1, LONG_PRESS_NAV_HANDLE_TIMEOUT_MS));
if (FeatureFlags.CUSTOM_LPNH_THRESHOLDS.get()) {
category.addPreference(createSeekBarPreference("Slop multiplier (applied to edge slop, "
+ "which is generally already 50% higher than touch slop)",
25, 200, 100, LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE));
category.addPreference(createSeekBarPreference("Trigger milliseconds",
100, 500, 1, LONG_PRESS_NAV_HANDLE_TIMEOUT_MS));
}
if (FeatureFlags.ENABLE_SEARCH_HAPTIC_HINT.get()) {
category.addPreference(createSeekBarPreference("Haptic hint start scale",
0, 100, 100, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT));
category.addPreference(createSeekBarPreference("Haptic hint end scale",
0, 100, 100, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT));
category.addPreference(createSeekBarPreference("Haptic hint scale exponent",
1, 5, 1, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT));
category.addPreference(createSeekBarPreference("Haptic hint iterations (12 ms each)",
0, 100, 1, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS));
}
}
/**
@@ -46,4 +46,19 @@ public class NavHandleLongPressHandler implements ResourceBasedOverride {
public @Nullable Runnable getLongPressRunnable() {
return null;
}
/**
* Called when nav handle gesture starts. Returns true if long press nav handle is enabled and
* supported.
*/
public boolean canStartTouch() {
return false;
}
/**
* Called when nav handle gesture is finished by the user lifting their finger or the system
* cancelling the touch for some other reason.
*/
public void onTouchFinished() {
}
}
@@ -80,7 +80,8 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
mCurrentDownEvent.recycle();
}
mCurrentDownEvent = MotionEvent.obtain(ev);
if (isInNavBarHorizontalArea(ev.getRawX())) {
if (isInNavBarHorizontalArea(ev.getRawX())
&& mNavHandleLongPressHandler.canStartTouch()) {
MAIN_EXECUTOR.getHandler().postDelayed(mTriggerLongPress,
mLongPressTimeout);
}
@@ -133,6 +134,7 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
private void cancelLongPress() {
MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
mNavHandleLongPressHandler.onTouchFinished();
}
private boolean isInNavBarHorizontalArea(float x) {
@@ -64,12 +64,6 @@ import com.android.launcher3.widget.custom.CustomWidgetManager;
public class LauncherAppState implements SafeCloseable {
public static final String ACTION_FORCE_ROLOAD = "force-reload-launcher";
public static final String KEY_ICON_STATE = "pref_icon_shape_path";
public static final String KEY_ALL_APPS_OVERVIEW_THRESHOLD = "pref_all_apps_overview_threshold";
public static final String KEY_LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE =
"pref_long_press_nav_handle_slop_multiplier";
public static final String KEY_LONG_PRESS_NAV_HANDLE_TIMEOUT_MS =
"pref_long_press_nav_handle_timeout_ms";
// We do not need any synchronization for this variable as its only written on UI thread.
public static final MainThreadInitializedObject<LauncherAppState> INSTANCE =
+40 -12
View File
@@ -297,31 +297,59 @@ class LauncherPrefs(private val encryptedContext: Context) {
@JvmField
val ICON_STATE =
nonRestorableItem(
LauncherAppState.KEY_ICON_STATE,
"pref_icon_shape_path",
"",
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val ALL_APPS_OVERVIEW_THRESHOLD =
nonRestorableItem(
LauncherAppState.KEY_ALL_APPS_OVERVIEW_THRESHOLD,
"pref_all_apps_overview_threshold",
180,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE =
nonRestorableItem(
LauncherAppState.KEY_LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE,
100,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
nonRestorableItem(
"pref_long_press_nav_handle_slop_multiplier",
100,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_TIMEOUT_MS =
nonRestorableItem(
LauncherAppState.KEY_LONG_PRESS_NAV_HANDLE_TIMEOUT_MS,
ViewConfiguration.getLongPressTimeout(),
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
nonRestorableItem(
"pref_long_press_nav_handle_timeout_ms",
ViewConfiguration.getLongPressTimeout(),
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT =
nonRestorableItem(
"pref_long_press_nav_handle_haptic_hint_start_scale_percent",
0,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT =
nonRestorableItem(
"pref_long_press_nav_handle_haptic_hint_end_scale_percent",
50,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT =
nonRestorableItem(
"pref_long_press_nav_handle_haptic_hint_scale_exponent",
2,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS =
nonRestorableItem(
"pref_long_press_nav_handle_haptic_hint_iterations",
40,
EncryptionType.MOVE_TO_DEVICE_PROTECTED
)
@JvmField
val THEMED_ICONS =
backedUpItem(Themes.KEY_THEMED_ICONS, false, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
@@ -373,7 +373,9 @@ public class AllAppsTransitionController
new VibrationAnimatorUpdateListener(this, mVibratorWrapper,
0, SWIPE_DRAG_COMMIT_THRESHOLD));
}
builder.addEndListener(mVibratorWrapper::cancelVibrate);
builder.addEndListener((unused) -> {
mVibratorWrapper.cancelVibrate();
});
}
float targetProgress = toState.getVerticalProgress(mLauncher);
@@ -262,6 +262,10 @@ public final class FeatureFlags {
getReleaseFlag(282993230, "ENABLE_LONG_PRESS_NAV_HANDLE", TEAMFOOD,
"Enables long pressing on the bottom bar nav handle to trigger events.");
public static final BooleanFlag ENABLE_SEARCH_HAPTIC_HINT =
getReleaseFlag(303023676, "ENABLE_SEARCH_HAPTIC_HINT", TEAMFOOD,
"Enables haptic hint when long pressing on the bottom bar nav handle.");
// TODO(Block 17): Clean up flags
public static final BooleanFlag ENABLE_TASKBAR_PINNING = getDebugFlag(270396583,
"ENABLE_TASKBAR_PINNING", DISABLED,
@@ -18,6 +18,10 @@ package com.android.launcher3.util;
import static android.os.VibrationEffect.createPredefined;
import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT;
import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
@@ -35,10 +39,9 @@ import android.provider.Settings;
import androidx.annotation.Nullable;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PendingAnimation;
import java.util.function.Consumer;
import com.android.launcher3.config.FeatureFlags;
/**
* Wrapper around {@link Vibrator} to easily perform haptic feedback where necessary.
@@ -70,7 +73,7 @@ public class VibratorWrapper {
private final VibrationEffect mBumpEffect;
@Nullable
private final VibrationEffect mAssistEffect;
private final VibrationEffect mSearchEffect;
private long mLastDragTime;
private final int mThresholdUntilNextDragCallMillis;
@@ -80,12 +83,14 @@ public class VibratorWrapper {
*/
public static final VibrationEffect OVERVIEW_HAPTIC = EFFECT_CLICK;
private final Context mContext;
private final Vibrator mVibrator;
private final boolean mHasVibrator;
private boolean mIsHapticFeedbackEnabled;
private VibratorWrapper(Context context) {
mContext = context;
mVibrator = context.getSystemService(Vibrator.class);
mHasVibrator = mVibrator.hasVibrator();
if (mHasVibrator) {
@@ -133,14 +138,20 @@ public class VibratorWrapper {
if (Utilities.ATLEAST_R && mVibrator.areAllPrimitivesSupported(
VibrationEffect.Composition.PRIMITIVE_QUICK_RISE,
VibrationEffect.Composition.PRIMITIVE_TICK)) {
// quiet ramp, short pause, then sharp tick
mAssistEffect = VibrationEffect.startComposition()
.addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.25f)
.addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1f, 50)
.compose();
if (FeatureFlags.ENABLE_SEARCH_HAPTIC_HINT.get()) {
mSearchEffect = VibrationEffect.startComposition()
.addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1f)
.compose();
} else {
// quiet ramp, short pause, then sharp tick
mSearchEffect = VibrationEffect.startComposition()
.addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.25f)
.addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, 1f, 50)
.compose();
}
} else {
// fallback for devices without composition support
mAssistEffect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK);
mSearchEffect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK);
}
}
@@ -183,21 +194,11 @@ public class VibratorWrapper {
}
}
/**
* The assist haptic is used to be called when an assistant is invoked
*/
public void vibrateForAssist() {
if (mAssistEffect != null) {
vibrate(mAssistEffect);
}
}
/**
* This should be used to cancel a haptic in case where the haptic shouldn't be vibrating. For
* example, when no animation is happening but a vibrator happens to be vibrating still. Need
* boolean parameter for {@link PendingAnimation#addEndListener(Consumer)}.
* example, when no animation is happening but a vibrator happens to be vibrating still.
*/
public void cancelVibrate(boolean unused) {
public void cancelVibrate() {
UI_HELPER_EXECUTOR.execute(mVibrator::cancel);
// reset dragTexture timestamp to be able to play dragTexture again whenever cancelled
mLastDragTime = 0;
@@ -233,4 +234,37 @@ public class VibratorWrapper {
});
}
}
/** Indicates that search has been invoked. */
public void vibrateForSearch() {
if (mSearchEffect != null) {
vibrate(mSearchEffect);
}
}
/** Indicates that search will be invoked if the current gesture is maintained. */
public void vibrateForSearchHint() {
if (FeatureFlags.ENABLE_SEARCH_HAPTIC_HINT.get() && Utilities.ATLEAST_S
&& mVibrator.areAllPrimitivesSupported(
VibrationEffect.Composition.PRIMITIVE_LOW_TICK)) {
float startScale = LauncherPrefs.get(mContext).get(
LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT) / 100f;
float endScale = LauncherPrefs.get(mContext).get(
LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT) / 100f;
int scaleExponent = LauncherPrefs.get(mContext).get(
LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT);
int iterations = LauncherPrefs.get(mContext).get(
LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS);
VibrationEffect.Composition composition = VibrationEffect.startComposition();
for (int i = 0; i < iterations; i++) {
float t = i / (iterations - 1f);
float scale = (float) Math.pow((1 - t) * startScale + t * endScale,
scaleExponent);
composition.addPrimitive(VibrationEffect.Composition.PRIMITIVE_LOW_TICK, scale);
}
vibrate(composition.compose());
}
}
}