From e0fa9f694cf0274093e62a41409b05d9bbf458f2 Mon Sep 17 00:00:00 2001 From: Darrell Shi Date: Fri, 18 Nov 2022 20:52:41 +0000 Subject: [PATCH] Dream complications styling update. - update complication weights so home controls, media entry chip, and smartspace are always shown below the clock - instead of applying the bottom padding to home controls at the layout engine level in order to center align with smartspace, apply to the home controls chip view, which prevents the layout engine from giving an exception to adding padding to a root node Bug: 259264239 Bug: 259719867 Test: https://screenshot.googleplex.com/BZNatvxHFHxqxaS Test: https://screenshot.googleplex.com/9gxsLUZWTFy7sGX Change-Id: Icfcc3653ad7eb52e707c8289803188388484666e --- .../dream_overlay_home_controls_chip.xml | 29 ++++---- .../ComplicationLayoutEngine.java | 4 +- .../ComplicationLayoutParams.java | 7 -- .../DreamHomeControlsComplication.java | 14 ++-- ...reamHomeControlsComplicationComponent.java | 6 +- .../dagger/RegisteredComplicationsModule.java | 19 +++--- .../ComplicationLayoutEngineTest.java | 66 +------------------ .../ComplicationLayoutParamsTest.java | 27 +------- .../DreamHomeControlsComplicationTest.java | 11 +++- 9 files changed, 47 insertions(+), 136 deletions(-) diff --git a/packages/SystemUI/res/layout/dream_overlay_home_controls_chip.xml b/packages/SystemUI/res/layout/dream_overlay_home_controls_chip.xml index 4f0a78e9c35d3..de96e9765668a 100644 --- a/packages/SystemUI/res/layout/dream_overlay_home_controls_chip.xml +++ b/packages/SystemUI/res/layout/dream_overlay_home_controls_chip.xml @@ -14,16 +14,21 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> - + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:paddingVertical="@dimen/dream_overlay_complication_home_controls_padding"> + + + + diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java index 48159aed524e3..ff7d78667fe8b 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java @@ -192,9 +192,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll break; } - // Add margin if specified by the complication. Otherwise add default margin - // between complications. - if (mLayoutParams.isMarginSpecified() || !isRoot) { + if (!isRoot) { final int margin = mLayoutParams.getMargin(mDefaultMargin); switch(direction) { case ComplicationLayoutParams.DIRECTION_DOWN: diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java index 4fae68d57ee8c..c600ebc8a77d6 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java @@ -260,13 +260,6 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { return mWeight; } - /** - * Returns whether margin has been specified by the complication. - */ - public boolean isMarginSpecified() { - return mMargin != MARGIN_UNSPECIFIED; - } - /** * Returns the margin to apply between complications, or the given default if no margin is * specified. diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java index c01cf43eae74a..ee0051220787b 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/DreamHomeControlsComplication.java @@ -32,6 +32,7 @@ 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.R; import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.controls.ControlsServiceInfo; import com.android.systemui.controls.dagger.ControlsComponent; @@ -151,7 +152,7 @@ public class DreamHomeControlsComplication implements Complication { @Inject DreamHomeControlsChipViewHolder( DreamHomeControlsChipViewController dreamHomeControlsChipViewController, - @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view, + @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) View view, @Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS) ComplicationLayoutParams layoutParams ) { mView = view; @@ -174,7 +175,7 @@ public class DreamHomeControlsComplication implements Complication { /** * Controls behavior of the dream complication. */ - static class DreamHomeControlsChipViewController extends ViewController { + static class DreamHomeControlsChipViewController extends ViewController { private static final String TAG = "DreamHomeControlsCtrl"; private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); @@ -203,7 +204,7 @@ public class DreamHomeControlsComplication implements Complication { @Inject DreamHomeControlsChipViewController( - @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) ImageView view, + @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) View view, ActivityStarter activityStarter, Context context, ControlsComponent controlsComponent, @@ -218,9 +219,10 @@ public class DreamHomeControlsComplication implements Complication { @Override protected void onViewAttached() { - mView.setImageResource(mControlsComponent.getTileImageId()); - mView.setContentDescription(mContext.getString(mControlsComponent.getTileTitleId())); - mView.setOnClickListener(this::onClickHomeControls); + final ImageView chip = mView.findViewById(R.id.home_controls_chip); + chip.setImageResource(mControlsComponent.getTileImageId()); + chip.setContentDescription(mContext.getString(mControlsComponent.getTileTitleId())); + chip.setOnClickListener(this::onClickHomeControls); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamHomeControlsComplicationComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamHomeControlsComplicationComponent.java index cf05d2d9cda03..a7aa97f74e311 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamHomeControlsComplicationComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamHomeControlsComplicationComponent.java @@ -19,7 +19,7 @@ package com.android.systemui.dreams.complication.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; import android.view.LayoutInflater; -import android.widget.ImageView; +import android.view.View; import com.android.systemui.R; import com.android.systemui.dreams.complication.DreamHomeControlsComplication; @@ -74,8 +74,8 @@ public interface DreamHomeControlsComplicationComponent { @Provides @DreamHomeControlsComplicationScope @Named(DREAM_HOME_CONTROLS_CHIP_VIEW) - static ImageView provideHomeControlsChipView(LayoutInflater layoutInflater) { - return (ImageView) layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip, + static View provideHomeControlsChipView(LayoutInflater layoutInflater) { + return layoutInflater.inflate(R.layout.dream_overlay_home_controls_chip, null, false); } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/RegisteredComplicationsModule.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/RegisteredComplicationsModule.java index a514c47f1fc1b..59392191e5bf3 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/RegisteredComplicationsModule.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/RegisteredComplicationsModule.java @@ -47,10 +47,10 @@ public interface RegisteredComplicationsModule { String DREAM_MEDIA_ENTRY_LAYOUT_PARAMS = "media_entry_layout_params"; int DREAM_CLOCK_TIME_COMPLICATION_WEIGHT = 1; - int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 0; + int DREAM_SMARTSPACE_COMPLICATION_WEIGHT = 2; int DREAM_MEDIA_COMPLICATION_WEIGHT = 0; - int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 2; - int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 1; + int DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT = 4; + int DREAM_MEDIA_ENTRY_COMPLICATION_WEIGHT = 3; /** * Provides layout parameters for the clock time complication. @@ -72,17 +72,14 @@ public interface RegisteredComplicationsModule { */ @Provides @Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS) - static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) { + static ComplicationLayoutParams provideHomeControlsChipLayoutParams() { return new ComplicationLayoutParams( - res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width), - res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height), + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT, ComplicationLayoutParams.POSITION_BOTTOM | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_UP, - DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT, - // Add margin to the bottom of home controls to horizontally align with smartspace. - res.getDimensionPixelSize( - R.dimen.dream_overlay_complication_home_controls_padding)); + ComplicationLayoutParams.DIRECTION_END, + DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT); } /** diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutEngineTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutEngineTest.java index 7a2ba95f74a01..7a2409876c52a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutEngineTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutEngineTest.java @@ -361,8 +361,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { assertThat(lp.getMarginEnd()).isEqualTo(margin); }); - // The third view should be at the top end corner. No margin should be applied if not - // specified. + // The third view should be at the top end corner. No margin should be applied. verifyChange(thirdViewInfo, true, lp -> { assertThat(lp.topToTop == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); @@ -441,69 +440,6 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { }); } - /** - * Ensures the root complication applies margin if specified. - */ - @Test - public void testRootComplicationSpecifiedMargin() { - final int defaultMargin = 5; - final int complicationMargin = 10; - final ComplicationLayoutEngine engine = - new ComplicationLayoutEngine(mLayout, defaultMargin, mTouchSession, 0, 0); - - final ViewInfo firstViewInfo = new ViewInfo( - new ComplicationLayoutParams( - 100, - 100, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_DOWN, - 0), - Complication.CATEGORY_STANDARD, - mLayout); - - addComplication(engine, firstViewInfo); - - final ViewInfo secondViewInfo = new ViewInfo( - new ComplicationLayoutParams( - 100, - 100, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_START, - 0), - Complication.CATEGORY_SYSTEM, - mLayout); - - addComplication(engine, secondViewInfo); - - firstViewInfo.clearInvocations(); - secondViewInfo.clearInvocations(); - - final ViewInfo thirdViewInfo = new ViewInfo( - new ComplicationLayoutParams( - 100, - 100, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_START, - 1, - complicationMargin), - Complication.CATEGORY_SYSTEM, - mLayout); - - addComplication(engine, thirdViewInfo); - - // The third view is the root view and has specified margin, which should be applied based - // on its direction. - verifyChange(thirdViewInfo, true, lp -> { - assertThat(lp.getMarginStart()).isEqualTo(0); - assertThat(lp.getMarginEnd()).isEqualTo(complicationMargin); - assertThat(lp.topMargin).isEqualTo(0); - assertThat(lp.bottomMargin).isEqualTo(0); - }); - } - /** * Ensures layout in a particular position updates. */ diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java index ce7561e95f1ec..19a88c39055c8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/ComplicationLayoutParamsTest.java @@ -96,36 +96,11 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { } } - /** - * Ensures ComplicationLayoutParams correctly returns whether the complication specified margin. - */ - @Test - public void testIsMarginSpecified() { - final ComplicationLayoutParams paramsNoMargin = new ComplicationLayoutParams( - 100, - 100, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_DOWN, - 0); - assertThat(paramsNoMargin.isMarginSpecified()).isFalse(); - - final ComplicationLayoutParams paramsWithMargin = new ComplicationLayoutParams( - 100, - 100, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_DOWN, - 0, - 20 /*margin*/); - assertThat(paramsWithMargin.isMarginSpecified()).isTrue(); - } - /** * Ensures unspecified margin uses default. */ @Test - public void testUnspecifiedMarginUsesDefault() { + public void testDefaultMargin() { final ComplicationLayoutParams params = new ComplicationLayoutParams( 100, 100, diff --git a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java index 30ad485d7ac3b..e6d3a69593cd8 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/dreams/complication/DreamHomeControlsComplicationTest.java @@ -35,6 +35,7 @@ import android.widget.ImageView; import androidx.test.filters.SmallTest; import com.android.internal.logging.UiEventLogger; +import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.controls.ControlsServiceInfo; import com.android.systemui.controls.controller.ControlsController; @@ -84,7 +85,10 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase { private ArgumentCaptor mCallbackCaptor; @Mock - private ImageView mView; + private View mView; + + @Mock + private ImageView mHomeControlsView; @Mock private ActivityStarter mActivityStarter; @@ -105,6 +109,7 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase { when(mControlsComponent.getControlsListingController()).thenReturn( Optional.of(mControlsListingController)); when(mControlsComponent.getVisibility()).thenReturn(AVAILABLE); + when(mView.findViewById(R.id.home_controls_chip)).thenReturn(mHomeControlsView); } @Test @@ -206,9 +211,9 @@ public class DreamHomeControlsComplicationTest extends SysuiTestCase { final ArgumentCaptor clickListenerCaptor = ArgumentCaptor.forClass(View.OnClickListener.class); - verify(mView).setOnClickListener(clickListenerCaptor.capture()); + verify(mHomeControlsView).setOnClickListener(clickListenerCaptor.capture()); - clickListenerCaptor.getValue().onClick(mView); + clickListenerCaptor.getValue().onClick(mHomeControlsView); verify(mUiEventLogger).log( DreamHomeControlsComplication.DreamHomeControlsChipViewController .DreamOverlayEvent.DREAM_HOME_CONTROLS_TAPPED);