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

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

Update GradientColorWallpaper to match the hub mode background

Flag: android.app.enable_connected_displays_wallpaper
Test: atest SystemUITests:GradientColorWallpaperTest
Bug: 384519696

Change-Id: Ie5b47faddaea0ef96c564f53bdb6722332eeb8d5
parent f02e481a
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ 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
@@ -31,14 +32,18 @@ import android.view.SurfaceHolder
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito.spy
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyZeroInteractions
import org.mockito.kotlin.whenever
@@ -56,6 +61,8 @@ class GradientColorWallpaperTest : SysuiTestCase() {

    @Mock private lateinit var mockContext: Context

    @Mock private lateinit var mockResources: Resources

    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
@@ -64,6 +71,13 @@ class GradientColorWallpaperTest : SysuiTestCase() {
        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)
    }

    private fun createGradientColorWallpaperEngine(): Engine {
@@ -93,9 +107,11 @@ class GradientColorWallpaperTest : SysuiTestCase() {
        engine.onSurfaceRedrawNeeded(surfaceHolder)

        verify(canvas).drawRect(any<RectF>(), any<Paint>())
        verify(canvas, times(2)).drawCircle(anyFloat(), anyFloat(), anyFloat(), any<Paint>())
    }

    private companion object {
        val surfaceFrame = Rect(0, 0, 100, 100)
        const val OFFSET_PX = 100
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -2138,4 +2138,8 @@
    <dimen name="volume_panel_slice_vertical_padding">8dp</dimen>
    <dimen name="volume_panel_slice_horizontal_padding">24dp</dimen>
    <!-- Volume end -->

    <!-- Gradient color wallpaper start -->
    <dimen name="gradient_color_wallpaper_center_offset">128dp</dimen>
    <!-- Gradient color wallpaper end -->
</resources>
+56 −1
Original line number Diff line number Diff line
@@ -19,10 +19,14 @@ package com.android.systemui.wallpapers
import android.app.Flags
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RadialGradient
import android.graphics.Shader
import android.service.wallpaper.WallpaperService
import android.util.Log
import android.view.SurfaceHolder
import androidx.core.graphics.ColorUtils
import androidx.core.graphics.toRectF
import com.android.systemui.res.R

/** A wallpaper that shows a static gradient color image wallpaper. */
class GradientColorWallpaper : WallpaperService() {
@@ -54,9 +58,60 @@ class GradientColorWallpaper : WallpaperService() {
                canvas = surface.lockHardwareCanvas()
                val destRectF = surfaceHolder.surfaceFrame.toRectF()
                val toColor = context.getColor(com.android.internal.R.color.materialColorPrimary)
                val fromColor =
                    ColorUtils.setAlphaComponent(
                        context.getColor(
                            com.android.internal.R.color.materialColorPrimaryContainer
                        ),
                        /* alpha= */ 153, // 0.6f * 255
                    )

                // TODO(b/384519696): Draw the actual gradient color wallpaper instead.
                canvas.drawRect(destRectF, Paint().apply { color = toColor })

                val offsetPx: Float =
                    context.resources
                        .getDimensionPixelSize(R.dimen.gradient_color_wallpaper_center_offset)
                        .toFloat()
                val totalHeight = destRectF.height() + (offsetPx * 2)
                val leftCenterX = -offsetPx
                val leftCenterY = -offsetPx
                val rightCenterX = offsetPx + destRectF.width()
                val rightCenterY = totalHeight - offsetPx
                val radius = (destRectF.width() / 2) + offsetPx

                canvas.drawCircle(
                    leftCenterX,
                    leftCenterY,
                    radius,
                    Paint().apply {
                        shader =
                            RadialGradient(
                                /* centerX= */ leftCenterX,
                                /* centerY= */ leftCenterY,
                                /* radius= */ radius,
                                /* centerColor= */ fromColor,
                                /* edgeColor= */ toColor,
                                /* tileMode= */ Shader.TileMode.CLAMP,
                            )
                    },
                )

                canvas.drawCircle(
                    rightCenterX,
                    rightCenterY,
                    radius,
                    Paint().apply {
                        shader =
                            RadialGradient(
                                /* centerX= */ rightCenterX,
                                /* centerY= */ rightCenterY,
                                /* radius= */ radius,
                                /* centerColor= */ fromColor,
                                /* edgeColor= */ toColor,
                                /* tileMode= */ Shader.TileMode.CLAMP,
                            )
                    },
                )
            } catch (exception: IllegalStateException) {
                Log.d(TAG, "Fail to draw in the canvas", exception)
            } finally {