diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java index 7dcedfe50b37f..0dd11fb7c5e9c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleController.java @@ -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) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java index 82849e2020e1f..ede42285d9cdb 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleOverflowContainerView.java @@ -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 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); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index c6a9c108135f7..219e8379e6c73 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -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) {