Merge changes from topic "complication-ui-event" into udc-qpr-dev
* changes:
Log UI event on tap clock complication
Add dagger scope to clock complication
Flatten clock complication layout
diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml b/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml
index 8bff1a1..6de10b4 100644
--- a/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml
+++ b/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml
@@ -14,34 +14,27 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<FrameLayout
+<com.android.systemui.shared.shadow.DoubleShadowTextClock
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
- android:layout_height="wrap_content">
-
- <com.android.systemui.shared.shadow.DoubleShadowTextClock
- android:id="@+id/time_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:fontFamily="@*android:string/config_clockFontFamily"
- android:textColor="@android:color/white"
- android:format12Hour="@string/dream_time_complication_12_hr_time_format"
- android:format24Hour="@string/dream_time_complication_24_hr_time_format"
- android:fontFeatureSettings="pnum, lnum"
- android:includeFontPadding="false"
- android:letterSpacing="0.02"
- android:maxLines="1"
- android:textSize="@dimen/dream_overlay_complication_clock_time_text_size"
- app:keyShadowBlur="@dimen/dream_overlay_clock_key_text_shadow_radius"
- app:keyShadowOffsetX="@dimen/dream_overlay_clock_key_text_shadow_dx"
- app:keyShadowOffsetY="@dimen/dream_overlay_clock_key_text_shadow_dy"
- app:keyShadowAlpha="0.3"
- app:ambientShadowBlur="@dimen/dream_overlay_clock_ambient_text_shadow_radius"
- app:ambientShadowOffsetX="@dimen/dream_overlay_clock_ambient_text_shadow_dx"
- app:ambientShadowOffsetY="@dimen/dream_overlay_clock_ambient_text_shadow_dy"
- app:ambientShadowAlpha="0.3"
- app:removeTextDescent="true"
- app:textDescentExtraPadding="@dimen/dream_overlay_clock_text_descent_extra_padding" />
-
-</FrameLayout>
+ android:layout_height="wrap_content"
+ android:fontFamily="@*android:string/config_clockFontFamily"
+ android:textColor="@android:color/white"
+ android:format12Hour="@string/dream_time_complication_12_hr_time_format"
+ android:format24Hour="@string/dream_time_complication_24_hr_time_format"
+ android:fontFeatureSettings="pnum, lnum"
+ android:includeFontPadding="false"
+ android:letterSpacing="0.02"
+ android:maxLines="1"
+ android:textSize="@dimen/dream_overlay_complication_clock_time_text_size"
+ app:keyShadowBlur="@dimen/dream_overlay_clock_key_text_shadow_radius"
+ app:keyShadowOffsetX="@dimen/dream_overlay_clock_key_text_shadow_dx"
+ app:keyShadowOffsetY="@dimen/dream_overlay_clock_key_text_shadow_dy"
+ app:keyShadowAlpha="0.3"
+ app:ambientShadowBlur="@dimen/dream_overlay_clock_ambient_text_shadow_radius"
+ app:ambientShadowOffsetX="@dimen/dream_overlay_clock_ambient_text_shadow_dx"
+ app:ambientShadowOffsetY="@dimen/dream_overlay_clock_ambient_text_shadow_dy"
+ app:ambientShadowAlpha="0.3"
+ app:removeTextDescent="true"
+ app:textDescentExtraPadding="@dimen/dream_overlay_clock_text_descent_extra_padding" />
diff --git a/packages/SystemUI/src/com/android/systemui/complication/DreamClockTimeComplication.java b/packages/SystemUI/src/com/android/systemui/complication/DreamClockTimeComplication.java
index 9c3448b..dc32a59 100644
--- a/packages/SystemUI/src/com/android/systemui/complication/DreamClockTimeComplication.java
+++ b/packages/SystemUI/src/com/android/systemui/complication/DreamClockTimeComplication.java
@@ -16,34 +16,36 @@
package com.android.systemui.complication;
-import static com.android.systemui.complication.dagger.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW;
+import static com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule.DREAM_CLOCK_TIME_COMPLICATION_VIEW;
import static com.android.systemui.complication.dagger.RegisteredComplicationsModule.DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS;
import android.view.View;
+import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
+import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent;
import com.android.systemui.dagger.qualifiers.SystemUser;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.shared.condition.Monitor;
+import com.android.systemui.util.ViewController;
import com.android.systemui.util.condition.ConditionalCoreStartable;
import javax.inject.Inject;
import javax.inject.Named;
-import javax.inject.Provider;
/**
* Clock Time Complication that produce Clock Time view holder.
*/
public class DreamClockTimeComplication implements Complication {
- private final Provider<DreamClockTimeViewHolder> mDreamClockTimeViewHolderProvider;
+ private final DreamClockTimeComplicationComponent.Factory mComponentFactory;
/**
* Default constructor for {@link DreamClockTimeComplication}.
*/
@Inject
public DreamClockTimeComplication(
- Provider<DreamClockTimeViewHolder> dreamClockTimeViewHolderProvider) {
- mDreamClockTimeViewHolderProvider = dreamClockTimeViewHolderProvider;
+ DreamClockTimeComplicationComponent.Factory componentFactory) {
+ mComponentFactory = componentFactory;
}
@Override
@@ -56,7 +58,7 @@
*/
@Override
public ViewHolder createView(ComplicationViewModel model) {
- return mDreamClockTimeViewHolderProvider.get();
+ return mComponentFactory.create().getViewHolder();
}
/**
@@ -94,11 +96,14 @@
private final ComplicationLayoutParams mLayoutParams;
@Inject
- DreamClockTimeViewHolder(@Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
+ DreamClockTimeViewHolder(
+ @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
@Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
- ComplicationLayoutParams layoutParams) {
+ ComplicationLayoutParams layoutParams,
+ DreamClockTimeViewController viewController) {
mView = view;
mLayoutParams = layoutParams;
+ viewController.init();
}
@Override
@@ -111,4 +116,29 @@
return mLayoutParams;
}
}
+
+ static class DreamClockTimeViewController extends ViewController<View> {
+ private final UiEventLogger mUiEventLogger;
+
+ @Inject
+ DreamClockTimeViewController(
+ @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) View view,
+ UiEventLogger uiEventLogger) {
+ super(view);
+
+ mUiEventLogger = uiEventLogger;
+ }
+
+ @Override
+ protected void onViewAttached() {
+ mView.setOnClickListener(this::onClick);
+ }
+
+ @Override
+ protected void onViewDetached() {}
+
+ private void onClick(View v) {
+ mUiEventLogger.log(DreamOverlayUiEvent.DREAM_CLOCK_TAPPED);
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/complication/DreamHomeControlsComplication.java b/packages/SystemUI/src/com/android/systemui/complication/DreamHomeControlsComplication.java
index 4d99282..7ac1cc7 100644
--- a/packages/SystemUI/src/com/android/systemui/complication/DreamHomeControlsComplication.java
+++ b/packages/SystemUI/src/com/android/systemui/complication/DreamHomeControlsComplication.java
@@ -29,8 +29,6 @@
import android.view.View;
import android.widget.ImageView;
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.CoreStartable;
import com.android.systemui.animation.ActivityLaunchAnimator;
@@ -201,23 +199,6 @@
private final UiEventLogger mUiEventLogger;
- @VisibleForTesting
- public enum DreamOverlayEvent implements UiEventLogger.UiEventEnum {
- @UiEvent(doc = "The home controls on the screensaver has been tapped.")
- DREAM_HOME_CONTROLS_TAPPED(1212);
-
- private final int mId;
-
- DreamOverlayEvent(int id) {
- mId = id;
- }
-
- @Override
- public int getId() {
- return mId;
- }
- }
-
@Inject
DreamHomeControlsChipViewController(
@Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view,
@@ -246,7 +227,7 @@
private void onClickHomeControls(View v) {
if (DEBUG) Log.d(TAG, "home controls complication tapped");
- mUiEventLogger.log(DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);
+ mUiEventLogger.log(DreamOverlayUiEvent.DREAM_HOME_CONTROLS_TAPPED);
final Intent intent = new Intent(mContext, ControlsActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
diff --git a/packages/SystemUI/src/com/android/systemui/complication/DreamOverlayUiEvent.kt b/packages/SystemUI/src/com/android/systemui/complication/DreamOverlayUiEvent.kt
new file mode 100644
index 0000000..17cc829
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/complication/DreamOverlayUiEvent.kt
@@ -0,0 +1,32 @@
+/*
+ * 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.complication
+
+import com.android.internal.logging.UiEvent
+import com.android.internal.logging.UiEventLogger.UiEventEnum
+
+/** UI log events for the dream overlay. */
+enum class DreamOverlayUiEvent(private val mId: Int) : UiEventEnum {
+ @UiEvent(doc = "The home controls on the screensaver has been tapped.")
+ DREAM_HOME_CONTROLS_TAPPED(1212),
+ @UiEvent(doc = "The clock on the screensaver has been tapped") DREAM_CLOCK_TAPPED(1440),
+ @UiEvent(doc = "The weather on the screensaver has been tapped") DREAM_WEATHER_TAPPED(1441);
+
+ override fun getId(): Int {
+ return mId
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationComponent.kt b/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationComponent.kt
new file mode 100644
index 0000000..87c3b2f
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationComponent.kt
@@ -0,0 +1,81 @@
+/*
+ * 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.complication.dagger
+
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.TextClock
+import com.android.internal.util.Preconditions
+import com.android.systemui.R
+import com.android.systemui.complication.DreamClockTimeComplication
+import com.android.systemui.complication.DreamClockTimeComplication.DreamClockTimeViewHolder
+import dagger.Module
+import dagger.Provides
+import dagger.Subcomponent
+import javax.inject.Named
+import javax.inject.Scope
+
+/** Responsible for generating dependencies for the [DreamClockTimeComplication]. */
+@Subcomponent(
+ modules = [DreamClockTimeComplicationComponent.DreamClockTimeComplicationModule::class]
+)
+@DreamClockTimeComplicationComponent.DreamClockTimeComplicationScope
+interface DreamClockTimeComplicationComponent {
+ /** Scope of the clock complication. */
+ @MustBeDocumented
+ @Retention(AnnotationRetention.RUNTIME)
+ @Scope
+ annotation class DreamClockTimeComplicationScope
+
+ /** Factory that generates a component for the clock complication. */
+ @Subcomponent.Factory
+ interface Factory {
+ fun create(): DreamClockTimeComplicationComponent
+ }
+
+ /** Creates a view holder for the clock complication. */
+ fun getViewHolder(): DreamClockTimeViewHolder
+
+ /** Module for providing injected values within the clock complication scope. */
+ @Module
+ interface DreamClockTimeComplicationModule {
+ companion object {
+ const val DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view"
+ private const val TAG_WEIGHT = "'wght' "
+ private const val WEIGHT = 400
+
+ /** Provides the complication view. */
+ @Provides
+ @DreamClockTimeComplicationScope
+ @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
+ fun provideComplicationView(layoutInflater: LayoutInflater): View {
+ val view =
+ Preconditions.checkNotNull(
+ layoutInflater.inflate(
+ R.layout.dream_overlay_complication_clock_time,
+ /* root = */ null,
+ /* attachToRoot = */ false,
+ ) as TextClock,
+ "R.layout.dream_overlay_complication_clock_time did not properly inflate"
+ )
+ view.setFontVariationSettings(TAG_WEIGHT + WEIGHT)
+ return view
+ }
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationModule.java b/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationModule.java
deleted file mode 100644
index fd711ee..0000000
--- a/packages/SystemUI/src/com/android/systemui/complication/dagger/DreamClockTimeComplicationModule.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2022 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.complication.dagger;
-
-
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextClock;
-
-import com.android.internal.util.Preconditions;
-import com.android.systemui.R;
-import com.android.systemui.complication.DreamClockTimeComplication;
-
-import dagger.Module;
-import dagger.Provides;
-
-import javax.inject.Named;
-
-/**
- * Module for providing {@link DreamClockTimeComplication}.
- */
-@Module
-public interface DreamClockTimeComplicationModule {
- String DREAM_CLOCK_TIME_COMPLICATION_VIEW = "clock_time_complication_view";
- String TAG_WEIGHT = "'wght' ";
- int WEIGHT = 400;
-
- /**
- * Provides the complication view.
- */
- @Provides
- @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW)
- static View provideComplicationView(LayoutInflater layoutInflater) {
- final View view = Preconditions.checkNotNull(
- layoutInflater.inflate(R.layout.dream_overlay_complication_clock_time,
- null, false),
- "R.layout.dream_overlay_complication_clock_time did not properly inflated");
- ((TextClock) view.findViewById(R.id.time_view)).setFontVariationSettings(
- TAG_WEIGHT + WEIGHT);
- return view;
- }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/complication/dagger/RegisteredComplicationsModule.java b/packages/SystemUI/src/com/android/systemui/complication/dagger/RegisteredComplicationsModule.java
index 98975fbd..776c972 100644
--- a/packages/SystemUI/src/com/android/systemui/complication/dagger/RegisteredComplicationsModule.java
+++ b/packages/SystemUI/src/com/android/systemui/complication/dagger/RegisteredComplicationsModule.java
@@ -35,10 +35,9 @@
* Module for all components with corresponding dream layer complications registered in
* {@link SystemUIBinder}.
*/
-@Module(includes = {
- DreamClockTimeComplicationModule.class,
- },
+@Module(
subcomponents = {
+ DreamClockTimeComplicationComponent.class,
DreamHomeControlsComplicationComponent.class,
DreamMediaEntryComplicationComponent.class
})
diff --git a/packages/SystemUI/tests/src/com/android/systemui/complication/DreamClockTimeComplicationTest.java b/packages/SystemUI/tests/src/com/android/systemui/complication/DreamClockTimeComplicationTest.java
index 57d3a01..cbbbe52 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/complication/DreamClockTimeComplicationTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/complication/DreamClockTimeComplicationTest.java
@@ -28,7 +28,9 @@
import androidx.test.filters.SmallTest;
+import com.android.internal.logging.UiEventLogger;
import com.android.systemui.SysuiTestCase;
+import com.android.systemui.complication.dagger.DreamClockTimeComplicationComponent;
import com.android.systemui.condition.SelfExecutingMonitor;
import com.android.systemui.dreams.DreamOverlayStateController;
import com.android.systemui.shared.condition.Monitor;
@@ -36,11 +38,10 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import javax.inject.Provider;
-
@SmallTest
@RunWith(AndroidTestingRunner.class)
public class DreamClockTimeComplicationTest extends SysuiTestCase {
@@ -55,8 +56,10 @@
private DreamClockTimeComplication mComplication;
@Mock
- private Provider<DreamClockTimeComplication.DreamClockTimeViewHolder>
- mDreamClockTimeViewHolderProvider;
+ private DreamClockTimeComplicationComponent.Factory mComponentFactory;
+
+ @Mock
+ private DreamClockTimeComplicationComponent mComponent;
@Mock
private DreamClockTimeComplication.DreamClockTimeViewHolder
@@ -71,12 +74,19 @@
@Mock
private ComplicationLayoutParams mLayoutParams;
+ @Mock
+ private DreamClockTimeComplication.DreamClockTimeViewController mViewController;
+
+ @Mock
+ private UiEventLogger mUiEventLogger;
+
private Monitor mMonitor;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- when(mDreamClockTimeViewHolderProvider.get()).thenReturn(mDreamClockTimeViewHolder);
+ when(mComponentFactory.create()).thenReturn(mComponent);
+ when(mComponent.getViewHolder()).thenReturn(mDreamClockTimeViewHolder);
mMonitor = SelfExecutingMonitor.createInstance();
}
@@ -100,21 +110,21 @@
@Test
public void testComplicationRequiredTypeAvailability() {
final DreamClockTimeComplication complication =
- new DreamClockTimeComplication(mDreamClockTimeViewHolderProvider);
+ new DreamClockTimeComplication(mComponentFactory);
assertEquals(Complication.COMPLICATION_TYPE_TIME,
complication.getRequiredTypeAvailability());
}
/**
* Verifies {@link DreamClockTimeComplication.DreamClockTimeViewHolder} is obtainable from its
- * provider when the complication creates view.
+ * component when the complication creates view.
*/
@Test
- public void testComplicationViewHolderProviderOnCreateView() {
+ public void testComplicationViewHolderComponentOnCreateView() {
final DreamClockTimeComplication complication =
- new DreamClockTimeComplication(mDreamClockTimeViewHolderProvider);
+ new DreamClockTimeComplication(mComponentFactory);
final Complication.ViewHolder viewHolder = complication.createView(mComplicationViewModel);
- verify(mDreamClockTimeViewHolderProvider).get();
+ verify(mComponent).getViewHolder();
assertThat(viewHolder).isEqualTo(mDreamClockTimeViewHolder);
}
@@ -125,8 +135,23 @@
@Test
public void testComplicationViewHolderContentAccessors() {
final DreamClockTimeComplication.DreamClockTimeViewHolder viewHolder =
- new DreamClockTimeComplication.DreamClockTimeViewHolder(mView, mLayoutParams);
+ new DreamClockTimeComplication.DreamClockTimeViewHolder(mView, mLayoutParams,
+ mViewController);
assertThat(viewHolder.getView()).isEqualTo(mView);
assertThat(viewHolder.getLayoutParams()).isEqualTo(mLayoutParams);
}
+
+ @Test
+ public void testClick_logUiEvent() {
+ final DreamClockTimeComplication.DreamClockTimeViewController controller =
+ new DreamClockTimeComplication.DreamClockTimeViewController(mView, mUiEventLogger);
+ controller.onViewAttached();
+
+ final ArgumentCaptor<View.OnClickListener> clickListenerCaptor =
+ ArgumentCaptor.forClass(View.OnClickListener.class);
+ verify(mView).setOnClickListener(clickListenerCaptor.capture());
+
+ clickListenerCaptor.getValue().onClick(mView);
+ verify(mUiEventLogger).log(DreamOverlayUiEvent.DREAM_CLOCK_TAPPED);
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/complication/DreamHomeControlsComplicationTest.java b/packages/SystemUI/tests/src/com/android/systemui/complication/DreamHomeControlsComplicationTest.java
index 63b0b25..2207180 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/complication/DreamHomeControlsComplicationTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/complication/DreamHomeControlsComplicationTest.java
@@ -234,9 +234,7 @@
verify(mHomeControlsView).setOnClickListener(clickListenerCaptor.capture());
clickListenerCaptor.getValue().onClick(mHomeControlsView);
- verify(mUiEventLogger).log(
- DreamHomeControlsComplication.DreamHomeControlsChipViewController
- .DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);
+ verify(mUiEventLogger).log(DreamOverlayUiEvent.DREAM_HOME_CONTROLS_TAPPED);
}
private void setHaveFavorites(boolean value) {