Merge "Define margins for complication overlay."
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
|
||||
<com.android.systemui.dreams.DreamOverlayStatusBarView
|
||||
android:id="@+id/dream_overlay_status_bar"
|
||||
|
||||
@@ -1349,13 +1349,8 @@
|
||||
<dimen name="dream_overlay_notifications_drag_area_height">100dp</dimen>
|
||||
|
||||
<!-- Dream overlay complications related dimensions -->
|
||||
<dimen name="dream_overlay_complication_clock_time_padding_left">50dp</dimen>
|
||||
<dimen name="dream_overlay_complication_clock_time_text_size">72sp</dimen>
|
||||
<dimen name="dream_overlay_complication_clock_date_padding_left">60dp</dimen>
|
||||
<dimen name="dream_overlay_complication_clock_date_padding_bottom">50dp</dimen>
|
||||
<dimen name="dream_overlay_complication_clock_date_text_size">18sp</dimen>
|
||||
<dimen name="dream_overlay_complication_weather_padding_left">20dp</dimen>
|
||||
<dimen name="dream_overlay_complication_weather_padding_bottom">50dp</dimen>
|
||||
<dimen name="dream_overlay_complication_weather_text_size">18sp</dimen>
|
||||
|
||||
<!-- The position of the end guide, which dream overlay complications can align their start with
|
||||
@@ -1390,4 +1385,13 @@
|
||||
<item name="dream_overlay_bouncer_start_region_screen_percentage" format="float" type="dimen">
|
||||
.2
|
||||
</item>
|
||||
|
||||
<!-- The margins applied to the dream overlay container -->
|
||||
<dimen name="dream_overlay_container_margin_start">0dp</dimen>
|
||||
<dimen name="dream_overlay_container_margin_end">0dp</dimen>
|
||||
<dimen name="dream_overlay_container_margin_top">0dp</dimen>
|
||||
<dimen name="dream_overlay_container_margin_bottom">0dp</dimen>
|
||||
|
||||
<!-- The margin applied between complications -->
|
||||
<dimen name="dream_overlay_complication_margin">0dp</dimen>
|
||||
</resources>
|
||||
|
||||
@@ -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<ComplicationId, ViewEntry> mEntries = new HashMap<>();
|
||||
private final HashMap<Integer, PositionGroup> 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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +104,7 @@ public interface DreamClockDateComplicationComponent {
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_END,
|
||||
INSERT_ORDER_WEIGHT,
|
||||
true);
|
||||
INSERT_ORDER_WEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,8 +109,7 @@ public interface DreamClockTimeComplicationComponent {
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_UP,
|
||||
INSERT_ORDER_WEIGHT,
|
||||
true);
|
||||
INSERT_ORDER_WEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +104,7 @@ public interface DreamWeatherComplicationComponent {
|
||||
ComplicationLayoutParams.POSITION_BOTTOM
|
||||
| ComplicationLayoutParams.POSITION_START,
|
||||
ComplicationLayoutParams.DIRECTION_END,
|
||||
INSERT_ORDER_WEIGHT,
|
||||
true);
|
||||
INSERT_ORDER_WEIGHT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user