Merge "Update overflow, expanded view dimens after dpi change" into rvc-dev

This commit is contained in:
Lyn Han
2020-05-26 17:35:04 +00:00
committed by Android (Google) Code Review
4 changed files with 30 additions and 13 deletions

View File

@@ -226,8 +226,12 @@ public class BubbleExpandedView extends LinearLayout {
public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr, public BubbleExpandedView(Context context, AttributeSet attrs, int defStyleAttr,
int defStyleRes) { int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
updateDimensions();
}
void updateDimensions() {
mDisplaySize = new Point(); mDisplaySize = new Point();
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
// Get the real size -- this includes screen decorations (notches, statusbar, navbar). // Get the real size -- this includes screen decorations (notches, statusbar, navbar).
mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize); mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize);
Resources res = getResources(); Resources res = getResources();

View File

@@ -61,9 +61,7 @@ public class BubbleOverflow implements BubbleViewProvider {
} }
void setUpOverflow(ViewGroup parentViewGroup, BubbleStackView stackView) { void setUpOverflow(ViewGroup parentViewGroup, BubbleStackView stackView) {
mBitmapSize = mContext.getResources().getDimensionPixelSize(R.dimen.bubble_bitmap_size); updateDimensions();
mIconBitmapSize = mContext.getResources().getDimensionPixelSize(
R.dimen.bubble_overflow_icon_bitmap_size);
mExpandedView = (BubbleExpandedView) mInflater.inflate( mExpandedView = (BubbleExpandedView) mInflater.inflate(
R.layout.bubble_expanded_view, parentViewGroup /* root */, R.layout.bubble_expanded_view, parentViewGroup /* root */,
@@ -74,6 +72,15 @@ public class BubbleOverflow implements BubbleViewProvider {
updateIcon(mContext, parentViewGroup); updateIcon(mContext, parentViewGroup);
} }
void updateDimensions() {
mBitmapSize = mContext.getResources().getDimensionPixelSize(R.dimen.bubble_bitmap_size);
mIconBitmapSize = mContext.getResources().getDimensionPixelSize(
R.dimen.bubble_overflow_icon_bitmap_size);
if (mExpandedView != null) {
mExpandedView.updateDimensions();
}
}
void updateIcon(Context context, ViewGroup parentViewGroup) { void updateIcon(Context context, ViewGroup parentViewGroup) {
mContext = context; mContext = context;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);

View File

@@ -92,6 +92,14 @@ public class BubbleOverflowActivity extends Activity {
mRecyclerView = findViewById(R.id.bubble_overflow_recycler); mRecyclerView = findViewById(R.id.bubble_overflow_recycler);
mEmptyStateImage = findViewById(R.id.bubble_overflow_empty_state_image); mEmptyStateImage = findViewById(R.id.bubble_overflow_empty_state_image);
updateDimensions();
onDataChanged(mBubbleController.getOverflowBubbles());
mBubbleController.setOverflowCallback(() -> {
onDataChanged(mBubbleController.getOverflowBubbles());
});
}
void updateDimensions() {
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);
mRecyclerView.setLayoutManager( mRecyclerView.setLayoutManager(
@@ -99,8 +107,9 @@ public class BubbleOverflowActivity extends Activity {
DisplayMetrics displayMetrics = new DisplayMetrics(); DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
final int recyclerViewWidth = (displayMetrics.widthPixels
- res.getDimensionPixelSize(R.dimen.bubble_overflow_padding)); final int overflowPadding = res.getDimensionPixelSize(R.dimen.bubble_overflow_padding);
final int recyclerViewWidth = displayMetrics.widthPixels - (overflowPadding * 2);
final int viewWidth = recyclerViewWidth / columns; final int viewWidth = recyclerViewWidth / columns;
final int maxOverflowBubbles = res.getInteger(R.integer.bubbles_max_overflow); final int maxOverflowBubbles = res.getInteger(R.integer.bubbles_max_overflow);
@@ -112,17 +121,12 @@ public class BubbleOverflowActivity extends Activity {
mAdapter = new BubbleOverflowAdapter(getApplicationContext(), mOverflowBubbles, mAdapter = new BubbleOverflowAdapter(getApplicationContext(), mOverflowBubbles,
mBubbleController::promoteBubbleFromOverflow, viewWidth, viewHeight); mBubbleController::promoteBubbleFromOverflow, viewWidth, viewHeight);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
onDataChanged(mBubbleController.getOverflowBubbles());
mBubbleController.setOverflowCallback(() -> {
onDataChanged(mBubbleController.getOverflowBubbles());
});
onThemeChanged();
} }
/** /**
* Handle theme changes. * Handle theme changes.
*/ */
void onThemeChanged() { void updateTheme() {
final int mode = final int mode =
getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
switch (mode) { switch (mode) {
@@ -181,7 +185,8 @@ public class BubbleOverflowActivity extends Activity {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
onThemeChanged(); updateDimensions();
updateTheme();
} }
@Override @Override

View File

@@ -1033,6 +1033,7 @@ public class BubbleStackView extends FrameLayout
mBubbleOverflow.setUpOverflow(mBubbleContainer, this); mBubbleOverflow.setUpOverflow(mBubbleContainer, this);
} else { } else {
mBubbleContainer.removeView(mBubbleOverflow.getBtn()); mBubbleContainer.removeView(mBubbleOverflow.getBtn());
mBubbleOverflow.updateDimensions();
mBubbleOverflow.updateIcon(mContext,this); mBubbleOverflow.updateIcon(mContext,this);
overflowBtnIndex = mBubbleContainer.getChildCount(); overflowBtnIndex = mBubbleContainer.getChildCount();
} }