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

Commit c4e06201 authored by Winson Chung's avatar Winson Chung
Browse files

Adding hit target hint from SysUI to launcher to defer recents animation

Bug: 73242451
Test: Swipe up over back with suitable launcher build and ensure that we
      don't start the recents animation on touch down

Change-Id: I3022ced8803caf9555efdbd9681c8ee2e627a216
parent 7b7b3b20
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -22,6 +22,14 @@ import com.android.systemui.shared.recents.ISystemUiProxy;
oneway interface IOverviewProxy {
    void onBind(in ISystemUiProxy sysUiProxy);

    /**
     * Called once immediately prior to the first onMotionEvent() call, providing a hint to the
     * target the initial source of the subsequent motion events.
     *
     * @param downHitTarget is one of the {@link NavigationBarCompat.HitTarget}s
     */
    void onPreMotionEvent(int downHitTarget);

    /**
     * Proxies motion events from the nav bar in SystemUI to the OverviewProxyService. The sender
     * guarantees the following order of events:
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.shared.system;

import android.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class NavigationBarCompat {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({HIT_TARGET_NONE, HIT_TARGET_BACK, HIT_TARGET_HOME})
    public @interface HitTarget{}

    public static final int HIT_TARGET_NONE = 0;
    public static final int HIT_TARGET_BACK = 1;
    public static final int HIT_TARGET_HOME = 2;
}
+5 −2
Original line number Diff line number Diff line
@@ -131,6 +131,9 @@ public class NavigationBarGestureHelper implements TunerService.Tunable, Gesture
            mNavigationBarView.requestUnbufferedDispatch(event);
            event.transform(mTransformGlobalMatrix);
            try {
                if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                    overviewProxy.onPreMotionEvent(mNavigationBarView.getDownHitTarget());
                }
                overviewProxy.onMotionEvent(event);
                if (DEBUG_OVERVIEW_PROXY) {
                    Log.d(TAG_OPS, "Send MotionEvent: " + event.toString());
@@ -146,8 +149,8 @@ public class NavigationBarGestureHelper implements TunerService.Tunable, Gesture
    }

    public boolean onInterceptTouchEvent(MotionEvent event) {
        int action = event.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
        int action = event.getActionMasked();
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                mTouchDownX = (int) event.getX();
                mTouchDownY = (int) event.getY();
+41 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package com.android.systemui.statusbar.phone;

import static android.view.MotionEvent.ACTION_DOWN;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_BACK;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_NONE;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
@@ -61,6 +66,7 @@ import com.android.systemui.plugins.PluginManager;
import com.android.systemui.plugins.statusbar.phone.NavGesture;
import com.android.systemui.plugins.statusbar.phone.NavGesture.GestureHelper;
import com.android.systemui.recents.RecentsOnboarding;
import com.android.systemui.shared.system.NavigationBarCompat;
import com.android.systemui.stackdivider.Divider;
import com.android.systemui.statusbar.policy.DeadZone;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
@@ -95,6 +101,11 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
    int mDisabledFlags = 0;
    int mNavigationIconHints = 0;

    private @NavigationBarCompat.HitTarget int mDownHitTarget = HIT_TARGET_NONE;
    private Rect mHomeButtonBounds = new Rect();
    private Rect mBackButtonBounds = new Rect();
    private int[] mTmpPosition = new int[2];

    private KeyButtonDrawable mBackIcon, mBackLandIcon, mBackAltIcon, mBackAltLandIcon;
    private KeyButtonDrawable mBackCarModeIcon, mBackLandCarModeIcon;
    private KeyButtonDrawable mBackAltCarModeIcon, mBackAltLandCarModeIcon;
@@ -284,6 +295,18 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        switch (event.getActionMasked()) {
            case ACTION_DOWN:
                int x = (int) event.getX();
                int y = (int) event.getY();
                mDownHitTarget = HIT_TARGET_NONE;
                if (mBackButtonBounds.contains(x, y)) {
                    mDownHitTarget = HIT_TARGET_BACK;
                } else if (mHomeButtonBounds.contains(x, y)) {
                    mDownHitTarget = HIT_TARGET_HOME;
                }
                break;
        }
        return mGestureHelper.onInterceptTouchEvent(event);
    }

@@ -295,6 +318,10 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
        return super.onTouchEvent(event);
    }

    public @NavigationBarCompat.HitTarget int getDownHitTarget() {
        return mDownHitTarget;
    }

    public void abortCurrentGesture() {
        getHomeButton().abortCurrentGesture();
    }
@@ -783,9 +810,23 @@ public class NavigationBarView extends FrameLayout implements PluginListener<Nav
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        updateButtonLocationOnScreen(getBackButton(), mBackButtonBounds);
        updateButtonLocationOnScreen(getHomeButton(), mHomeButtonBounds);
        mGestureHelper.onLayout(changed, left, top, right, bottom);
    }

    private void updateButtonLocationOnScreen(ButtonDispatcher button, Rect buttonBounds) {
        View view = button.getCurrentView();
        if (view == null) {
            buttonBounds.setEmpty();
            return;
        }
        view.getLocationInWindow(mTmpPosition);
        buttonBounds.set(mTmpPosition[0], mTmpPosition[1],
                mTmpPosition[0] + view.getMeasuredWidth(),
                mTmpPosition[1] + view.getMeasuredHeight());
    }

    private void updateRotatedViews() {
        mRotatedViews[Surface.ROTATION_0] =
                mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0);
+4 −14
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import static android.view.WindowManagerPolicyConstants.NAV_BAR_LEFT;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_BOTTOM;
import static com.android.systemui.OverviewProxyService.DEBUG_OVERVIEW_PROXY;
import static com.android.systemui.OverviewProxyService.TAG_OPS;
import static com.android.systemui.shared.system.NavigationBarCompat.HIT_TARGET_HOME;

/**
 * Class to detect gestures on the navigation bar and implement quick scrub and switch.
@@ -92,7 +93,6 @@ public class QuickScrubController extends GestureDetector.SimpleOnGestureListene
    private final Handler mHandler = new Handler();
    private final Interpolator mQuickScrubEndInterpolator = new DecelerateInterpolator();
    private final Rect mTrackRect = new Rect();
    private final Rect mHomeButtonRect = new Rect();
    private final Paint mTrackPaint = new Paint();
    private final int mScrollTouchSlop;
    private final OverviewProxyService mOverviewEventSender;
@@ -138,7 +138,7 @@ public class QuickScrubController extends GestureDetector.SimpleOnGestureListene
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velX, float velY) {
                if (!isQuickScrubEnabled() || mQuickScrubActive || !mAllowQuickSwitch ||
                        !mHomeButtonRect.contains(mTouchDownX, mTouchDownY)) {
                        mNavigationBarView.getDownHitTarget() != HIT_TARGET_HOME) {
                    return false;
                }
                float velocityX = mIsRTL ? -velX : velX;
@@ -226,7 +226,8 @@ public class QuickScrubController extends GestureDetector.SimpleOnGestureListene
            case MotionEvent.ACTION_DOWN: {
                int x = (int) event.getX();
                int y = (int) event.getY();
                if (isQuickScrubEnabled() && mHomeButtonRect.contains(x, y)) {
                if (isQuickScrubEnabled()
                        && mNavigationBarView.getDownHitTarget() == HIT_TARGET_HOME) {
                    mTouchDownX = x;
                    mTouchDownY = y;
                    homeButton.setDelayTouchFeedback(true);
@@ -346,17 +347,6 @@ public class QuickScrubController extends GestureDetector.SimpleOnGestureListene
            x2 = x1 + width / 2 - mTrackPadding;
        }
        mTrackRect.set(x1, y1, x2, y2);

        // Get the touch rect of the home button location
        View homeView = mNavigationBarView.getHomeButton().getCurrentView();
        if (homeView != null) {
            int[] globalHomePos = homeView.getLocationOnScreen();
            int[] globalNavBarPos = mNavigationBarView.getLocationOnScreen();
            int homeX = globalHomePos[0] - globalNavBarPos[0];
            int homeY = globalHomePos[1] - globalNavBarPos[1];
            mHomeButtonRect.set(homeX, homeY, homeX + homeView.getMeasuredWidth(),
                    homeY + homeView.getMeasuredHeight());
        }
    }

    @Override