Merging from ub-launcher3-rvc-qpr-dev @ build 6809704

Bug:150504032
Test: manual, presubmit on the source branch
x20/teams/android-launcher/merge/ub-launcher3-rvc-qpr-dev_rvc-qpr-dev_6809704.html

Change-Id: I870f8ec233dfae0c9c857ebb050217879f83ba65
Merged-In: Ib9d52ba333f2982d2420cab42a0935e8e8a303b3
This commit is contained in:
vadimt
2020-09-02 15:52:59 -07:00
committed by Vadim Tryshev
6 changed files with 151 additions and 51 deletions
@@ -19,7 +19,6 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL_APPS_EDU;
import static com.android.launcher3.LauncherState.ALL_APPS;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.LauncherState.OVERVIEW;
import static com.android.launcher3.allapps.AllAppsTransitionController.ALL_APPS_PROGRESS;
import static com.android.launcher3.anim.Interpolators.DEACCEL_3;
import static com.android.launcher3.config.FeatureFlags.ENABLE_ALL_APPS_EDU;
@@ -222,7 +221,7 @@ public class NavBarToHomeTouchController implements TouchController,
recentsView.switchToScreenshot(null,
() -> recentsView.finishRecentsAnimation(true /* toRecents */, null));
}
if (mStartState == OVERVIEW) {
if (mStartState.overviewUi) {
new OverviewToHomeAnim(mLauncher, () -> onSwipeInteractionCompleted(mEndState))
.animateWithVelocity(velocity);
} else {
@@ -22,6 +22,7 @@ import static com.android.launcher3.anim.Interpolators.FINAL_FRAME;
import static com.android.launcher3.anim.Interpolators.INSTANT;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_COMPONENTS;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_ACTIONS_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y;
@@ -106,10 +107,16 @@ public class OverviewToHomeAnim {
// StaggeredWorkspaceAnim doesn't animate overview, so we handle it here.
? PLAY_ATOMIC_OVERVIEW_PEEK
: ANIM_ALL_COMPONENTS;
config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, DEACCEL);
boolean isLayoutNaturalToLauncher = recentsView.getPagedOrientationHandler()
.isLayoutNaturalToLauncher();
config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_X, isLayoutNaturalToLauncher
? DEACCEL : FINAL_FRAME);
config.setInterpolator(ANIM_OVERVIEW_TRANSLATE_Y, FINAL_FRAME);
config.setInterpolator(ANIM_OVERVIEW_SCALE, FINAL_FRAME);
config.setInterpolator(ANIM_OVERVIEW_ACTIONS_FADE, INSTANT);
if (!isLayoutNaturalToLauncher) {
config.setInterpolator(ANIM_OVERVIEW_FADE, DEACCEL);
}
AnimatorSet stateAnim = stateManager.createAtomicAnimation(
startState, NORMAL, config);
stateAnim.addListener(new AnimationSuccessListener() {
@@ -79,7 +79,6 @@ import android.view.HapticFeedbackConstants;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
@@ -700,12 +699,9 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
super.onTouchEvent(ev);
TaskView taskView = getCurrentPageTaskView();
if (taskView != null) {
TouchDelegate mChildTouchDelegate = taskView.getIconTouchDelegate(ev);
if (mChildTouchDelegate != null && mChildTouchDelegate.onTouchEvent(ev)) {
// Keep consuming events to pass to delegate
return true;
}
if (taskView != null && taskView.offerTouchToChildren(ev)) {
// Keep consuming events to pass to delegate
return true;
}
final int x = (int) ev.getX();
@@ -135,6 +135,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
* delegated bounds only to be updated.
*/
private TransformingTouchDelegate mIconTouchDelegate;
private TransformingTouchDelegate mChipTouchDelegate;
private static final List<Rect> SYSTEM_GESTURE_EXCLUSION_RECT =
Collections.singletonList(new Rect());
@@ -200,6 +201,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
private View mContextualChipWrapper;
private View mContextualChip;
private final float[] mIconCenterCoords = new float[2];
private final float[] mChipCenterCoords = new float[2];
public TaskView(Context context) {
this(context, null);
@@ -263,11 +265,22 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
mIconTouchDelegate = new TransformingTouchDelegate(mIconView);
}
public TouchDelegate getIconTouchDelegate(MotionEvent event) {
/**
* Whether the taskview should take the touch event from parent. Events passed to children
* that might require special handling.
*/
public boolean offerTouchToChildren(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
computeAndSetIconTouchDelegate();
computeAndSetChipTouchDelegate();
}
return mIconTouchDelegate;
if (mIconTouchDelegate != null && mIconTouchDelegate.onTouchEvent(event)) {
return true;
}
if (mChipTouchDelegate != null && mChipTouchDelegate.onTouchEvent(event)) {
return true;
}
return false;
}
private void computeAndSetIconTouchDelegate() {
@@ -282,6 +295,23 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
(int) (mIconCenterCoords[1] + iconHalfSize));
}
private void computeAndSetChipTouchDelegate() {
if (mContextualChipWrapper != null) {
float chipHalfWidth = mContextualChipWrapper.getWidth() / 2f;
float chipHalfHeight = mContextualChipWrapper.getHeight() / 2f;
mChipCenterCoords[0] = chipHalfWidth;
mChipCenterCoords[1] = chipHalfHeight;
getDescendantCoordRelativeToAncestor(mContextualChipWrapper, mActivity.getDragLayer(),
mChipCenterCoords,
false);
mChipTouchDelegate.setBounds(
(int) (mChipCenterCoords[0] - chipHalfWidth),
(int) (mChipCenterCoords[1] - chipHalfHeight),
(int) (mChipCenterCoords[0] + chipHalfWidth),
(int) (mChipCenterCoords[1] + chipHalfHeight));
}
}
/**
* The modalness of this view is how it should be displayed when it is shown on its own in the
* modal state of overview.
@@ -289,6 +319,9 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
* @param modalness [0, 1] 0 being in context with other tasks, 1 being shown on its own.
*/
public void setModalness(float modalness) {
if (mModalness == modalness) {
return;
}
mModalness = modalness;
mIconView.setAlpha(comp(modalness));
if (mContextualChip != null) {
@@ -298,7 +331,6 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
if (mContextualChipWrapper != null) {
mContextualChipWrapper.setAlpha(comp(modalness));
}
updateFooterVerticalOffset(mFooterVerticalOffset);
}
@@ -546,7 +578,11 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
.getInterpolation(progress);
mIconView.setScaleX(scale);
mIconView.setScaleY(scale);
if (mContextualChip != null && mContextualChipWrapper != null) {
mContextualChipWrapper.setAlpha(scale);
mContextualChip.setScaleX(scale);
mContextualChip.setScaleY(scale);
}
updateFooterVerticalOffset(1.0f - scale);
}
@@ -725,6 +761,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
mContextualChip.animate().scaleX(1f).scaleY(1f).setDuration(50);
}
if (mContextualChipWrapper != null) {
mChipTouchDelegate = new TransformingTouchDelegate(mContextualChipWrapper);
mContextualChipWrapper.animate().alpha(1f).setDuration(50);
}
}
@@ -746,6 +783,7 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
View oldContextualChipWrapper = mContextualChipWrapper;
mContextualChipWrapper = null;
mContextualChip = null;
mChipTouchDelegate = null;
return oldContextualChipWrapper;
}
@@ -31,11 +31,12 @@ import android.util.FloatProperty;
import androidx.annotation.Nullable;
import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Launcher;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.touch.PagedOrientationHandler;
import com.android.quickstep.LauncherActivityInterface;
import com.android.quickstep.SysUINavigationMode;
import com.android.quickstep.views.RecentsView;
@@ -54,11 +55,12 @@ public class AnimatorControllerWithResistance {
*/
public static final float TWO_BUTTON_EXTRA_DRAG_FACTOR = 0.25f;
private enum RecentsParams {
private enum RecentsResistanceParams {
FROM_APP(0.75f, 0.5f, 1f),
FROM_OVERVIEW(1f, 0.75f, 0.5f);
RecentsParams(float scaleStartResist, float scaleMaxResist, float translationFactor) {
RecentsResistanceParams(float scaleStartResist, float scaleMaxResist,
float translationFactor) {
this.scaleStartResist = scaleStartResist;
this.scaleMaxResist = scaleMaxResist;
this.translationFactor = translationFactor;
@@ -139,9 +141,9 @@ public class AnimatorControllerWithResistance {
FloatProperty<SCALE> scaleProperty, TRANSLATION translationTarget,
FloatProperty<TRANSLATION> translationProperty) {
PendingAnimation resistAnim = createRecentsResistanceAnim(null, context,
recentsOrientedState, dp, scaleTarget, scaleProperty, translationTarget,
translationProperty, RecentsParams.FROM_APP);
RecentsParams params = new RecentsParams(context, recentsOrientedState, dp, scaleTarget,
scaleProperty, translationTarget, translationProperty);
PendingAnimation resistAnim = createRecentsResistanceAnim(params);
AnimatorPlaybackController resistanceController = resistAnim.createPlaybackController();
return new AnimatorControllerWithResistance(normalController, resistanceController);
@@ -152,31 +154,30 @@ public class AnimatorControllerWithResistance {
* when starting from recents, i.e. {@link #createRecentsResistanceFromOverviewAnim}.
*/
public static <SCALE, TRANSLATION> PendingAnimation createRecentsResistanceAnim(
@Nullable PendingAnimation resistAnim, Context context,
RecentsOrientedState recentsOrientedState, DeviceProfile dp, SCALE scaleTarget,
FloatProperty<SCALE> scaleProperty, TRANSLATION translationTarget,
FloatProperty<TRANSLATION> translationProperty, RecentsParams params) {
RecentsParams<SCALE, TRANSLATION> params) {
Rect startRect = new Rect();
LauncherActivityInterface.INSTANCE.calculateTaskSize(context, dp, startRect,
recentsOrientedState.getOrientationHandler());
PagedOrientationHandler orientationHandler = params.recentsOrientedState
.getOrientationHandler();
LauncherActivityInterface.INSTANCE.calculateTaskSize(params.context, params.dp, startRect,
orientationHandler);
long distanceToCover = startRect.bottom;
boolean isTwoButtonMode = SysUINavigationMode.getMode(context) == TWO_BUTTONS;
boolean isTwoButtonMode = SysUINavigationMode.getMode(params.context) == TWO_BUTTONS;
if (isTwoButtonMode) {
// We can only drag a small distance past overview, not to the top of the screen.
distanceToCover = (long)
((dp.heightPx - startRect.bottom) * TWO_BUTTON_EXTRA_DRAG_FACTOR);
}
if (resistAnim == null) {
resistAnim = new PendingAnimation(distanceToCover * 2);
((params.dp.heightPx - startRect.bottom) * TWO_BUTTON_EXTRA_DRAG_FACTOR);
}
PendingAnimation resistAnim = params.resistAnim != null
? params.resistAnim
: new PendingAnimation(distanceToCover * 2);
PointF pivot = new PointF();
float fullscreenScale = recentsOrientedState.getFullScreenScaleAndPivot(
startRect, dp, pivot);
float startScale = 1;
float prevScaleRate = (fullscreenScale - startScale) / (dp.heightPx - startRect.bottom);
float fullscreenScale = params.recentsOrientedState.getFullScreenScaleAndPivot(
startRect, params.dp, pivot);
float prevScaleRate = (fullscreenScale - params.startScale)
/ (params.dp.heightPx - startRect.bottom);
// This is what the scale would be at the end of the drag if we didn't apply resistance.
float endScale = startScale - prevScaleRate * distanceToCover;
float endScale = params.startScale - prevScaleRate * distanceToCover;
final TimeInterpolator scaleInterpolator;
if (isTwoButtonMode) {
// We are bounded by the distance of the drag, so we don't need to apply resistance.
@@ -184,9 +185,10 @@ public class AnimatorControllerWithResistance {
} else {
// Create an interpolator that resists the scale so the scale doesn't get smaller than
// RECENTS_SCALE_MAX_RESIST.
float startResist = Utilities.getProgress(params.scaleStartResist , startScale,
endScale);
float maxResist = Utilities.getProgress(params.scaleMaxResist, startScale, endScale);
float startResist = Utilities.getProgress(params.resistanceParams.scaleStartResist,
params.startScale, endScale);
float maxResist = Utilities.getProgress(params.resistanceParams.scaleMaxResist,
params.startScale, endScale);
scaleInterpolator = t -> {
if (t < startResist) {
return t;
@@ -196,20 +198,22 @@ public class AnimatorControllerWithResistance {
return startResist + resistProgress * (maxResist - startResist);
};
}
resistAnim.addFloat(scaleTarget, scaleProperty, startScale, endScale,
resistAnim.addFloat(params.scaleTarget, params.scaleProperty, params.startScale, endScale,
scaleInterpolator);
if (!isTwoButtonMode) {
// Compute where the task view would be based on the end scale, if we didn't translate.
RectF endRectF = new RectF(startRect);
Matrix temp = new Matrix();
temp.setScale(params.scaleMaxResist, params.scaleMaxResist, pivot.x, pivot.y);
temp.setScale(params.resistanceParams.scaleMaxResist,
params.resistanceParams.scaleMaxResist, pivot.x, pivot.y);
temp.mapRect(endRectF);
// Translate such that the task view touches the top of the screen when drag does.
float endTranslation = endRectF.top * recentsOrientedState.getOrientationHandler()
.getSecondaryTranslationDirectionFactor() * params.translationFactor;
resistAnim.addFloat(translationTarget, translationProperty, 0, endTranslation,
RECENTS_TRANSLATE_RESIST_INTERPOLATOR);
float endTranslation = endRectF.top
* orientationHandler.getSecondaryTranslationDirectionFactor()
* params.resistanceParams.translationFactor;
resistAnim.addFloat(params.translationTarget, params.translationProperty,
params.startTranslation, endTranslation, RECENTS_TRANSLATE_RESIST_INTERPOLATOR);
}
return resistAnim;
@@ -220,11 +224,66 @@ public class AnimatorControllerWithResistance {
* a RecentsView interaction that started from the overview state.
*/
public static PendingAnimation createRecentsResistanceFromOverviewAnim(
BaseDraggingActivity activity, @Nullable PendingAnimation resistanceAnim) {
RecentsView recentsView = activity.getOverviewPanel();
return createRecentsResistanceAnim(resistanceAnim, activity,
recentsView.getPagedViewOrientedState(), activity.getDeviceProfile(),
recentsView, RECENTS_SCALE_PROPERTY, recentsView, TASK_SECONDARY_TRANSLATION,
RecentsParams.FROM_OVERVIEW);
Launcher launcher, @Nullable PendingAnimation resistanceAnim) {
RecentsView recentsView = launcher.getOverviewPanel();
RecentsParams params = new RecentsParams(launcher, recentsView.getPagedViewOrientedState(),
launcher.getDeviceProfile(), recentsView, RECENTS_SCALE_PROPERTY, recentsView,
TASK_SECONDARY_TRANSLATION)
.setResistAnim(resistanceAnim)
.setResistanceParams(RecentsResistanceParams.FROM_OVERVIEW)
.setStartScale(recentsView.getScaleX());
return createRecentsResistanceAnim(params);
}
/**
* Params to compute resistance when scaling/translating recents.
*/
private static class RecentsParams<SCALE, TRANSLATION> {
// These are all required and can't have default values, hence are final.
public final Context context;
public final RecentsOrientedState recentsOrientedState;
public final DeviceProfile dp;
public final SCALE scaleTarget;
public final FloatProperty<SCALE> scaleProperty;
public final TRANSLATION translationTarget;
public final FloatProperty<TRANSLATION> translationProperty;
// These are not required, or can have a default value that is generally correct.
@Nullable public PendingAnimation resistAnim = null;
public RecentsResistanceParams resistanceParams = RecentsResistanceParams.FROM_APP;
public float startScale = 1f;
public float startTranslation = 0f;
private RecentsParams(Context context, RecentsOrientedState recentsOrientedState,
DeviceProfile dp, SCALE scaleTarget, FloatProperty<SCALE> scaleProperty,
TRANSLATION translationTarget, FloatProperty<TRANSLATION> translationProperty) {
this.context = context;
this.recentsOrientedState = recentsOrientedState;
this.dp = dp;
this.scaleTarget = scaleTarget;
this.scaleProperty = scaleProperty;
this.translationTarget = translationTarget;
this.translationProperty = translationProperty;
}
private RecentsParams setResistAnim(PendingAnimation resistAnim) {
this.resistAnim = resistAnim;
return this;
}
private RecentsParams setResistanceParams(RecentsResistanceParams resistanceParams) {
this.resistanceParams = resistanceParams;
return this;
}
private RecentsParams setStartScale(float startScale) {
this.startScale = startScale;
return this;
}
private RecentsParams setStartTranslation(float startTranslation) {
this.startTranslation = startTranslation;
return this;
}
}
}
+1
View File
@@ -929,6 +929,7 @@ public class Launcher extends StatefulActivity<LauncherState> implements Launche
protected void handlePendingActivityRequest() { }
private void logStopAndResume(int command) {
if (mPendingExecutor != null) return;
int pageIndex = mWorkspace.isOverlayShown() ? -1 : mWorkspace.getCurrentPage();
int containerType = mStateManager.getState().containerType;