Constraint smartspace width.
This change adds a new attribute in the complication layout params to allow constraint on width or height, depending on its direction. Smartspace is added a constraint width so not to overflow. Bug: 258455314 Fix: 258455314 Test: atest ComplicationEngineTest Test: atest ComplicationLayoutParamsTest Test: on device create a meeting with a long title and see that smartspace does not overflow Change-Id: Ie5a1278810ac77a8aa3f0046970642919c46f7ed
This commit is contained in:
@@ -1507,6 +1507,7 @@
|
||||
<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
|
||||
|
||||
@@ -211,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -268,6 +299,21 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
||||
return mMargin == MARGIN_UNSPECIFIED ? defaultMargin : mMargin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -103,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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,6 +440,133 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures layout sets correct max width constraint.
|
||||
*/
|
||||
@Test
|
||||
public void testWidthConstraint() {
|
||||
final int maxWidth = 20;
|
||||
final ComplicationLayoutEngine engine =
|
||||
new ComplicationLayoutEngine(mLayout, 0, mTouchSession, 0, 0);
|
||||
|
||||
final ViewInfo viewStartDirection = new ViewInfo(
|
||||
new ComplicationLayoutParams(
|
||||
100,
|
||||
100,
|
||||
ComplicationLayoutParams.POSITION_TOP
|
||||
| ComplicationLayoutParams.POSITION_END,
|
||||
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, viewStartDirection);
|
||||
addComplication(engine, viewEndDirection);
|
||||
|
||||
// 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_DOWN,
|
||||
0,
|
||||
5,
|
||||
maxHeight),
|
||||
Complication.CATEGORY_STANDARD,
|
||||
mLayout);
|
||||
|
||||
addComplication(engine, viewUpDirection);
|
||||
addComplication(engine, viewDownDirection);
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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_DOWN,
|
||||
0,
|
||||
5),
|
||||
Complication.CATEGORY_STANDARD,
|
||||
mLayout);
|
||||
|
||||
addComplication(engine, view);
|
||||
|
||||
// Verify neither max height nor max width set.
|
||||
verifyChange(view, false, lp -> {
|
||||
assertThat(lp.matchConstraintMaxHeight).isEqualTo(0);
|
||||
assertThat(lp.matchConstraintMaxWidth).isEqualTo(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures layout in a particular position updates.
|
||||
*/
|
||||
|
||||
@@ -136,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();
|
||||
}
|
||||
@@ -168,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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user