diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml b/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml index b6f516fd2042a..91d81a2b0b2f1 100644 --- a/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml +++ b/packages/SystemUI/res/layout/dream_overlay_complication_clock_date.xml @@ -19,8 +19,6 @@ android:id="@+id/date_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="@dimen/dream_overlay_complication_clock_date_padding_left" - android:paddingBottom="@dimen/dream_overlay_complication_clock_date_padding_bottom" android:gravity="center_horizontal" android:textColor="@android:color/white" android:shadowColor="@color/keyguard_shadow_color" 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 82c8d5f04327f..4824f4c8d2453 100644 --- a/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml +++ b/packages/SystemUI/res/layout/dream_overlay_complication_clock_time.xml @@ -19,7 +19,6 @@ android:id="@+id/time_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="@dimen/dream_overlay_complication_clock_time_padding_left" android:fontFamily="@font/clock" android:textColor="@android:color/white" android:format12Hour="h:mm" diff --git a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml b/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml index 08f0d6781b045..3900ea56dda38 100644 --- a/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml +++ b/packages/SystemUI/res/layout/dream_overlay_complication_weather.xml @@ -19,8 +19,6 @@ android:id="@+id/weather_view" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:paddingLeft="@dimen/dream_overlay_complication_weather_padding_left" - android:paddingBottom="@dimen/dream_overlay_complication_weather_padding_bottom" android:textColor="@android:color/white" android:shadowColor="@color/keyguard_shadow_color" android:shadowRadius="?attr/shadowRadius" diff --git a/packages/SystemUI/res/layout/dream_overlay_container.xml b/packages/SystemUI/res/layout/dream_overlay_container.xml index 3c2183d0ca616..330f515a29fca 100644 --- a/packages/SystemUI/res/layout/dream_overlay_container.xml +++ b/packages/SystemUI/res/layout/dream_overlay_container.xml @@ -25,8 +25,14 @@ android:id="@+id/dream_overlay_content" android:layout_width="match_parent" android:layout_height="0dp" + android:layout_marginTop="@dimen/dream_overlay_container_margin_top" + android:layout_marginEnd="@dimen/dream_overlay_container_margin_end" + android:layout_marginBottom="@dimen/dream_overlay_container_margin_bottom" + android:layout_marginStart="@dimen/dream_overlay_container_margin_start" + app:layout_constraintTop_toBottomOf="@id/dream_overlay_status_bar" - app:layout_constraintBottom_toBottomOf="parent" /> + app:layout_constraintBottom_toBottomOf="parent" + /> 100dp - 50dp 72sp - 60dp - 50dp 18sp - 20dp - 50dp 18sp + 0dp + 0dp + 0dp + 0dp + + + 0dp 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 5223f379508f3..0b80d8a878797 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationLayoutEngine.java @@ -16,6 +16,7 @@ package com.android.systemui.dreams.complication; +import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewComponent.COMPLICATION_MARGIN; import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewComponent.SCOPED_COMPLICATIONS_LAYOUT; import android.util.Log; @@ -54,12 +55,14 @@ public class ComplicationLayoutEngine { private final Parent mParent; @Complication.Category private final int mCategory; + private final int mMargin; /** * Default constructor. {@link Parent} allows for the {@link ViewEntry}'s surrounding * view hierarchy to be accessed without traversing the entire view tree. */ - ViewEntry(View view, ComplicationLayoutParams layoutParams, int category, Parent parent) { + ViewEntry(View view, ComplicationLayoutParams layoutParams, int category, Parent parent, + int margin) { 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 @@ -69,6 +72,7 @@ public class ComplicationLayoutEngine { mLayoutParams = layoutParams; mCategory = category; mParent = parent; + mMargin = margin; } /** @@ -173,6 +177,23 @@ public class ComplicationLayoutEngine { } break; } + + if (!isRoot) { + switch(direction) { + case ComplicationLayoutParams.DIRECTION_DOWN: + params.setMargins(0, mMargin, 0, 0); + break; + case ComplicationLayoutParams.DIRECTION_UP: + params.setMargins(0, 0, 0, mMargin); + break; + case ComplicationLayoutParams.DIRECTION_END: + params.setMarginStart(mMargin); + break; + case ComplicationLayoutParams.DIRECTION_START: + params.setMarginEnd(mMargin); + break; + } + } }); mView.setLayoutParams(params); @@ -224,6 +245,7 @@ public class ComplicationLayoutEngine { private final ComplicationLayoutParams mLayoutParams; private final int mCategory; private Parent mParent; + private int mMargin; Builder(View view, ComplicationLayoutParams lp, @Complication.Category int category) { mView = view; @@ -256,11 +278,20 @@ public class ComplicationLayoutEngine { return this; } + /** + * Sets the margin that will be applied in the direction the complication is laid out + * towards. + */ + Builder setMargin(int margin) { + mMargin = margin; + return this; + } + /** * Builds and returns the resulting {@link ViewEntry}. */ ViewEntry build() { - return new ViewEntry(mView, mLayoutParams, mCategory, mParent); + return new ViewEntry(mView, mLayoutParams, mCategory, mParent, mMargin); } } @@ -408,13 +439,16 @@ public class ComplicationLayoutEngine { } private final ConstraintLayout mLayout; + private final int mMargin; private final HashMap mEntries = new HashMap<>(); private final HashMap mPositions = new HashMap<>(); /** */ @Inject - public ComplicationLayoutEngine(@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout layout) { + public ComplicationLayoutEngine(@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout layout, + @Named(COMPLICATION_MARGIN) int margin) { mLayout = layout; + mMargin = margin; } /** @@ -434,7 +468,8 @@ public class ComplicationLayoutEngine { removeComplication(id); } - final ViewEntry.Builder entryBuilder = new ViewEntry.Builder(view, lp, category); + final ViewEntry.Builder entryBuilder = new ViewEntry.Builder(view, lp, category) + .setMargin(mMargin); // Add position group if doesn't already exist final int position = lp.getPosition(); diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewComponent.java index 4cc905e9a1907..20b0e50db9846 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/ComplicationHostViewComponent.java @@ -18,12 +18,14 @@ package com.android.systemui.dreams.complication.dagger; import static java.lang.annotation.RetentionPolicy.RUNTIME; +import android.content.res.Resources; import android.view.LayoutInflater; import androidx.constraintlayout.widget.ConstraintLayout; import com.android.internal.util.Preconditions; import com.android.systemui.R; +import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dreams.complication.ComplicationHostViewController; import java.lang.annotation.Documented; @@ -48,7 +50,7 @@ import dagger.Subcomponent; @ComplicationHostViewComponent.ComplicationHostViewScope public interface ComplicationHostViewComponent { String SCOPED_COMPLICATIONS_LAYOUT = "scoped_complications_layout"; - + String COMPLICATION_MARGIN = "complication_margin"; /** Scope annotation for singleton items within {@link ComplicationHostViewComponent}. */ @Documented @Retention(RUNTIME) @@ -85,5 +87,12 @@ public interface ComplicationHostViewComponent { null), "R.layout.dream_overlay_complications_layer did not properly inflated"); } + + @Provides + @Named(COMPLICATION_MARGIN) + @ComplicationHostViewScope + 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/DreamClockDateComplicationComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockDateComplicationComponent.java index eaffb1ca5b3ef..dd7f10c204e1f 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockDateComplicationComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockDateComplicationComponent.java @@ -104,8 +104,7 @@ public interface DreamClockDateComplicationComponent { ComplicationLayoutParams.POSITION_BOTTOM | ComplicationLayoutParams.POSITION_START, ComplicationLayoutParams.DIRECTION_END, - INSERT_ORDER_WEIGHT, - true); + INSERT_ORDER_WEIGHT); } } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationComponent.java index d539f5c2b870a..de11b61f47594 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamClockTimeComplicationComponent.java @@ -109,8 +109,7 @@ public interface DreamClockTimeComplicationComponent { ComplicationLayoutParams.POSITION_BOTTOM | ComplicationLayoutParams.POSITION_START, ComplicationLayoutParams.DIRECTION_UP, - INSERT_ORDER_WEIGHT, - true); + INSERT_ORDER_WEIGHT); } } } diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamWeatherComplicationComponent.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamWeatherComplicationComponent.java index a282594ff282e..536f3dcd28506 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamWeatherComplicationComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/dagger/DreamWeatherComplicationComponent.java @@ -104,8 +104,7 @@ public interface DreamWeatherComplicationComponent { ComplicationLayoutParams.POSITION_BOTTOM | ComplicationLayoutParams.POSITION_START, ComplicationLayoutParams.DIRECTION_END, - INSERT_ORDER_WEIGHT, - true); + INSERT_ORDER_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 d5ab708f893bd..64b267d6e1424 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 @@ -112,7 +112,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { Complication.CATEGORY_STANDARD, mLayout); - final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout); + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, 0); addComplication(engine, firstViewInfo); // Ensure the view is added to the top end corner @@ -139,7 +139,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { Complication.CATEGORY_STANDARD, mLayout); - final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout); + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, 0); addComplication(engine, firstViewInfo); // Ensure the view is added to the top end corner @@ -155,7 +155,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { */ @Test public void testDirectionLayout() { - final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout); + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, 0); final ViewInfo firstViewInfo = new ViewInfo( new ComplicationLayoutParams( @@ -203,7 +203,7 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { */ @Test public void testPositionLayout() { - final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout); + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, 0); final ViewInfo firstViewInfo = new ViewInfo( new ComplicationLayoutParams( @@ -284,12 +284,87 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase { }); } + /** + * Ensures margin is applied + */ + @Test + public void testMargin() { + final int margin = 5; + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, margin); + + 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), + 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(margin); + }); + + // 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(margin); + }); + + // The third view should be in at the top. + verifyChange(thirdViewInfo, true, lp -> { + assertThat(lp.topToTop == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); + assertThat(lp.endToEnd == ConstraintLayout.LayoutParams.PARENT_ID).isTrue(); + assertThat(lp.getMarginStart()).isEqualTo(0); + assertThat(lp.getMarginEnd()).isEqualTo(0); + assertThat(lp.topMargin).isEqualTo(0); + assertThat(lp.bottomMargin).isEqualTo(0); + }); + } + /** * Ensures layout in a particular position updates. */ @Test public void testRemoval() { - final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout); + final ComplicationLayoutEngine engine = new ComplicationLayoutEngine(mLayout, 0); final ViewInfo firstViewInfo = new ViewInfo( new ComplicationLayoutParams(