Loading packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt +22 −8 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,8 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec private val debugTransparentRegionPaint: Paint? private val debugTransparentRegionPaint: Paint? private val tempRect: Rect = Rect() private val tempRect: Rect = Rect() private var hasTopRoundedCorner = false private var hasBottomRoundedCorner = false private var roundedCornerTopSize = 0 private var roundedCornerTopSize = 0 private var roundedCornerBottomSize = 0 private var roundedCornerBottomSize = 0 private var roundedCornerDrawableTop: Drawable? = null private var roundedCornerDrawableTop: Drawable? = null Loading Loading @@ -300,7 +302,7 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec } } private fun drawRoundedCorners(canvas: Canvas) { private fun drawRoundedCorners(canvas: Canvas) { if (roundedCornerTopSize == 0 && roundedCornerBottomSize == 0) { if (!hasTopRoundedCorner && !hasBottomRoundedCorner) { return return } } var degree: Int var degree: Int Loading @@ -312,9 +314,11 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec canvas.translate( canvas.translate( getRoundedCornerTranslationX(degree).toFloat(), getRoundedCornerTranslationX(degree).toFloat(), getRoundedCornerTranslationY(degree).toFloat()) getRoundedCornerTranslationY(degree).toFloat()) if (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT) { if (hasTopRoundedCorner && (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT)) { drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize) drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize) } else { } else if (hasBottomRoundedCorner && (i == RoundedCorner.POSITION_BOTTOM_LEFT || i == RoundedCorner.POSITION_BOTTOM_RIGHT)) { drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize) drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize) } } canvas.restore() canvas.restore() Loading Loading @@ -366,14 +370,24 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec } } /** /** * Update the rounded corner size. * Update the rounded corner existence and size. */ */ fun updateRoundedCornerSize(top: Int, bottom: Int) { fun updateRoundedCornerExistenceAndSize( if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) { hasTop: Boolean, hasBottom: Boolean, topSize: Int, bottomSize: Int ) { if (hasTopRoundedCorner == hasTop && hasBottomRoundedCorner == hasBottom && roundedCornerBottomSize == bottomSize && roundedCornerBottomSize == bottomSize) { return return } } roundedCornerTopSize = top hasTopRoundedCorner = hasTop roundedCornerBottomSize = bottom hasBottomRoundedCorner = hasBottom roundedCornerTopSize = topSize roundedCornerBottomSize = bottomSize updateRoundedCornerDrawableBounds() updateRoundedCornerDrawableBounds() // Use requestLayout() to trigger transparent region recalculated // Use requestLayout() to trigger transparent region recalculated Loading packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -132,9 +132,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab private final ThreadFactory mThreadFactory; private final ThreadFactory mThreadFactory; private final DecorProviderFactory mDotFactory; private final DecorProviderFactory mDotFactory; //TODO: These are piecemeal being updated to Points for now to support non-square rounded // corners. for now it is only supposed when reading the intrinsic size from the drawables with // mIsRoundedCornerMultipleRadius is set @VisibleForTesting @VisibleForTesting protected RoundedCornerResDelegate mRoundedCornerResDelegate; protected RoundedCornerResDelegate mRoundedCornerResDelegate; @VisibleForTesting @VisibleForTesting Loading Loading @@ -406,7 +403,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) { updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); } } updateOverlayProviderViews(); updateOverlayProviderViews(); Loading Loading @@ -699,7 +696,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams( mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams( MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START)); MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START)); mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams()); mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams()); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener( mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener( new ValidatingPreDrawListener(mScreenDecorHwcWindow)); new ValidatingPreDrawListener(mScreenDecorHwcWindow)); Loading Loading @@ -961,7 +958,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) { mScreenDecorHwcLayer.pendingRotationChange = false; mScreenDecorHwcLayer.pendingRotationChange = false; mScreenDecorHwcLayer.updateRotation(mRotation); mScreenDecorHwcLayer.updateRotation(mRotation); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); } } updateLayoutParams(); updateLayoutParams(); Loading Loading @@ -1090,7 +1087,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation, overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation, mDisplayUniqueId); mDisplayUniqueId); } } updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); }); }); } } Loading @@ -1108,15 +1105,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable); mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable); } } private void updateHwLayerRoundedCornerSize() { private void updateHwLayerRoundedCornerExistAndSize() { if (mScreenDecorHwcLayer == null) { if (mScreenDecorHwcLayer == null) { return; return; } } mScreenDecorHwcLayer.updateRoundedCornerExistenceAndSize( final int topWidth = mRoundedCornerResDelegate.getTopRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasTop(), final int bottomWidth = mRoundedCornerResDelegate.getBottomRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasBottom(), mRoundedCornerResDelegate.getTopRoundedSize().getWidth(), mScreenDecorHwcLayer.updateRoundedCornerSize(topWidth, bottomWidth); mRoundedCornerResDelegate.getBottomRoundedSize().getWidth()); } } @VisibleForTesting @VisibleForTesting Loading packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt +3 −4 Original line number Original line Diff line number Diff line Loading @@ -25,8 +25,7 @@ class RoundedCornerDecorProviderFactory( override val hasProviders: Boolean override val hasProviders: Boolean get() = roundedCornerResDelegate.run { get() = roundedCornerResDelegate.run { // We don't consider isMultipleRadius here because it makes no sense if size is zero. hasTop || hasBottom topRoundedSize.width > 0 || bottomRoundedSize.width > 0 } } override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { Loading @@ -35,8 +34,8 @@ class RoundedCornerDecorProviderFactory( override val providers: List<DecorProvider> override val providers: List<DecorProvider> get() { get() { val hasTop = roundedCornerResDelegate.topRoundedSize.width > 0 val hasTop = roundedCornerResDelegate.hasTop val hasBottom = roundedCornerResDelegate.bottomRoundedSize.width > 0 val hasBottom = roundedCornerResDelegate.hasBottom return when { return when { hasTop && hasBottom -> listOf( hasTop && hasBottom -> listOf( RoundedCornerDecorProviderImpl( RoundedCornerDecorProviderImpl( Loading packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt +17 −58 Original line number Original line Diff line number Diff line Loading @@ -37,10 +37,11 @@ class RoundedCornerResDelegate( private var reloadToken: Int = 0 private var reloadToken: Int = 0 var isMultipleRadius: Boolean = false var hasTop: Boolean = false private set private set private var roundedDrawable: Drawable? = null var hasBottom: Boolean = false private set var topRoundedDrawable: Drawable? = null var topRoundedDrawable: Drawable? = null private set private set Loading @@ -48,8 +49,6 @@ class RoundedCornerResDelegate( var bottomRoundedDrawable: Drawable? = null var bottomRoundedDrawable: Drawable? = null private set private set private var roundedSize = Size(0, 0) var topRoundedSize = Size(0, 0) var topRoundedSize = Size(0, 0) private set private set Loading Loading @@ -83,53 +82,32 @@ class RoundedCornerResDelegate( private fun reloadRes() { private fun reloadRes() { val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) isMultipleRadius = getIsMultipleRadius(configIdx) roundedDrawable = getDrawable( val hasDefaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) > 0 displayConfigIndex = configIdx, hasTop = hasDefaultRadius || arrayResId = R.array.config_roundedCornerDrawableArray, (RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) > 0) backupDrawableId = R.drawable.rounded hasBottom = hasDefaultRadius || ) (RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) > 0) topRoundedDrawable = getDrawable( topRoundedDrawable = getDrawable( displayConfigIndex = configIdx, displayConfigIndex = configIdx, arrayResId = R.array.config_roundedCornerTopDrawableArray, arrayResId = R.array.config_roundedCornerTopDrawableArray, backupDrawableId = R.drawable.rounded_corner_top backupDrawableId = R.drawable.rounded_corner_top ) ?: roundedDrawable ) bottomRoundedDrawable = getDrawable( bottomRoundedDrawable = getDrawable( displayConfigIndex = configIdx, displayConfigIndex = configIdx, arrayResId = R.array.config_roundedCornerBottomDrawableArray, arrayResId = R.array.config_roundedCornerBottomDrawableArray, backupDrawableId = R.drawable.rounded_corner_bottom backupDrawableId = R.drawable.rounded_corner_bottom ) ?: roundedDrawable ) } } private fun reloadMeasures(roundedSizeFactor: Int? = null) { private fun reloadMeasures(roundedSizeFactor: Int? = null) { // If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the // (width, height) size of drawable/rounded.xml instead of rounded_corner_radius if (isMultipleRadius) { roundedSize = Size( roundedDrawable?.intrinsicWidth ?: 0, roundedDrawable?.intrinsicHeight ?: 0) topRoundedDrawable?.let { topRoundedDrawable?.let { topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } } bottomRoundedDrawable?.let { bottomRoundedDrawable?.let { bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } } } else { val defaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) val topRadius = RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) val bottomRadius = RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) roundedSize = Size(defaultRadius, defaultRadius) topRoundedSize = Size(topRadius, topRadius) bottomRoundedSize = Size(bottomRadius, bottomRadius) } if (topRoundedSize.width == 0) { topRoundedSize = roundedSize } if (bottomRoundedSize.width == 0) { bottomRoundedSize = roundedSize } if (roundedSizeFactor != null && roundedSizeFactor > 0) { if (roundedSizeFactor != null && roundedSizeFactor > 0) { val length: Int = (roundedSizeFactor * density).toInt() val length: Int = (roundedSizeFactor * density).toInt() Loading @@ -146,25 +124,6 @@ class RoundedCornerResDelegate( reloadMeasures(factor) reloadMeasures(factor) } } /** * Gets whether the rounded corners are multiple radii for current display. * * Loads the default config {@link R.bool#config_roundedCornerMultipleRadius} if * {@link com.android.internal.R.array#config_displayUniqueIdArray} is not set. */ private fun getIsMultipleRadius(displayConfigIndex: Int): Boolean { val isMultipleRadius: Boolean res.obtainTypedArray(R.array.config_roundedCornerMultipleRadiusArray).let { array -> isMultipleRadius = if (displayConfigIndex >= 0 && displayConfigIndex < array.length()) { array.getBoolean(displayConfigIndex, false) } else { res.getBoolean(R.bool.config_roundedCornerMultipleRadius) } array.recycle() } return isMultipleRadius } private fun getDrawable( private fun getDrawable( displayConfigIndex: Int, displayConfigIndex: Int, @ArrayRes arrayResId: Int, @ArrayRes arrayResId: Int, Loading @@ -184,8 +143,8 @@ class RoundedCornerResDelegate( override fun dump(pw: PrintWriter, args: Array<out String>) { override fun dump(pw: PrintWriter, args: Array<out String>) { pw.println("RoundedCornerResDelegate state:") pw.println("RoundedCornerResDelegate state:") pw.println(" isMultipleRadius:$isMultipleRadius") pw.println(" hasTop=$hasTop") pw.println(" roundedSize(w,h)=(${roundedSize.width},${roundedSize.height})") pw.println(" hasBottom=$hasBottom") pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})") pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})") pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," + pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," + "${bottomRoundedSize.height})") "${bottomRoundedSize.height})") Loading packages/SystemUI/tests/res/drawable/rounded3px.xml 0 → 100644 +24 −0 Original line number Original line Diff line number Diff line <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="3px" android:height="3px" android:viewportWidth="3" android:viewportHeight="3"> <path android:fillColor="#000000" android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" /> </vector> Loading
packages/SystemUI/src/com/android/systemui/ScreenDecorHwcLayer.kt +22 −8 Original line number Original line Diff line number Diff line Loading @@ -60,6 +60,8 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec private val debugTransparentRegionPaint: Paint? private val debugTransparentRegionPaint: Paint? private val tempRect: Rect = Rect() private val tempRect: Rect = Rect() private var hasTopRoundedCorner = false private var hasBottomRoundedCorner = false private var roundedCornerTopSize = 0 private var roundedCornerTopSize = 0 private var roundedCornerBottomSize = 0 private var roundedCornerBottomSize = 0 private var roundedCornerDrawableTop: Drawable? = null private var roundedCornerDrawableTop: Drawable? = null Loading Loading @@ -300,7 +302,7 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec } } private fun drawRoundedCorners(canvas: Canvas) { private fun drawRoundedCorners(canvas: Canvas) { if (roundedCornerTopSize == 0 && roundedCornerBottomSize == 0) { if (!hasTopRoundedCorner && !hasBottomRoundedCorner) { return return } } var degree: Int var degree: Int Loading @@ -312,9 +314,11 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec canvas.translate( canvas.translate( getRoundedCornerTranslationX(degree).toFloat(), getRoundedCornerTranslationX(degree).toFloat(), getRoundedCornerTranslationY(degree).toFloat()) getRoundedCornerTranslationY(degree).toFloat()) if (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT) { if (hasTopRoundedCorner && (i == RoundedCorner.POSITION_TOP_LEFT || i == RoundedCorner.POSITION_TOP_RIGHT)) { drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize) drawRoundedCorner(canvas, roundedCornerDrawableTop, roundedCornerTopSize) } else { } else if (hasBottomRoundedCorner && (i == RoundedCorner.POSITION_BOTTOM_LEFT || i == RoundedCorner.POSITION_BOTTOM_RIGHT)) { drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize) drawRoundedCorner(canvas, roundedCornerDrawableBottom, roundedCornerBottomSize) } } canvas.restore() canvas.restore() Loading Loading @@ -366,14 +370,24 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec } } /** /** * Update the rounded corner size. * Update the rounded corner existence and size. */ */ fun updateRoundedCornerSize(top: Int, bottom: Int) { fun updateRoundedCornerExistenceAndSize( if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) { hasTop: Boolean, hasBottom: Boolean, topSize: Int, bottomSize: Int ) { if (hasTopRoundedCorner == hasTop && hasBottomRoundedCorner == hasBottom && roundedCornerBottomSize == bottomSize && roundedCornerBottomSize == bottomSize) { return return } } roundedCornerTopSize = top hasTopRoundedCorner = hasTop roundedCornerBottomSize = bottom hasBottomRoundedCorner = hasBottom roundedCornerTopSize = topSize roundedCornerBottomSize = bottomSize updateRoundedCornerDrawableBounds() updateRoundedCornerDrawableBounds() // Use requestLayout() to trigger transparent region recalculated // Use requestLayout() to trigger transparent region recalculated Loading
packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +10 −13 Original line number Original line Diff line number Diff line Loading @@ -132,9 +132,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab private final ThreadFactory mThreadFactory; private final ThreadFactory mThreadFactory; private final DecorProviderFactory mDotFactory; private final DecorProviderFactory mDotFactory; //TODO: These are piecemeal being updated to Points for now to support non-square rounded // corners. for now it is only supposed when reading the intrinsic size from the drawables with // mIsRoundedCornerMultipleRadius is set @VisibleForTesting @VisibleForTesting protected RoundedCornerResDelegate mRoundedCornerResDelegate; protected RoundedCornerResDelegate mRoundedCornerResDelegate; @VisibleForTesting @VisibleForTesting Loading Loading @@ -406,7 +403,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) { updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); } } updateOverlayProviderViews(); updateOverlayProviderViews(); Loading Loading @@ -699,7 +696,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams( mScreenDecorHwcWindow.addView(mScreenDecorHwcLayer, new FrameLayout.LayoutParams( MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START)); MATCH_PARENT, MATCH_PARENT, Gravity.TOP | Gravity.START)); mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams()); mWindowManager.addView(mScreenDecorHwcWindow, getHwcWindowLayoutParams()); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener( mScreenDecorHwcWindow.getViewTreeObserver().addOnPreDrawListener( new ValidatingPreDrawListener(mScreenDecorHwcWindow)); new ValidatingPreDrawListener(mScreenDecorHwcWindow)); Loading Loading @@ -961,7 +958,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab if (mScreenDecorHwcLayer != null) { if (mScreenDecorHwcLayer != null) { mScreenDecorHwcLayer.pendingRotationChange = false; mScreenDecorHwcLayer.pendingRotationChange = false; mScreenDecorHwcLayer.updateRotation(mRotation); mScreenDecorHwcLayer.updateRotation(mRotation); updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); updateHwLayerRoundedCornerDrawable(); updateHwLayerRoundedCornerDrawable(); } } updateLayoutParams(); updateLayoutParams(); Loading Loading @@ -1090,7 +1087,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation, overlay.onReloadResAndMeasure(filterIds, mProviderRefreshToken, mRotation, mDisplayUniqueId); mDisplayUniqueId); } } updateHwLayerRoundedCornerSize(); updateHwLayerRoundedCornerExistAndSize(); }); }); } } Loading @@ -1108,15 +1105,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable); mScreenDecorHwcLayer.updateRoundedCornerDrawable(topDrawable, bottomDrawable); } } private void updateHwLayerRoundedCornerSize() { private void updateHwLayerRoundedCornerExistAndSize() { if (mScreenDecorHwcLayer == null) { if (mScreenDecorHwcLayer == null) { return; return; } } mScreenDecorHwcLayer.updateRoundedCornerExistenceAndSize( final int topWidth = mRoundedCornerResDelegate.getTopRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasTop(), final int bottomWidth = mRoundedCornerResDelegate.getBottomRoundedSize().getWidth(); mRoundedCornerResDelegate.getHasBottom(), mRoundedCornerResDelegate.getTopRoundedSize().getWidth(), mScreenDecorHwcLayer.updateRoundedCornerSize(topWidth, bottomWidth); mRoundedCornerResDelegate.getBottomRoundedSize().getWidth()); } } @VisibleForTesting @VisibleForTesting Loading
packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt +3 −4 Original line number Original line Diff line number Diff line Loading @@ -25,8 +25,7 @@ class RoundedCornerDecorProviderFactory( override val hasProviders: Boolean override val hasProviders: Boolean get() = roundedCornerResDelegate.run { get() = roundedCornerResDelegate.run { // We don't consider isMultipleRadius here because it makes no sense if size is zero. hasTop || hasBottom topRoundedSize.width > 0 || bottomRoundedSize.width > 0 } } override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { Loading @@ -35,8 +34,8 @@ class RoundedCornerDecorProviderFactory( override val providers: List<DecorProvider> override val providers: List<DecorProvider> get() { get() { val hasTop = roundedCornerResDelegate.topRoundedSize.width > 0 val hasTop = roundedCornerResDelegate.hasTop val hasBottom = roundedCornerResDelegate.bottomRoundedSize.width > 0 val hasBottom = roundedCornerResDelegate.hasBottom return when { return when { hasTop && hasBottom -> listOf( hasTop && hasBottom -> listOf( RoundedCornerDecorProviderImpl( RoundedCornerDecorProviderImpl( Loading
packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt +17 −58 Original line number Original line Diff line number Diff line Loading @@ -37,10 +37,11 @@ class RoundedCornerResDelegate( private var reloadToken: Int = 0 private var reloadToken: Int = 0 var isMultipleRadius: Boolean = false var hasTop: Boolean = false private set private set private var roundedDrawable: Drawable? = null var hasBottom: Boolean = false private set var topRoundedDrawable: Drawable? = null var topRoundedDrawable: Drawable? = null private set private set Loading @@ -48,8 +49,6 @@ class RoundedCornerResDelegate( var bottomRoundedDrawable: Drawable? = null var bottomRoundedDrawable: Drawable? = null private set private set private var roundedSize = Size(0, 0) var topRoundedSize = Size(0, 0) var topRoundedSize = Size(0, 0) private set private set Loading Loading @@ -83,53 +82,32 @@ class RoundedCornerResDelegate( private fun reloadRes() { private fun reloadRes() { val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId) isMultipleRadius = getIsMultipleRadius(configIdx) roundedDrawable = getDrawable( val hasDefaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) > 0 displayConfigIndex = configIdx, hasTop = hasDefaultRadius || arrayResId = R.array.config_roundedCornerDrawableArray, (RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) > 0) backupDrawableId = R.drawable.rounded hasBottom = hasDefaultRadius || ) (RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) > 0) topRoundedDrawable = getDrawable( topRoundedDrawable = getDrawable( displayConfigIndex = configIdx, displayConfigIndex = configIdx, arrayResId = R.array.config_roundedCornerTopDrawableArray, arrayResId = R.array.config_roundedCornerTopDrawableArray, backupDrawableId = R.drawable.rounded_corner_top backupDrawableId = R.drawable.rounded_corner_top ) ?: roundedDrawable ) bottomRoundedDrawable = getDrawable( bottomRoundedDrawable = getDrawable( displayConfigIndex = configIdx, displayConfigIndex = configIdx, arrayResId = R.array.config_roundedCornerBottomDrawableArray, arrayResId = R.array.config_roundedCornerBottomDrawableArray, backupDrawableId = R.drawable.rounded_corner_bottom backupDrawableId = R.drawable.rounded_corner_bottom ) ?: roundedDrawable ) } } private fun reloadMeasures(roundedSizeFactor: Int? = null) { private fun reloadMeasures(roundedSizeFactor: Int? = null) { // If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the // (width, height) size of drawable/rounded.xml instead of rounded_corner_radius if (isMultipleRadius) { roundedSize = Size( roundedDrawable?.intrinsicWidth ?: 0, roundedDrawable?.intrinsicHeight ?: 0) topRoundedDrawable?.let { topRoundedDrawable?.let { topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } } bottomRoundedDrawable?.let { bottomRoundedDrawable?.let { bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } } } else { val defaultRadius = RoundedCorners.getRoundedCornerRadius(res, displayUniqueId) val topRadius = RoundedCorners.getRoundedCornerTopRadius(res, displayUniqueId) val bottomRadius = RoundedCorners.getRoundedCornerBottomRadius(res, displayUniqueId) roundedSize = Size(defaultRadius, defaultRadius) topRoundedSize = Size(topRadius, topRadius) bottomRoundedSize = Size(bottomRadius, bottomRadius) } if (topRoundedSize.width == 0) { topRoundedSize = roundedSize } if (bottomRoundedSize.width == 0) { bottomRoundedSize = roundedSize } if (roundedSizeFactor != null && roundedSizeFactor > 0) { if (roundedSizeFactor != null && roundedSizeFactor > 0) { val length: Int = (roundedSizeFactor * density).toInt() val length: Int = (roundedSizeFactor * density).toInt() Loading @@ -146,25 +124,6 @@ class RoundedCornerResDelegate( reloadMeasures(factor) reloadMeasures(factor) } } /** * Gets whether the rounded corners are multiple radii for current display. * * Loads the default config {@link R.bool#config_roundedCornerMultipleRadius} if * {@link com.android.internal.R.array#config_displayUniqueIdArray} is not set. */ private fun getIsMultipleRadius(displayConfigIndex: Int): Boolean { val isMultipleRadius: Boolean res.obtainTypedArray(R.array.config_roundedCornerMultipleRadiusArray).let { array -> isMultipleRadius = if (displayConfigIndex >= 0 && displayConfigIndex < array.length()) { array.getBoolean(displayConfigIndex, false) } else { res.getBoolean(R.bool.config_roundedCornerMultipleRadius) } array.recycle() } return isMultipleRadius } private fun getDrawable( private fun getDrawable( displayConfigIndex: Int, displayConfigIndex: Int, @ArrayRes arrayResId: Int, @ArrayRes arrayResId: Int, Loading @@ -184,8 +143,8 @@ class RoundedCornerResDelegate( override fun dump(pw: PrintWriter, args: Array<out String>) { override fun dump(pw: PrintWriter, args: Array<out String>) { pw.println("RoundedCornerResDelegate state:") pw.println("RoundedCornerResDelegate state:") pw.println(" isMultipleRadius:$isMultipleRadius") pw.println(" hasTop=$hasTop") pw.println(" roundedSize(w,h)=(${roundedSize.width},${roundedSize.height})") pw.println(" hasBottom=$hasBottom") pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})") pw.println(" topRoundedSize(w,h)=(${topRoundedSize.width},${topRoundedSize.height})") pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," + pw.println(" bottomRoundedSize(w,h)=(${bottomRoundedSize.width}," + "${bottomRoundedSize.height})") "${bottomRoundedSize.height})") Loading
packages/SystemUI/tests/res/drawable/rounded3px.xml 0 → 100644 +24 −0 Original line number Original line Diff line number Diff line <!-- ~ Copyright (C) 2022 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="3px" android:height="3px" android:viewportWidth="3" android:viewportHeight="3"> <path android:fillColor="#000000" android:pathData="M8,0H0v8C0,3.6,3.6,0,8,0z" /> </vector>