Methods Summary |
---|
private void | inflate(int resource)
mSizeAdaptiveLayout = (SizeAdaptiveLayout) mInflater.inflate(resource, null);
mSizeAdaptiveLayout.onAttachedToWindow();
mSmallView = mSizeAdaptiveLayout.findViewById(R.id.one_u);
mMediumView = mSizeAdaptiveLayout.findViewById(R.id.two_u);
mLargeView = mSizeAdaptiveLayout.findViewById(R.id.four_u);
|
private void | measureAndLayout(int height)
// manually measure it, and lay it out
int measureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST);
mSizeAdaptiveLayout.measure(500, measureSpec);
mSizeAdaptiveLayout.layout(0, 0, 500, mSizeAdaptiveLayout.getMeasuredHeight());
|
protected void | setUp()
super.setUp();
// inflate the layout
final Context context = getContext();
mInflater = LayoutInflater.from(context);
mOneU = 64;
mFourU = 4 * mOneU;
|
public void | testModestyPanelChangesColorWhite()
inflate(R.layout.size_adaptive_color);
View panel = mSizeAdaptiveLayout.getModestyPanel();
assertTrue("ModestyPanel should have a ColorDrawable background",
panel.getBackground() instanceof ColorDrawable);
ColorDrawable panelColor = (ColorDrawable) panel.getBackground();
ColorDrawable salColor = (ColorDrawable) mSizeAdaptiveLayout.getBackground();
assertEquals("ModestyPanel color should match the SizeAdaptiveLayout",
panelColor.getColor(), salColor.getColor());
|
public void | testModestyPanelTracksStateListColor()
inflate(R.layout.size_adaptive_color_statelist);
View panel = mSizeAdaptiveLayout.getModestyPanel();
assertEquals("ModestyPanel should have a ColorDrawable background" ,
panel.getBackground().getClass(), ColorDrawable.class);
ColorDrawable panelColor = (ColorDrawable) panel.getBackground();
assertEquals("ModestyPanel color should match the SizeAdaptiveLayout",
panelColor.getColor(), Color.RED);
|
public void | testOpenFourUOnlyJustRight()
inflate(R.layout.size_adaptive_large_only);
assertNull("smallView should be NULL in the singleton layout", mSmallView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
|
public void | testOpenFourUOnlyLarge()
inflate(R.layout.size_adaptive_large_only);
assertNull("smallView should be NULL in the singleton layout", mSmallView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.maxHeight + 10;
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
|
public void | testOpenFourUOnlySmall()
inflate(R.layout.size_adaptive_large_only);
assertNull("smallView should be NULL in the singleton layout", mSmallView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight - 10;
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
|
public void | testOpenIntoAGap()
inflate(R.layout.size_adaptive_gappy);
SizeAdaptiveLayout.LayoutParams smallParams =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
SizeAdaptiveLayout.LayoutParams largeParams =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
assertTrue("gappy layout should have a gap",
smallParams.maxHeight + 10 < largeParams.minHeight);
int height = (int) smallParams.maxHeight + 10;
measureAndLayout(height);
assertTrue("one and only one view should be visible",
mLargeView.getVisibility() != mSmallView.getVisibility());
// behavior is undefined in this case.
|
public void | testOpenIntoAnOverlap()
inflate(R.layout.size_adaptive_overlapping);
SizeAdaptiveLayout.LayoutParams smallParams =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
SizeAdaptiveLayout.LayoutParams largeParams =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
assertEquals("overlapping layout should overlap",
smallParams.minHeight,
largeParams.minHeight);
int height = (int) smallParams.maxHeight;
measureAndLayout(height);
assertTrue("one and only one view should be visible",
mLargeView.getVisibility() != mSmallView.getVisibility());
assertEquals("1U should get priority in an overlap because it is first",
View.VISIBLE,
mSmallView.getVisibility());
|
public void | testOpenLarge()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight + 10;
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertEquals("1U should be gone",
View.GONE,
mSmallView.getVisibility());
|
public void | testOpenLargeEvenWhenLargeIsActuallySmall()
inflate(R.layout.size_adaptive_lies);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertTrue("4U should also have been measured",
mLargeView.getMeasuredHeight() > 0);
|
public void | testOpenOneUOnlyJustRight()
inflate(R.layout.size_adaptive_singleton);
assertNull("largeView should be NULL in the singleton layout", mLargeView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
|
public void | testOpenOneUOnlyLarge()
inflate(R.layout.size_adaptive_singleton);
assertNull("largeView should be NULL in the singleton layout", mLargeView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.maxHeight + 10;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
|
public void | testOpenOneUOnlySmall()
inflate(R.layout.size_adaptive_singleton);
assertNull("largeView should be NULL in the singleton layout", mLargeView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight - 10;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
|
public void | testOpenSmall()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
assertEquals("4U should be gone",
View.GONE,
mLargeView.getVisibility());
|
public void | testOpenSmallEvenWhenLargeIsActuallySmall()
inflate(R.layout.size_adaptive_lies);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
assertTrue("1U should also have been measured",
mSmallView.getMeasuredHeight() > 0);
|
public void | testOpenThreeWayViewLarge()
inflate(R.layout.size_adaptive_three_way);
assertNotNull("mMediumView should not be NULL in the three view layout", mMediumView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be gone",
View.GONE,
mSmallView.getVisibility());
assertEquals("2U should be gone",
View.GONE,
mMediumView.getVisibility());
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
|
public void | testOpenThreeWayViewMedium()
inflate(R.layout.size_adaptive_three_way);
assertNotNull("mMediumView should not be NULL in the three view layout", mMediumView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mMediumView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be gone",
View.GONE,
mSmallView.getVisibility());
assertEquals("2U should be visible",
View.VISIBLE,
mMediumView.getVisibility());
assertEquals("4U should be gone",
View.GONE,
mLargeView.getVisibility());
|
public void | testOpenThreeWayViewSmall()
inflate(R.layout.size_adaptive_three_way);
assertNotNull("mMediumView should not be NULL in the three view layout", mMediumView);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
assertEquals("2U should be gone",
View.GONE,
mMediumView.getVisibility());
assertEquals("4U should be gone",
View.GONE,
mLargeView.getVisibility());
|
public void | testOpenTooBig()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
lp.maxHeight = 500;
mLargeView.setLayoutParams(lp);
int height = (int) (lp.minHeight + 10);
measureAndLayout(height);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertEquals("1U should be gone",
View.GONE,
mSmallView.getVisibility());
|
public void | testOpenTooSmall()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
int height = (int) lp.minHeight - 10;
measureAndLayout(height);
assertEquals("1U should be visible",
View.VISIBLE,
mSmallView.getVisibility());
assertEquals("4U should be gone",
View.GONE,
mLargeView.getVisibility());
|
public void | testOpenWrapContent()
inflate(R.layout.size_adaptive_text);
SizeAdaptiveLayout.LayoutParams lp =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int height = (int) lp.minHeight + 10;
// manually measure it, and lay it out
int measureSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.AT_MOST);
mSizeAdaptiveLayout.measure(500, measureSpec);
assertTrue("should not be forced to 4U",
mSizeAdaptiveLayout.getMeasuredHeight() < mFourU);
|
public void | testPreconditions()The name 'test preconditions' is a convention to signal that if this
test doesn't pass, the test case was not set up properly and it might
explain any and all failures in other tests. This is not guaranteed
to run before other tests, as junit uses reflection to find the tests.
assertNotNull(mInflater);
inflate(R.layout.size_adaptive);
assertNotNull(mSizeAdaptiveLayout);
assertNotNull(mSmallView);
assertNotNull(mLargeView);
|
public void | testResizeWithAnimation()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams smallParams =
(SizeAdaptiveLayout.LayoutParams) mSmallView.getLayoutParams();
SizeAdaptiveLayout.LayoutParams largeParams =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int startHeight = (int) largeParams.minHeight + 10;
int endHeight = (int) smallParams.maxHeight;
measureAndLayout(startHeight);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertFalse("There should be no animation on initial rendering.",
mSizeAdaptiveLayout.getTransitionAnimation().isRunning());
measureAndLayout(endHeight);
assertEquals("1U should now be visible",
View.VISIBLE,
mSmallView.getVisibility());
assertTrue("There should be an animation on scale between views.",
mSizeAdaptiveLayout.getTransitionAnimation().isRunning());
|
public void | testResizeWithoutAnimation()
inflate(R.layout.size_adaptive);
SizeAdaptiveLayout.LayoutParams largeParams =
(SizeAdaptiveLayout.LayoutParams) mLargeView.getLayoutParams();
int startHeight = (int) largeParams.minHeight + 10;
int endHeight = (int) largeParams.minHeight + 10;
measureAndLayout(startHeight);
assertEquals("4U should be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertFalse("There should be no animation on initial rendering.",
mSizeAdaptiveLayout.getTransitionAnimation().isRunning());
measureAndLayout(endHeight);
assertEquals("4U should still be visible",
View.VISIBLE,
mLargeView.getVisibility());
assertFalse("There should be no animation on scale within a view.",
mSizeAdaptiveLayout.getTransitionAnimation().isRunning());
|