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

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

Merge "Show and hide taskbar tooltips immediately." into main

parents 76b2dad6 b488c88f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static android.window.SplashScreen.SPLASH_SCREEN_STYLE_UNDEFINED;

import static com.android.launcher3.AbstractFloatingView.TYPE_ALL;
import static com.android.launcher3.AbstractFloatingView.TYPE_ON_BOARD_POPUP;
import static com.android.launcher3.AbstractFloatingView.TYPE_REBIND_SAFE;
import static com.android.launcher3.AbstractFloatingView.TYPE_TASKBAR_OVERLAY_PROXY;
import static com.android.launcher3.Flags.enableCursorHoverStates;
@@ -1514,6 +1515,12 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
                itemView.setHapticFeedbackEnabled(true);
                return false;
            });

            // Close any open taskbar tooltips.
            if (AbstractFloatingView.hasOpenView(this, TYPE_ON_BOARD_POPUP)) {
                AbstractFloatingView.getOpenView(this, TYPE_ON_BOARD_POPUP)
                        .close(/* animate= */ false);
            }
        });
    }

+12 −69
Original line number Diff line number Diff line
@@ -18,30 +18,22 @@ package com.android.launcher3.taskbar;
import static android.view.MotionEvent.ACTION_HOVER_ENTER;
import static android.view.MotionEvent.ACTION_HOVER_EXIT;
import static android.view.View.ALPHA;
import static android.view.View.SCALE_Y;
import static android.view.accessibility.AccessibilityManager.FLAG_CONTENT_TEXT;

import static com.android.app.animation.Interpolators.LINEAR;
import static com.android.launcher3.AbstractFloatingView.TYPE_ALL_EXCEPT_ON_BOARD_POPUP;
import static com.android.launcher3.AbstractFloatingView.TYPE_FOLDER;
import static com.android.launcher3.taskbar.TaskbarAutohideSuspendController.FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS;
import static com.android.launcher3.views.ArrowTipView.TEXT_ALPHA;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Looper;
import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.view.View;

import com.android.app.animation.Interpolators;
import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.apppairs.AppPairIcon;
import com.android.launcher3.compat.AccessibilityManagerCompat;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.views.ArrowTipView;

@@ -49,13 +41,9 @@ import com.android.launcher3.views.ArrowTipView;
 * Controls showing a tooltip in the taskbar above each icon when it is hovered.
 */
public class TaskbarHoverToolTipController implements View.OnHoverListener {

    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());
    private final Runnable mRevealHoverToolTipRunnable = this::revealHoverToolTip;
    private final Runnable mHideHoverToolTipRunnable = this::hideHoverToolTip;
    // Short duration to reveal tooltip, as it is positioned in the x/y via a post() call in
    // parallel with the open animation. An instant animation could show in the wrong location.
    private static final int HOVER_TOOL_TIP_REVEAL_DURATION = 15;

    private final TaskbarActivityContext mActivity;
    private final TaskbarView mTaskbarView;
@@ -90,35 +78,11 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
                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);
        textCloseAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0, 0.33f));
        ObjectAnimator alphaCloseAnimator = ObjectAnimator.ofFloat(mHoverToolTipView, ALPHA, 0);
        alphaCloseAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0.33f, 0.66f));
        ObjectAnimator scaleCloseAnimator = ObjectAnimator.ofFloat(mHoverToolTipView, SCALE_Y, 0);
        scaleCloseAnimator.setInterpolator(Interpolators.STANDARD);
        hoverCloseAnimator.playTogether(
                textCloseAnimator,
                alphaCloseAnimator,
                scaleCloseAnimator);
        hoverCloseAnimator.setStartDelay(0);
        hoverCloseAnimator.setDuration(HOVER_TOOL_TIP_EXIT_DURATION);
        mHoverToolTipView.setCustomCloseAnimation(hoverCloseAnimator);
        mHoverToolTipView.setAlpha(0);

        AnimatorSet hoverOpenAnimator = new AnimatorSet();
        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, 0f, 1f);
        alphaOpenAnimator.setInterpolator(Interpolators.clampToProgress(LINEAR, 0f, 0.33f));
        hoverOpenAnimator.playTogether(
                scaleOpenAnimator,
                textOpenAnimator,
                alphaOpenAnimator);
        hoverOpenAnimator.play(alphaOpenAnimator);
        hoverOpenAnimator.setDuration(HOVER_TOOL_TIP_REVEAL_DURATION);
        mHoverToolTipView.setCustomOpenAnimation(hoverOpenAnimator);

@@ -131,28 +95,17 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {

    @Override
    public boolean onHover(View v, MotionEvent event) {
        boolean isAnyOtherFloatingViewOpen =
                AbstractFloatingView.hasOpenView(mActivity, TYPE_ALL_EXCEPT_ON_BOARD_POPUP);
        if (isAnyOtherFloatingViewOpen) {
            mHoverToolTipHandler.removeCallbacksAndMessages(null);
        }
        boolean isFolderOpen = AbstractFloatingView.hasOpenView(mActivity, TYPE_FOLDER);
        // If hover leaves a taskbar icon animate the tooltip closed.
        if (event.getAction() == ACTION_HOVER_EXIT) {
            startHideHoverToolTip();
            mHoverToolTipView.close(/* animate= */ false);
            mActivity.setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS, false);
            return true;
        } else if (!isAnyOtherFloatingViewOpen && event.getAction() == ACTION_HOVER_ENTER) {
            // 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();
        } else if (!isFolderOpen && event.getAction() == ACTION_HOVER_ENTER) {
            // Do not reveal if any floating views such as folders or edu pop-ups are open.
            revealHoverToolTip();
            mActivity.setAutohideSuspendFlag(FLAG_AUTOHIDE_SUSPEND_HOVERING_ICONS, true);
            return true;
        }
        return false;
        }

    private void startRevealHoverToolTip() {
        mHoverToolTipHandler.post(mRevealHoverToolTipRunnable);
        return true;
    }

    private void revealHoverToolTip() {
@@ -170,14 +123,4 @@ public class TaskbarHoverToolTipController implements View.OnHoverListener {
        mHoverToolTipView.showAtLocation(mToolTipText, iconViewBounds.centerX(),
                mTaskbarView.getTop(), /* shouldAutoClose= */ false);
    }

    private void startHideHoverToolTip() {
        int accessibilityHideTimeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(
                mActivity, /* originalTimeout= */ 0, FLAG_CONTENT_TEXT);
        mHoverToolTipHandler.postDelayed(mHideHoverToolTipRunnable, accessibilityHideTimeout);
    }

    private void hideHoverToolTip() {
        mHoverToolTipView.close(/* animate = */ true);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -202,7 +202,7 @@ public class TaskbarHoverToolTipControllerTest extends TaskbarBaseTestCase {
        boolean hoverHandled =
                mTaskbarHoverToolTipController.onHover(mHoverFolderIcon, mMotionEvent);

        assertThat(hoverHandled).isFalse();
        assertThat(hoverHandled).isTrue();
    }

    @Test
@@ -213,7 +213,7 @@ public class TaskbarHoverToolTipControllerTest extends TaskbarBaseTestCase {
        boolean hoverHandled =
                mTaskbarHoverToolTipController.onHover(mHoverFolderIcon, mMotionEvent);

        assertThat(hoverHandled).isFalse();
        assertThat(hoverHandled).isTrue();
    }

    @Test
+0 −3
Original line number Diff line number Diff line
@@ -138,9 +138,6 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch
    public static final int TYPE_TOUCH_CONTROLLER_NO_INTERCEPT = TYPE_ALL & ~TYPE_DISCOVERY_BOUNCE
            & ~TYPE_LISTENER & ~TYPE_TASKBAR_OVERLAYS;

    public static final int TYPE_ALL_EXCEPT_ON_BOARD_POPUP = TYPE_ALL & ~TYPE_ON_BOARD_POPUP
            & ~TYPE_PIN_IME_POPUP;

    protected boolean mIsOpen;

    public AbstractFloatingView(Context context, AttributeSet attrs) {