diff options
| author | 2022-11-30 02:02:30 +0000 | |
|---|---|---|
| committer | 2022-11-30 02:02:30 +0000 | |
| commit | f49d45d69c27c3d4622d1cbad68e12c669c8f3e5 (patch) | |
| tree | 410b1e129d5cd6208a1257303b04d770deffb28a | |
| parent | 37cd9ae8493f82812dffc39ca086870f2a0e4498 (diff) | |
| parent | 21cbd245661598fd77e5d67b3d763706d7a28e4b (diff) | |
Merge changes I7350981a,Ie5a12788,Icfcc3653 into tm-qpr-dev
* changes:
Add a y translation to clock complication.
Constraint smartspace width.
Dream complications styling update.
12 files changed, 269 insertions, 131 deletions
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 2d67d95ab17e..efcb6f3435b9 100644 --- a/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml +++ b/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml @@ -14,25 +14,32 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License. --> -<com.android.systemui.shared.shadow.DoubleShadowTextClock +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" - 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:letterSpacing="0.02" - 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" -/> + 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:letterSpacing="0.02" + android:textSize="@dimen/dream_overlay_complication_clock_time_text_size" + android:translationY="@dimen/dream_overlay_complication_clock_time_translation_y" + 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" + /> + +</FrameLayout> 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 4f0a78e9c35d..de96e9765668 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. --> -<ImageView +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/home_controls_chip" - android:layout_height="@dimen/keyguard_affordance_fixed_height" - android:layout_width="@dimen/keyguard_affordance_fixed_width" - android:layout_gravity="bottom|start" - android:scaleType="center" - android:tint="?android:attr/textColorPrimary" - android:src="@drawable/controls_icon" - android:background="@drawable/keyguard_bottom_affordance_bg" - android:layout_marginStart="@dimen/keyguard_affordance_horizontal_offset" - android:layout_marginBottom="@dimen/keyguard_affordance_vertical_offset" - android:contentDescription="@string/quick_controls_title" /> + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:paddingVertical="@dimen/dream_overlay_complication_home_controls_padding"> + + <ImageView + android:id="@+id/home_controls_chip" + android:layout_height="@dimen/keyguard_affordance_fixed_height" + android:layout_width="@dimen/keyguard_affordance_fixed_width" + android:layout_gravity="bottom|start" + android:scaleType="center" + android:tint="?android:attr/textColorPrimary" + android:src="@drawable/controls_icon" + android:background="@drawable/keyguard_bottom_affordance_bg" + android:contentDescription="@string/quick_controls_title" /> + +</FrameLayout> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 738981db6823..4f2ff228e8e8 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -1500,13 +1500,15 @@ <dimen name="dream_overlay_status_bar_extra_margin">8dp</dimen> <!-- Dream overlay complications related dimensions --> - <dimen name="dream_overlay_complication_clock_time_text_size">86sp</dimen> + <dimen name="dream_overlay_complication_clock_time_text_size">86dp</dimen> + <dimen name="dream_overlay_complication_clock_time_translation_y">28dp</dimen> <dimen name="dream_overlay_complication_home_controls_padding">28dp</dimen> <dimen name="dream_overlay_complication_clock_subtitle_text_size">24sp</dimen> <dimen name="dream_overlay_complication_preview_text_size">36sp</dimen> <dimen name="dream_overlay_complication_preview_icon_padding">28dp</dimen> <dimen name="dream_overlay_complication_shadow_padding">2dp</dimen> <dimen name="dream_overlay_complication_smartspace_padding">24dp</dimen> + <dimen name="dream_overlay_complication_smartspace_max_width">408dp</dimen> <!-- The position of the end guide, which dream overlay complications can align their start with if their end is aligned with the parent end. Represented as the percentage over from the 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 48159aed524e..46ce7a90f5a3 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: @@ -213,6 +211,19 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll } }); + if (mLayoutParams.constraintSpecified()) { + switch (direction) { + case ComplicationLayoutParams.DIRECTION_START: + case ComplicationLayoutParams.DIRECTION_END: + params.matchConstraintMaxWidth = mLayoutParams.getConstraint(); + break; + case ComplicationLayoutParams.DIRECTION_UP: + case ComplicationLayoutParams.DIRECTION_DOWN: + params.matchConstraintMaxHeight = mLayoutParams.getConstraint(); + break; + } + } + mView.setLayoutParams(params); } 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 4fae68d57ee8..1755cb92da70 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java @@ -52,6 +52,7 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { private static final int LAST_POSITION = POSITION_END; private static final int MARGIN_UNSPECIFIED = 0xFFFFFFFF; + private static final int CONSTRAINT_UNSPECIFIED = 0xFFFFFFFF; @Retention(RetentionPolicy.SOURCE) @IntDef(flag = true, prefix = { "DIRECTION_" }, value = { @@ -81,6 +82,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { private final int mMargin; + private final int mConstraint; + private final boolean mSnapToGuide; // Do not allow specifying opposite positions @@ -110,7 +113,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { */ public ComplicationLayoutParams(int width, int height, @Position int position, @Direction int direction, int weight) { - this(width, height, position, direction, weight, MARGIN_UNSPECIFIED, false); + this(width, height, position, direction, weight, MARGIN_UNSPECIFIED, CONSTRAINT_UNSPECIFIED, + false); } /** @@ -127,7 +131,27 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { */ public ComplicationLayoutParams(int width, int height, @Position int position, @Direction int direction, int weight, int margin) { - this(width, height, position, direction, weight, margin, false); + this(width, height, position, direction, weight, margin, CONSTRAINT_UNSPECIFIED, false); + } + + /** + * Constructs a {@link ComplicationLayoutParams}. + * @param width The width {@link android.view.View.MeasureSpec} for the view. + * @param height The height {@link android.view.View.MeasureSpec} for the view. + * @param position The place within the parent container where the view should be positioned. + * @param direction The direction the view should be laid out from either the parent container + * or preceding view. + * @param weight The weight that should be considered for this view when compared to other + * views. This has an impact on the placement of the view but not the rendering of + * the view. + * @param margin The margin to apply between complications. + * @param constraint The max width or height the complication is allowed to spread, depending on + * its direction. For horizontal directions, this would be applied on width, + * and for vertical directions, height. + */ + public ComplicationLayoutParams(int width, int height, @Position int position, + @Direction int direction, int weight, int margin, int constraint) { + this(width, height, position, direction, weight, margin, constraint, false); } /** @@ -148,7 +172,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { */ public ComplicationLayoutParams(int width, int height, @Position int position, @Direction int direction, int weight, boolean snapToGuide) { - this(width, height, position, direction, weight, MARGIN_UNSPECIFIED, snapToGuide); + this(width, height, position, direction, weight, MARGIN_UNSPECIFIED, CONSTRAINT_UNSPECIFIED, + snapToGuide); } /** @@ -162,6 +187,9 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { * views. This has an impact on the placement of the view but not the rendering of * the view. * @param margin The margin to apply between complications. + * @param constraint The max width or height the complication is allowed to spread, depending on + * its direction. For horizontal directions, this would be applied on width, + * and for vertical directions, height. * @param snapToGuide When set to {@code true}, the dimension perpendicular to the direction * will be automatically set to align with a predetermined guide for that * side. For example, if the complication is aligned to the top end and @@ -169,7 +197,7 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { * from the end of the parent to the guide. */ public ComplicationLayoutParams(int width, int height, @Position int position, - @Direction int direction, int weight, int margin, boolean snapToGuide) { + @Direction int direction, int weight, int margin, int constraint, boolean snapToGuide) { super(width, height); if (!validatePosition(position)) { @@ -187,6 +215,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { mMargin = margin; + mConstraint = constraint; + mSnapToGuide = snapToGuide; } @@ -199,6 +229,7 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { mDirection = source.mDirection; mWeight = source.mWeight; mMargin = source.mMargin; + mConstraint = source.mConstraint; mSnapToGuide = source.mSnapToGuide; } @@ -261,13 +292,6 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { } /** - * 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. */ @@ -276,6 +300,21 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { } /** + * Returns whether the horizontal or vertical constraint has been specified. + */ + public boolean constraintSpecified() { + return mConstraint != CONSTRAINT_UNSPECIFIED; + } + + /** + * Returns the horizontal or vertical constraint of the complication, depending its direction. + * For horizontal directions, this is the max width, and for vertical directions, max height. + */ + public int getConstraint() { + return mConstraint; + } + + /** * Returns whether the complication's dimension perpendicular to direction should be * automatically set. */ 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 c01cf43eae74..ee0051220787 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<ImageView> { + static class DreamHomeControlsChipViewController extends ViewController<View> { 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/DreamClockTimeComplicationModule.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationModule.java index 7d9f1059f3b8..5290e44aa7fb 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationModule.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationModule.java @@ -45,11 +45,12 @@ public interface DreamClockTimeComplicationModule { @Provides @Named(DREAM_CLOCK_TIME_COMPLICATION_VIEW) static View provideComplicationView(LayoutInflater layoutInflater) { - final TextClock view = Preconditions.checkNotNull((TextClock) + 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"); - view.setFontVariationSettings(TAG_WEIGHT + WEIGHT); + ((TextClock) view.findViewById(R.id.time_view)).setFontVariationSettings( + TAG_WEIGHT + WEIGHT); return view; } } 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 cf05d2d9cda0..a7aa97f74e31 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 a514c47f1fc1..9b954f5f0c4a 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); } /** @@ -106,12 +103,14 @@ public interface RegisteredComplicationsModule { @Provides @Named(DREAM_SMARTSPACE_LAYOUT_PARAMS) static ComplicationLayoutParams provideSmartspaceLayoutParams(@Main Resources res) { - return new ComplicationLayoutParams(0, + return new ComplicationLayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, ComplicationLayoutParams.POSITION_BOTTOM | ComplicationLayoutParams.POSITION_START, ComplicationLayoutParams.DIRECTION_END, DREAM_SMARTSPACE_COMPLICATION_WEIGHT, - res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_padding)); + res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_padding), + res.getDimensionPixelSize(R.dimen.dream_overlay_complication_smartspace_max_width)); } } 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 7a2ba95f74a0..06a944e7a6d3 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(); @@ -442,65 +441,129 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { } /** - * Ensures the root complication applies margin if specified. + * Ensures layout sets correct max width constraint. */ @Test - public void testRootComplicationSpecifiedMargin() { - final int defaultMargin = 5; - final int complicationMargin = 10; + public void testWidthConstraint() { + final int maxWidth = 20; final ComplicationLayoutEngine engine = - new ComplicationLayoutEngine(mLayout, defaultMargin, mTouchSession, 0, 0); + new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0); - final ViewInfo firstViewInfo = new ViewInfo( + final ViewInfo viewStartDirection = new ViewInfo( new ComplicationLayoutParams( 100, 100, ComplicationLayoutParams.POSITION_TOP | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_DOWN, - 0), + ComplicationLayoutParams.DIRECTION_START, + 0, + 5, + maxWidth), + Complication.CATEGORY_STANDARD, + mLayout); + final ViewInfo viewEndDirection = new ViewInfo( + new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP + | ComplicationLayoutParams.POSITION_START, + ComplicationLayoutParams.DIRECTION_END, + 0, + 5, + maxWidth), Complication.CATEGORY_STANDARD, mLayout); - addComplication(engine, firstViewInfo); + addComplication(engine, viewStartDirection); + addComplication(engine, viewEndDirection); - final ViewInfo secondViewInfo = new ViewInfo( + // Verify both horizontal direction views have max width set correctly, and max height is + // not set. + verifyChange(viewStartDirection, false, lp -> { + assertThat(lp.matchConstraintMaxWidth).isEqualTo(maxWidth); + assertThat(lp.matchConstraintMaxHeight).isEqualTo(0); + }); + verifyChange(viewEndDirection, false, lp -> { + assertThat(lp.matchConstraintMaxWidth).isEqualTo(maxWidth); + assertThat(lp.matchConstraintMaxHeight).isEqualTo(0); + }); + } + + /** + * Ensures layout sets correct max height constraint. + */ + @Test + public void testHeightConstraint() { + final int maxHeight = 20; + final ComplicationLayoutEngine engine = + new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0); + + final ViewInfo viewUpDirection = new ViewInfo( + new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_BOTTOM + | ComplicationLayoutParams.POSITION_END, + ComplicationLayoutParams.DIRECTION_UP, + 0, + 5, + maxHeight), + Complication.CATEGORY_STANDARD, + mLayout); + final ViewInfo viewDownDirection = new ViewInfo( new ComplicationLayoutParams( 100, 100, ComplicationLayoutParams.POSITION_TOP | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_START, - 0), - Complication.CATEGORY_SYSTEM, + ComplicationLayoutParams.DIRECTION_DOWN, + 0, + 5, + maxHeight), + Complication.CATEGORY_STANDARD, mLayout); - addComplication(engine, secondViewInfo); + addComplication(engine, viewUpDirection); + addComplication(engine, viewDownDirection); - firstViewInfo.clearInvocations(); - secondViewInfo.clearInvocations(); + // Verify both vertical direction views have max height set correctly, and max width is + // not set. + verifyChange(viewUpDirection, false, lp -> { + assertThat(lp.matchConstraintMaxHeight).isEqualTo(maxHeight); + assertThat(lp.matchConstraintMaxWidth).isEqualTo(0); + }); + verifyChange(viewDownDirection, false, lp -> { + assertThat(lp.matchConstraintMaxHeight).isEqualTo(maxHeight); + assertThat(lp.matchConstraintMaxWidth).isEqualTo(0); + }); + } - final ViewInfo thirdViewInfo = new ViewInfo( + /** + * Ensures layout does not set any constraint if not specified. + */ + @Test + public void testConstraintNotSetWhenNotSpecified() { + final ComplicationLayoutEngine engine = + new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0); + + final ViewInfo view = new ViewInfo( new ComplicationLayoutParams( 100, 100, ComplicationLayoutParams.POSITION_TOP | ComplicationLayoutParams.POSITION_END, - ComplicationLayoutParams.DIRECTION_START, - 1, - complicationMargin), - Complication.CATEGORY_SYSTEM, + ComplicationLayoutParams.DIRECTION_DOWN, + 0, + 5), + Complication.CATEGORY_STANDARD, mLayout); - addComplication(engine, thirdViewInfo); + addComplication(engine, view); - // 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); + // Verify neither max height nor max width set. + verifyChange(view, false, lp -> { + assertThat(lp.matchConstraintMaxHeight).isEqualTo(0); + assertThat(lp.matchConstraintMaxWidth).isEqualTo(0); }); } 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 ce7561e95f1e..fdb4cc4480da 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 @@ -97,35 +97,10 @@ 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, @@ -161,13 +136,15 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { ComplicationLayoutParams.POSITION_TOP, ComplicationLayoutParams.DIRECTION_DOWN, 3, - 10); + 10, + 20); final ComplicationLayoutParams copy = new ComplicationLayoutParams(params); assertThat(copy.getDirection() == params.getDirection()).isTrue(); assertThat(copy.getPosition() == params.getPosition()).isTrue(); assertThat(copy.getWeight() == params.getWeight()).isTrue(); assertThat(copy.getMargin(0) == params.getMargin(1)).isTrue(); + assertThat(copy.getConstraint() == params.getConstraint()).isTrue(); assertThat(copy.height == params.height).isTrue(); assertThat(copy.width == params.width).isTrue(); } @@ -193,4 +170,31 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { assertThat(copy.height == params.height).isTrue(); assertThat(copy.width == params.width).isTrue(); } + + /** + * Ensures that constraint is set correctly. + */ + @Test + public void testConstraint() { + final ComplicationLayoutParams paramsWithoutConstraint = new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP, + ComplicationLayoutParams.DIRECTION_DOWN, + 3, + 10); + assertThat(paramsWithoutConstraint.constraintSpecified()).isFalse(); + + final int constraint = 10; + final ComplicationLayoutParams paramsWithConstraint = new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP, + ComplicationLayoutParams.DIRECTION_DOWN, + 3, + 10, + constraint); + assertThat(paramsWithConstraint.constraintSpecified()).isTrue(); + assertThat(paramsWithConstraint.getConstraint()).isEqualTo(constraint); + } } 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 30ad485d7ac3..e6d3a69593cd 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<ControlsListingController.ControlsListingCallback> 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<View.OnClickListener> 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); |