diff options
| author | 2022-10-07 18:37:24 +0000 | |
|---|---|---|
| committer | 2022-10-07 18:37:24 +0000 | |
| commit | e84cc4cdce307da65df3aaa7e002810e4557f1d0 (patch) | |
| tree | 627ee4f1ec4959718e6e7581873ee7ca1999604d | |
| parent | 99f5cefd6c9544a0d0bbc1123c944e4e0e983fc1 (diff) | |
| parent | add6c8c21322af602ea13e92837f47ee301e5a22 (diff) | |
Merge "Provide a way to specify complication margin." into tm-qpr-dev
6 files changed, 215 insertions, 38 deletions
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 9cd149b9bfee..5694f6da0ea5 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java @@ -18,7 +18,7 @@ package com.android.systemui.dreams.complication; import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATIONS_FADE_IN_DURATION; import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATIONS_FADE_OUT_DURATION; -import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATION_MARGIN; +import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATION_MARGIN_DEFAULT; import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.SCOPED_COMPLICATIONS_LAYOUT; import android.animation.Animator; @@ -67,7 +67,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll private final Parent mParent; @Complication.Category private final int mCategory; - private final int mMargin; + private final int mDefaultMargin; /** * Default constructor. {@link Parent} allows for the {@link ViewEntry}'s surrounding @@ -75,7 +75,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll */ ViewEntry(View view, ComplicationLayoutParams layoutParams, TouchInsetManager.TouchInsetSession touchSession, int category, Parent parent, - int margin) { + int defaultMargin) { mView = view; // Views that are generated programmatically do not have a unique id assigned to them // at construction. A new id is assigned here to enable ConstraintLayout relative @@ -86,7 +86,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll mTouchInsetSession = touchSession; mCategory = category; mParent = parent; - mMargin = margin; + mDefaultMargin = defaultMargin; touchSession.addViewToTracking(mView); } @@ -195,18 +195,19 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll } if (!isRoot) { + final int margin = mLayoutParams.getMargin(mDefaultMargin); switch(direction) { case ComplicationLayoutParams.DIRECTION_DOWN: - params.setMargins(0, mMargin, 0, 0); + params.setMargins(0, margin, 0, 0); break; case ComplicationLayoutParams.DIRECTION_UP: - params.setMargins(0, 0, 0, mMargin); + params.setMargins(0, 0, 0, margin); break; case ComplicationLayoutParams.DIRECTION_END: - params.setMarginStart(mMargin); + params.setMarginStart(margin); break; case ComplicationLayoutParams.DIRECTION_START: - params.setMarginEnd(mMargin); + params.setMarginEnd(margin); break; } } @@ -263,7 +264,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll private final ComplicationLayoutParams mLayoutParams; private final int mCategory; private Parent mParent; - private int mMargin; + private int mDefaultMargin; Builder(View view, TouchInsetManager.TouchInsetSession touchSession, ComplicationLayoutParams lp, @Complication.Category int category) { @@ -302,8 +303,8 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll * Sets the margin that will be applied in the direction the complication is laid out * towards. */ - Builder setMargin(int margin) { - mMargin = margin; + Builder setDefaultMargin(int margin) { + mDefaultMargin = margin; return this; } @@ -312,7 +313,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll */ ViewEntry build() { return new ViewEntry(mView, mLayoutParams, mTouchSession, mCategory, mParent, - mMargin); + mDefaultMargin); } } @@ -472,7 +473,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll } private final ConstraintLayout mLayout; - private final int mMargin; + private final int mDefaultMargin; private final HashMap<ComplicationId, ViewEntry> mEntries = new HashMap<>(); private final HashMap<Integer, PositionGroup> mPositions = new HashMap<>(); private final TouchInsetManager.TouchInsetSession mSession; @@ -483,12 +484,12 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll /** */ @Inject public ComplicationLayoutEngine(@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout layout, - @Named(COMPLICATION_MARGIN) int margin, + @Named(COMPLICATION_MARGIN_DEFAULT) int defaultMargin, TouchInsetManager.TouchInsetSession session, @Named(COMPLICATIONS_FADE_IN_DURATION) int fadeInDuration, @Named(COMPLICATIONS_FADE_OUT_DURATION) int fadeOutDuration) { mLayout = layout; - mMargin = margin; + mDefaultMargin = defaultMargin; mSession = session; mFadeInDuration = fadeInDuration; mFadeOutDuration = fadeOutDuration; @@ -537,7 +538,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll } final ViewEntry.Builder entryBuilder = new ViewEntry.Builder(view, mSession, lp, category) - .setMargin(mMargin); + .setDefaultMargin(mDefaultMargin); // Add position group if doesn't already exist final int position = lp.getPosition(); 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 8e8cb72d6ad0..a21eb19bd548 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutParams.java @@ -51,6 +51,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { private static final int FIRST_POSITION = POSITION_TOP; private static final int LAST_POSITION = POSITION_END; + private static final int MARGIN_UNSPECIFIED = 0xFFFFFFFF; + @Retention(RetentionPolicy.SOURCE) @IntDef(flag = true, prefix = { "DIRECTION_" }, value = { DIRECTION_UP, @@ -77,6 +79,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { private final int mWeight; + private final int mMargin; + private final boolean mSnapToGuide; // Do not allow specifying opposite positions @@ -106,7 +110,24 @@ 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, false); + this(width, height, position, direction, weight, MARGIN_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. + */ + public ComplicationLayoutParams(int width, int height, @Position int position, + @Direction int direction, int weight, int margin) { + this(width, height, position, direction, weight, margin, false); } /** @@ -127,6 +148,28 @@ 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); + } + + /** + * 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 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 + * direction is down, then the width of the complication will be set to span + * 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) { super(width, height); if (!validatePosition(position)) { @@ -142,6 +185,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { mWeight = weight; + mMargin = margin; + mSnapToGuide = snapToGuide; } @@ -153,6 +198,7 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { mPosition = source.mPosition; mDirection = source.mDirection; mWeight = source.mWeight; + mMargin = source.mMargin; mSnapToGuide = source.mSnapToGuide; } @@ -215,6 +261,14 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams { } /** + * Returns the margin to apply between complications, or the given default if no margin is + * specified. + */ + public int getMargin(int defaultMargin) { + return mMargin == MARGIN_UNSPECIFIED ? defaultMargin : mMargin; + } + + /** * Returns whether the complication's dimension perpendicular to direction should be * automatically set. */ diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java index 11d89d2dc816..c9fecc96c1b5 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewModule.java @@ -37,7 +37,7 @@ import dagger.Provides; @Module public abstract class ComplicationHostViewModule { public static final String SCOPED_COMPLICATIONS_LAYOUT = "scoped_complications_layout"; - public static final String COMPLICATION_MARGIN = "complication_margin"; + public static final String COMPLICATION_MARGIN_DEFAULT = "complication_margin_default"; public static final String COMPLICATIONS_FADE_OUT_DURATION = "complications_fade_out_duration"; public static final String COMPLICATIONS_FADE_IN_DURATION = "complications_fade_in_duration"; public static final String COMPLICATIONS_RESTORE_TIMEOUT = "complication_restore_timeout"; @@ -58,7 +58,7 @@ public abstract class ComplicationHostViewModule { } @Provides - @Named(COMPLICATION_MARGIN) + @Named(COMPLICATION_MARGIN_DEFAULT) @DreamOverlayComponent.DreamOverlayScope static int providesComplicationPadding(@Main Resources resources) { return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin); 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 759d6ec3bf21..7d2ce51ffbf6 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 @@ -59,11 +59,11 @@ public interface RegisteredComplicationsModule { @Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS) static ComplicationLayoutParams provideClockTimeLayoutParams() { return new ComplicationLayoutParams(0, - ViewGroup.LayoutParams.WRAP_CONTENT, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_DOWN, - DREAM_CLOCK_TIME_COMPLICATION_WEIGHT); + ViewGroup.LayoutParams.WRAP_CONTENT, + ComplicationLayoutParams.POSITION_TOP + | ComplicationLayoutParams.POSITION_START, + ComplicationLayoutParams.DIRECTION_DOWN, + DREAM_CLOCK_TIME_COMPLICATION_WEIGHT); } /** @@ -73,12 +73,12 @@ public interface RegisteredComplicationsModule { @Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS) static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) { return new ComplicationLayoutParams( - res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width), - res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height), - ComplicationLayoutParams.POSITION_BOTTOM - | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_END, - DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT); + res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width), + res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height), + ComplicationLayoutParams.POSITION_BOTTOM + | ComplicationLayoutParams.POSITION_START, + ComplicationLayoutParams.DIRECTION_END, + DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT); } /** @@ -103,11 +103,12 @@ public interface RegisteredComplicationsModule { @Named(DREAM_SMARTSPACE_LAYOUT_PARAMS) static ComplicationLayoutParams provideSmartspaceLayoutParams() { return new ComplicationLayoutParams(0, - ViewGroup.LayoutParams.WRAP_CONTENT, - ComplicationLayoutParams.POSITION_TOP - | ComplicationLayoutParams.POSITION_START, - ComplicationLayoutParams.DIRECTION_DOWN, - DREAM_SMARTSPACE_COMPLICATION_WEIGHT, - true /*snapToGuide*/); + ViewGroup.LayoutParams.WRAP_CONTENT, + ComplicationLayoutParams.POSITION_TOP + | ComplicationLayoutParams.POSITION_START, + ComplicationLayoutParams.DIRECTION_DOWN, + DREAM_SMARTSPACE_COMPLICATION_WEIGHT, + 0, + true /*snapToGuide*/); } } 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 2448f1a7633d..849ac5ef90d7 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 @@ -297,10 +297,10 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { } /** - * Ensures margin is applied + * Ensures default margin is applied */ @Test - public void testMargin() { + public void testDefaultMargin() { final int margin = 5; final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, margin, mTouchSession, 0, 0); @@ -373,6 +373,74 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { } /** + * Ensures complication margin is applied + */ + @Test + public void testComplicationMargin() { + 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, + complicationMargin), + 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), + Complication.CATEGORY_SYSTEM, + mLayout); + + addComplication(engine, thirdViewInfo); + + // The first added view should now be underneath the second view. + verifyChange(firstViewInfo, false, lp -> { + assertThat(lp.topToBottom == thirdViewInfo.view.getId()).isTrue(); + assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); + assertThat(lp.topMargin).isEqualTo(complicationMargin); + }); + + // The second view should be in underneath the third view. + verifyChange(secondViewInfo, false, lp -> { + assertThat(lp.endToStart == thirdViewInfo.view.getId()).isTrue(); + assertThat(lp.topToTop == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); + assertThat(lp.getMarginEnd()).isEqualTo(defaultMargin); + }); + } + + /** * Ensures layout in a particular position updates. */ @Test 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 967b30d07e63..cb7e47b28bcd 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,6 +97,35 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { } /** + * Ensures unspecified margin uses default. + */ + @Test + public void testUnspecifiedMarginUsesDefault() { + final ComplicationLayoutParams params = new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP, + ComplicationLayoutParams.DIRECTION_DOWN, + 3); + assertThat(params.getMargin(10) == 10).isTrue(); + } + + /** + * Ensures specified margin is used instead of default. + */ + @Test + public void testSpecifiedMargin() { + final ComplicationLayoutParams params = new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP, + ComplicationLayoutParams.DIRECTION_DOWN, + 3, + 10); + assertThat(params.getMargin(5) == 10).isTrue(); + } + + /** * Ensures ComplicationLayoutParams is properly duplicated on copy construction. */ @Test @@ -106,12 +135,36 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase { 100, ComplicationLayoutParams.POSITION_TOP, ComplicationLayoutParams.DIRECTION_DOWN, + 3, + 10); + 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.height == params.height).isTrue(); + assertThat(copy.width == params.width).isTrue(); + } + + /** + * Ensures ComplicationLayoutParams is properly duplicated on copy construction with unspecified + * margin. + */ + @Test + public void testCopyConstructionWithUnspecifiedMargin() { + final ComplicationLayoutParams params = new ComplicationLayoutParams( + 100, + 100, + ComplicationLayoutParams.POSITION_TOP, + ComplicationLayoutParams.DIRECTION_DOWN, 3); 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(1) == params.getMargin(1)).isTrue(); assertThat(copy.height == params.height).isTrue(); assertThat(copy.width == params.width).isTrue(); } |