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

Commit ed001607 authored by Andy Wickham's avatar Andy Wickham
Browse files

Speed up Home ripple if Launcher has requested override.

Also add a Runnable which runs when the ripple is next invisible.
In this case, startAssist runs at that time for the override case.

Demo: https://drive.google.com/file/d/1kaw0yfNt-T9mi8tLZhpsVkKnpXIeJotM/view?usp=drive_link&resourcekey=0-LLuCOx-TXH91C5bfB_8J9A
Fix: 306131168
Test: Manual with regular home press + long press, with and without
override requested.
Flag: LEGACY INVOKE_LPH DISABLED

Change-Id: I59c45fd180636476c4c6942c23215e0ee7fa5e18
parent 0bab1185
Loading
Loading
Loading
Loading
+31 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.graphics.PixelFormat;
import android.graphics.RecordingCanvas;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.os.Trace;
import android.view.RenderNodeAnimator;
import android.view.View;
@@ -48,6 +49,7 @@ public class KeyButtonRipple extends Drawable {
    private static final float GLOW_MAX_ALPHA_DARK = 0.1f;
    private static final int ANIMATION_DURATION_SCALE = 350;
    private static final int ANIMATION_DURATION_FADE = 450;
    private static final int ANIMATION_DURATION_FADE_FAST = 80;
    private static final Interpolator ALPHA_OUT_INTERPOLATOR =
            new PathInterpolator(0f, 0f, 0.8f, 1f);

@@ -71,6 +73,9 @@ public class KeyButtonRipple extends Drawable {
    private boolean mLastDark;
    private boolean mDark;
    private boolean mDelayTouchFeedback;
    private boolean mSpeedUpNextFade;
    // When non-null, this runs the next time this ripple is drawn invisibly.
    private Runnable mOnInvisibleRunnable;

    private final Interpolator mInterpolator = new LogInterpolator();
    private boolean mSupportHardware;
@@ -112,6 +117,18 @@ public class KeyButtonRipple extends Drawable {
        mDelayTouchFeedback = delay;
    }

    /** Next time we fade out (pressed==false), use a shorter duration than the standard. */
    public void speedUpNextFade() {
        mSpeedUpNextFade = true;
    }

    /**
     *  @param onInvisibleRunnable run after we are next drawn invisibly. Only used once.
     */
    void setOnInvisibleRunnable(Runnable onInvisibleRunnable) {
        mOnInvisibleRunnable = onInvisibleRunnable;
    }

    public void setType(Type type) {
        mType = type;
    }
@@ -161,6 +178,11 @@ public class KeyButtonRipple extends Drawable {
        } else {
            drawSoftware(canvas);
        }

        if (!mPressed && !mVisible && mOnInvisibleRunnable != null) {
            new Handler(Looper.getMainLooper()).post(mOnInvisibleRunnable);
            mOnInvisibleRunnable = null;
        }
    }

    @Override
@@ -270,7 +292,7 @@ public class KeyButtonRipple extends Drawable {
        return true;
    }

    public void setPressed(boolean pressed) {
    private void setPressed(boolean pressed) {
        if (mDark != mLastDark && pressed) {
            mRipplePaint = null;
            mLastDark = mDark;
@@ -350,7 +372,7 @@ public class KeyButtonRipple extends Drawable {
    private void exitSoftware() {
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(this, "glowAlpha", mGlowAlpha, 0f);
        alphaAnimator.setInterpolator(ALPHA_OUT_INTERPOLATOR);
        alphaAnimator.setDuration(ANIMATION_DURATION_FADE);
        alphaAnimator.setDuration(getFadeDuration());
        alphaAnimator.addListener(mAnimatorListener);
        alphaAnimator.start();
        mRunningAnimations.add(alphaAnimator);
@@ -414,6 +436,12 @@ public class KeyButtonRipple extends Drawable {
        return Math.min(size, mMaxWidth);
    }

    private int getFadeDuration() {
        int duration = mSpeedUpNextFade ? ANIMATION_DURATION_FADE_FAST : ANIMATION_DURATION_FADE;
        mSpeedUpNextFade = false;
        return duration;
    }

    private void enterHardware() {
        endAnimations("enterHardware", true /* cancel */);
        mVisible = true;
@@ -471,7 +499,7 @@ public class KeyButtonRipple extends Drawable {
        mPaintProp = CanvasProperty.createPaint(getRipplePaint());
        final RenderNodeAnimator opacityAnim = new RenderNodeAnimator(mPaintProp,
                RenderNodeAnimator.PAINT_ALPHA, 0);
        opacityAnim.setDuration(ANIMATION_DURATION_FADE);
        opacityAnim.setDuration(getFadeDuration());
        opacityAnim.setInterpolator(ALPHA_OUT_INTERPOLATOR);
        opacityAnim.addListener(mAnimatorListener);
        opacityAnim.addListener(mExitHwTraceAnimator);
+12 −2
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ import com.android.internal.statusbar.LetterboxDetails;
import com.android.internal.util.LatencyTracker;
import com.android.internal.view.AppearanceRegion;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.res.R;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.DisplayId;
@@ -130,6 +129,7 @@ import com.android.systemui.navigationbar.gestural.QuickswitchOrientedNavHandle;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.recents.Recents;
import com.android.systemui.res.R;
import com.android.systemui.settings.DisplayTracker;
import com.android.systemui.settings.UserContextProvider;
import com.android.systemui.settings.UserTracker;
@@ -1378,7 +1378,17 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
        args.putInt(
                AssistManager.INVOCATION_TYPE_KEY,
                AssistManager.INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS);
        // If Launcher has requested to override long press home, add a delay for the ripple.
        // TODO(b/304146255): Remove this delay once we can exclude 3-button nav from screenshot.
        boolean delayAssistInvocation = mAssistManagerLazy.get().shouldOverrideAssist(
                AssistManager.INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS);
        // In practice, I think v should always be a KeyButtonView, but just being safe.
        if (delayAssistInvocation && v instanceof KeyButtonView) {
            ((KeyButtonView) v).setOnRippleInvisibleRunnable(
                    () -> mAssistManagerLazy.get().startAssist(args));
        } else {
            mAssistManagerLazy.get().startAssist(args);
        }
        mCentralSurfacesOptionalLazy.get().ifPresent(CentralSurfaces::awakenDreams);
        mView.abortCurrentGesture();
        return true;
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,6 @@ import com.android.app.animation.Interpolators;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settingslib.Utils;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.res.R;
import com.android.systemui.model.SysUiState;
import com.android.systemui.navigationbar.buttons.ButtonDispatcher;
import com.android.systemui.navigationbar.buttons.ContextualButton;
@@ -73,6 +72,7 @@ import com.android.systemui.navigationbar.buttons.NearestTouchFrame;
import com.android.systemui.navigationbar.buttons.RotationContextButton;
import com.android.systemui.navigationbar.gestural.EdgeBackGestureHandler;
import com.android.systemui.recents.Recents;
import com.android.systemui.res.R;
import com.android.systemui.settings.DisplayTracker;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shared.rotation.FloatingRotationButton;
+13 −1
Original line number Diff line number Diff line
@@ -58,8 +58,9 @@ import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLoggerImpl;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.Dependency;
import com.android.systemui.res.R;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.res.R;
import com.android.systemui.shared.system.QuickStepContract;

public class KeyButtonView extends ImageView implements ButtonInterface {
@@ -439,11 +440,22 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        if (mCode != KeyEvent.KEYCODE_UNKNOWN) {
            sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
        }
        // When aborting long-press home and Launcher has requested to override it, fade out the
        // ripple more quickly.
        if (mCode == KeyEvent.KEYCODE_HOME && Dependency.get(AssistManager.class)
                .shouldOverrideAssist(AssistManager.INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS)) {
            mRipple.speedUpNextFade();
        }
        setPressed(false);
        mRipple.abortDelayedRipple();
        mGestureAborted = true;
    }

    /** Run when the ripple for this button is next invisible. Only used once. */
    public void setOnRippleInvisibleRunnable(Runnable onRippleInvisibleRunnable) {
        mRipple.setOnInvisibleRunnable(onRippleInvisibleRunnable);
    }

    @Override
    public void setDarkIntensity(float darkIntensity) {
        mDarkIntensity = darkIntensity;
+2 −0
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import androidx.test.filters.SmallTest;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.assist.AssistManager;
import com.android.systemui.recents.OverviewProxyService;

import org.junit.Before;
@@ -76,6 +77,7 @@ public class KeyButtonViewTest extends SysuiTestCase {
        MockitoAnnotations.initMocks(this);
        mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
        mDependency.injectMockDependency(OverviewProxyService.class);
        mDependency.injectMockDependency(AssistManager.class);
        mUiEventLogger = mDependency.injectMockDependency(UiEventLogger.class);

        TestableLooper.get(this).runWithLooper(() -> {