Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66c1051e authored by Pat Manning's avatar Pat Manning Committed by Android (Google) Code Review
Browse files

Merge "Remove taskbar tooltip hover delay." into main

parents dcae359a 2db8ce7e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -317,6 +317,8 @@
    <dimen name="transient_taskbar_stashed_height">32dp</dimen>
    <dimen name="transient_taskbar_all_apps_button_translation_x_offset">4dp</dimen>
    <dimen name="transient_taskbar_stash_spring_velocity_dp_per_s">400dp</dimen>
    <dimen name="taskbar_tooltip_vertical_padding">8dp</dimen>
    <dimen name="taskbar_tooltip_horizontal_padding">16dp</dimen>

    <!-- An additional touch slop to prevent x-axis movement during the swipe up to show taskbar -->
    <dimen name="transient_taskbar_clamped_offset_bound">16dp</dimen>
+24 −16
Original line number Diff line number Diff line
@@ -35,8 +35,6 @@ import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.view.View;

import androidx.annotation.VisibleForTesting;

import com.android.app.animation.Interpolators;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BubbleTextView;
@@ -51,8 +49,7 @@ import com.android.launcher3.views.ArrowTipView;
 */
public class TaskbarHoverToolTipController implements View.OnHoverListener {

    @VisibleForTesting protected static final int HOVER_TOOL_TIP_REVEAL_START_DELAY = 400;
    private static final int HOVER_TOOL_TIP_REVEAL_DURATION = 300;
    private static final int HOVER_TOOL_TIP_REVEAL_DURATION = 250;
    private static final int HOVER_TOOL_TIP_EXIT_DURATION = 150;

    private final Handler mHoverToolTipHandler = new Handler(Looper.getMainLooper());
@@ -84,6 +81,12 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
                R.style.ArrowTipTaskbarStyle);
        mHoverToolTipView = new ArrowTipView(arrowContextWrapper, /* isPointingUp = */ false,
                R.layout.arrow_toast);
        int verticalPadding = arrowContextWrapper.getResources().getDimensionPixelSize(
                R.dimen.taskbar_tooltip_vertical_padding);
        int horizontalPadding = arrowContextWrapper.getResources().getDimensionPixelSize(
                R.dimen.taskbar_tooltip_horizontal_padding);
        mHoverToolTipView.findViewById(R.id.text).setPadding(horizontalPadding, verticalPadding,
                horizontalPadding, verticalPadding);

        AnimatorSet hoverCloseAnimator = new AnimatorSet();
        ObjectAnimator textCloseAnimator = ObjectAnimator.ofInt(mHoverToolTipView, TEXT_ALPHA, 0);
@@ -101,17 +104,18 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
        mHoverToolTipView.setCustomCloseAnimation(hoverCloseAnimator);

        AnimatorSet hoverOpenAnimator = new AnimatorSet();
        ObjectAnimator textOpenAnimator = ObjectAnimator.ofInt(mHoverToolTipView, TEXT_ALPHA, 255);
        textOpenAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0.33f, 1f));
        ObjectAnimator scaleOpenAnimator = ObjectAnimator.ofFloat(mHoverToolTipView, SCALE_Y, 1f);
        ObjectAnimator textOpenAnimator =
                ObjectAnimator.ofInt(mHoverToolTipView, TEXT_ALPHA, 0, 255);
        textOpenAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0.15f, 0.75f));
        ObjectAnimator scaleOpenAnimator =
                ObjectAnimator.ofFloat(mHoverToolTipView, SCALE_Y, 0f, 1f);
        scaleOpenAnimator.setInterpolator(Interpolators.EMPHASIZED);
        ObjectAnimator alphaOpenAnimator = ObjectAnimator.ofFloat(mHoverToolTipView, ALPHA, 1f);
        alphaOpenAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0.1f, 0.33f));
        ObjectAnimator alphaOpenAnimator = ObjectAnimator.ofFloat(mHoverToolTipView, ALPHA, 0f, 1f);
        alphaOpenAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0f, 0.33f));
        hoverOpenAnimator.playTogether(
                scaleOpenAnimator,
                textOpenAnimator,
                alphaOpenAnimator);
        hoverOpenAnimator.setStartDelay(HOVER_TOOL_TIP_REVEAL_START_DELAY);
        hoverOpenAnimator.setDuration(HOVER_TOOL_TIP_REVEAL_DURATION);
        mHoverToolTipView.setCustomOpenAnimation(hoverOpenAnimator);

@@ -120,8 +124,6 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
                    mHoverToolTipView.setPivotY(bottom);
                    mHoverToolTipView.setY(mTaskbarView.getTop() - (bottom - top));
                });
        mHoverToolTipView.setScaleY(0f);
        mHoverToolTipView.setAlpha(0f);
    }

    @Override
@@ -137,6 +139,15 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
            mActivity.setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS, false);
            return true;
        } else if (!isAnyOtherFloatingViewOpen && event.getAction() == ACTION_HOVER_ENTER) {
            if (!mActivity.isTaskbarWindowFullscreen()) {
                // First time we want to animate a tooltip open, we set the drag layer to
                // fullscreen so the tooltip will fit within the window. This causes a layout
                // pass which will trigger a hover exit and hover enter event while still
                // hovering the view, so we do not animate open on the first hover enter if we
                // are not already in fullscreen.
                mActivity.setTaskbarWindowFullscreen(true);
                return false;
            }
            // If hovering above a taskbar icon starts, animate the tooltip open. Do not
            // reveal if any floating views such as folders or edu pop-ups are open.
            startRevealHoverToolTip();
@@ -147,8 +158,7 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
    }

    private void startRevealHoverToolTip() {
        mHoverToolTipHandler.postDelayed(mRevealHoverToolTipRunnable,
                HOVER_TOOL_TIP_REVEAL_START_DELAY);
        mHoverToolTipHandler.post(mRevealHoverToolTipRunnable);
    }

    private void revealHoverToolTip() {
@@ -158,14 +168,12 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
        if (mHoverView instanceof FolderIcon && !((FolderIcon) mHoverView).getIconVisible()) {
            return;
        }
        mActivity.setTaskbarWindowFullscreen(true);
        Rect iconViewBounds = Utilities.getViewBounds(mHoverView);
        mHoverToolTipView.showAtLocation(mToolTipText, iconViewBounds.centerX(),
                mTaskbarView.getTop(), /* shouldAutoClose= */ false);
    }

    private void startHideHoverToolTip() {
        mHoverToolTipHandler.removeCallbacks(mRevealHoverToolTipRunnable);
        int accessibilityHideTimeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(
                mActivity, /* originalTimeout= */ 0, FLAG_CONTENT_TEXT);
        mHoverToolTipHandler.postDelayed(mHideHoverToolTipRunnable, accessibilityHideTimeout);
+22 −9
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ package com.android.launcher3.taskbar;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;

import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS;
import static com.android.launcher3.taskbar.TaskbarHoverToolTipController.HOVER_TOOL_TIP_REVEAL_START_DELAY;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
@@ -125,16 +125,31 @@ public class TaskbarHoverToolTipControllerTest extends TaskbarBaseTestCase {
    public void onHover_hoverEnterIcon_revealToolTip() {
        when(mMotionEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(mMotionEvent.getActionMasked()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(taskbarActivityContext.isTaskbarWindowFullscreen()).thenReturn(true);

        boolean hoverHandled =
                mTaskbarHoverToolTipController.onHover(mHoverBubbleTextView, mMotionEvent);

        // Verify fullscreen is not set until the delayed runnable to reveal the tooltip has run
        verify(taskbarActivityContext, never()).setTaskbarWindowFullscreen(true);
        waitForIdleSync();

        assertThat(hoverHandled).isTrue();
        verify(taskbarActivityContext).setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS,
                true);
        verify(taskbarActivityContext, never()).setTaskbarWindowFullscreen(anyBoolean());
    }

    @Test
    public void onHover_hoverEnterIcon_setFullScreenFirstHover() {
        when(mMotionEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(mMotionEvent.getActionMasked()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(taskbarActivityContext.isTaskbarWindowFullscreen()).thenReturn(false);

        boolean hoverHandled =
                mTaskbarHoverToolTipController.onHover(mHoverBubbleTextView, mMotionEvent);
        waitForIdleSync();

        assertThat(hoverHandled).isFalse();
        verify(taskbarActivityContext, never()).setAutohideSuspendFlag(
                FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS, true);
        verify(taskbarActivityContext).setTaskbarWindowFullscreen(true);
    }

@@ -156,17 +171,16 @@ public class TaskbarHoverToolTipControllerTest extends TaskbarBaseTestCase {
    public void onHover_hoverEnterFolderIcon_revealToolTip() {
        when(mMotionEvent.getAction()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(mMotionEvent.getActionMasked()).thenReturn(MotionEvent.ACTION_HOVER_ENTER);
        when(taskbarActivityContext.isTaskbarWindowFullscreen()).thenReturn(true);

        boolean hoverHandled =
                mTaskbarHoverToolTipController.onHover(mHoverFolderIcon, mMotionEvent);

        // Verify fullscreen is not set until the delayed runnable to reveal the tooltip has run
        verify(taskbarActivityContext, never()).setTaskbarWindowFullscreen(true);
        waitForIdleSync();

        assertThat(hoverHandled).isTrue();
        verify(taskbarActivityContext).setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS,
                true);
        verify(taskbarActivityContext).setTaskbarWindowFullscreen(true);
        verify(taskbarActivityContext, never()).setTaskbarWindowFullscreen(anyBoolean());
    }

    @Test
@@ -222,7 +236,6 @@ public class TaskbarHoverToolTipControllerTest extends TaskbarBaseTestCase {
    }

    private void waitForIdleSync() {
        mTestableLooper.moveTimeForward(HOVER_TOOL_TIP_REVEAL_START_DELAY + 1);
        mTestableLooper.processAllMessages();
    }
}
+8 −7
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class ArrowTipView extends AbstractFloatingView {
        setOrientation(LinearLayout.VERTICAL);

        mArrowView = findViewById(R.id.arrow);
        updateArrowTipInView();
        updateArrowTipInView(mIsPointingUp);
        setAlpha(0);

        // Create default open animator.
@@ -364,17 +364,18 @@ public class ArrowTipView extends AbstractFloatingView {

            // Adjust the tooltip vertically.
            @Px int viewHeight = getHeight();
            boolean isPointingUp = mIsPointingUp;
            if (mIsPointingUp
                    ? (yCoordUpPointingTip + viewHeight > parentViewHeight)
                    : (yCoordDownPointingTip - viewHeight < 0)) {
                // Flip the view if it exceeds the vertical bounds of screen.
                mIsPointingUp = !mIsPointingUp;
                updateArrowTipInView();
                isPointingUp = !mIsPointingUp;
            }
            updateArrowTipInView(isPointingUp);
            // Place the tooltip such that its top is at yCoordUpPointingTip if arrow is displayed
            // pointing upwards, otherwise place it such that its bottom is at
            // yCoordDownPointingTip.
            setY(mIsPointingUp ? yCoordUpPointingTip : yCoordDownPointingTip - viewHeight);
            setY(isPointingUp ? yCoordUpPointingTip : yCoordDownPointingTip - viewHeight);

            // Adjust the arrow's relative position on tooltip to make sure the actual position of
            // arrow's pointed tip is always at arrowXCoord.
@@ -391,10 +392,10 @@ public class ArrowTipView extends AbstractFloatingView {
        return this;
    }

    private void updateArrowTipInView() {
    private void updateArrowTipInView(boolean isPointingUp) {
        ViewGroup.LayoutParams arrowLp = mArrowView.getLayoutParams();
        ShapeDrawable arrowDrawable = new ShapeDrawable(TriangleShape.create(
                arrowLp.width, arrowLp.height, mIsPointingUp));
                arrowLp.width, arrowLp.height, isPointingUp));
        Paint arrowPaint = arrowDrawable.getPaint();
        @Px int arrowTipRadius = getContext().getResources()
                .getDimensionPixelSize(R.dimen.arrow_toast_corner_radius);
@@ -403,7 +404,7 @@ public class ArrowTipView extends AbstractFloatingView {
        mArrowView.setBackground(arrowDrawable);
        // Add negative margin so that the rounded corners on base of arrow are not visible.
        removeView(mArrowView);
        if (mIsPointingUp) {
        if (isPointingUp) {
            addView(mArrowView, 0);
            ((ViewGroup.MarginLayoutParams) arrowLp).setMargins(0, 0, 0, -1 * arrowTipRadius);
        } else {