Merge "Add haptic feedback to Launcher recent apps scrolling" into sc-dev am: b1858afaf2 am: 9abd4fd726
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14678275 Change-Id: I1d44780c57cf6a93b84fd232485c306898edcba4
This commit is contained in:
@@ -75,6 +75,7 @@ import android.graphics.Typeface;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.os.VibrationEffect;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.StaticLayout;
|
import android.text.StaticLayout;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
@@ -131,6 +132,7 @@ import com.android.launcher3.util.SplitConfigurationOptions;
|
|||||||
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
|
import com.android.launcher3.util.SplitConfigurationOptions.SplitPositionOption;
|
||||||
import com.android.launcher3.util.Themes;
|
import com.android.launcher3.util.Themes;
|
||||||
import com.android.launcher3.util.TranslateEdgeEffect;
|
import com.android.launcher3.util.TranslateEdgeEffect;
|
||||||
|
import com.android.launcher3.util.VibratorWrapper;
|
||||||
import com.android.launcher3.util.ViewPool;
|
import com.android.launcher3.util.ViewPool;
|
||||||
import com.android.quickstep.AnimatedFloat;
|
import com.android.quickstep.AnimatedFloat;
|
||||||
import com.android.quickstep.BaseActivityInterface;
|
import com.android.quickstep.BaseActivityInterface;
|
||||||
@@ -342,6 +344,17 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
|
|||||||
private static final float ADDITIONAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET = 0.05f;
|
private static final float ADDITIONAL_DISMISS_TRANSLATION_INTERPOLATION_OFFSET = 0.05f;
|
||||||
private static final float ANIMATION_DISMISS_PROGRESS_MIDPOINT = 0.5f;
|
private static final float ANIMATION_DISMISS_PROGRESS_MIDPOINT = 0.5f;
|
||||||
|
|
||||||
|
private static final int SNAP_TO_PAGE_VIBRATION_PRIMITIVE =
|
||||||
|
Utilities.ATLEAST_S ? VibrationEffect.Composition.PRIMITIVE_LOW_TICK : -1;
|
||||||
|
private static final float SNAP_TO_PAGE_VIBRATION_PRIMITIVE_SCALE = 0.4f;
|
||||||
|
private static final VibrationEffect SNAP_TO_PAGE_VIBRATION_FALLBACK =
|
||||||
|
VibrationEffect.createPredefined(VibrationEffect.EFFECT_TEXTURE_TICK);
|
||||||
|
private static final int EDGE_IMPACT_VIBRATION_PRIMITIVE =
|
||||||
|
Utilities.ATLEAST_R ? VibrationEffect.Composition.PRIMITIVE_TICK : -1;
|
||||||
|
private static final float EDGE_IMPACT_VIBRATION_PRIMITIVE_SCALE = 0.8f;
|
||||||
|
private static final VibrationEffect EDGE_IMPACT_VIBRATION_FALLBACK =
|
||||||
|
VibrationEffect.createPredefined(VibrationEffect.EFFECT_TICK);
|
||||||
|
|
||||||
protected final RecentsOrientedState mOrientationState;
|
protected final RecentsOrientedState mOrientationState;
|
||||||
protected final BaseActivityInterface<STATE_TYPE, ACTIVITY_TYPE> mSizeStrategy;
|
protected final BaseActivityInterface<STATE_TYPE, ACTIVITY_TYPE> mSizeStrategy;
|
||||||
protected RecentsAnimationController mRecentsAnimationController;
|
protected RecentsAnimationController mRecentsAnimationController;
|
||||||
@@ -966,6 +979,8 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
|
|||||||
@Override
|
@Override
|
||||||
protected void onPageEndTransition() {
|
protected void onPageEndTransition() {
|
||||||
super.onPageEndTransition();
|
super.onPageEndTransition();
|
||||||
|
VibratorWrapper.INSTANCE.get(mContext).vibrate(SNAP_TO_PAGE_VIBRATION_PRIMITIVE,
|
||||||
|
SNAP_TO_PAGE_VIBRATION_PRIMITIVE_SCALE, SNAP_TO_PAGE_VIBRATION_FALLBACK);
|
||||||
if (isClearAllHidden()) {
|
if (isClearAllHidden()) {
|
||||||
mActionsView.updateDisabledFlags(OverviewActionsView.DISABLED_SCROLLING, false);
|
mActionsView.updateDisabledFlags(OverviewActionsView.DISABLED_SCROLLING, false);
|
||||||
}
|
}
|
||||||
@@ -1068,6 +1083,13 @@ public abstract class RecentsView<ACTIVITY_TYPE extends StatefulActivity<STATE_T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onEdgeAbsorbingScroll() {
|
||||||
|
super.onEdgeAbsorbingScroll();
|
||||||
|
VibratorWrapper.INSTANCE.get(mContext).vibrate(EDGE_IMPACT_VIBRATION_PRIMITIVE,
|
||||||
|
EDGE_IMPACT_VIBRATION_PRIMITIVE_SCALE, EDGE_IMPACT_VIBRATION_FALLBACK);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void determineScrollingStart(MotionEvent ev, float touchSlopScale) {
|
protected void determineScrollingStart(MotionEvent ev, float touchSlopScale) {
|
||||||
// Enables swiping to the left or right only if the task overlay is not modal.
|
// Enables swiping to the left or right only if the task overlay is not modal.
|
||||||
|
|||||||
@@ -506,9 +506,11 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
|
|||||||
if (newPos < mMinScroll && oldPos >= mMinScroll) {
|
if (newPos < mMinScroll && oldPos >= mMinScroll) {
|
||||||
mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity());
|
mEdgeGlowLeft.onAbsorb((int) mScroller.getCurrVelocity());
|
||||||
mScroller.abortAnimation();
|
mScroller.abortAnimation();
|
||||||
|
onEdgeAbsorbingScroll();
|
||||||
} else if (newPos > mMaxScroll && oldPos <= mMaxScroll) {
|
} else if (newPos > mMaxScroll && oldPos <= mMaxScroll) {
|
||||||
mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity());
|
mEdgeGlowRight.onAbsorb((int) mScroller.getCurrVelocity());
|
||||||
mScroller.abortAnimation();
|
mScroller.abortAnimation();
|
||||||
|
onEdgeAbsorbingScroll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1359,6 +1361,13 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
|
|||||||
|
|
||||||
protected void onNotSnappingToPageInFreeScroll() { }
|
protected void onNotSnappingToPageInFreeScroll() { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the view edges absorb part of the scroll. Subclasses can override this
|
||||||
|
* to provide custom behavior during animation.
|
||||||
|
*/
|
||||||
|
protected void onEdgeAbsorbingScroll() {
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean shouldFlingForVelocity(int velocity) {
|
protected boolean shouldFlingForVelocity(int velocity) {
|
||||||
float threshold = mAllowEasyFling ? mEasyFlingThresholdVelocity : mFlingThresholdVelocity;
|
float threshold = mAllowEasyFling ? mEasyFlingThresholdVelocity : mFlingThresholdVelocity;
|
||||||
return Math.abs(velocity) > threshold;
|
return Math.abs(velocity) > threshold;
|
||||||
|
|||||||
@@ -21,15 +21,19 @@ import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;
|
|||||||
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
|
||||||
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.media.AudioAttributes;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.launcher3.Utilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper around {@link Vibrator} to easily perform haptic feedback where necessary.
|
* Wrapper around {@link Vibrator} to easily perform haptic feedback where necessary.
|
||||||
*/
|
*/
|
||||||
@@ -39,6 +43,11 @@ public class VibratorWrapper {
|
|||||||
public static final MainThreadInitializedObject<VibratorWrapper> INSTANCE =
|
public static final MainThreadInitializedObject<VibratorWrapper> INSTANCE =
|
||||||
new MainThreadInitializedObject<>(VibratorWrapper::new);
|
new MainThreadInitializedObject<>(VibratorWrapper::new);
|
||||||
|
|
||||||
|
public static final AudioAttributes VIBRATION_ATTRS = new AudioAttributes.Builder()
|
||||||
|
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
|
||||||
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||||
|
.build();
|
||||||
|
|
||||||
public static final VibrationEffect EFFECT_CLICK =
|
public static final VibrationEffect EFFECT_CLICK =
|
||||||
createPredefined(VibrationEffect.EFFECT_CLICK);
|
createPredefined(VibrationEffect.EFFECT_CLICK);
|
||||||
|
|
||||||
@@ -81,4 +90,24 @@ public class VibratorWrapper {
|
|||||||
UI_HELPER_EXECUTOR.execute(() -> mVibrator.vibrate(vibrationEffect));
|
UI_HELPER_EXECUTOR.execute(() -> mVibrator.vibrate(vibrationEffect));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vibrates with a single primitive, if supported, or use a fallback effect instead. This only
|
||||||
|
* vibrates if haptic feedback is available and enabled.
|
||||||
|
*/
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
public void vibrate(int primitiveId, float primitiveScale, VibrationEffect fallbackEffect) {
|
||||||
|
if (mHasVibrator && mIsHapticFeedbackEnabled) {
|
||||||
|
UI_HELPER_EXECUTOR.execute(() -> {
|
||||||
|
if (Utilities.ATLEAST_R && primitiveId >= 0
|
||||||
|
&& mVibrator.areAllPrimitivesSupported(primitiveId)) {
|
||||||
|
mVibrator.vibrate(VibrationEffect.startComposition()
|
||||||
|
.addPrimitive(primitiveId, primitiveScale)
|
||||||
|
.compose(), VIBRATION_ATTRS);
|
||||||
|
} else {
|
||||||
|
mVibrator.vibrate(fallbackEffect, VIBRATION_ATTRS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user