Merge "Passing info to RoundedCornerResDelegate directly" into tm-dev

This commit is contained in:
Milton Wu
2022-04-19 15:26:42 +00:00
committed by Android (Google) Code Review
7 changed files with 43 additions and 47 deletions

View File

@@ -64,7 +64,6 @@ import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
@@ -292,11 +291,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
return decorProviders; return decorProviders;
} }
private void updateDisplayIdToProviderFactories() {
mDotFactory.onDisplayUniqueIdChanged(mDisplayUniqueId);
mRoundedCornerFactory.onDisplayUniqueIdChanged(mDisplayUniqueId);
}
/** /**
* Check that newProviders is the same list with decorProviders inside mOverlay. * Check that newProviders is the same list with decorProviders inside mOverlay.
* @param newProviders expected comparing DecorProviders * @param newProviders expected comparing DecorProviders
@@ -389,7 +383,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
final DisplayDecorationSupport newScreenDecorationSupport = final DisplayDecorationSupport newScreenDecorationSupport =
mContext.getDisplay().getDisplayDecorationSupport(); mContext.getDisplay().getDisplayDecorationSupport();
updateDisplayIdToProviderFactories(); mRoundedCornerResDelegate.updateDisplayUniqueId(newUniqueId, null);
// When providers or the value of mSupportHwcScreenDecoration is changed, // When providers or the value of mSupportHwcScreenDecoration is changed,
// re-setup the whole screen decoration. // re-setup the whole screen decoration.
@@ -857,6 +851,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
} }
ColorStateList tintList = ColorStateList.valueOf(mTintColor); ColorStateList tintList = ColorStateList.valueOf(mTintColor);
mRoundedCornerResDelegate.setColorTintList(tintList);
Integer[] roundedCornerIds = {
R.id.rounded_corner_top_left,
R.id.rounded_corner_top_right,
R.id.rounded_corner_bottom_left,
R.id.rounded_corner_bottom_right
};
for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) { for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
if (mOverlays[i] == null) { if (mOverlays[i] == null) {
continue; continue;
@@ -866,19 +869,12 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
View child; View child;
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
child = overlayView.getChildAt(j); child = overlayView.getChildAt(j);
if (child.getId() == R.id.privacy_dot_top_left_container if (child instanceof DisplayCutoutView) {
|| child.getId() == R.id.privacy_dot_top_right_container
|| child.getId() == R.id.privacy_dot_bottom_left_container
|| child.getId() == R.id.privacy_dot_bottom_right_container) {
// Exclude privacy dot from color inversion (for now?)
continue;
}
if (child instanceof ImageView) {
((ImageView) child).setImageTintList(tintList);
} else if (child instanceof DisplayCutoutView) {
((DisplayCutoutView) child).setColor(mTintColor); ((DisplayCutoutView) child).setColor(mTintColor);
} }
} }
mOverlays[i].onReloadResAndMeasure(roundedCornerIds, mProviderRefreshToken, mRotation,
mDisplayUniqueId);
} }
} }
@@ -1067,12 +1063,11 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab
if (mOverlays == null || !SIZE.equals(key)) { if (mOverlays == null || !SIZE.equals(key)) {
return; return;
} }
++mProviderRefreshToken;
try { try {
final int sizeFactor = Integer.parseInt(newValue); final int sizeFactor = Integer.parseInt(newValue);
mRoundedCornerResDelegate.updateTuningSizeFactor(sizeFactor, mProviderRefreshToken); mRoundedCornerResDelegate.setTuningSizeFactor(sizeFactor);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
mRoundedCornerResDelegate.updateTuningSizeFactor(null, mProviderRefreshToken); mRoundedCornerResDelegate.setTuningSizeFactor(null);
} }
Integer[] filterIds = { Integer[] filterIds = {
R.id.rounded_corner_top_left, R.id.rounded_corner_top_left,

View File

@@ -19,5 +19,4 @@ package com.android.systemui.decor
abstract class DecorProviderFactory { abstract class DecorProviderFactory {
abstract val providers: List<DecorProvider> abstract val providers: List<DecorProvider>
abstract val hasProviders: Boolean abstract val hasProviders: Boolean
abstract fun onDisplayUniqueIdChanged(displayUniqueId: String?)
} }

View File

@@ -39,10 +39,6 @@ class PrivacyDotDecorProviderFactory @Inject constructor(
override val hasProviders: Boolean override val hasProviders: Boolean
get() = isPrivacyDotEnabled get() = isPrivacyDotEnabled
override fun onDisplayUniqueIdChanged(displayUniqueId: String?) {
// Do nothing for privacy dot
}
override val providers: List<DecorProvider> override val providers: List<DecorProvider>
get() { get() {
return if (hasProviders) { return if (hasProviders) {

View File

@@ -28,10 +28,6 @@ class RoundedCornerDecorProviderFactory(
hasTop || hasBottom hasTop || hasBottom
} }
override fun onDisplayUniqueIdChanged(displayUniqueId: String?) {
roundedCornerResDelegate.updateDisplayUniqueId(displayUniqueId, null)
}
override val providers: List<DecorProvider> override val providers: List<DecorProvider>
get() { get() {
val hasTop = roundedCornerResDelegate.hasTop val hasTop = roundedCornerResDelegate.hasTop

View File

@@ -65,7 +65,7 @@ class RoundedCornerDecorProviderImpl(
private fun initView(view: ImageView, @Surface.Rotation rotation: Int) { private fun initView(view: ImageView, @Surface.Rotation rotation: Int) {
view.setRoundedCornerImage(roundedCornerResDelegate, isTop) view.setRoundedCornerImage(roundedCornerResDelegate, isTop)
view.adjustRotation(alignedBounds, rotation) view.adjustRotation(alignedBounds, rotation)
view.setColorFilter(IMAGE_TINT_COLOR) view.imageTintList = roundedCornerResDelegate.colorTintList
} }
override fun onReloadResAndMeasure( override fun onReloadResAndMeasure(
@@ -93,8 +93,6 @@ class RoundedCornerDecorProviderImpl(
} }
} }
private const val IMAGE_TINT_COLOR: Int = 0xFF000000.toInt()
@DisplayCutout.BoundsPosition @DisplayCutout.BoundsPosition
private fun Int.toLayoutGravity(@Surface.Rotation rotation: Int): Int = when (rotation) { private fun Int.toLayoutGravity(@Surface.Rotation rotation: Int): Int = when (rotation) {
Surface.ROTATION_0 -> when (this) { Surface.ROTATION_0 -> when (this) {

View File

@@ -18,7 +18,9 @@ package com.android.systemui.decor
import android.annotation.ArrayRes import android.annotation.ArrayRes
import android.annotation.DrawableRes import android.annotation.DrawableRes
import android.content.res.ColorStateList
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Color
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.util.DisplayUtils import android.util.DisplayUtils
import android.util.Size import android.util.Size
@@ -55,6 +57,17 @@ class RoundedCornerResDelegate(
var bottomRoundedSize = Size(0, 0) var bottomRoundedSize = Size(0, 0)
private set private set
var colorTintList = ColorStateList.valueOf(Color.BLACK)
var tuningSizeFactor: Int? = null
set(value) {
if (field == value) {
return
}
field = value
reloadMeasures()
}
init { init {
reloadRes() reloadRes()
reloadMeasures() reloadMeasures()
@@ -101,7 +114,7 @@ class RoundedCornerResDelegate(
) )
} }
private fun reloadMeasures(roundedSizeFactor: Int? = null) { private fun reloadMeasures() {
topRoundedDrawable?.let { topRoundedDrawable?.let {
topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
} }
@@ -109,21 +122,20 @@ class RoundedCornerResDelegate(
bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight)
} }
if (roundedSizeFactor != null && roundedSizeFactor > 0) { tuningSizeFactor?.let {
val length: Int = (roundedSizeFactor * density).toInt() if (it <= 0) {
topRoundedSize = Size(length, length) return
bottomRoundedSize = Size(length, length) }
val length: Int = (it * density).toInt()
if (topRoundedSize.width > 0) {
topRoundedSize = Size(length, length)
}
if (bottomRoundedSize.width > 0) {
bottomRoundedSize = Size(length, length)
}
} }
} }
fun updateTuningSizeFactor(factor: Int?, newReloadToken: Int) {
if (reloadToken == newReloadToken) {
return
}
reloadToken = newReloadToken
reloadMeasures(factor)
}
private fun getDrawable( private fun getDrawable(
displayConfigIndex: Int, displayConfigIndex: Int,
@ArrayRes arrayResId: Int, @ArrayRes arrayResId: Int,

View File

@@ -121,13 +121,13 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
val factor = 5 val factor = 5
roundedCornerResDelegate.updateTuningSizeFactor(factor, 1) roundedCornerResDelegate.tuningSizeFactor = factor
val length = (factor * mContext.resources.displayMetrics.density).toInt() val length = (factor * mContext.resources.displayMetrics.density).toInt()
assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize)
roundedCornerResDelegate.updateTuningSizeFactor(null, 2) roundedCornerResDelegate.tuningSizeFactor = null
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)