diff options
| author | 2020-05-13 19:32:53 +0000 | |
|---|---|---|
| committer | 2020-05-13 19:32:53 +0000 | |
| commit | b375d0f628ca338daaabb8aec20fe657686db359 (patch) | |
| tree | 1e8dbc93eff85c2ddda6a37210d75e1f18aef00f | |
| parent | 0269ef125c5274ea0c7794b352d2026e25cacd21 (diff) | |
| parent | b4b06136633089f64381de3059e841984790c389 (diff) | |
Merge "Update resources after display size change" into rvc-dev
5 files changed, 53 insertions, 22 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java index 6a5e94ce7096..887f1a7a34b9 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java @@ -198,6 +198,11 @@ public class BubbleController implements ConfigurationController.ConfigurationLi /** Last known orientation, used to detect orientation changes in {@link #onConfigChanged}. */ private int mOrientation = Configuration.ORIENTATION_UNDEFINED; + /** + * Last known screen density, used to detect display size changes in {@link #onConfigChanged}. + */ + private int mDensityDpi = Configuration.DENSITY_DPI_UNDEFINED; + private boolean mInflateSynchronously; // TODO (b/145659174): allow for multiple callbacks to support the "shadow" new notif pipeline @@ -705,9 +710,16 @@ public class BubbleController implements ConfigurationController.ConfigurationLi @Override public void onConfigChanged(Configuration newConfig) { - if (mStackView != null && newConfig != null && newConfig.orientation != mOrientation) { - mOrientation = newConfig.orientation; - mStackView.onOrientationChanged(newConfig.orientation); + if (mStackView != null && newConfig != null) { + if (newConfig.orientation != mOrientation) { + mOrientation = newConfig.orientation; + mStackView.onOrientationChanged(newConfig.orientation); + } + if (newConfig.densityDpi != mDensityDpi) { + mDensityDpi = newConfig.densityDpi; + mBubbleIconFactory = new BubbleIconFactory(mContext); + mStackView.onDisplaySizeChanged(); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflow.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflow.java index e96bef36ba18..f4eb580d70ff 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflow.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleOverflow.java @@ -58,12 +58,13 @@ public class BubbleOverflow implements BubbleViewProvider { public BubbleOverflow(Context context) { mContext = context; mInflater = LayoutInflater.from(context); + } + + void setUpOverflow(ViewGroup parentViewGroup, BubbleStackView stackView) { mBitmapSize = mContext.getResources().getDimensionPixelSize(R.dimen.bubble_bitmap_size); mIconBitmapSize = mContext.getResources().getDimensionPixelSize( R.dimen.bubble_overflow_icon_bitmap_size); - } - void setUpOverflow(ViewGroup parentViewGroup, BubbleStackView stackView) { mExpandedView = (BubbleExpandedView) mInflater.inflate( R.layout.bubble_expanded_view, parentViewGroup /* root */, false /* attachToRoot */); @@ -74,6 +75,7 @@ public class BubbleOverflow implements BubbleViewProvider { } void updateIcon(Context context, ViewGroup parentViewGroup) { + mContext = context; mInflater = LayoutInflater.from(context); mOverflowBtn = (BadgedImageView) mInflater.inflate(R.layout.bubble_overflow_button, parentViewGroup /* root */, @@ -87,7 +89,7 @@ public class BubbleOverflow implements BubbleViewProvider { ta.recycle(); TypedValue typedValue = new TypedValue(); - context.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); + mContext.getTheme().resolveAttribute(android.R.attr.colorAccent, typedValue, true); int colorAccent = mContext.getColor(typedValue.resourceId); mOverflowBtn.getDrawable().setTint(colorAccent); mDotColor = colorAccent; @@ -97,7 +99,7 @@ public class BubbleOverflow implements BubbleViewProvider { mBitmapSize - mIconBitmapSize /* inset */); AdaptiveIconDrawable adaptiveIconDrawable = new AdaptiveIconDrawable(bg, fg); - BubbleIconFactory iconFactory = new BubbleIconFactory(context); + BubbleIconFactory iconFactory = new BubbleIconFactory(mContext); mIcon = iconFactory.createBadgedIconBitmap(adaptiveIconDrawable, null /* user */, true /* shrinkNonAdaptiveIcons */).icon; @@ -106,7 +108,7 @@ public class BubbleOverflow implements BubbleViewProvider { null /* outBounds */, null /* path */, null /* outMaskShape */); float radius = DEFAULT_PATH_SIZE / 2f; mPath = PathParser.createPathFromPathData( - context.getResources().getString(com.android.internal.R.string.config_icon_mask)); + mContext.getResources().getString(com.android.internal.R.string.config_icon_mask)); Matrix matrix = new Matrix(); matrix.setScale(scale /* x scale */, scale /* y scale */, radius /* pivot x */, radius /* pivot y */); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index 4b29e1960825..88f5eb0b250c 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -790,8 +790,8 @@ public class BubbleStackView extends FrameLayout mOrientationChangedListener = (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { - mExpandedAnimationController.updateOrientation(mOrientation, mDisplaySize); - mStackAnimationController.updateOrientation(mOrientation); + mExpandedAnimationController.updateResources(mOrientation, mDisplaySize); + mStackAnimationController.updateResources(mOrientation); // Reposition & adjust the height for new orientation if (mIsExpanded) { @@ -1007,7 +1007,7 @@ public class BubbleStackView extends FrameLayout mBubbleOverflow.setUpOverflow(mBubbleContainer, this); } else { mBubbleContainer.removeView(mBubbleOverflow.getBtn()); - mBubbleOverflow.updateIcon(mContext, this); + mBubbleOverflow.updateIcon(mContext,this); overflowBtnIndex = mBubbleContainer.getChildCount(); } mBubbleContainer.addView(mBubbleOverflow.getBtn(), overflowBtnIndex, @@ -1054,6 +1054,28 @@ public class BubbleStackView extends FrameLayout mShowingManage = false; } + /** Respond to the display size change by recalculating view size and location. */ + public void onDisplaySizeChanged() { + setUpOverflow(); + + WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); + wm.getDefaultDisplay().getRealSize(mDisplaySize); + Resources res = getContext().getResources(); + mStatusBarHeight = res.getDimensionPixelSize( + com.android.internal.R.dimen.status_bar_height); + mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); + mBubbleSize = getResources().getDimensionPixelSize(R.dimen.individual_bubble_size); + for (Bubble b : mBubbleData.getBubbles()) { + if (b.getIconView() == null) { + Log.d(TAG, "Display size changed. Icon null: " + b); + continue; + } + b.getIconView().setLayoutParams(new LayoutParams(mBubbleSize, mBubbleSize)); + } + mExpandedAnimationController.updateResources(mOrientation, mDisplaySize); + mStackAnimationController.updateResources(mOrientation); + } + @Override public void onComputeInternalInsets(ViewTreeObserver.InternalInsetsInfo inoutInfo) { inoutInfo.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION); @@ -1294,7 +1316,7 @@ public class BubbleStackView extends FrameLayout Log.d(TAG, "was asked to remove Bubble, but didn't find the view! " + bubble); } - private void updateOverflowBtnVisibility(boolean apply) { + private void updateOverflowBtnVisibility() { if (!BubbleExperimentConfig.allowBubbleOverflow(mContext)) { return; } @@ -1303,11 +1325,6 @@ public class BubbleStackView extends FrameLayout Log.d(TAG, "Show overflow button."); } mBubbleOverflow.setBtnVisible(VISIBLE); - if (apply) { - mExpandedAnimationController.expandFromStack(() -> { - updatePointerPosition(); - } /* after */); - } } else { if (DEBUG_BUBBLE_STACK_VIEW) { Log.d(TAG, "Collapsed. Hide overflow button."); @@ -1567,7 +1584,7 @@ public class BubbleStackView extends FrameLayout Log.d(TAG, BubbleDebugConfig.formatBubblesString(getBubblesOnScreen(), mExpandedBubble)); } - updateOverflowBtnVisibility(/* apply */ false); + updateOverflowBtnVisibility(); mBubbleContainer.cancelAllAnimations(); mExpandedAnimationController.collapseBackToStack( mStackAnimationController.getStackPositionAlongNearestHorizontalEdge() @@ -1591,7 +1608,7 @@ public class BubbleStackView extends FrameLayout beforeExpandedViewAnimation(); mBubbleContainer.setActiveController(mExpandedAnimationController); - updateOverflowBtnVisibility(/* apply */ false); + updateOverflowBtnVisibility(); mExpandedAnimationController.expandFromStack(() -> { updatePointerPosition(); afterExpandedViewAnimation(); diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java b/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java index 35406c71a080..f57cf42ce4ff 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/animation/ExpandedAnimationController.java @@ -118,7 +118,7 @@ public class ExpandedAnimationController public ExpandedAnimationController(Point displaySize, int expandedViewPadding, int orientation) { - updateOrientation(orientation, displaySize); + updateResources(orientation, displaySize); mExpandedViewPadding = expandedViewPadding; } @@ -168,7 +168,7 @@ public class ExpandedAnimationController * @param orientation Landscape or portrait. * @param displaySize Updated display size. */ - public void updateOrientation(int orientation, Point displaySize) { + public void updateResources(int orientation, Point displaySize) { mScreenOrientation = orientation; mDisplaySize = displaySize; if (mLayout != null) { diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java index 5f3a2bd9eb8b..2cfe1dde0b51 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/animation/StackAnimationController.java @@ -809,7 +809,7 @@ public class StackAnimationController extends * Update effective screen width based on current orientation. * @param orientation Landscape or portrait. */ - public void updateOrientation(int orientation) { + public void updateResources(int orientation) { if (mLayout != null) { Resources res = mLayout.getContext().getResources(); mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); |