Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ constructor( fun getDimen(context: Context, name: String): Int { val res = context.packageManager.getResourcesForApplication(context.packageName) val id = res.getIdentifier(name, "dimen", context.packageName) return res.getDimensionPixelSize(id) return if (id == 0) 0 else res.getDimensionPixelSize(id) } } } packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt +55 −33 Original line number Diff line number Diff line Loading @@ -67,12 +67,15 @@ class ClockSectionTest : SysuiTestCase() { context.resources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) + Utils.getStatusBarHeaderHeightKeyguard(context) private val LARGE_CLOCK_TOP = private val LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE = context.resources.getDimensionPixelSize(R.dimen.status_bar_height) + context.resources.getDimensionPixelSize( com.android.systemui.customization.R.dimen.small_clock_padding_top ) + context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) + context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) private val LARGE_CLOCK_TOP = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE + SMART_SPACE_DATE_WEATHER_HEIGHT + ENHANCED_SMART_SPACE_HEIGHT Loading @@ -81,35 +84,29 @@ class ClockSectionTest : SysuiTestCase() { com.android.systemui.customization.R.dimen.small_clock_height ) private var DIMENSION_BY_IDENTIFIER_NAME: List<Pair<String, Int>> = listOf() @Before fun setup() { DIMENSION_BY_IDENTIFIER_NAME = listOf( "date_weather_view_height" to SMART_SPACE_DATE_WEATHER_HEIGHT, "enhanced_smartspace_height" to ENHANCED_SMART_SPACE_HEIGHT, ) MockitoAnnotations.initMocks(this) val remoteResources = mock<Resources>() whenever( remoteResources.getIdentifier( anyString(), eq("dimen"), anyString(), ) ) .then { invocation -> whenever(remoteResources.getIdentifier(anyString(), eq("dimen"), anyString())).then { invocation -> val name = invocation.arguments[0] as String val index = DIMENSION_BY_IDENTIFIER_NAME.indexOfFirst { (key, _) -> key == name } if (index == -1) { error( "No entry for a dimension named \"$name\", please add it to the list above." ) } index // increment index so that the not-found sentinel value lines up w/ what is // returned by getIdentifier when a resource is not found index + 1 } whenever( remoteResources.getDimensionPixelSize( anyInt(), ) ) .then { invocation -> whenever(remoteResources.getDimensionPixelSize(anyInt())).then { invocation -> val id = invocation.arguments[0] as Int DIMENSION_BY_IDENTIFIER_NAME[id].second DIMENSION_BY_IDENTIFIER_NAME[id - 1].second } val packageManager = mock<PackageManager>() whenever(packageManager.getResourcesForApplication(anyString())).thenReturn(remoteResources) Loading Loading @@ -158,6 +155,36 @@ class ClockSectionTest : SysuiTestCase() { assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_SplitShade() { DIMENSION_BY_IDENTIFIER_NAME = listOf() // Remove Smartspace from mock setLargeClock(true) setSplitShade(true) val cs = ConstraintSet() underTest.applyDefaultConstraints(cs) val expectedLargeClockTopMargin = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE assertLargeClockTop(cs, expectedLargeClockTopMargin) val expectedSmallClockTopMargin = SMALL_CLOCK_TOP_SPLIT_SHADE assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_NonSplitShade() { DIMENSION_BY_IDENTIFIER_NAME = listOf() // Remove Smartspace from mock setLargeClock(true) setSplitShade(false) val cs = ConstraintSet() underTest.applyDefaultConstraints(cs) val expectedLargeClockTopMargin = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE assertLargeClockTop(cs, expectedLargeClockTopMargin) val expectedSmallClockTopMargin = SMALL_CLOCK_TOP_NON_SPLIT_SHADE assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_SmallClock_SplitShade() { setLargeClock(false) Loading Loading @@ -249,10 +276,5 @@ class ClockSectionTest : SysuiTestCase() { companion object { private val SMART_SPACE_DATE_WEATHER_HEIGHT = 10 private val ENHANCED_SMART_SPACE_HEIGHT = 11 private val DIMENSION_BY_IDENTIFIER_NAME = listOf( "date_weather_view_height" to SMART_SPACE_DATE_WEATHER_HEIGHT, "enhanced_smartspace_height" to ENHANCED_SMART_SPACE_HEIGHT, ) } } Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt +1 −1 Original line number Diff line number Diff line Loading @@ -205,7 +205,7 @@ constructor( fun getDimen(context: Context, name: String): Int { val res = context.packageManager.getResourcesForApplication(context.packageName) val id = res.getIdentifier(name, "dimen", context.packageName) return res.getDimensionPixelSize(id) return if (id == 0) 0 else res.getDimensionPixelSize(id) } } }
packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt +55 −33 Original line number Diff line number Diff line Loading @@ -67,12 +67,15 @@ class ClockSectionTest : SysuiTestCase() { context.resources.getDimensionPixelSize(R.dimen.keyguard_clock_top_margin) + Utils.getStatusBarHeaderHeightKeyguard(context) private val LARGE_CLOCK_TOP = private val LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE = context.resources.getDimensionPixelSize(R.dimen.status_bar_height) + context.resources.getDimensionPixelSize( com.android.systemui.customization.R.dimen.small_clock_padding_top ) + context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) + context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) private val LARGE_CLOCK_TOP = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE + SMART_SPACE_DATE_WEATHER_HEIGHT + ENHANCED_SMART_SPACE_HEIGHT Loading @@ -81,35 +84,29 @@ class ClockSectionTest : SysuiTestCase() { com.android.systemui.customization.R.dimen.small_clock_height ) private var DIMENSION_BY_IDENTIFIER_NAME: List<Pair<String, Int>> = listOf() @Before fun setup() { DIMENSION_BY_IDENTIFIER_NAME = listOf( "date_weather_view_height" to SMART_SPACE_DATE_WEATHER_HEIGHT, "enhanced_smartspace_height" to ENHANCED_SMART_SPACE_HEIGHT, ) MockitoAnnotations.initMocks(this) val remoteResources = mock<Resources>() whenever( remoteResources.getIdentifier( anyString(), eq("dimen"), anyString(), ) ) .then { invocation -> whenever(remoteResources.getIdentifier(anyString(), eq("dimen"), anyString())).then { invocation -> val name = invocation.arguments[0] as String val index = DIMENSION_BY_IDENTIFIER_NAME.indexOfFirst { (key, _) -> key == name } if (index == -1) { error( "No entry for a dimension named \"$name\", please add it to the list above." ) } index // increment index so that the not-found sentinel value lines up w/ what is // returned by getIdentifier when a resource is not found index + 1 } whenever( remoteResources.getDimensionPixelSize( anyInt(), ) ) .then { invocation -> whenever(remoteResources.getDimensionPixelSize(anyInt())).then { invocation -> val id = invocation.arguments[0] as Int DIMENSION_BY_IDENTIFIER_NAME[id].second DIMENSION_BY_IDENTIFIER_NAME[id - 1].second } val packageManager = mock<PackageManager>() whenever(packageManager.getResourcesForApplication(anyString())).thenReturn(remoteResources) Loading Loading @@ -158,6 +155,36 @@ class ClockSectionTest : SysuiTestCase() { assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_SplitShade() { DIMENSION_BY_IDENTIFIER_NAME = listOf() // Remove Smartspace from mock setLargeClock(true) setSplitShade(true) val cs = ConstraintSet() underTest.applyDefaultConstraints(cs) val expectedLargeClockTopMargin = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE assertLargeClockTop(cs, expectedLargeClockTopMargin) val expectedSmallClockTopMargin = SMALL_CLOCK_TOP_SPLIT_SHADE assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_LargeClock_MissingSmartspace_NonSplitShade() { DIMENSION_BY_IDENTIFIER_NAME = listOf() // Remove Smartspace from mock setLargeClock(true) setSplitShade(false) val cs = ConstraintSet() underTest.applyDefaultConstraints(cs) val expectedLargeClockTopMargin = LARGE_CLOCK_TOP_WITHOUT_SMARTSPACE assertLargeClockTop(cs, expectedLargeClockTopMargin) val expectedSmallClockTopMargin = SMALL_CLOCK_TOP_NON_SPLIT_SHADE assertSmallClockTop(cs, expectedSmallClockTopMargin) } @Test fun testApplyDefaultConstraints_SmallClock_SplitShade() { setLargeClock(false) Loading Loading @@ -249,10 +276,5 @@ class ClockSectionTest : SysuiTestCase() { companion object { private val SMART_SPACE_DATE_WEATHER_HEIGHT = 10 private val ENHANCED_SMART_SPACE_HEIGHT = 11 private val DIMENSION_BY_IDENTIFIER_NAME = listOf( "date_weather_view_height" to SMART_SPACE_DATE_WEATHER_HEIGHT, "enhanced_smartspace_height" to ENHANCED_SMART_SPACE_HEIGHT, ) } }