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

Commit 5c28b369 authored by Mady Mellor's avatar Mady Mellor Committed by Automerger Merge Worker
Browse files

Merge "Fix overflow not receiving onBackPress events" into sc-dev am: 3c01aa0f

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14684140

Change-Id: I315e1b958530bba9a3e60a54fbd8267f8fc0d415
parents f65188c0 3c01aa0f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -613,6 +613,18 @@ public class BubbleController {
        }
    }

    /** For the overflow to be focusable & receive key events the flags must be update. **/
    void updateWindowFlagsForOverflow(boolean showingOverflow) {
        if (mStackView != null && mAddedToWindowManager) {
            mWmLayoutParams.flags = showingOverflow
                    ? 0
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
            mWmLayoutParams.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
            mWindowManager.updateViewLayout(mStackView, mWmLayoutParams);
        }
    }

    /** Removes the BubbleStackView from the WindowManager if it's there. */
    private void removeFromWindowManagerMaybe() {
        if (!mAddedToWindowManager) {
+31 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -62,6 +63,15 @@ public class BubbleOverflowContainerView extends LinearLayout {
    private RecyclerView mRecyclerView;
    private List<Bubble> mOverflowBubbles = new ArrayList<>();

    private View.OnKeyListener mKeyListener = (view, i, keyEvent) -> {
        if (keyEvent.getAction() == KeyEvent.ACTION_UP
                && keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            mController.collapseStack();
            return true;
        }
        return false;
    };

    private class OverflowGridLayoutManager extends GridLayoutManager {
        OverflowGridLayoutManager(Context context, int columns) {
            super(context, columns);
@@ -104,6 +114,7 @@ public class BubbleOverflowContainerView extends LinearLayout {
    public BubbleOverflowContainerView(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        setFocusableInTouchMode(true);
    }

    public void setBubbleController(BubbleController controller) {
@@ -111,14 +122,10 @@ public class BubbleOverflowContainerView extends LinearLayout {
    }

    public void show() {
        setVisibility(View.VISIBLE);
        requestFocus();
        updateOverflow();
    }

    public void hide() {
        setVisibility(View.INVISIBLE);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
@@ -130,6 +137,25 @@ public class BubbleOverflowContainerView extends LinearLayout {
        mEmptyStateImage = findViewById(R.id.bubble_overflow_empty_state_image);
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (mController != null) {
            // For the overflow to get key events (e.g. back press) we need to adjust the flags
            mController.updateWindowFlagsForOverflow(true);
        }
        setOnKeyListener(mKeyListener);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (mController != null) {
            mController.updateWindowFlagsForOverflow(false);
        }
        setOnKeyListener(null);
    }

    void updateOverflow() {
        Resources res = getResources();
        final int columns = res.getInteger(R.integer.bubbles_overflow_columns);
+0 −7
Original line number Diff line number Diff line
@@ -2167,13 +2167,6 @@ public class BubbleStackView extends FrameLayout
        }
    }

    /**
     */
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() != MotionEvent.ACTION_DOWN && ev.getActionIndex() != mPointerIndexDown) {