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

Commit 47b11e31 authored by Mady Mellor's avatar Mady Mellor
Browse files

Fix back-swipe gesture on bubble expanded state

Tapping around the edges of the expanded state collapses the bubble, it
also means back-swipe doesn't work properly / show the animation (even
though the bubble is technically collapsing).

This CL includes a bit of a slop around ActivityView when checking if
the touch is intersecting it. We might need to adjust the value but
in my testing so far it seems much better.

Also removes onInterceptTouchEvent code -- that was totally unneeded!!

Fixes: 131267438
Test: manual - expand a bubble and tap near the top / left / right / bottom
               edges => ensure it doesn't collapse when you wouldn't
               expect it to
             - perform backswipe gesture => ensure you see arrow animation
               and bubble collapses

Change-Id: Id42e6d5fbaff832b9d8f0a415d8f91a5358af5de
parent 084dbe01
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1121,6 +1121,9 @@
    <dimen name="bubble_icon_inset">16dp</dimen>
    <!-- Padding around the view displayed when the bubble is expanded -->
    <dimen name="bubble_expanded_view_padding">4dp</dimen>
    <!-- This should be at least the size of bubble_expanded_view_padding; it is used to include
         a slight touch slop around the expanded view. -->
    <dimen name="bubble_expanded_view_slop">8dp</dimen>
    <!-- Default (and minimum) height of the expanded view shown when the bubble is expanded -->
    <dimen name="bubble_expanded_default_height">180dp</dimen>
    <!-- Height of the triangle that points to the expanded bubble -->
+37 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.os.RemoteException;
@@ -93,6 +94,9 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    private int mPointerWidth;
    private int mPointerHeight;
    private ShapeDrawable mPointerDrawable;
    private Rect mTempRect = new Rect();
    private int[] mTempLoc = new int[2];
    private int mExpandedViewTouchSlop;

    private Bubble mBubble;
    private PackageManager mPm;
@@ -166,9 +170,10 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        mDisplaySize = new Point();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getSize(mDisplaySize);
        mMinHeight = getResources().getDimensionPixelSize(
                R.dimen.bubble_expanded_default_height);
        mPointerMargin = getResources().getDimensionPixelSize(R.dimen.bubble_pointer_margin);
        Resources res = getResources();
        mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height);
        mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin);
        mExpandedViewTouchSlop = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_slop);
    }

    @Override
@@ -374,6 +379,35 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        return mDisplaySize.y - windowLocation[1] - mSettingsIconHeight;
    }

    /**
     * Whether the provided x, y values (in raw coordinates) are in a touchable area of the
     * expanded view.
     *
     * The touchable areas are the ActivityView (plus some slop around it) and the manage button.
     */
    boolean intersectingTouchableContent(int rawX, int rawY) {
        mTempRect.setEmpty();
        if (mActivityView != null) {
            mTempLoc = mActivityView.getLocationOnScreen();
            mTempRect.set(mTempLoc[0] - mExpandedViewTouchSlop,
                    mTempLoc[1] - mExpandedViewTouchSlop,
                    mTempLoc[0] + mActivityView.getWidth() + mExpandedViewTouchSlop,
                    mTempLoc[1] + mActivityView.getHeight() + mExpandedViewTouchSlop);
        }
        if (mTempRect.contains(rawX, rawY)) {
            return true;
        }
        mTempLoc = mSettingsIcon.getLocationOnScreen();
        mTempRect.set(mTempLoc[0],
                mTempLoc[1],
                mTempLoc[0] + mSettingsIcon.getWidth(),
                mTempLoc[1] + mSettingsIcon.getHeight());
        if (mTempRect.contains(rawX, rawY)) {
            return true;
        }
        return false;
    }

    @Override
    public void onClick(View view) {
        if (mBubble == null) {
+6 −18
Original line number Diff line number Diff line
@@ -412,8 +412,6 @@ public class BubbleStackView extends FrameLayout {
        mBubbleContainer.bringToFront();

        setOnApplyWindowInsetsListener((View view, WindowInsets insets) -> {
            final int keyboardHeight = insets.getSystemWindowInsetBottom()
                    - insets.getStableInsetBottom();
            if (!mIsExpanded || mIsExpansionAnimating) {
                return view.onApplyWindowInsets(insets);
            }
@@ -509,18 +507,6 @@ public class BubbleStackView extends FrameLayout {
        getViewTreeObserver().removeOnPreDrawListener(mViewUpdater);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        float x = ev.getRawX();
        float y = ev.getRawY();
        // If we're expanded only intercept if the tap is outside of the widget container
        if (mIsExpanded && isIntersecting(mExpandedViewContainer, x, y)) {
            return false;
        } else {
            return isIntersecting(mBubbleContainer, x, y);
        }
    }

    @Override
    public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfoInternal(info);
@@ -831,21 +817,23 @@ public class BubbleStackView extends FrameLayout {
        float y = event.getRawY();
        if (mIsExpanded) {
            if (isIntersecting(mBubbleContainer, x, y)) {
                // Could be tapping or dragging a bubble while expanded
                for (int i = 0; i < mBubbleContainer.getChildCount(); i++) {
                    BubbleView view = (BubbleView) mBubbleContainer.getChildAt(i);
                    if (isIntersecting(view, x, y)) {
                        return view;
                    }
                }
            } else if (isIntersecting(mExpandedViewContainer, x, y)) {
                return mExpandedViewContainer;
            }
            // Outside parts of view we care about.
            BubbleExpandedView bev = (BubbleExpandedView) mExpandedViewContainer.getChildAt(0);
            if (bev.intersectingTouchableContent((int) x, (int) y)) {
                return bev;
            }
            // Outside of the parts we care about.
            return null;
        } else if (mFlyout.getVisibility() == VISIBLE && isIntersecting(mFlyout, x, y)) {
            return mFlyout;
        }

        // If it wasn't an individual bubble in the expanded state, or the flyout, it's the stack.
        return this;
    }
+9 −0
Original line number Diff line number Diff line
@@ -95,6 +95,15 @@ class BubbleTouchHandler implements View.OnTouchListener {
            return false;
        }

        if (!(mTouchedView instanceof BubbleView)
                && !(mTouchedView instanceof BubbleStackView)
                && !(mTouchedView instanceof BubbleFlyoutView)) {
            // Not touching anything touchable, but we shouldn't collapse (e.g. touching edge
            // of expanded view).
            resetForNextGesture();
            return false;
        }

        final boolean isStack = mStack.equals(mTouchedView);
        final boolean isFlyout = mStack.getFlyoutView().equals(mTouchedView);
        final float rawX = event.getRawX();