diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/wallpapers/GradientColorWallpaper.kt | 31 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/wallpapers/GradientColorWallpaperTest.kt | 20 |
2 files changed, 38 insertions, 13 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/wallpapers/GradientColorWallpaper.kt b/packages/SystemUI/src/com/android/systemui/wallpapers/GradientColorWallpaper.kt index 33e1929ebf8b..952d40ed63eb 100644 --- a/packages/SystemUI/src/com/android/systemui/wallpapers/GradientColorWallpaper.kt +++ b/packages/SystemUI/src/com/android/systemui/wallpapers/GradientColorWallpaper.kt @@ -17,8 +17,13 @@ package com.android.systemui.wallpapers import android.app.Flags +import android.content.res.Configuration.UI_MODE_NIGHT_MASK +import android.content.res.Configuration.UI_MODE_NIGHT_YES import android.graphics.Canvas +import android.graphics.Color import android.graphics.Paint +import android.graphics.PorterDuff +import android.graphics.PorterDuffXfermode import android.graphics.RadialGradient import android.graphics.Shader import android.service.wallpaper.WallpaperService @@ -74,9 +79,9 @@ class GradientColorWallpaper : WallpaperService() { .toFloat() val totalHeight = destRectF.height() + (offsetPx * 2) val leftCenterX = -offsetPx - val leftCenterY = -offsetPx + val leftCenterY = totalHeight - offsetPx val rightCenterX = offsetPx + destRectF.width() - val rightCenterY = totalHeight - offsetPx + val rightCenterY = -offsetPx val radius = (destRectF.width() / 2) + offsetPx canvas.drawCircle( @@ -112,6 +117,28 @@ class GradientColorWallpaper : WallpaperService() { ) }, ) + + val isDarkMode = + context.resources.configuration.uiMode and UI_MODE_NIGHT_MASK == + UI_MODE_NIGHT_YES + val maskColor = + ColorUtils.setAlphaComponent( + if (isDarkMode) Color.BLACK else Color.WHITE, + /* alpha= */ 87, // 0.34f * 255 + ) + val maskPaint = + Paint().apply { + xfermode = + PorterDuffXfermode( + if (isDarkMode) { + PorterDuff.Mode.DARKEN + } else { + PorterDuff.Mode.LIGHTEN + } + ) + color = maskColor + } + canvas.drawRect(destRectF, maskPaint) } catch (exception: IllegalStateException) { Log.d(TAG, "Fail to draw in the canvas", exception) } finally { diff --git a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/GradientColorWallpaperTest.kt b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/GradientColorWallpaperTest.kt index b4fbaad6ab37..5f3442048fcd 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/wallpapers/GradientColorWallpaperTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/wallpapers/GradientColorWallpaperTest.kt @@ -18,7 +18,6 @@ package com.android.systemui.wallpapers import android.app.Flags import android.content.Context -import android.content.res.Resources import android.graphics.Canvas import android.graphics.Paint import android.graphics.Rect @@ -43,6 +42,7 @@ import org.mockito.Mock import org.mockito.Mockito.spy import org.mockito.MockitoAnnotations import org.mockito.kotlin.any +import org.mockito.kotlin.doReturn import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.verifyZeroInteractions @@ -61,23 +61,20 @@ class GradientColorWallpaperTest : SysuiTestCase() { @Mock private lateinit var mockContext: Context - @Mock private lateinit var mockResources: Resources - @Before fun setUp() { MockitoAnnotations.initMocks(this) + val spyResources = spy(context.resources) + whenever(surfaceHolder.surface).thenReturn(surface) whenever(surfaceHolder.surfaceFrame).thenReturn(surfaceFrame) whenever(surface.lockHardwareCanvas()).thenReturn(canvas) whenever(mockContext.getColor(anyInt())).thenReturn(1) - whenever(mockContext.resources).thenReturn(mockResources) - whenever( - mockResources.getDimensionPixelOffset( - eq(R.dimen.gradient_color_wallpaper_center_offset) - ) - ) - .thenReturn(OFFSET_PX) + whenever(mockContext.resources).thenReturn(spyResources) + doReturn(OFFSET_PX) + .`when`(spyResources) + .getDimensionPixelOffset(eq(R.dimen.gradient_color_wallpaper_center_offset)) } private fun createGradientColorWallpaperEngine(): Engine { @@ -106,7 +103,8 @@ class GradientColorWallpaperTest : SysuiTestCase() { engine.onSurfaceRedrawNeeded(surfaceHolder) - verify(canvas).drawRect(any<RectF>(), any<Paint>()) + // One rect for the background, one rect for the foreground mask. + verify(canvas, times(2)).drawRect(any<RectF>(), any<Paint>()) verify(canvas, times(2)).drawCircle(anyFloat(), anyFloat(), anyFloat(), any<Paint>()) } |