Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5261926 authored by Steven Ng's avatar Steven Ng
Browse files

Change the GradientColorWallpaper to match hub container background

Test: atest SystemUITests:GradientColorWallpaperTest. Also, manually compare the GradientColorWallpaper and hub container background in dark and light mode
Flag: android.app.enable_connected_displays_wallpaper
Bug: 399356692
Change-Id: I6c205461310ba110ff6e9d4a94dbcd01b625efd9
parent 2f39979e
Loading
Loading
Loading
Loading
+29 −2
Original line number Diff line number Diff line
@@ -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 {
+9 −11
Original line number Diff line number Diff line
@@ -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>())
    }