Merge "Fix overflow not receiving onBackPress events" into sc-dev am: 3c01aa0fea
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14684140 Change-Id: Ieee08a475afe8f39e06b2cc447eb990c4c0f411a
This commit is contained in:
@@ -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. */
|
/** Removes the BubbleStackView from the WindowManager if it's there. */
|
||||||
private void removeFromWindowManagerMaybe() {
|
private void removeFromWindowManagerMaybe() {
|
||||||
if (!mAddedToWindowManager) {
|
if (!mAddedToWindowManager) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import android.graphics.Color;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -62,6 +63,15 @@ public class BubbleOverflowContainerView extends LinearLayout {
|
|||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private List<Bubble> mOverflowBubbles = new ArrayList<>();
|
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 {
|
private class OverflowGridLayoutManager extends GridLayoutManager {
|
||||||
OverflowGridLayoutManager(Context context, int columns) {
|
OverflowGridLayoutManager(Context context, int columns) {
|
||||||
super(context, columns);
|
super(context, columns);
|
||||||
@@ -104,6 +114,7 @@ public class BubbleOverflowContainerView extends LinearLayout {
|
|||||||
public BubbleOverflowContainerView(Context context, AttributeSet attrs, int defStyleAttr,
|
public BubbleOverflowContainerView(Context context, AttributeSet attrs, int defStyleAttr,
|
||||||
int defStyleRes) {
|
int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
setFocusableInTouchMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBubbleController(BubbleController controller) {
|
public void setBubbleController(BubbleController controller) {
|
||||||
@@ -111,14 +122,10 @@ public class BubbleOverflowContainerView extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
setVisibility(View.VISIBLE);
|
requestFocus();
|
||||||
updateOverflow();
|
updateOverflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hide() {
|
|
||||||
setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
protected void onFinishInflate() {
|
||||||
super.onFinishInflate();
|
super.onFinishInflate();
|
||||||
@@ -130,6 +137,25 @@ public class BubbleOverflowContainerView extends LinearLayout {
|
|||||||
mEmptyStateImage = findViewById(R.id.bubble_overflow_empty_state_image);
|
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() {
|
void updateOverflow() {
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
final int columns = res.getInteger(R.integer.bubbles_overflow_columns);
|
final int columns = res.getInteger(R.integer.bubbles_overflow_columns);
|
||||||
|
|||||||
@@ -2167,13 +2167,6 @@ public class BubbleStackView extends FrameLayout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
||||||
return super.onInterceptTouchEvent(ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||||
if (ev.getAction() != MotionEvent.ACTION_DOWN && ev.getActionIndex() != mPointerIndexDown) {
|
if (ev.getAction() != MotionEvent.ACTION_DOWN && ev.getActionIndex() != mPointerIndexDown) {
|
||||||
|
|||||||
Reference in New Issue
Block a user