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

Commit 723f5086 authored by Coco Duan's avatar Coco Duan
Browse files

Enforce rounded corners for communal widgets

- Created CommunalAppWidgetHostView that subclasses AppWidgetHostView
  with support for rounded corner.
- Created CommunalAppWidgetHost that creates a CommunalAppWidgetHostView.
- Forked RoundedCornerEnforcement class from Launcher3 code.

Bug: b/318560812
Flag: ACONFIG com.android.systemui.communal_hub DEVELOPMENT
Test: manually with google tv widget
Test: atest CommunalAppWidgetHostTest
Change-Id: Ib4e2f705a070766eca605af81b38f8a88b95204c
parent 2853caae
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -610,7 +610,7 @@ private fun WidgetContent(
                model.appWidgetHost.setInteractionHandler(viewModel.getInteractionHandler())
                val view =
                    model.appWidgetHost
                        .createView(context, model.appWidgetId, model.providerInfo)
                        .createViewForCommunal(context, model.appWidgetId, model.providerInfo)
                        .apply { updateAppWidgetSize(Bundle.EMPTY, listOf(size)) }
                model.appWidgetHost.setInteractionHandler(null)
                view
+2 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.communal.data.repository

import android.appwidget.AppWidgetHost
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
@@ -32,6 +31,7 @@ import com.android.systemui.communal.data.db.CommunalWidgetDao
import com.android.systemui.communal.data.db.CommunalWidgetItem
import com.android.systemui.communal.shared.CommunalWidgetHost
import com.android.systemui.communal.shared.model.CommunalWidgetContentModel
import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.FakeLogBuffer
@@ -65,7 +65,7 @@ class CommunalWidgetRepositoryImplTest : SysuiTestCase() {

    @Mock private lateinit var appWidgetManager: AppWidgetManager

    @Mock private lateinit var appWidgetHost: AppWidgetHost
    @Mock private lateinit var appWidgetHost: CommunalAppWidgetHost

    @Mock private lateinit var userManager: UserManager

+59 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.communal.ui.widgets

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.communal.widgets.CommunalAppWidgetHostView
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalAppWidgetHostTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    private lateinit var underTest: CommunalAppWidgetHost

    @Before
    fun setUp() {
        underTest = CommunalAppWidgetHost(context = context, hostId = 116)
    }

    @Test
    fun createViewForCommunal_returnCommunalAppWidgetView() =
        testScope.runTest {
            val appWidgetId = 789
            val view =
                underTest.createViewForCommunal(
                    context = context,
                    appWidgetId = appWidgetId,
                    appWidget = null
                )
            assertThat(view).isInstanceOf(CommunalAppWidgetHostView::class.java)
            assertThat(view).isNotNull()
            assertThat(view.appWidgetId).isEqualTo(appWidgetId)
        }
}
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.communal.view.viewmodel
import android.app.Activity.RESULT_CANCELED
import android.app.Activity.RESULT_OK
import android.app.smartspace.SmartspaceTarget
import android.appwidget.AppWidgetHost
import android.content.ComponentName
import android.provider.Settings
import android.widget.RemoteViews
@@ -36,6 +35,7 @@ import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalUiEvent
import com.android.systemui.communal.shared.model.CommunalWidgetContentModel
import com.android.systemui.communal.ui.viewmodel.CommunalEditModeViewModel
import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.kosmos.testScope
@@ -61,7 +61,7 @@ import org.mockito.MockitoAnnotations
@RunWith(AndroidJUnit4::class)
class CommunalEditModeViewModelTest : SysuiTestCase() {
    @Mock private lateinit var mediaHost: MediaHost
    @Mock private lateinit var appWidgetHost: AppWidgetHost
    @Mock private lateinit var appWidgetHost: CommunalAppWidgetHost
    @Mock private lateinit var uiEventLogger: UiEventLogger

    private val kosmos = testKosmos()
+4 −0
Original line number Diff line number Diff line
@@ -897,6 +897,10 @@
    <dimen name="communal_tutorial_indicator_padding">24dp</dimen>
    <dimen name="communal_tutorial_indicator_horizontal_offset">32dp</dimen>

    <!-- Size of the maximum radius for the enforced rounded rectangles on communal hub.
        Keep it the same as in Launcher-->
    <dimen name="communal_enforced_rounded_corner_max_radius">16dp</dimen>

    <!-- The width/height of the unlock icon view on keyguard. -->
    <dimen name="keyguard_lock_height">42dp</dimen>
    <dimen name="keyguard_lock_padding">20dp</dimen>
Loading