Loading libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/LetterboxConfiguration.kt +45 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,21 @@ class LetterboxConfiguration @Inject constructor( // Color resource id for the solid color letterbox background type. private var letterboxBackgroundColorResourceIdOverride: Int? = null // Default value for corners radius for activities presented in the letterbox mode. // Values < 0 will be ignored. private val letterboxActivityDefaultCornersRadius: Int // Current corners radius for activities presented in the letterbox mode. // Values can be modified at runtime and values < 0 will be ignored. private var letterboxActivityCornersRadius = 0 init { letterboxActivityDefaultCornersRadius = context.resources.getInteger( R.integer.config_letterboxActivityCornersRadius ) letterboxActivityCornersRadius = letterboxActivityDefaultCornersRadius } /** * Sets color of letterbox background which is used when using the solid background mode. */ Loading Loading @@ -64,7 +79,7 @@ class LetterboxConfiguration @Inject constructor( } // Query color dynamically because material colors extracted from wallpaper are updated // when wallpaper is changed. return Color.valueOf(context.getResources().getColor(colorId!!, /* theme */null)) return Color.valueOf(context.getResources().getColor(colorId!!, null)) } /** Loading @@ -79,4 +94,33 @@ class LetterboxConfiguration @Inject constructor( * The background color for the Letterbox. */ fun getBackgroundColorRgbArray(): FloatArray = getLetterboxBackgroundColor().components /** * Overrides corners radius for activities presented in the letterbox mode. Values < 0, * will be ignored and corners of the activity won't be rounded. */ fun setLetterboxActivityCornersRadius(cornersRadius: Int) { letterboxActivityCornersRadius = cornersRadius } /** * Resets corners radius for activities presented in the letterbox mode. */ fun resetLetterboxActivityCornersRadius() { letterboxActivityCornersRadius = letterboxActivityDefaultCornersRadius } /** * Whether corners of letterboxed activities are rounded. */ fun isLetterboxActivityCornersRounded(): Boolean { return getLetterboxActivityCornersRadius() > 0 } /** * Gets corners radius for activities presented in the letterbox mode. */ fun getLetterboxActivityCornersRadius(): Int { return maxOf(letterboxActivityCornersRadius, 0) } } libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/LetterboxConfigurationTest.kt +92 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn import com.android.internal.R import com.android.wm.shell.ShellTestCase import java.util.function.Consumer import kotlin.test.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.doReturn Loading @@ -51,6 +52,14 @@ class LetterboxConfigurationTest : ShellTestCase() { val COLOR_WHITE_RESOURCE_ID = android.R.color.white @JvmStatic val COLOR_BLACK_RESOURCE_ID = android.R.color.black @JvmStatic val ROUNDED_CORNER_RADIUS_DEFAULT = 32 @JvmStatic val ROUNDED_CORNER_RADIUS_VALID = 16 @JvmStatic val ROUNDED_CORNER_RADIUS_NONE = 0 @JvmStatic val ROUNDED_CORNER_RADIUS_INVALID = -10 } @Test Loading Loading @@ -112,6 +121,68 @@ class LetterboxConfigurationTest : ShellTestCase() { } } @Test fun `default rounded corner radius is used if override is not set`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) } } @Test fun `new rounded corner radius is used after setting a valid value`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) } } @Test fun `no rounded corner radius is used after setting an invalid value`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_INVALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_NONE) } } @Test fun `has rounded corners for different values`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkIsLetterboxActivityCornersRounded(true) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_INVALID) r.checkIsLetterboxActivityCornersRounded(false) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_NONE) r.checkIsLetterboxActivityCornersRounded(false) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkIsLetterboxActivityCornersRounded(true) } } @Test fun `reset rounded corners radius`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.resetRoundedCornersRadius() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) } } /** * Runs a test scenario providing a Robot. */ Loading @@ -135,6 +206,11 @@ class LetterboxConfigurationTest : ShellTestCase() { .getColor(R.color.config_letterboxBackgroundColor, null) } fun setDefaultRoundedCornerRadius(radius: Int) { doReturn(radius).`when`(resources) .getInteger(R.integer.config_letterboxActivityCornersRadius) } fun loadConfiguration() { letterboxConfig = LetterboxConfiguration(ctx) } Loading @@ -147,14 +223,30 @@ class LetterboxConfigurationTest : ShellTestCase() { letterboxConfig.resetLetterboxBackgroundColor() } fun resetRoundedCornersRadius() { letterboxConfig.resetLetterboxActivityCornersRadius() } fun overrideBackgroundColorId(@ColorRes colorId: Int) { letterboxConfig.setLetterboxBackgroundColorResourceId(colorId) } fun overrideRoundedCornersRadius(radius: Int) { letterboxConfig.setLetterboxActivityCornersRadius(radius) } fun checkBackgroundColor(expected: Color) { val colorComponents = letterboxConfig.getBackgroundColorRgbArray() val expectedComponents = expected.components assert(expectedComponents.contentEquals(colorComponents)) } fun checkRoundedCornersRadius(expected: Int) { assertEquals(expected, letterboxConfig.getLetterboxActivityCornersRadius()) } fun checkIsLetterboxActivityCornersRounded(expected: Boolean) { assertEquals(expected, letterboxConfig.isLetterboxActivityCornersRounded()) } } } Loading
libs/WindowManager/Shell/src/com/android/wm/shell/compatui/letterbox/LetterboxConfiguration.kt +45 −1 Original line number Diff line number Diff line Loading @@ -36,6 +36,21 @@ class LetterboxConfiguration @Inject constructor( // Color resource id for the solid color letterbox background type. private var letterboxBackgroundColorResourceIdOverride: Int? = null // Default value for corners radius for activities presented in the letterbox mode. // Values < 0 will be ignored. private val letterboxActivityDefaultCornersRadius: Int // Current corners radius for activities presented in the letterbox mode. // Values can be modified at runtime and values < 0 will be ignored. private var letterboxActivityCornersRadius = 0 init { letterboxActivityDefaultCornersRadius = context.resources.getInteger( R.integer.config_letterboxActivityCornersRadius ) letterboxActivityCornersRadius = letterboxActivityDefaultCornersRadius } /** * Sets color of letterbox background which is used when using the solid background mode. */ Loading Loading @@ -64,7 +79,7 @@ class LetterboxConfiguration @Inject constructor( } // Query color dynamically because material colors extracted from wallpaper are updated // when wallpaper is changed. return Color.valueOf(context.getResources().getColor(colorId!!, /* theme */null)) return Color.valueOf(context.getResources().getColor(colorId!!, null)) } /** Loading @@ -79,4 +94,33 @@ class LetterboxConfiguration @Inject constructor( * The background color for the Letterbox. */ fun getBackgroundColorRgbArray(): FloatArray = getLetterboxBackgroundColor().components /** * Overrides corners radius for activities presented in the letterbox mode. Values < 0, * will be ignored and corners of the activity won't be rounded. */ fun setLetterboxActivityCornersRadius(cornersRadius: Int) { letterboxActivityCornersRadius = cornersRadius } /** * Resets corners radius for activities presented in the letterbox mode. */ fun resetLetterboxActivityCornersRadius() { letterboxActivityCornersRadius = letterboxActivityDefaultCornersRadius } /** * Whether corners of letterboxed activities are rounded. */ fun isLetterboxActivityCornersRounded(): Boolean { return getLetterboxActivityCornersRadius() > 0 } /** * Gets corners radius for activities presented in the letterbox mode. */ fun getLetterboxActivityCornersRadius(): Int { return maxOf(letterboxActivityCornersRadius, 0) } }
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/compatui/letterbox/LetterboxConfigurationTest.kt +92 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn import com.android.internal.R import com.android.wm.shell.ShellTestCase import java.util.function.Consumer import kotlin.test.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.doReturn Loading @@ -51,6 +52,14 @@ class LetterboxConfigurationTest : ShellTestCase() { val COLOR_WHITE_RESOURCE_ID = android.R.color.white @JvmStatic val COLOR_BLACK_RESOURCE_ID = android.R.color.black @JvmStatic val ROUNDED_CORNER_RADIUS_DEFAULT = 32 @JvmStatic val ROUNDED_CORNER_RADIUS_VALID = 16 @JvmStatic val ROUNDED_CORNER_RADIUS_NONE = 0 @JvmStatic val ROUNDED_CORNER_RADIUS_INVALID = -10 } @Test Loading Loading @@ -112,6 +121,68 @@ class LetterboxConfigurationTest : ShellTestCase() { } } @Test fun `default rounded corner radius is used if override is not set`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) } } @Test fun `new rounded corner radius is used after setting a valid value`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) } } @Test fun `no rounded corner radius is used after setting an invalid value`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_INVALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_NONE) } } @Test fun `has rounded corners for different values`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkIsLetterboxActivityCornersRounded(true) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_INVALID) r.checkIsLetterboxActivityCornersRounded(false) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_NONE) r.checkIsLetterboxActivityCornersRounded(false) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkIsLetterboxActivityCornersRounded(true) } } @Test fun `reset rounded corners radius`() { runTestScenario { r -> r.setDefaultRoundedCornerRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.loadConfiguration() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) r.overrideRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_VALID) r.resetRoundedCornersRadius() r.checkRoundedCornersRadius(ROUNDED_CORNER_RADIUS_DEFAULT) } } /** * Runs a test scenario providing a Robot. */ Loading @@ -135,6 +206,11 @@ class LetterboxConfigurationTest : ShellTestCase() { .getColor(R.color.config_letterboxBackgroundColor, null) } fun setDefaultRoundedCornerRadius(radius: Int) { doReturn(radius).`when`(resources) .getInteger(R.integer.config_letterboxActivityCornersRadius) } fun loadConfiguration() { letterboxConfig = LetterboxConfiguration(ctx) } Loading @@ -147,14 +223,30 @@ class LetterboxConfigurationTest : ShellTestCase() { letterboxConfig.resetLetterboxBackgroundColor() } fun resetRoundedCornersRadius() { letterboxConfig.resetLetterboxActivityCornersRadius() } fun overrideBackgroundColorId(@ColorRes colorId: Int) { letterboxConfig.setLetterboxBackgroundColorResourceId(colorId) } fun overrideRoundedCornersRadius(radius: Int) { letterboxConfig.setLetterboxActivityCornersRadius(radius) } fun checkBackgroundColor(expected: Color) { val colorComponents = letterboxConfig.getBackgroundColorRgbArray() val expectedComponents = expected.components assert(expectedComponents.contentEquals(colorComponents)) } fun checkRoundedCornersRadius(expected: Int) { assertEquals(expected, letterboxConfig.getLetterboxActivityCornersRadius()) } fun checkIsLetterboxActivityCornersRounded(expected: Boolean) { assertEquals(expected, letterboxConfig.isLetterboxActivityCornersRounded()) } } }