Merge "Re-land "Support tuning sysui_rounded_size"" into tm-dev

This commit is contained in:
Milton Wu
2022-03-30 09:29:31 +00:00
committed by Android (Google) Code Review
4 changed files with 25 additions and 38 deletions

View File

@@ -369,10 +369,15 @@ class ScreenDecorHwcLayer(context: Context, displayDecorationSupport: DisplayDec
* Update the rounded corner size.
*/
fun updateRoundedCornerSize(top: Int, bottom: Int) {
if (roundedCornerTopSize == top && roundedCornerBottomSize == bottom) {
return
}
roundedCornerTopSize = top
roundedCornerBottomSize = bottom
updateRoundedCornerDrawableBounds()
invalidate()
// Use requestLayout() to trigger transparent region recalculated
requestLayout()
}
private fun updateRoundedCornerDrawableBounds() {

View File

@@ -1045,13 +1045,22 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
mExecutor.execute(() -> {
if (mOverlays == null) return;
if (SIZE.equals(key)) {
boolean hasReloadRoundedCornerRes = false;
if (newValue != null) {
try {
mRoundedCornerResDelegate.updateTuningSizeFactor(
Integer.parseInt(newValue));
hasReloadRoundedCornerRes = true;
} catch (Exception e) {
}
}
// When onTuningChanged() is not called through updateRoundedCornerRadii(),
// we need to reload rounded corner res to prevent incorrect dimen
if (!hasReloadRoundedCornerRes) {
mRoundedCornerResDelegate.reloadAll(mDisplayUniqueId);
}
updateRoundedCornerSize(
mRoundedCornerResDelegate.getTopRoundedSize(),
mRoundedCornerResDelegate.getBottomRoundedSize());

View File

@@ -56,17 +56,17 @@ class RoundedCornerResDelegate(
private set
init {
reloadDrawables()
reloadRes()
reloadMeasures()
}
fun reloadAll(newDisplayUniqueId: String?) {
displayUniqueId = newDisplayUniqueId
reloadDrawables()
reloadRes()
reloadMeasures()
}
private fun reloadDrawables() {
private fun reloadRes() {
val configIdx = DisplayUtils.getDisplayUniqueIdConfigIndex(res, displayUniqueId)
isMultipleRadius = getIsMultipleRadius(configIdx)
@@ -85,34 +85,6 @@ class RoundedCornerResDelegate(
arrayResId = R.array.config_roundedCornerBottomDrawableArray,
backupDrawableId = R.drawable.rounded_corner_bottom
) ?: roundedDrawable
// 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 {
topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
}
bottomRoundedDrawable?.let {
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
}
}
private fun reloadMeasures(roundedSizeFactor: Int? = null) {
@@ -137,17 +109,18 @@ class RoundedCornerResDelegate(
bottomRoundedSize = Size(bottomRadius, bottomRadius)
}
roundedSizeFactor ?.let {
val length: Int = (it * density).toInt()
roundedSize = Size(length, length)
}
if (topRoundedSize.width == 0) {
topRoundedSize = roundedSize
}
if (bottomRoundedSize.width == 0) {
bottomRoundedSize = roundedSize
}
if (roundedSizeFactor != null && roundedSizeFactor > 0) {
val length: Int = (roundedSizeFactor * density).toInt()
topRoundedSize = Size(length, length)
bottomRoundedSize = Size(length, length)
}
}
fun updateTuningSizeFactor(factor: Int) {

View File

@@ -75,7 +75,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
fun testUpdateTuningSizeFactor() {
mContext.orCreateTestableResources.addOverrides(
mockTypeArray = mockTypedArray,
radiusTop = 0,
radiusTop = 2,
radiusBottom = 0,
multipleRadius = false)