Merge "Provide a way to specify complication margin." into tm-qpr-dev am: e84cc4cdce
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19981195 Change-Id: I1885a1c5136287682769253c187d9880ff3d87ea Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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_IN_DURATION;
|
||||||
import static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.COMPLICATIONS_FADE_OUT_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 static com.android.systemui.dreams.complication.dagger.ComplicationHostViewModule.SCOPED_COMPLICATIONS_LAYOUT;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
@@ -67,7 +67,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
private final Parent mParent;
|
private final Parent mParent;
|
||||||
@Complication.Category
|
@Complication.Category
|
||||||
private final int mCategory;
|
private final int mCategory;
|
||||||
private final int mMargin;
|
private final int mDefaultMargin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor. {@link Parent} allows for the {@link ViewEntry}'s surrounding
|
* 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,
|
ViewEntry(View view, ComplicationLayoutParams layoutParams,
|
||||||
TouchInsetManager.TouchInsetSession touchSession, int category, Parent parent,
|
TouchInsetManager.TouchInsetSession touchSession, int category, Parent parent,
|
||||||
int margin) {
|
int defaultMargin) {
|
||||||
mView = view;
|
mView = view;
|
||||||
// Views that are generated programmatically do not have a unique id assigned to them
|
// 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
|
// at construction. A new id is assigned here to enable ConstraintLayout relative
|
||||||
@@ -86,7 +86,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
mTouchInsetSession = touchSession;
|
mTouchInsetSession = touchSession;
|
||||||
mCategory = category;
|
mCategory = category;
|
||||||
mParent = parent;
|
mParent = parent;
|
||||||
mMargin = margin;
|
mDefaultMargin = defaultMargin;
|
||||||
|
|
||||||
touchSession.addViewToTracking(mView);
|
touchSession.addViewToTracking(mView);
|
||||||
}
|
}
|
||||||
@@ -195,18 +195,19 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isRoot) {
|
if (!isRoot) {
|
||||||
|
final int margin = mLayoutParams.getMargin(mDefaultMargin);
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case ComplicationLayoutParams.DIRECTION_DOWN:
|
case ComplicationLayoutParams.DIRECTION_DOWN:
|
||||||
params.setMargins(0, mMargin, 0, 0);
|
params.setMargins(0, margin, 0, 0);
|
||||||
break;
|
break;
|
||||||
case ComplicationLayoutParams.DIRECTION_UP:
|
case ComplicationLayoutParams.DIRECTION_UP:
|
||||||
params.setMargins(0, 0, 0, mMargin);
|
params.setMargins(0, 0, 0, margin);
|
||||||
break;
|
break;
|
||||||
case ComplicationLayoutParams.DIRECTION_END:
|
case ComplicationLayoutParams.DIRECTION_END:
|
||||||
params.setMarginStart(mMargin);
|
params.setMarginStart(margin);
|
||||||
break;
|
break;
|
||||||
case ComplicationLayoutParams.DIRECTION_START:
|
case ComplicationLayoutParams.DIRECTION_START:
|
||||||
params.setMarginEnd(mMargin);
|
params.setMarginEnd(margin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,7 +264,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
private final ComplicationLayoutParams mLayoutParams;
|
private final ComplicationLayoutParams mLayoutParams;
|
||||||
private final int mCategory;
|
private final int mCategory;
|
||||||
private Parent mParent;
|
private Parent mParent;
|
||||||
private int mMargin;
|
private int mDefaultMargin;
|
||||||
|
|
||||||
Builder(View view, TouchInsetManager.TouchInsetSession touchSession,
|
Builder(View view, TouchInsetManager.TouchInsetSession touchSession,
|
||||||
ComplicationLayoutParams lp, @Complication.Category int category) {
|
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
|
* Sets the margin that will be applied in the direction the complication is laid out
|
||||||
* towards.
|
* towards.
|
||||||
*/
|
*/
|
||||||
Builder setMargin(int margin) {
|
Builder setDefaultMargin(int margin) {
|
||||||
mMargin = margin;
|
mDefaultMargin = margin;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +313,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
*/
|
*/
|
||||||
ViewEntry build() {
|
ViewEntry build() {
|
||||||
return new ViewEntry(mView, mLayoutParams, mTouchSession, mCategory, mParent,
|
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 ConstraintLayout mLayout;
|
||||||
private final int mMargin;
|
private final int mDefaultMargin;
|
||||||
private final HashMap<ComplicationId, ViewEntry> mEntries = new HashMap<>();
|
private final HashMap<ComplicationId, ViewEntry> mEntries = new HashMap<>();
|
||||||
private final HashMap<Integer, PositionGroup> mPositions = new HashMap<>();
|
private final HashMap<Integer, PositionGroup> mPositions = new HashMap<>();
|
||||||
private final TouchInsetManager.TouchInsetSession mSession;
|
private final TouchInsetManager.TouchInsetSession mSession;
|
||||||
@@ -483,12 +484,12 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
/** */
|
/** */
|
||||||
@Inject
|
@Inject
|
||||||
public ComplicationLayoutEngine(@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout layout,
|
public ComplicationLayoutEngine(@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout layout,
|
||||||
@Named(COMPLICATION_MARGIN) int margin,
|
@Named(COMPLICATION_MARGIN_DEFAULT) int defaultMargin,
|
||||||
TouchInsetManager.TouchInsetSession session,
|
TouchInsetManager.TouchInsetSession session,
|
||||||
@Named(COMPLICATIONS_FADE_IN_DURATION) int fadeInDuration,
|
@Named(COMPLICATIONS_FADE_IN_DURATION) int fadeInDuration,
|
||||||
@Named(COMPLICATIONS_FADE_OUT_DURATION) int fadeOutDuration) {
|
@Named(COMPLICATIONS_FADE_OUT_DURATION) int fadeOutDuration) {
|
||||||
mLayout = layout;
|
mLayout = layout;
|
||||||
mMargin = margin;
|
mDefaultMargin = defaultMargin;
|
||||||
mSession = session;
|
mSession = session;
|
||||||
mFadeInDuration = fadeInDuration;
|
mFadeInDuration = fadeInDuration;
|
||||||
mFadeOutDuration = fadeOutDuration;
|
mFadeOutDuration = fadeOutDuration;
|
||||||
@@ -537,7 +538,7 @@ public class ComplicationLayoutEngine implements Complication.VisibilityControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
final ViewEntry.Builder entryBuilder = new ViewEntry.Builder(view, mSession, lp, category)
|
final ViewEntry.Builder entryBuilder = new ViewEntry.Builder(view, mSession, lp, category)
|
||||||
.setMargin(mMargin);
|
.setDefaultMargin(mDefaultMargin);
|
||||||
|
|
||||||
// Add position group if doesn't already exist
|
// Add position group if doesn't already exist
|
||||||
final int position = lp.getPosition();
|
final int position = lp.getPosition();
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
|||||||
private static final int FIRST_POSITION = POSITION_TOP;
|
private static final int FIRST_POSITION = POSITION_TOP;
|
||||||
private static final int LAST_POSITION = POSITION_END;
|
private static final int LAST_POSITION = POSITION_END;
|
||||||
|
|
||||||
|
private static final int MARGIN_UNSPECIFIED = 0xFFFFFFFF;
|
||||||
|
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef(flag = true, prefix = { "DIRECTION_" }, value = {
|
@IntDef(flag = true, prefix = { "DIRECTION_" }, value = {
|
||||||
DIRECTION_UP,
|
DIRECTION_UP,
|
||||||
@@ -77,6 +79,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
|||||||
|
|
||||||
private final int mWeight;
|
private final int mWeight;
|
||||||
|
|
||||||
|
private final int mMargin;
|
||||||
|
|
||||||
private final boolean mSnapToGuide;
|
private final boolean mSnapToGuide;
|
||||||
|
|
||||||
// Do not allow specifying opposite positions
|
// 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,
|
public ComplicationLayoutParams(int width, int height, @Position int position,
|
||||||
@Direction int direction, int weight) {
|
@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,
|
public ComplicationLayoutParams(int width, int height, @Position int position,
|
||||||
@Direction int direction, int weight, boolean snapToGuide) {
|
@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);
|
super(width, height);
|
||||||
|
|
||||||
if (!validatePosition(position)) {
|
if (!validatePosition(position)) {
|
||||||
@@ -142,6 +185,8 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
|||||||
|
|
||||||
mWeight = weight;
|
mWeight = weight;
|
||||||
|
|
||||||
|
mMargin = margin;
|
||||||
|
|
||||||
mSnapToGuide = snapToGuide;
|
mSnapToGuide = snapToGuide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,6 +198,7 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
|||||||
mPosition = source.mPosition;
|
mPosition = source.mPosition;
|
||||||
mDirection = source.mDirection;
|
mDirection = source.mDirection;
|
||||||
mWeight = source.mWeight;
|
mWeight = source.mWeight;
|
||||||
|
mMargin = source.mMargin;
|
||||||
mSnapToGuide = source.mSnapToGuide;
|
mSnapToGuide = source.mSnapToGuide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,6 +260,14 @@ public class ComplicationLayoutParams extends ViewGroup.LayoutParams {
|
|||||||
return mWeight;
|
return mWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Returns whether the complication's dimension perpendicular to direction should be
|
||||||
* automatically set.
|
* automatically set.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import dagger.Provides;
|
|||||||
@Module
|
@Module
|
||||||
public abstract class ComplicationHostViewModule {
|
public abstract class ComplicationHostViewModule {
|
||||||
public static final String SCOPED_COMPLICATIONS_LAYOUT = "scoped_complications_layout";
|
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_OUT_DURATION = "complications_fade_out_duration";
|
||||||
public static final String COMPLICATIONS_FADE_IN_DURATION = "complications_fade_in_duration";
|
public static final String COMPLICATIONS_FADE_IN_DURATION = "complications_fade_in_duration";
|
||||||
public static final String COMPLICATIONS_RESTORE_TIMEOUT = "complication_restore_timeout";
|
public static final String COMPLICATIONS_RESTORE_TIMEOUT = "complication_restore_timeout";
|
||||||
@@ -58,7 +58,7 @@ public abstract class ComplicationHostViewModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
@Named(COMPLICATION_MARGIN)
|
@Named(COMPLICATION_MARGIN_DEFAULT)
|
||||||
@DreamOverlayComponent.DreamOverlayScope
|
@DreamOverlayComponent.DreamOverlayScope
|
||||||
static int providesComplicationPadding(@Main Resources resources) {
|
static int providesComplicationPadding(@Main Resources resources) {
|
||||||
return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
|
return resources.getDimensionPixelSize(R.dimen.dream_overlay_complication_margin);
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ public interface RegisteredComplicationsModule {
|
|||||||
@Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
|
@Named(DREAM_CLOCK_TIME_COMPLICATION_LAYOUT_PARAMS)
|
||||||
static ComplicationLayoutParams provideClockTimeLayoutParams() {
|
static ComplicationLayoutParams provideClockTimeLayoutParams() {
|
||||||
return new ComplicationLayoutParams(0,
|
return new ComplicationLayoutParams(0,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
ComplicationLayoutParams.POSITION_TOP
|
ComplicationLayoutParams.POSITION_TOP
|
||||||
| ComplicationLayoutParams.POSITION_START,
|
| ComplicationLayoutParams.POSITION_START,
|
||||||
ComplicationLayoutParams.DIRECTION_DOWN,
|
ComplicationLayoutParams.DIRECTION_DOWN,
|
||||||
DREAM_CLOCK_TIME_COMPLICATION_WEIGHT);
|
DREAM_CLOCK_TIME_COMPLICATION_WEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,12 +73,12 @@ public interface RegisteredComplicationsModule {
|
|||||||
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
|
@Named(DREAM_HOME_CONTROLS_CHIP_LAYOUT_PARAMS)
|
||||||
static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) {
|
static ComplicationLayoutParams provideHomeControlsChipLayoutParams(@Main Resources res) {
|
||||||
return new ComplicationLayoutParams(
|
return new ComplicationLayoutParams(
|
||||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width),
|
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width),
|
||||||
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height),
|
res.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height),
|
||||||
ComplicationLayoutParams.POSITION_BOTTOM
|
ComplicationLayoutParams.POSITION_BOTTOM
|
||||||
| ComplicationLayoutParams.POSITION_START,
|
| ComplicationLayoutParams.POSITION_START,
|
||||||
ComplicationLayoutParams.DIRECTION_END,
|
ComplicationLayoutParams.DIRECTION_END,
|
||||||
DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
|
DREAM_HOME_CONTROLS_CHIP_COMPLICATION_WEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,11 +103,12 @@ public interface RegisteredComplicationsModule {
|
|||||||
@Named(DREAM_SMARTSPACE_LAYOUT_PARAMS)
|
@Named(DREAM_SMARTSPACE_LAYOUT_PARAMS)
|
||||||
static ComplicationLayoutParams provideSmartspaceLayoutParams() {
|
static ComplicationLayoutParams provideSmartspaceLayoutParams() {
|
||||||
return new ComplicationLayoutParams(0,
|
return new ComplicationLayoutParams(0,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||||
ComplicationLayoutParams.POSITION_TOP
|
ComplicationLayoutParams.POSITION_TOP
|
||||||
| ComplicationLayoutParams.POSITION_START,
|
| ComplicationLayoutParams.POSITION_START,
|
||||||
ComplicationLayoutParams.DIRECTION_DOWN,
|
ComplicationLayoutParams.DIRECTION_DOWN,
|
||||||
DREAM_SMARTSPACE_COMPLICATION_WEIGHT,
|
DREAM_SMARTSPACE_COMPLICATION_WEIGHT,
|
||||||
true /*snapToGuide*/);
|
0,
|
||||||
|
true /*snapToGuide*/);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,10 +297,10 @@ public class ComplicationLayoutEngineTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensures margin is applied
|
* Ensures default margin is applied
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testMargin() {
|
public void testDefaultMargin() {
|
||||||
final int margin = 5;
|
final int margin = 5;
|
||||||
final ComplicationLayoutEngine engine =
|
final ComplicationLayoutEngine engine =
|
||||||
new ComplicationLayoutEngine(mLayout, margin, mTouchSession, 0, 0);
|
new ComplicationLayoutEngine(mLayout, margin, mTouchSession, 0, 0);
|
||||||
@@ -372,6 +372,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.
|
* Ensures layout in a particular position updates.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -96,11 +96,63 @@ 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.
|
* Ensures ComplicationLayoutParams is properly duplicated on copy construction.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCopyConstruction() {
|
public void testCopyConstruction() {
|
||||||
|
final ComplicationLayoutParams params = new ComplicationLayoutParams(
|
||||||
|
100,
|
||||||
|
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(
|
final ComplicationLayoutParams params = new ComplicationLayoutParams(
|
||||||
100,
|
100,
|
||||||
100,
|
100,
|
||||||
@@ -112,6 +164,7 @@ public class ComplicationLayoutParamsTest extends SysuiTestCase {
|
|||||||
assertThat(copy.getDirection() == params.getDirection()).isTrue();
|
assertThat(copy.getDirection() == params.getDirection()).isTrue();
|
||||||
assertThat(copy.getPosition() == params.getPosition()).isTrue();
|
assertThat(copy.getPosition() == params.getPosition()).isTrue();
|
||||||
assertThat(copy.getWeight() == params.getWeight()).isTrue();
|
assertThat(copy.getWeight() == params.getWeight()).isTrue();
|
||||||
|
assertThat(copy.getMargin(1) == params.getMargin(1)).isTrue();
|
||||||
assertThat(copy.height == params.height).isTrue();
|
assertThat(copy.height == params.height).isTrue();
|
||||||
assertThat(copy.width == params.width).isTrue();
|
assertThat(copy.width == params.width).isTrue();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user