summaryrefslogtreecommitdiff
path: root/library/test/instrumentation/src/com/android/setupwizardlib/test
diff options
context:
space:
mode:
Diffstat (limited to 'library/test/instrumentation/src/com/android/setupwizardlib/test')
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/BottomScrollViewTest.java146
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ButtonBarItemTest.java175
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java189
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/GlifLayoutTest.java177
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/GlifListLayoutTest.java180
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/GlifPatternDrawableTest.java212
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/IllustrationTest.java53
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ItemAdapterTest.java116
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ItemInflaterTest.java45
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ItemLayoutTest.java86
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ItemTest.java298
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/ReflectionInflaterTest.java79
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java390
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardListLayoutTest.java171
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SimpleInflaterTest.java47
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SpanHelperTest.java28
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/StatusBarBackgroundLayoutTest.java70
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java432
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/util/DrawingTestHelper.java106
-rw-r--r--library/test/instrumentation/src/com/android/setupwizardlib/test/util/MockWindow.java491
20 files changed, 1737 insertions, 1754 deletions
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/BottomScrollViewTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/BottomScrollViewTest.java
index 1a8eb21..4f9487c 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/BottomScrollViewTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/BottomScrollViewTest.java
@@ -21,13 +21,11 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import android.content.Context;
+import android.view.View;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-
import com.android.setupwizardlib.view.BottomScrollView;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,101 +34,101 @@ import org.junit.runner.RunWith;
@SmallTest
public class BottomScrollViewTest {
- private TestBottomScrollListener mListener;
+ private TestBottomScrollListener mListener;
- @Before
- public void setUp() throws Exception {
- mListener = new TestBottomScrollListener();
- }
+ @Before
+ public void setUp() throws Exception {
+ mListener = new TestBottomScrollListener();
+ }
- @Test
- public void testNoNeedScroll() {
- createScrollView(20);
- assertTrue("Scroll should not be required", mListener.mScrolledToBottom);
- }
+ @Test
+ public void testNoNeedScroll() {
+ createScrollView(20);
+ assertTrue("Scroll should not be required", mListener.mScrolledToBottom);
+ }
- @Test
- public void testNeedScroll() {
- createScrollView(110);
- assertFalse("Scroll should be required", mListener.mScrolledToBottom);
- }
+ @Test
+ public void testNeedScroll() {
+ createScrollView(110);
+ assertFalse("Scroll should be required", mListener.mScrolledToBottom);
+ }
- @Test
- public void testScrollToBottom() {
- final BottomScrollView bottomScrollView = createScrollView(110);
+ @Test
+ public void testScrollToBottom() {
+ final BottomScrollView bottomScrollView = createScrollView(110);
- assertFalse("Scroll should be required", mListener.mScrolledToBottom);
+ assertFalse("Scroll should be required", mListener.mScrolledToBottom);
- bottomScrollView.scrollTo(0, 10);
- assertTrue("Should already be scrolled to bottom", mListener.mScrolledToBottom);
- }
+ bottomScrollView.scrollTo(0, 10);
+ assertTrue("Should already be scrolled to bottom", mListener.mScrolledToBottom);
+ }
- @Test
- public void testScrollThreshold() {
- final BottomScrollView bottomScrollView = createScrollView(110);
- assertEquals("Scroll threshold should be 10", 10, bottomScrollView.getScrollThreshold());
- }
+ @Test
+ public void testScrollThreshold() {
+ final BottomScrollView bottomScrollView = createScrollView(110);
+ assertEquals("Scroll threshold should be 10", 10, bottomScrollView.getScrollThreshold());
+ }
- private BottomScrollView createScrollView(final int childHeight) {
- final Context context = InstrumentationRegistry.getContext();
- final BottomScrollView bottomScrollView = new TestBottomScrollView(context);
- bottomScrollView.setBottomScrollListener(mListener);
+ private BottomScrollView createScrollView(final int childHeight) {
+ final Context context = InstrumentationRegistry.getContext();
+ final BottomScrollView bottomScrollView = new TestBottomScrollView(context);
+ bottomScrollView.setBottomScrollListener(mListener);
- final View child = new TestChildView(context, childHeight);
+ final View child = new TestChildView(context, childHeight);
- child.measure(0, 0); // TestChildView's measured dimensions doesn't depend on the arguments
- bottomScrollView.addView(child);
- bottomScrollView.layout(0, 0, 100, 100);
+ child.measure(0, 0); // TestChildView's measured dimensions doesn't depend on the arguments
+ bottomScrollView.addView(child);
+ bottomScrollView.layout(0, 0, 100, 100);
- return bottomScrollView;
- }
+ return bottomScrollView;
+ }
- private static class TestChildView extends View {
+ private static class TestChildView extends View {
- private static final int WIDTH = 10;
- private int mHeight;
+ private static final int WIDTH = 10;
+ private int mHeight;
- TestChildView(Context context, int height) {
- super(context);
- mHeight = height;
- }
+ TestChildView(Context context, int height) {
+ super(context);
+ mHeight = height;
+ }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- setMeasuredDimension(WIDTH, mHeight);
- }
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ setMeasuredDimension(WIDTH, mHeight);
+ }
- public void setHeight(int height) {
- mHeight = height;
- }
+ public void setHeight(int height) {
+ mHeight = height;
}
+ }
- private static class TestBottomScrollView extends BottomScrollView {
+ private static class TestBottomScrollView extends BottomScrollView {
- TestBottomScrollView(Context context) {
- super(context);
- }
+ TestBottomScrollView(Context context) {
+ super(context);
+ }
- @Override
- public boolean post(Runnable action) {
- // Post all runnables synchronously so that tests can check the callbacks.
- action.run();
- return true;
- }
+ @Override
+ public boolean post(Runnable action) {
+ // Post all runnables synchronously so that tests can check the callbacks.
+ action.run();
+ return true;
}
+ }
- private static class TestBottomScrollListener implements BottomScrollView.BottomScrollListener {
+ private static class TestBottomScrollListener implements BottomScrollView.BottomScrollListener {
- boolean mScrolledToBottom = true;
+ boolean mScrolledToBottom = true;
- @Override
- public void onScrolledToBottom() {
- mScrolledToBottom = true;
- }
+ @Override
+ public void onScrolledToBottom() {
+ mScrolledToBottom = true;
+ }
- @Override
- public void onRequiresScroll() {
- mScrolledToBottom = false;
- }
+ @Override
+ public void onRequiresScroll() {
+ mScrolledToBottom = false;
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ButtonBarItemTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ButtonBarItemTest.java
index 18c295e..aacffeb 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ButtonBarItemTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ButtonBarItemTest.java
@@ -20,18 +20,16 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.items.ButtonBarItem;
import com.android.setupwizardlib.items.ButtonItem;
import com.android.setupwizardlib.items.Item;
import com.android.setupwizardlib.items.ItemHierarchy;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -40,87 +38,92 @@ import org.junit.runner.RunWith;
@SmallTest
public class ButtonBarItemTest {
- private ButtonItem mChild1;
- private ButtonItem mChild2;
- private ButtonItem mChild3;
-
- @Before
- public void setUp() throws Exception {
- mChild1 = new ButtonItem();
- mChild2 = new ButtonItem();
- mChild3 = new ButtonItem();
+ private ButtonItem mChild1;
+ private ButtonItem mChild2;
+ private ButtonItem mChild3;
+
+ @Before
+ public void setUp() throws Exception {
+ mChild1 = new ButtonItem();
+ mChild2 = new ButtonItem();
+ mChild3 = new ButtonItem();
+ }
+
+ @Test
+ public void testFindItemById() {
+ ButtonBarItem item = new ButtonBarItem();
+ item.setId(888);
+
+ mChild1.setId(123);
+ mChild2.setId(456);
+ mChild3.setId(789);
+ item.addChild(mChild1);
+ item.addChild(mChild2);
+ item.addChild(mChild3);
+
+ assertEquals("Finding 123 should return child1", mChild1, item.findItemById(123));
+ assertEquals("Finding 456 should return child2", mChild2, item.findItemById(456));
+ assertEquals("Finding 789 should return child3", mChild3, item.findItemById(789));
+
+ assertEquals("Finding 888 should return ButtonBarItem itself", item, item.findItemById(888));
+
+ assertNull("Finding 999 should return null", item.findItemById(999));
+ }
+
+ @Test
+ public void testBindEmpty() {
+ ButtonBarItem item = new ButtonBarItem();
+ final ViewGroup layout = createLayout();
+ item.onBindView(layout);
+
+ assertEquals(
+ "Binding empty ButtonBar should not create any children", 0, layout.getChildCount());
+ }
+
+ @Test
+ public void testBind() {
+ ButtonBarItem item = new ButtonBarItem();
+
+ item.addChild(mChild1);
+ mChild1.setText("child1");
+ item.addChild(mChild2);
+ mChild2.setText("child2");
+ item.addChild(mChild3);
+ mChild3.setText("child3");
+
+ final ViewGroup layout = createLayout();
+ item.onBindView(layout);
+
+ assertEquals("Binding ButtonBar should create 3 children", 3, layout.getChildCount());
+ assertEquals(
+ "First button should have text \"child1\"",
+ "child1",
+ ((Button) layout.getChildAt(0)).getText());
+ assertEquals(
+ "Second button should have text \"child2\"",
+ "child2",
+ ((Button) layout.getChildAt(1)).getText());
+ assertEquals(
+ "Third button should have text \"child3\"",
+ "child3",
+ ((Button) layout.getChildAt(2)).getText());
+ }
+
+ @Test
+ public void testAddInvalidChild() {
+ ButtonBarItem item = new ButtonBarItem();
+
+ ItemHierarchy invalidChild = new Item();
+
+ try {
+ item.addChild(invalidChild);
+ fail("Adding non ButtonItem to ButtonBarItem should throw exception");
+ } catch (UnsupportedOperationException e) {
+ // pass
}
+ }
- @Test
- public void testFindItemById() {
- ButtonBarItem item = new ButtonBarItem();
- item.setId(888);
-
- mChild1.setId(123);
- mChild2.setId(456);
- mChild3.setId(789);
- item.addChild(mChild1);
- item.addChild(mChild2);
- item.addChild(mChild3);
-
- assertEquals("Finding 123 should return child1", mChild1, item.findItemById(123));
- assertEquals("Finding 456 should return child2", mChild2, item.findItemById(456));
- assertEquals("Finding 789 should return child3", mChild3, item.findItemById(789));
-
- assertEquals("Finding 888 should return ButtonBarItem itself", item,
- item.findItemById(888));
-
- assertNull("Finding 999 should return null", item.findItemById(999));
- }
-
- @Test
- public void testBindEmpty() {
- ButtonBarItem item = new ButtonBarItem();
- final ViewGroup layout = createLayout();
- item.onBindView(layout);
-
- assertEquals("Binding empty ButtonBar should not create any children", 0,
- layout.getChildCount());
- }
-
- @Test
- public void testBind() {
- ButtonBarItem item = new ButtonBarItem();
-
- item.addChild(mChild1);
- mChild1.setText("child1");
- item.addChild(mChild2);
- mChild2.setText("child2");
- item.addChild(mChild3);
- mChild3.setText("child3");
-
- final ViewGroup layout = createLayout();
- item.onBindView(layout);
-
- assertEquals("Binding ButtonBar should create 3 children", 3, layout.getChildCount());
- assertEquals("First button should have text \"child1\"", "child1",
- ((Button) layout.getChildAt(0)).getText());
- assertEquals("Second button should have text \"child2\"", "child2",
- ((Button) layout.getChildAt(1)).getText());
- assertEquals("Third button should have text \"child3\"", "child3",
- ((Button) layout.getChildAt(2)).getText());
- }
-
- @Test
- public void testAddInvalidChild() {
- ButtonBarItem item = new ButtonBarItem();
-
- ItemHierarchy invalidChild = new Item();
-
- try {
- item.addChild(invalidChild);
- fail("Adding non ButtonItem to ButtonBarItem should throw exception");
- } catch (UnsupportedOperationException e) {
- // pass
- }
- }
-
- private ViewGroup createLayout() {
- return new LinearLayout(InstrumentationRegistry.getContext());
- }
+ private ViewGroup createLayout() {
+ return new LinearLayout(InstrumentationRegistry.getContext());
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java
index 95245b0..1445660 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/DrawableLayoutDirectionHelperTest.java
@@ -28,117 +28,124 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
+import android.view.View;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-
import com.android.setupwizardlib.util.DrawableLayoutDirectionHelper;
-
+import java.util.Locale;
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.Locale;
-
@RunWith(AndroidJUnit4.class)
@SmallTest
public class DrawableLayoutDirectionHelperTest {
- @Test
- public void testCreateRelativeInsetDrawableLtr() {
- final Drawable drawable = new ColorDrawable(Color.RED);
- @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
- final InsetDrawable insetDrawable =
- DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
- 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */,
- View.LAYOUT_DIRECTION_LTR);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- assertSame("Drawable from getDrawable() should be same as passed in", drawable,
- insetDrawable.getDrawable());
- }
- Rect outRect = new Rect();
- insetDrawable.getPadding(outRect);
- assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
- outRect);
+ @Test
+ public void testCreateRelativeInsetDrawableLtr() {
+ final Drawable drawable = new ColorDrawable(Color.RED);
+ @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
+ final InsetDrawable insetDrawable =
+ DrawableLayoutDirectionHelper.createRelativeInsetDrawable(
+ drawable,
+ 1 /* start */,
+ 2 /* top */,
+ 3 /* end */,
+ 4 /* bottom */,
+ View.LAYOUT_DIRECTION_LTR);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ assertSame(
+ "Drawable from getDrawable() should be same as passed in",
+ drawable,
+ insetDrawable.getDrawable());
}
+ Rect outRect = new Rect();
+ insetDrawable.getPadding(outRect);
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4), outRect);
+ }
- @Test
- public void testCreateRelativeInsetDrawableRtl() {
- final Drawable drawable = new ColorDrawable(Color.RED);
- @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
- final InsetDrawable insetDrawable =
- DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
- 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */,
- View.LAYOUT_DIRECTION_RTL);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- assertSame("Drawable from getDrawable() should be same as passed in", drawable,
- insetDrawable.getDrawable());
- }
- Rect outRect = new Rect();
- insetDrawable.getPadding(outRect);
- assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
- outRect);
+ @Test
+ public void testCreateRelativeInsetDrawableRtl() {
+ final Drawable drawable = new ColorDrawable(Color.RED);
+ @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
+ final InsetDrawable insetDrawable =
+ DrawableLayoutDirectionHelper.createRelativeInsetDrawable(
+ drawable,
+ 1 /* start */,
+ 2 /* top */,
+ 3 /* end */,
+ 4 /* bottom */,
+ View.LAYOUT_DIRECTION_RTL);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ assertSame(
+ "Drawable from getDrawable() should be same as passed in",
+ drawable,
+ insetDrawable.getDrawable());
}
+ Rect outRect = new Rect();
+ insetDrawable.getPadding(outRect);
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4), outRect);
+ }
- @Test
- public void testCreateRelativeInsetDrawableViewRtl() {
- final Drawable drawable = new ColorDrawable(Color.RED);
- final View view = new ForceRtlView(InstrumentationRegistry.getContext());
- final InsetDrawable insetDrawable =
- DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
- 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, view);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- assertSame("Drawable from getDrawable() should be same as passed in", drawable,
- insetDrawable.getDrawable());
- }
- Rect outRect = new Rect();
- insetDrawable.getPadding(outRect);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
- outRect);
- } else {
- assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
- outRect);
- }
+ @Test
+ public void testCreateRelativeInsetDrawableViewRtl() {
+ final Drawable drawable = new ColorDrawable(Color.RED);
+ final View view = new ForceRtlView(InstrumentationRegistry.getContext());
+ final InsetDrawable insetDrawable =
+ DrawableLayoutDirectionHelper.createRelativeInsetDrawable(
+ drawable, 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, view);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ assertSame(
+ "Drawable from getDrawable() should be same as passed in",
+ drawable,
+ insetDrawable.getDrawable());
+ }
+ Rect outRect = new Rect();
+ insetDrawable.getPadding(outRect);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4), outRect);
+ } else {
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4), outRect);
}
+ }
- @Test
- public void testCreateRelativeInsetDrawableContextRtl() {
- Context context = InstrumentationRegistry.getContext();
- final Drawable drawable = new ColorDrawable(Color.RED);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- final Configuration config = new Configuration();
- config.setLayoutDirection(new Locale("fa", "IR"));
- context = context.createConfigurationContext(config);
- }
- final InsetDrawable insetDrawable =
- DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
- 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, context);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- assertSame("Drawable from getDrawable() should be same as passed in", drawable,
- insetDrawable.getDrawable());
- }
- Rect outRect = new Rect();
- insetDrawable.getPadding(outRect);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
- outRect);
- } else {
- assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
- outRect);
- }
+ @Test
+ public void testCreateRelativeInsetDrawableContextRtl() {
+ Context context = InstrumentationRegistry.getContext();
+ final Drawable drawable = new ColorDrawable(Color.RED);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ final Configuration config = new Configuration();
+ config.setLayoutDirection(new Locale("fa", "IR"));
+ context = context.createConfigurationContext(config);
+ }
+ final InsetDrawable insetDrawable =
+ DrawableLayoutDirectionHelper.createRelativeInsetDrawable(
+ drawable, 1 /* start */, 2 /* top */, 3 /* end */, 4 /* bottom */, context);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ assertSame(
+ "Drawable from getDrawable() should be same as passed in",
+ drawable,
+ insetDrawable.getDrawable());
}
+ Rect outRect = new Rect();
+ insetDrawable.getPadding(outRect);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4), outRect);
+ } else {
+ assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4), outRect);
+ }
+ }
- private static class ForceRtlView extends View {
+ private static class ForceRtlView extends View {
- ForceRtlView(Context context) {
- super(context);
- }
+ ForceRtlView(Context context) {
+ super(context);
+ }
- @Override
- @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
- public int getLayoutDirection() {
- return View.LAYOUT_DIRECTION_RTL;
- }
+ @Override
+ @SuppressLint("InlinedApi") // Testing with inlined constant is OK here
+ public int getLayoutDirection() {
+ return View.LAYOUT_DIRECTION_RTL;
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifLayoutTest.java
index e12b31d..f8aae5a 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifLayoutTest.java
@@ -26,9 +26,6 @@ import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -36,9 +33,10 @@ import android.view.View;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.GlifLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,94 +45,99 @@ import org.junit.runner.RunWith;
@SmallTest
public class GlifLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlif_Light);
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlif_Light);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ GlifLayout layout = (GlifLayout) inflater.inflate(R.layout.test_glif_layout, null);
+ assertDefaultTemplateInflated(layout);
+ View content = layout.findViewById(R.id.test_content);
+ assertTrue("@id/test_content should be a TextView", content instanceof TextView);
+ }
+
+ @Test
+ public void testPrimaryColorFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ GlifLayout layout =
+ (GlifLayout) inflater.inflate(R.layout.test_glif_layout_primary_color, null);
+ assertDefaultTemplateInflated(layout);
+
+ assertEquals(ColorStateList.valueOf(Color.RED), layout.getPrimaryColor());
+ }
+
+ @Test
+ public void testSetProgressBarShownInvalid() {
+ GlifLayout layout = new GlifLayout(mContext, R.layout.test_template);
+ layout.setProgressBarShown(true);
+ // This is a no-op because there is no progress bar stub
+ }
+
+ @Test
+ public void testGlifTheme() {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlif_Light);
+ final GlifLayout glifLayout = new GlifLayout(mContext);
+
+ if (VERSION.SDK_INT >= VERSION_CODES.M) {
+ // Scroll indicators are only available on versions >= M
+ assertEquals(View.SCROLL_INDICATOR_BOTTOM, glifLayout.getScrollView().getScrollIndicators());
}
-
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- GlifLayout layout = (GlifLayout) inflater.inflate(R.layout.test_glif_layout, null);
- assertDefaultTemplateInflated(layout);
- View content = layout.findViewById(R.id.test_content);
- assertTrue("@id/test_content should be a TextView", content instanceof TextView);
- }
-
- @Test
- public void testPrimaryColorFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- GlifLayout layout =
- (GlifLayout) inflater.inflate(R.layout.test_glif_layout_primary_color, null);
- assertDefaultTemplateInflated(layout);
-
- assertEquals(ColorStateList.valueOf(Color.RED), layout.getPrimaryColor());
+ }
+
+ @Test
+ public void testGlifV2Theme() {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlifV2_Light);
+ final GlifLayout glifLayout = new GlifLayout(mContext);
+ final TextView titleView = (TextView) glifLayout.findManagedViewById(R.id.suw_layout_title);
+ if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
+ assertEquals(View.TEXT_ALIGNMENT_GRAVITY, titleView.getTextAlignment());
}
-
- @Test
- public void testSetProgressBarShownInvalid() {
- GlifLayout layout = new GlifLayout(mContext, R.layout.test_template);
- layout.setProgressBarShown(true);
- // This is a no-op because there is no progress bar stub
- }
-
- @Test
- public void testGlifTheme() {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlif_Light);
- final GlifLayout glifLayout = new GlifLayout(mContext);
-
- if (VERSION.SDK_INT >= VERSION_CODES.M) {
- // Scroll indicators are only available on versions >= M
- assertEquals(View.SCROLL_INDICATOR_BOTTOM,
- glifLayout.getScrollView().getScrollIndicators());
- }
+ assertEquals(
+ "Title text should be center aligned on GLIF v2 theme",
+ Gravity.CENTER_HORIZONTAL,
+ titleView.getGravity() & Gravity.CENTER_HORIZONTAL);
+
+ if (VERSION.SDK_INT >= VERSION_CODES.N) {
+ // LinearLayout.getGravity is only available on versions >= N
+ final View iconView = glifLayout.findManagedViewById(R.id.suw_layout_icon);
+ final LinearLayout parent = (LinearLayout) iconView.getParent();
+ assertEquals(
+ "Icon should be center aligned on GLIF v2 theme",
+ Gravity.CENTER_HORIZONTAL,
+ parent.getGravity() & Gravity.CENTER_HORIZONTAL);
}
- @Test
- public void testGlifV2Theme() {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlifV2_Light);
- final GlifLayout glifLayout = new GlifLayout(mContext);
- final TextView titleView = (TextView) glifLayout.findManagedViewById(R.id.suw_layout_title);
- if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
- assertEquals(View.TEXT_ALIGNMENT_GRAVITY, titleView.getTextAlignment());
- }
- assertEquals("Title text should be center aligned on GLIF v2 theme",
- Gravity.CENTER_HORIZONTAL, titleView.getGravity() & Gravity.CENTER_HORIZONTAL);
-
- if (VERSION.SDK_INT >= VERSION_CODES.N) {
- // LinearLayout.getGravity is only available on versions >= N
- final View iconView = glifLayout.findManagedViewById(R.id.suw_layout_icon);
- final LinearLayout parent = (LinearLayout) iconView.getParent();
- assertEquals("Icon should be center aligned on GLIF v2 theme",
- Gravity.CENTER_HORIZONTAL, parent.getGravity() & Gravity.CENTER_HORIZONTAL);
- }
-
- assertEquals("Status bar color should be white in GLIF v2 theme",
- "ffffffff",
- Integer.toHexString(glifLayout.getBackgroundBaseColor().getDefaultColor()));
- assertFalse("GLIF v2 theme shuold not have patterned background",
- glifLayout.isBackgroundPatterned());
-
- if (VERSION.SDK_INT >= VERSION_CODES.M) {
- // Scroll indicators are only available on versions >= M
- assertEquals(View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM,
- glifLayout.getScrollView().getScrollIndicators());
- }
+ assertEquals(
+ "Status bar color should be white in GLIF v2 theme",
+ "ffffffff",
+ Integer.toHexString(glifLayout.getBackgroundBaseColor().getDefaultColor()));
+ assertFalse(
+ "GLIF v2 theme shuold not have patterned background", glifLayout.isBackgroundPatterned());
+
+ if (VERSION.SDK_INT >= VERSION_CODES.M) {
+ // Scroll indicators are only available on versions >= M
+ assertEquals(
+ View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM,
+ glifLayout.getScrollView().getScrollIndicators());
}
+ }
- private void assertDefaultTemplateInflated(GlifLayout layout) {
- View title = layout.findViewById(R.id.suw_layout_title);
- assertNotNull("@id/suw_layout_title should not be null", title);
+ private void assertDefaultTemplateInflated(GlifLayout layout) {
+ View title = layout.findViewById(R.id.suw_layout_title);
+ assertNotNull("@id/suw_layout_title should not be null", title);
- View icon = layout.findViewById(R.id.suw_layout_icon);
- assertNotNull("@id/suw_layout_icon should not be null", icon);
+ View icon = layout.findViewById(R.id.suw_layout_icon);
+ assertNotNull("@id/suw_layout_icon should not be null", icon);
- View scrollView = layout.findViewById(R.id.suw_scroll_view);
- assertTrue("@id/suw_scroll_view should be a ScrollView", scrollView instanceof ScrollView);
- }
+ View scrollView = layout.findViewById(R.id.suw_scroll_view);
+ assertTrue("@id/suw_scroll_view should be a ScrollView", scrollView instanceof ScrollView);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifListLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifListLayoutTest.java
index c2e932c..0665bfe 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifListLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifListLayoutTest.java
@@ -26,9 +26,6 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
@@ -36,9 +33,10 @@ import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.GlifListLayout;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,102 +45,100 @@ import org.junit.runner.RunWith;
@SmallTest
public class GlifListLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeGlif_Light);
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), R.style.SuwThemeGlif_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testAddView() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ TextView tv = new TextView(mContext);
+ try {
+ layout.addView(tv);
+ fail("Adding view to ListLayout should throw");
+ } catch (UnsupportedOperationException e) {
+ // Expected exception
}
-
- @Test
- public void testDefaultTemplate() {
- GlifListLayout layout = new GlifListLayout(mContext);
- assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ GlifListLayout layout = (GlifListLayout) inflater.inflate(R.layout.test_glif_list_layout, null);
+ assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testGetListView() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ assertListTemplateInflated(layout);
+ assertNotNull("getListView should not be null", layout.getListView());
+ }
+
+ @Test
+ public void testAdapter() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ assertListTemplateInflated(layout);
+
+ final ArrayAdapter<String> adapter =
+ new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1);
+ adapter.add("Abracadabra");
+ layout.setAdapter(adapter);
+
+ final ListAdapter gotAdapter = layout.getAdapter();
+ // Note: the wrapped adapter should be returned directly, not the HeaderViewListAdapter.
+ assertSame("Adapter got from GlifListLayout should be same as set", adapter, gotAdapter);
+ }
+
+ @Test
+ public void testDividerInsetLegacy() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertListTemplateInflated(layout);
- @Test
- public void testAddView() {
- GlifListLayout layout = new GlifListLayout(mContext);
- TextView tv = new TextView(mContext);
- try {
- layout.addView(tv);
- fail("Adding view to ListLayout should throw");
- } catch (UnsupportedOperationException e) {
- // Expected exception
- }
- }
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- GlifListLayout layout = (GlifListLayout)
- inflater.inflate(R.layout.test_glif_list_layout, null);
- assertListTemplateInflated(layout);
- }
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- @Test
- public void testGetListView() {
- GlifListLayout layout = new GlifListLayout(mContext);
- assertListTemplateInflated(layout);
- assertNotNull("getListView should not be null", layout.getListView());
+ @Test
+ public void testDividerInsets() {
+ GlifListLayout layout = new GlifListLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertListTemplateInflated(layout);
- @Test
- public void testAdapter() {
- GlifListLayout layout = new GlifListLayout(mContext);
- assertListTemplateInflated(layout);
+ layout.setDividerInsets(10, 15);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInsetStart());
+ assertEquals("Divider inset should be 15", 15, layout.getDividerInsetEnd());
- final ArrayAdapter<String> adapter =
- new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1);
- adapter.add("Abracadabra");
- layout.setAdapter(adapter);
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- final ListAdapter gotAdapter = layout.getAdapter();
- // Note: the wrapped adapter should be returned directly, not the HeaderViewListAdapter.
- assertSame("Adapter got from GlifListLayout should be same as set",
- adapter, gotAdapter);
- }
-
- @Test
- public void testDividerInsetLegacy() {
- GlifListLayout layout = new GlifListLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertListTemplateInflated(layout);
-
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
-
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- @Test
- public void testDividerInsets() {
- GlifListLayout layout = new GlifListLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertListTemplateInflated(layout);
+ private void assertListTemplateInflated(GlifListLayout layout) {
+ View title = layout.findViewById(R.id.suw_layout_title);
+ assertNotNull("@id/suw_layout_title should not be null", title);
- layout.setDividerInsets(10, 15);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInsetStart());
- assertEquals("Divider inset should be 15", 15, layout.getDividerInsetEnd());
+ View icon = layout.findViewById(R.id.suw_layout_icon);
+ assertNotNull("@id/suw_layout_icon should not be null", icon);
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- private void assertListTemplateInflated(GlifListLayout layout) {
- View title = layout.findViewById(R.id.suw_layout_title);
- assertNotNull("@id/suw_layout_title should not be null", title);
-
- View icon = layout.findViewById(R.id.suw_layout_icon);
- assertNotNull("@id/suw_layout_icon should not be null", icon);
-
- View listView = layout.findViewById(android.R.id.list);
- assertTrue("@android:id/list should be a ListView", listView instanceof ListView);
- }
+ View listView = layout.findViewById(android.R.id.list);
+ assertTrue("@android:id/list should be a ListView", listView instanceof ListView);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifPatternDrawableTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifPatternDrawableTest.java
index 37ac41a..1783d4e 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifPatternDrawableTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/GlifPatternDrawableTest.java
@@ -25,14 +25,11 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.Debug;
+import android.util.Log;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.util.Log;
-
import com.android.setupwizardlib.GlifPatternDrawable;
-
import junit.framework.AssertionFailedError;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -41,141 +38,144 @@ import org.junit.runner.RunWith;
@SmallTest
public class GlifPatternDrawableTest {
- private static final String TAG = "GlifPatternDrawableTest";
+ private static final String TAG = "GlifPatternDrawableTest";
- @Before
- public void setUp() throws Exception {
- GlifPatternDrawable.invalidatePattern();
- }
+ @Before
+ public void setUp() throws Exception {
+ GlifPatternDrawable.invalidatePattern();
+ }
- @Test
- public void testDraw() {
- final Bitmap bitmap = Bitmap.createBitmap(1366, 768, Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(bitmap);
+ @Test
+ public void testDraw() {
+ final Bitmap bitmap = Bitmap.createBitmap(1366, 768, Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(bitmap);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 1366, 768);
- drawable.draw(canvas);
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 1366, 768);
+ drawable.draw(canvas);
- assertSameColor("Top left pixel should be #e61a1a", 0xffe61a1a, bitmap.getPixel(0, 0));
- assertSameColor("Center pixel should be #d90d0d", 0xffd90d0d, bitmap.getPixel(683, 384));
- assertSameColor("Bottom right pixel should be #d40808", 0xffd40808,
- bitmap.getPixel(1365, 767));
- }
+ assertSameColor("Top left pixel should be #e61a1a", 0xffe61a1a, bitmap.getPixel(0, 0));
+ assertSameColor("Center pixel should be #d90d0d", 0xffd90d0d, bitmap.getPixel(683, 384));
+ assertSameColor("Bottom right pixel should be #d40808", 0xffd40808, bitmap.getPixel(1365, 767));
+ }
- @Test
- public void testDrawTwice() {
- // Test that the second time the drawable is drawn is also correct, to make sure caching is
- // done correctly.
+ @Test
+ public void testDrawTwice() {
+ // Test that the second time the drawable is drawn is also correct, to make sure caching is
+ // done correctly.
- final Bitmap bitmap = Bitmap.createBitmap(1366, 768, Bitmap.Config.ARGB_8888);
- final Canvas canvas = new Canvas(bitmap);
+ final Bitmap bitmap = Bitmap.createBitmap(1366, 768, Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(bitmap);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 1366, 768);
- drawable.draw(canvas);
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 1366, 768);
+ drawable.draw(canvas);
- Paint paint = new Paint();
- paint.setColor(Color.WHITE);
- canvas.drawRect(0, 0, 1366, 768, paint); // Erase the entire canvas
+ Paint paint = new Paint();
+ paint.setColor(Color.WHITE);
+ canvas.drawRect(0, 0, 1366, 768, paint); // Erase the entire canvas
- drawable.draw(canvas);
+ drawable.draw(canvas);
- assertSameColor("Top left pixel should be #e61a1a", 0xffe61a1a, bitmap.getPixel(0, 0));
- assertSameColor("Center pixel should be #d90d0d", 0xffd90d0d, bitmap.getPixel(683, 384));
- assertSameColor("Bottom right pixel should be #d40808", 0xffd40808,
- bitmap.getPixel(1365, 767));
- }
+ assertSameColor("Top left pixel should be #e61a1a", 0xffe61a1a, bitmap.getPixel(0, 0));
+ assertSameColor("Center pixel should be #d90d0d", 0xffd90d0d, bitmap.getPixel(683, 384));
+ assertSameColor("Bottom right pixel should be #d40808", 0xffd40808, bitmap.getPixel(1365, 767));
+ }
- @Test
- public void testScaleToCanvasSquare() {
- final Canvas canvas = new Canvas();
- Matrix expected = new Matrix(canvas.getMatrix());
+ @Test
+ public void testScaleToCanvasSquare() {
+ final Canvas canvas = new Canvas();
+ Matrix expected = new Matrix(canvas.getMatrix());
- Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
+ Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 683, 384); // half each side of the view box
- drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 683, 384); // half each side of the view box
+ drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
- expected.postScale(0.5f, 0.5f);
+ expected.postScale(0.5f, 0.5f);
- assertEquals("Matrices should match", expected, canvas.getMatrix());
- }
+ assertEquals("Matrices should match", expected, canvas.getMatrix());
+ }
- @Test
- public void testScaleToCanvasTall() {
- final Canvas canvas = new Canvas();
- final Matrix expected = new Matrix(canvas.getMatrix());
+ @Test
+ public void testScaleToCanvasTall() {
+ final Canvas canvas = new Canvas();
+ final Matrix expected = new Matrix(canvas.getMatrix());
- Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
+ Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 683, 768); // half the width only
- drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 683, 768); // half the width only
+ drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
- expected.postScale(1f, 1f);
- expected.postTranslate(-99.718f, 0f);
+ expected.postScale(1f, 1f);
+ expected.postTranslate(-99.718f, 0f);
- assertEquals("Matrices should match", expected, canvas.getMatrix());
- }
+ assertEquals("Matrices should match", expected, canvas.getMatrix());
+ }
- @Test
- public void testScaleToCanvasWide() {
- final Canvas canvas = new Canvas();
- final Matrix expected = new Matrix(canvas.getMatrix());
+ @Test
+ public void testScaleToCanvasWide() {
+ final Canvas canvas = new Canvas();
+ final Matrix expected = new Matrix(canvas.getMatrix());
- Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
+ Bitmap mockBitmapCache = Bitmap.createBitmap(1366, 768, Bitmap.Config.ALPHA_8);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 1366, 384); // half the height only
- drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 1366, 384); // half the height only
+ drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
- expected.postScale(1f, 1f);
- expected.postTranslate(0f, -87.552f);
+ expected.postScale(1f, 1f);
+ expected.postTranslate(0f, -87.552f);
- assertEquals("Matrices should match", expected, canvas.getMatrix());
- }
+ assertEquals("Matrices should match", expected, canvas.getMatrix());
+ }
- @Test
- public void testScaleToCanvasMaxSize() {
- final Canvas canvas = new Canvas();
- final Matrix expected = new Matrix(canvas.getMatrix());
+ @Test
+ public void testScaleToCanvasMaxSize() {
+ final Canvas canvas = new Canvas();
+ final Matrix expected = new Matrix(canvas.getMatrix());
- Bitmap mockBitmapCache = Bitmap.createBitmap(2049, 1152, Bitmap.Config.ALPHA_8);
+ Bitmap mockBitmapCache = Bitmap.createBitmap(2049, 1152, Bitmap.Config.ALPHA_8);
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 1366, 768); // original viewbox size
- drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 1366, 768); // original viewbox size
+ drawable.scaleCanvasToBounds(canvas, mockBitmapCache, drawable.getBounds());
- expected.postScale(1 / 1.5f, 1 / 1.5f);
- expected.postTranslate(0f, 0f);
+ expected.postScale(1 / 1.5f, 1 / 1.5f);
+ expected.postTranslate(0f, 0f);
- assertEquals("Matrices should match", expected, canvas.getMatrix());
- }
+ assertEquals("Matrices should match", expected, canvas.getMatrix());
+ }
- @Test
- public void testMemoryAllocation() {
- Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
- Debug.getMemoryInfo(memoryInfo);
- final long memoryBefore = memoryInfo.getTotalPss(); // Get memory usage in KB
+ @Test
+ public void testMemoryAllocation() {
+ Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
+ Debug.getMemoryInfo(memoryInfo);
+ final long memoryBefore = memoryInfo.getTotalPss(); // Get memory usage in KB
- final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
- drawable.setBounds(0, 0, 1366, 768);
- drawable.createBitmapCache(2049, 1152);
+ final GlifPatternDrawable drawable = new GlifPatternDrawable(Color.RED);
+ drawable.setBounds(0, 0, 1366, 768);
+ drawable.createBitmapCache(2049, 1152);
- Debug.getMemoryInfo(memoryInfo);
- final long memoryAfter = memoryInfo.getTotalPss();
- Log.i(TAG, "Memory allocated for bitmap cache: " + (memoryAfter - memoryBefore));
- assertTrue("Memory allocation should not exceed 5MB", memoryAfter < memoryBefore + 5000);
- }
+ Debug.getMemoryInfo(memoryInfo);
+ final long memoryAfter = memoryInfo.getTotalPss();
+ Log.i(TAG, "Memory allocated for bitmap cache: " + (memoryAfter - memoryBefore));
+ assertTrue("Memory allocation should not exceed 5MB", memoryAfter < memoryBefore + 5000);
+ }
- private void assertSameColor(String message, int expected, int actual) {
- try {
- assertEquals(expected, actual);
- } catch (AssertionFailedError e) {
- throw new AssertionFailedError(message + " expected <#" + Integer.toHexString(expected)
- + "> but found <#" + Integer.toHexString(actual) + "> instead");
- }
+ private void assertSameColor(String message, int expected, int actual) {
+ try {
+ assertEquals(expected, actual);
+ } catch (AssertionFailedError e) {
+ throw new AssertionFailedError(
+ message
+ + " expected <#"
+ + Integer.toHexString(expected)
+ + "> but found <#"
+ + Integer.toHexString(actual)
+ + "> instead");
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/IllustrationTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/IllustrationTest.java
index a4b6f27..253893e 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/IllustrationTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/IllustrationTest.java
@@ -23,13 +23,11 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
+import android.view.View;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.view.View;
-
import com.android.setupwizardlib.view.Illustration;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,28 +35,29 @@ import org.junit.runner.RunWith;
@SmallTest
public class IllustrationTest {
- @Test
- public void testWillDraw() {
- final Illustration illustration = new Illustration(InstrumentationRegistry.getContext());
- assertFalse("The illustration needs to be drawn", illustration.willNotDraw());
- }
-
- @Test
- public void testAspectRatio() {
- final Context context = InstrumentationRegistry.getContext();
- // Force the context to be xhdpi
- context.getResources().getDisplayMetrics().density = 2.0f;
-
- final Illustration illustration = new Illustration(context);
- illustration.setAspectRatio(3.0f);
- final Drawable backgroundDrawable = new ColorDrawable(Color.RED);
- final Drawable illustrationDrawable = new ColorDrawable(Color.BLUE);
- illustration.setBackgroundDrawable(backgroundDrawable);
- illustration.setIllustration(illustrationDrawable);
-
- illustration.measure(View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY),
- View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
- // (300px / 3) round down to nearest mod (8dp = 16px) = 96px
- assertEquals("Top padding should be 96", 96, illustration.getPaddingTop());
- }
+ @Test
+ public void testWillDraw() {
+ final Illustration illustration = new Illustration(InstrumentationRegistry.getContext());
+ assertFalse("The illustration needs to be drawn", illustration.willNotDraw());
+ }
+
+ @Test
+ public void testAspectRatio() {
+ final Context context = InstrumentationRegistry.getContext();
+ // Force the context to be xhdpi
+ context.getResources().getDisplayMetrics().density = 2.0f;
+
+ final Illustration illustration = new Illustration(context);
+ illustration.setAspectRatio(3.0f);
+ final Drawable backgroundDrawable = new ColorDrawable(Color.RED);
+ final Drawable illustrationDrawable = new ColorDrawable(Color.BLUE);
+ illustration.setBackgroundDrawable(backgroundDrawable);
+ illustration.setIllustration(illustrationDrawable);
+
+ illustration.measure(
+ View.MeasureSpec.makeMeasureSpec(300, View.MeasureSpec.EXACTLY),
+ View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
+ // (300px / 3) round down to nearest mod (8dp = 16px) = 96px
+ assertEquals("Top padding should be 96", 96, illustration.getPaddingTop());
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemAdapterTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemAdapterTest.java
index e5875e4..63180dc 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemAdapterTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemAdapterTest.java
@@ -24,78 +24,74 @@ import static org.mockito.Mockito.mock;
import android.database.DataSetObserver;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-
import com.android.setupwizardlib.items.Item;
import com.android.setupwizardlib.items.ItemAdapter;
import com.android.setupwizardlib.items.ItemGroup;
import com.android.setupwizardlib.items.ItemHierarchy;
-
+import java.util.Arrays;
+import java.util.HashSet;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
-import java.util.Arrays;
-import java.util.HashSet;
-
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ItemAdapterTest {
- private Item[] mItems = new Item[5];
- private ItemGroup mItemGroup = new ItemGroup();
-
- @Before
- public void setUp() throws Exception {
- for (int i = 0; i < 5; i++) {
- Item item = new Item();
- item.setTitle("TestTitle" + i);
- item.setId(i);
- item.setLayoutResource(((i % 3) + 1) * 10);
- mItems[i] = item;
- mItemGroup.addChild(item);
- }
- }
-
- @Test
- public void testAdapter() {
- ItemAdapter adapter = new ItemAdapter(mItemGroup);
- assertEquals("Adapter should have 5 items", 5, adapter.getCount());
- assertEquals("Adapter should return the first item", mItems[0], adapter.getItem(0));
- assertEquals("ID should be same as position", 2, adapter.getItemId(2));
-
- // Each test item has its own layout resource, and therefore its own view type
- assertEquals("Should have 3 different view types", 3, adapter.getViewTypeCount());
- HashSet<Integer> viewTypes = new HashSet<>(3);
- viewTypes.add(adapter.getItemViewType(0));
- viewTypes.add(adapter.getItemViewType(1));
- viewTypes.add(adapter.getItemViewType(2));
-
- assertEquals("View types should be 0, 1, 2",
- new HashSet<>(Arrays.asList(0, 1, 2)), viewTypes);
- }
-
- @Test
- public void testGetRootItemHierarchy() {
- ItemAdapter adapter = new ItemAdapter(mItemGroup);
- ItemHierarchy root = adapter.getRootItemHierarchy();
- assertSame("Root item hierarchy should be mItemGroup", mItemGroup, root);
- }
-
- @Test
- public void testAdapterNotifications() {
- ItemAdapter adapter = new ItemAdapter(mItemGroup);
- final DataSetObserver observer = mock(DataSetObserver.class);
- adapter.registerDataSetObserver(observer);
- final InOrder inOrder = inOrder(observer);
-
- mItems[0].setTitle("Child 1");
- inOrder.verify(observer).onChanged();
-
- mItemGroup.removeChild(mItems[1]);
- inOrder.verify(observer).onChanged();
-
- mItemGroup.addChild(mItems[1]);
- inOrder.verify(observer).onChanged();
+ private Item[] mItems = new Item[5];
+ private ItemGroup mItemGroup = new ItemGroup();
+
+ @Before
+ public void setUp() throws Exception {
+ for (int i = 0; i < 5; i++) {
+ Item item = new Item();
+ item.setTitle("TestTitle" + i);
+ item.setId(i);
+ item.setLayoutResource(((i % 3) + 1) * 10);
+ mItems[i] = item;
+ mItemGroup.addChild(item);
}
+ }
+
+ @Test
+ public void testAdapter() {
+ ItemAdapter adapter = new ItemAdapter(mItemGroup);
+ assertEquals("Adapter should have 5 items", 5, adapter.getCount());
+ assertEquals("Adapter should return the first item", mItems[0], adapter.getItem(0));
+ assertEquals("ID should be same as position", 2, adapter.getItemId(2));
+
+ // Each test item has its own layout resource, and therefore its own view type
+ assertEquals("Should have 3 different view types", 3, adapter.getViewTypeCount());
+ HashSet<Integer> viewTypes = new HashSet<>(3);
+ viewTypes.add(adapter.getItemViewType(0));
+ viewTypes.add(adapter.getItemViewType(1));
+ viewTypes.add(adapter.getItemViewType(2));
+
+ assertEquals("View types should be 0, 1, 2", new HashSet<>(Arrays.asList(0, 1, 2)), viewTypes);
+ }
+
+ @Test
+ public void testGetRootItemHierarchy() {
+ ItemAdapter adapter = new ItemAdapter(mItemGroup);
+ ItemHierarchy root = adapter.getRootItemHierarchy();
+ assertSame("Root item hierarchy should be mItemGroup", mItemGroup, root);
+ }
+
+ @Test
+ public void testAdapterNotifications() {
+ ItemAdapter adapter = new ItemAdapter(mItemGroup);
+ final DataSetObserver observer = mock(DataSetObserver.class);
+ adapter.registerDataSetObserver(observer);
+ final InOrder inOrder = inOrder(observer);
+
+ mItems[0].setTitle("Child 1");
+ inOrder.verify(observer).onChanged();
+
+ mItemGroup.removeChild(mItems[1]);
+ inOrder.verify(observer).onChanged();
+
+ mItemGroup.addChild(mItems[1]);
+ inOrder.verify(observer).onChanged();
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemInflaterTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemInflaterTest.java
index 20fd2cc..9e96bae 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemInflaterTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemInflaterTest.java
@@ -22,12 +22,10 @@ import static org.junit.Assert.assertTrue;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-
import com.android.setupwizardlib.items.Item;
import com.android.setupwizardlib.items.ItemGroup;
import com.android.setupwizardlib.items.ItemHierarchy;
import com.android.setupwizardlib.items.ItemInflater;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -35,25 +33,26 @@ import org.junit.runner.RunWith;
@SmallTest
public class ItemInflaterTest {
- @Test
- public void testDefaultPackage() {
- ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
- assertEquals("Default package should be the one containing Item class",
- "com.android.setupwizardlib.items.", inflater.getDefaultPackage());
- }
-
- @Test
- public void testInflate() {
- ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
- ItemHierarchy item = inflater.inflate(R.xml.test_items);
- assertTrue("Inflated item should be ItemGroup", item instanceof ItemGroup);
- ItemGroup itemGroup = (ItemGroup) item;
-
- Item child0 = (Item) itemGroup.getItemAt(0);
- Item child1 = (Item) itemGroup.getItemAt(1);
- assertEquals("Title of first child should be Title1", "Title1", child0.getTitle());
- assertEquals("ID of second child should be test_item_2", R.id.test_item_2, child1.getId());
- assertEquals("Summary of second child should be Summary2", "Summary2",
- child1.getSummary());
- }
+ @Test
+ public void testDefaultPackage() {
+ ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
+ assertEquals(
+ "Default package should be the one containing Item class",
+ "com.android.setupwizardlib.items.",
+ inflater.getDefaultPackage());
+ }
+
+ @Test
+ public void testInflate() {
+ ItemInflater inflater = new ItemInflater(InstrumentationRegistry.getContext());
+ ItemHierarchy item = inflater.inflate(R.xml.test_items);
+ assertTrue("Inflated item should be ItemGroup", item instanceof ItemGroup);
+ ItemGroup itemGroup = (ItemGroup) item;
+
+ Item child0 = (Item) itemGroup.getItemAt(0);
+ Item child1 = (Item) itemGroup.getItemAt(1);
+ assertEquals("Title of first child should be Title1", "Title1", child0.getTitle());
+ assertEquals("ID of second child should be test_item_2", R.id.test_item_2, child1.getId());
+ assertEquals("Summary of second child should be Summary2", "Summary2", child1.getSummary());
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemLayoutTest.java
index 85876b4..dbf71b2 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemLayoutTest.java
@@ -17,26 +17,22 @@
package com.android.setupwizardlib.test;
import static android.support.test.InstrumentationRegistry.getTargetContext;
-
import static org.junit.Assert.assertNotNull;
import android.content.Context;
-import android.support.test.filters.SmallTest;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
-
+import android.support.test.filters.SmallTest;
import com.android.setupwizardlib.R;
import com.android.setupwizardlib.items.Item;
-
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* Sanity test for all the item layouts to make sure they won't crash when being inflated in
* different themes.
@@ -45,50 +41,50 @@ import java.util.List;
@SmallTest
public class ItemLayoutTest {
- @Parameters
- public static Iterable<Object[]> data() {
- int[] themes = new int[] {
- R.style.SuwThemeMaterial_Light,
- R.style.SuwThemeMaterial,
- R.style.SuwThemeGlif_Light,
- R.style.SuwThemeGlif,
- R.style.SuwThemeGlifV2_Light,
- R.style.SuwThemeGlifV2
+ @Parameters
+ public static Iterable<Object[]> data() {
+ int[] themes =
+ new int[] {
+ R.style.SuwThemeMaterial_Light,
+ R.style.SuwThemeMaterial,
+ R.style.SuwThemeGlif_Light,
+ R.style.SuwThemeGlif,
+ R.style.SuwThemeGlifV2_Light,
+ R.style.SuwThemeGlifV2
};
- int[] layouts = new int[] {
- R.layout.suw_items_default,
- R.layout.suw_items_verbose,
- R.layout.suw_items_description
+ int[] layouts =
+ new int[] {
+ R.layout.suw_items_default, R.layout.suw_items_verbose, R.layout.suw_items_description
};
- // Test all the possible combinations of themes and layouts.
- List<Object[]> params = new ArrayList<>();
- for (int theme : themes) {
- for (int layout : layouts) {
- params.add(new Object[] { theme, layout });
- }
- }
- return params;
+ // Test all the possible combinations of themes and layouts.
+ List<Object[]> params = new ArrayList<>();
+ for (int theme : themes) {
+ for (int layout : layouts) {
+ params.add(new Object[] {theme, layout});
+ }
}
+ return params;
+ }
- private final Context mContext;
- private final FrameLayout mParent;
- private final Item mItem;
+ private final Context mContext;
+ private final FrameLayout mParent;
+ private final Item mItem;
- public ItemLayoutTest(int theme, int layout) {
- mContext = new ContextThemeWrapper(getTargetContext(), theme);
- mParent = new FrameLayout(mContext);
- mItem = new Item();
- mItem.setLayoutResource(layout);
- }
+ public ItemLayoutTest(int theme, int layout) {
+ mContext = new ContextThemeWrapper(getTargetContext(), theme);
+ mParent = new FrameLayout(mContext);
+ mItem = new Item();
+ mItem.setLayoutResource(layout);
+ }
- @Test
- public void testInflateLayoutHasBasicViews() {
- LayoutInflater.from(mContext).inflate(mItem.getLayoutResource(), mParent, true);
- mItem.onBindView(mParent);
+ @Test
+ public void testInflateLayoutHasBasicViews() {
+ LayoutInflater.from(mContext).inflate(mItem.getLayoutResource(), mParent, true);
+ mItem.onBindView(mParent);
- assertNotNull("Title should exist", mParent.findViewById(R.id.suw_items_title));
- assertNotNull("Summary should exist", mParent.findViewById(R.id.suw_items_summary));
- assertNotNull("Icon should exist", mParent.findViewById(R.id.suw_items_icon));
- }
+ assertNotNull("Title should exist", mParent.findViewById(R.id.suw_items_title));
+ assertNotNull("Summary should exist", mParent.findViewById(R.id.suw_items_summary));
+ assertNotNull("Icon should exist", mParent.findViewById(R.id.suw_items_icon));
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemTest.java
index b4ebabb..84990dd 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ItemTest.java
@@ -28,19 +28,17 @@ import static org.mockito.Mockito.verify;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.R;
import com.android.setupwizardlib.items.Item;
import com.android.setupwizardlib.items.ItemHierarchy.Observer;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,149 +50,149 @@ import org.mockito.MockitoAnnotations;
@SmallTest
public class ItemTest {
- private TextView mTitleView;
- private TextView mSummaryView;
- private ImageView mIconView;
- private FrameLayout mIconContainer;
-
- @Mock
- private Observer mObserver;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void testOnBindView() {
- Item item = new Item();
- item.setTitle("TestTitle");
- item.setSummary("TestSummary");
- Drawable icon = new ShapeDrawable();
- icon.setLevel(4);
- item.setIcon(icon);
- View view = createLayout();
-
- mIconView.setImageLevel(1);
- Drawable recycledIcon = new ShapeDrawable();
- mIconView.setImageDrawable(recycledIcon);
-
- item.onBindView(view);
-
- assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
- assertEquals("Summary should be \"TestSummary\"", "TestSummary",
- mSummaryView.getText().toString());
- assertSame("Icon should be the icon shape drawable", icon, mIconView.getDrawable());
- assertEquals("Recycled icon level should not change", 1, recycledIcon.getLevel());
- assertEquals("Icon should be level 4", 4, icon.getLevel());
- }
-
- @Test
- public void testSingleLineItem() {
- Item item = new Item();
- item.setTitle("TestTitle");
- View view = createLayout();
-
- item.onBindView(view);
-
- assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
- assertEquals("Summary should be gone", View.GONE, mSummaryView.getVisibility());
- assertEquals("IconContainer should be gone", View.GONE, mIconContainer.getVisibility());
- }
-
- @Test
- public void testProperties() {
- Item item = new Item();
- item.registerObserver(mObserver);
- final InOrder inOrder = inOrder(mObserver);
-
- item.setTitle("TestTitle");
- inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
-
- item.setSummary("TestSummary");
- inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
-
- item.setEnabled(false);
- inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
-
- ShapeDrawable icon = new ShapeDrawable();
- item.setIcon(icon);
- inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
-
- item.setId(12345);
-
- item.setLayoutResource(56789);
- inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
-
- assertEquals("Title should be \"TestTitle\"", "TestTitle", item.getTitle());
- assertEquals("Summary should be \"TestSummary\"", "TestSummary", item.getSummary());
- assertFalse("Enabled should be false", item.isEnabled());
- assertSame("Icon should be same as set", icon, item.getIcon());
- assertEquals("ID should be 12345", 12345, item.getId());
- assertEquals("Layout resource should be 56789", 56789, item.getLayoutResource());
- }
-
- @Test
- public void testDefaultValues() {
- Item item = new Item();
-
- assertNull("Default title should be null", item.getTitle());
- assertNull("Default summary should be null", item.getSummary());
- assertNull("Default icon should be null", item.getIcon());
- assertTrue("Default enabled should be true", item.isEnabled());
- assertEquals("Default ID should be 0", 0, item.getId());
- assertEquals("Default layout resource should be R.layout.suw_items_text",
- R.layout.suw_items_default, item.getLayoutResource());
- assertTrue("Default visible should be true", item.isVisible());
- }
-
- @Test
- public void testHierarchyImplementation() {
- Item item = new Item();
- item.setId(12345);
-
- assertEquals("getCount should be 1", 1, item.getCount());
- assertSame("getItemAt should return itself", item, item.getItemAt(0));
- assertSame("findItemById with same ID should return itself", item,
- item.findItemById(12345));
- assertNull("findItemById with different ID should return null", item.findItemById(34567));
- }
-
- @Test
- public void testVisible() {
- Item item = new Item();
- item.registerObserver(mObserver);
- item.setVisible(false);
-
- assertFalse("Item should not be visible", item.isVisible());
- assertEquals("Item count should be 0 when not visible", 0, item.getCount());
-
- verify(mObserver).onItemRangeRemoved(eq(item), eq(0), eq(1));
-
- item.setVisible(true);
- verify(mObserver).onItemRangeInserted(eq(item), eq(0), eq(1));
- }
-
- private ViewGroup createLayout() {
- Context context = InstrumentationRegistry.getContext();
- ViewGroup root = new FrameLayout(context);
-
- mTitleView = new TextView(context);
- mTitleView.setId(R.id.suw_items_title);
- root.addView(mTitleView);
-
- mSummaryView = new TextView(context);
- mSummaryView.setId(R.id.suw_items_summary);
- root.addView(mSummaryView);
-
- mIconContainer = new FrameLayout(context);
- mIconContainer.setId(R.id.suw_items_icon_container);
- root.addView(mIconContainer);
-
- mIconView = new ImageView(context);
- mIconView.setId(R.id.suw_items_icon);
- mIconContainer.addView(mIconView);
-
- return root;
- }
+ private TextView mTitleView;
+ private TextView mSummaryView;
+ private ImageView mIconView;
+ private FrameLayout mIconContainer;
+
+ @Mock private Observer mObserver;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testOnBindView() {
+ Item item = new Item();
+ item.setTitle("TestTitle");
+ item.setSummary("TestSummary");
+ Drawable icon = new ShapeDrawable();
+ icon.setLevel(4);
+ item.setIcon(icon);
+ View view = createLayout();
+
+ mIconView.setImageLevel(1);
+ Drawable recycledIcon = new ShapeDrawable();
+ mIconView.setImageDrawable(recycledIcon);
+
+ item.onBindView(view);
+
+ assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
+ assertEquals(
+ "Summary should be \"TestSummary\"", "TestSummary", mSummaryView.getText().toString());
+ assertSame("Icon should be the icon shape drawable", icon, mIconView.getDrawable());
+ assertEquals("Recycled icon level should not change", 1, recycledIcon.getLevel());
+ assertEquals("Icon should be level 4", 4, icon.getLevel());
+ }
+
+ @Test
+ public void testSingleLineItem() {
+ Item item = new Item();
+ item.setTitle("TestTitle");
+ View view = createLayout();
+
+ item.onBindView(view);
+
+ assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString());
+ assertEquals("Summary should be gone", View.GONE, mSummaryView.getVisibility());
+ assertEquals("IconContainer should be gone", View.GONE, mIconContainer.getVisibility());
+ }
+
+ @Test
+ public void testProperties() {
+ Item item = new Item();
+ item.registerObserver(mObserver);
+ final InOrder inOrder = inOrder(mObserver);
+
+ item.setTitle("TestTitle");
+ inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
+
+ item.setSummary("TestSummary");
+ inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
+
+ item.setEnabled(false);
+ inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
+
+ ShapeDrawable icon = new ShapeDrawable();
+ item.setIcon(icon);
+ inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
+
+ item.setId(12345);
+
+ item.setLayoutResource(56789);
+ inOrder.verify(mObserver).onItemRangeChanged(eq(item), eq(0), eq(1));
+
+ assertEquals("Title should be \"TestTitle\"", "TestTitle", item.getTitle());
+ assertEquals("Summary should be \"TestSummary\"", "TestSummary", item.getSummary());
+ assertFalse("Enabled should be false", item.isEnabled());
+ assertSame("Icon should be same as set", icon, item.getIcon());
+ assertEquals("ID should be 12345", 12345, item.getId());
+ assertEquals("Layout resource should be 56789", 56789, item.getLayoutResource());
+ }
+
+ @Test
+ public void testDefaultValues() {
+ Item item = new Item();
+
+ assertNull("Default title should be null", item.getTitle());
+ assertNull("Default summary should be null", item.getSummary());
+ assertNull("Default icon should be null", item.getIcon());
+ assertTrue("Default enabled should be true", item.isEnabled());
+ assertEquals("Default ID should be 0", 0, item.getId());
+ assertEquals(
+ "Default layout resource should be R.layout.suw_items_text",
+ R.layout.suw_items_default,
+ item.getLayoutResource());
+ assertTrue("Default visible should be true", item.isVisible());
+ }
+
+ @Test
+ public void testHierarchyImplementation() {
+ Item item = new Item();
+ item.setId(12345);
+
+ assertEquals("getCount should be 1", 1, item.getCount());
+ assertSame("getItemAt should return itself", item, item.getItemAt(0));
+ assertSame("findItemById with same ID should return itself", item, item.findItemById(12345));
+ assertNull("findItemById with different ID should return null", item.findItemById(34567));
+ }
+
+ @Test
+ public void testVisible() {
+ Item item = new Item();
+ item.registerObserver(mObserver);
+ item.setVisible(false);
+
+ assertFalse("Item should not be visible", item.isVisible());
+ assertEquals("Item count should be 0 when not visible", 0, item.getCount());
+
+ verify(mObserver).onItemRangeRemoved(eq(item), eq(0), eq(1));
+
+ item.setVisible(true);
+ verify(mObserver).onItemRangeInserted(eq(item), eq(0), eq(1));
+ }
+
+ private ViewGroup createLayout() {
+ Context context = InstrumentationRegistry.getContext();
+ ViewGroup root = new FrameLayout(context);
+
+ mTitleView = new TextView(context);
+ mTitleView.setId(R.id.suw_items_title);
+ root.addView(mTitleView);
+
+ mSummaryView = new TextView(context);
+ mSummaryView.setId(R.id.suw_items_summary);
+ root.addView(mSummaryView);
+
+ mIconContainer = new FrameLayout(context);
+ mIconContainer.setId(R.id.suw_items_icon_container);
+ root.addView(mIconContainer);
+
+ mIconView = new ImageView(context);
+ mIconView.setId(R.id.suw_items_icon);
+ mIconContainer.addView(mIconView);
+
+ return root;
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/ReflectionInflaterTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/ReflectionInflaterTest.java
index 137a146..69e5882 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/ReflectionInflaterTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/ReflectionInflaterTest.java
@@ -20,64 +20,59 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import android.content.Context;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.annotation.NonNull;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
-
-import androidx.annotation.NonNull;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.items.ReflectionInflater;
-
+import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.List;
-
@SmallTest
@RunWith(AndroidJUnit4.class)
public class ReflectionInflaterTest {
- @Test
- public void testInflateXml() {
- final Context context = InstrumentationRegistry.getContext();
- TestInflater inflater = new TestInflater(context);
- final Animation result = inflater.inflate(R.xml.reflection_inflater_test);
+ @Test
+ public void testInflateXml() {
+ final Context context = InstrumentationRegistry.getContext();
+ TestInflater inflater = new TestInflater(context);
+ final Animation result = inflater.inflate(R.xml.reflection_inflater_test);
- assertTrue(result instanceof AnimationSet);
- final AnimationSet set = (AnimationSet) result;
- final List<Animation> animations = set.getAnimations();
- assertEquals(1, animations.size());
- assertTrue(animations.get(0) instanceof ScaleAnimation);
- }
+ assertTrue(result instanceof AnimationSet);
+ final AnimationSet set = (AnimationSet) result;
+ final List<Animation> animations = set.getAnimations();
+ assertEquals(1, animations.size());
+ assertTrue(animations.get(0) instanceof ScaleAnimation);
+ }
- @Test
- public void testDefaultPackage() {
- final Context context = InstrumentationRegistry.getContext();
- TestInflater inflater = new TestInflater(context);
- inflater.setDefaultPackage("android.view.animation.");
- final Animation result =
- inflater.inflate(R.xml.reflection_inflater_test_with_default_package);
+ @Test
+ public void testDefaultPackage() {
+ final Context context = InstrumentationRegistry.getContext();
+ TestInflater inflater = new TestInflater(context);
+ inflater.setDefaultPackage("android.view.animation.");
+ final Animation result = inflater.inflate(R.xml.reflection_inflater_test_with_default_package);
- assertTrue(result instanceof AnimationSet);
- final AnimationSet set = (AnimationSet) result;
- final List<Animation> animations = set.getAnimations();
- assertEquals(1, animations.size());
- assertTrue(animations.get(0) instanceof ScaleAnimation);
- }
+ assertTrue(result instanceof AnimationSet);
+ final AnimationSet set = (AnimationSet) result;
+ final List<Animation> animations = set.getAnimations();
+ assertEquals(1, animations.size());
+ assertTrue(animations.get(0) instanceof ScaleAnimation);
+ }
- private static class TestInflater extends ReflectionInflater<Animation> {
+ private static class TestInflater extends ReflectionInflater<Animation> {
- protected TestInflater(@NonNull Context context) {
- super(context);
- }
+ protected TestInflater(@NonNull Context context) {
+ super(context);
+ }
- @Override
- protected void onAddChildItem(Animation parent, Animation child) {
- final AnimationSet group = (AnimationSet) parent;
- group.addAnimation(child);
- }
+ @Override
+ protected void onAddChildItem(Animation parent, Animation child) {
+ final AnimationSet group = (AnimationSet) parent;
+ group.addAnimation(child);
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java
index 531d69e..9d2f784 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardLayoutTest.java
@@ -27,9 +27,7 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Parcelable;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
+import androidx.annotation.IdRes;
import android.util.SparseArray;
import android.view.AbsSavedState;
import android.view.ContextThemeWrapper;
@@ -37,15 +35,14 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
-
-import androidx.annotation.IdRes;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.SetupWizardLayout;
import com.android.setupwizardlib.template.HeaderMixin;
import com.android.setupwizardlib.template.NavigationBarMixin;
import com.android.setupwizardlib.template.ProgressBarMixin;
import com.android.setupwizardlib.view.NavigationBar;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -54,191 +51,196 @@ import org.junit.runner.RunWith;
@SmallTest
public class SetupWizardLayoutTest {
- @IdRes
- private static final int ID1234 = 1234;
-
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeMaterial_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- SetupWizardLayout layout = new SetupWizardLayout(mContext);
- assertDefaultTemplateInflated(layout);
- }
-
- @Test
- public void testSetHeaderText() {
- SetupWizardLayout layout = new SetupWizardLayout(mContext);
- TextView title = (TextView) layout.findViewById(R.id.suw_layout_title);
- layout.setHeaderText("Abracadabra");
- assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText());
- }
-
- @Test
- public void testAddView() {
- SetupWizardLayout layout = new SetupWizardLayout(mContext);
- TextView tv = new TextView(mContext);
- tv.setId(R.id.test_view_id);
- layout.addView(tv);
- assertDefaultTemplateInflated(layout);
- View view = layout.findViewById(R.id.test_view_id);
- assertSame("The view added should be the same text view", tv, view);
- }
-
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- SetupWizardLayout layout = (SetupWizardLayout) inflater.inflate(R.layout.test_layout, null);
- assertDefaultTemplateInflated(layout);
- View content = layout.findViewById(R.id.test_content);
- assertTrue("@id/test_content should be a TextView", content instanceof TextView);
- }
-
- @Test
- public void testCustomTemplate() {
- SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
- View templateView = layout.findViewById(R.id.test_template_view);
- assertNotNull("@id/test_template_view should exist in template", templateView);
-
- TextView tv = new TextView(mContext);
- tv.setId(R.id.test_view_id);
- layout.addView(tv);
-
- templateView = layout.findViewById(R.id.test_template_view);
- assertNotNull("@id/test_template_view should exist in template", templateView);
- View contentView = layout.findViewById(R.id.test_view_id);
- assertSame("The view added should be the same text view", tv, contentView);
-
- // The following methods should be no-ops because the custom template doesn't contain the
- // corresponding optional views. Just check that they don't throw exceptions.
- layout.setHeaderText("Abracadabra");
- layout.setIllustration(new ColorDrawable(Color.MAGENTA));
- layout.setLayoutBackground(new ColorDrawable(Color.RED));
- }
-
- @Test
- public void testGetNavigationBar() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- final NavigationBar navigationBar = layout.getNavigationBar();
- assertEquals("Navigation bar should have ID = @id/suw_layout_navigation_bar",
- R.id.suw_layout_navigation_bar, navigationBar.getId());
- }
-
- @Test
- public void testGetNavigationBarNull() {
- // test_template does not have navigation bar so getNavigationBar() should return null.
- final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
- final NavigationBar navigationBar = layout.getNavigationBar();
- assertNull("getNavigationBar() in test_template should return null", navigationBar);
- }
-
- @Test
- public void testShowProgressBar() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- layout.showProgressBar();
- assertTrue("Progress bar should be shown", layout.isProgressBarShown());
- final View progressBar = layout.findViewById(R.id.suw_layout_progress);
- assertTrue("Progress bar view should be shown",
- progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE);
- }
-
- @Test
- public void testHideProgressBar() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- layout.showProgressBar();
- assertTrue("Progress bar should be shown", layout.isProgressBarShown());
- layout.hideProgressBar();
- assertFalse("Progress bar should be hidden", layout.isProgressBarShown());
- final View progressBar = layout.findViewById(R.id.suw_layout_progress);
- assertTrue("Progress bar view should exist",
- progressBar == null || progressBar.getVisibility() != View.VISIBLE);
- }
-
- @Test
- public void testShowProgressBarNotExist() {
- // test_template does not have progress bar, so showNavigationBar() should do nothing.
- final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
- layout.showProgressBar();
- assertFalse("Progress bar should not be shown", layout.isProgressBarShown());
- }
-
- @Test
- public void testNonMaterialTheme() {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- android.R.style.Theme);
- new SetupWizardLayout(mContext);
- // Inflating with a non-Material theme should not crash
- }
-
- @Test
- public void testOnRestoreFromInstanceState() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- layout.setId(ID1234);
-
- SparseArray<Parcelable> container = new SparseArray<>();
- layout.saveHierarchyState(container);
-
- final SetupWizardLayout layout2 = new SetupWizardLayout(mContext);
- layout2.setId(ID1234);
- layout2.restoreHierarchyState(container);
-
- assertFalse("Progress bar should not be shown", layout2.isProgressBarShown());
- }
-
- @Test
- public void testOnRestoreFromInstanceStateProgressBarShown() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- layout.setId(ID1234);
-
- layout.setProgressBarShown(true);
-
- SparseArray<Parcelable> container = new SparseArray<>();
- layout.saveHierarchyState(container);
-
- final SetupWizardLayout layout2 = new SetupWizardLayout(mContext);
- layout2.setId(ID1234);
- layout2.restoreHierarchyState(container);
-
- assertTrue("Progress bar should be shown", layout2.isProgressBarShown());
- }
-
- @Test
- public void testOnRestoreFromIncompatibleInstanceState() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- layout.setId(ID1234);
-
- SparseArray<Parcelable> container = new SparseArray<>();
- container.put(1234, AbsSavedState.EMPTY_STATE);
- layout.restoreHierarchyState(container);
-
- // SetupWizardLayout shouldn't crash with incompatible Parcelable
-
- assertFalse("Progress bar should not be shown", layout.isProgressBarShown());
- }
-
- @Test
- public void testGetMixins() {
- final SetupWizardLayout layout = new SetupWizardLayout(mContext);
- assertNotNull("SetupWizardLayout should have header mixin",
- layout.getMixin(HeaderMixin.class));
- assertNotNull("SetupWizardLayout should have progress bar mixin",
- layout.getMixin(ProgressBarMixin.class));
- assertNotNull("SetupWizardLayout should have navigation bar mixin",
- layout.getMixin(NavigationBarMixin.class));
- }
-
- private void assertDefaultTemplateInflated(SetupWizardLayout layout) {
- View decorView = layout.findViewById(R.id.suw_layout_decor);
- View navbar = layout.findViewById(R.id.suw_layout_navigation_bar);
- View title = layout.findViewById(R.id.suw_layout_title);
- assertNotNull("@id/suw_layout_decor_view should not be null", decorView);
- assertTrue("@id/suw_layout_navigation_bar should be an instance of NavigationBar",
- navbar instanceof NavigationBar);
- assertNotNull("@id/suw_layout_title should not be null", title);
- }
+ @IdRes private static final int ID1234 = 1234;
+
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(
+ InstrumentationRegistry.getContext(), R.style.SuwThemeMaterial_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ assertDefaultTemplateInflated(layout);
+ }
+
+ @Test
+ public void testSetHeaderText() {
+ SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ TextView title = (TextView) layout.findViewById(R.id.suw_layout_title);
+ layout.setHeaderText("Abracadabra");
+ assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText());
+ }
+
+ @Test
+ public void testAddView() {
+ SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ TextView tv = new TextView(mContext);
+ tv.setId(R.id.test_view_id);
+ layout.addView(tv);
+ assertDefaultTemplateInflated(layout);
+ View view = layout.findViewById(R.id.test_view_id);
+ assertSame("The view added should be the same text view", tv, view);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ SetupWizardLayout layout = (SetupWizardLayout) inflater.inflate(R.layout.test_layout, null);
+ assertDefaultTemplateInflated(layout);
+ View content = layout.findViewById(R.id.test_content);
+ assertTrue("@id/test_content should be a TextView", content instanceof TextView);
+ }
+
+ @Test
+ public void testCustomTemplate() {
+ SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
+ View templateView = layout.findViewById(R.id.test_template_view);
+ assertNotNull("@id/test_template_view should exist in template", templateView);
+
+ TextView tv = new TextView(mContext);
+ tv.setId(R.id.test_view_id);
+ layout.addView(tv);
+
+ templateView = layout.findViewById(R.id.test_template_view);
+ assertNotNull("@id/test_template_view should exist in template", templateView);
+ View contentView = layout.findViewById(R.id.test_view_id);
+ assertSame("The view added should be the same text view", tv, contentView);
+
+ // The following methods should be no-ops because the custom template doesn't contain the
+ // corresponding optional views. Just check that they don't throw exceptions.
+ layout.setHeaderText("Abracadabra");
+ layout.setIllustration(new ColorDrawable(Color.MAGENTA));
+ layout.setLayoutBackground(new ColorDrawable(Color.RED));
+ }
+
+ @Test
+ public void testGetNavigationBar() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ final NavigationBar navigationBar = layout.getNavigationBar();
+ assertEquals(
+ "Navigation bar should have ID = @id/suw_layout_navigation_bar",
+ R.id.suw_layout_navigation_bar,
+ navigationBar.getId());
+ }
+
+ @Test
+ public void testGetNavigationBarNull() {
+ // test_template does not have navigation bar so getNavigationBar() should return null.
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
+ final NavigationBar navigationBar = layout.getNavigationBar();
+ assertNull("getNavigationBar() in test_template should return null", navigationBar);
+ }
+
+ @Test
+ public void testShowProgressBar() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ layout.showProgressBar();
+ assertTrue("Progress bar should be shown", layout.isProgressBarShown());
+ final View progressBar = layout.findViewById(R.id.suw_layout_progress);
+ assertTrue(
+ "Progress bar view should be shown",
+ progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE);
+ }
+
+ @Test
+ public void testHideProgressBar() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ layout.showProgressBar();
+ assertTrue("Progress bar should be shown", layout.isProgressBarShown());
+ layout.hideProgressBar();
+ assertFalse("Progress bar should be hidden", layout.isProgressBarShown());
+ final View progressBar = layout.findViewById(R.id.suw_layout_progress);
+ assertTrue(
+ "Progress bar view should exist",
+ progressBar == null || progressBar.getVisibility() != View.VISIBLE);
+ }
+
+ @Test
+ public void testShowProgressBarNotExist() {
+ // test_template does not have progress bar, so showNavigationBar() should do nothing.
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template);
+ layout.showProgressBar();
+ assertFalse("Progress bar should not be shown", layout.isProgressBarShown());
+ }
+
+ @Test
+ public void testNonMaterialTheme() {
+ mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(), android.R.style.Theme);
+ new SetupWizardLayout(mContext);
+ // Inflating with a non-Material theme should not crash
+ }
+
+ @Test
+ public void testOnRestoreFromInstanceState() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ layout.setId(ID1234);
+
+ SparseArray<Parcelable> container = new SparseArray<>();
+ layout.saveHierarchyState(container);
+
+ final SetupWizardLayout layout2 = new SetupWizardLayout(mContext);
+ layout2.setId(ID1234);
+ layout2.restoreHierarchyState(container);
+
+ assertFalse("Progress bar should not be shown", layout2.isProgressBarShown());
+ }
+
+ @Test
+ public void testOnRestoreFromInstanceStateProgressBarShown() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ layout.setId(ID1234);
+
+ layout.setProgressBarShown(true);
+
+ SparseArray<Parcelable> container = new SparseArray<>();
+ layout.saveHierarchyState(container);
+
+ final SetupWizardLayout layout2 = new SetupWizardLayout(mContext);
+ layout2.setId(ID1234);
+ layout2.restoreHierarchyState(container);
+
+ assertTrue("Progress bar should be shown", layout2.isProgressBarShown());
+ }
+
+ @Test
+ public void testOnRestoreFromIncompatibleInstanceState() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ layout.setId(ID1234);
+
+ SparseArray<Parcelable> container = new SparseArray<>();
+ container.put(1234, AbsSavedState.EMPTY_STATE);
+ layout.restoreHierarchyState(container);
+
+ // SetupWizardLayout shouldn't crash with incompatible Parcelable
+
+ assertFalse("Progress bar should not be shown", layout.isProgressBarShown());
+ }
+
+ @Test
+ public void testGetMixins() {
+ final SetupWizardLayout layout = new SetupWizardLayout(mContext);
+ assertNotNull("SetupWizardLayout should have header mixin", layout.getMixin(HeaderMixin.class));
+ assertNotNull(
+ "SetupWizardLayout should have progress bar mixin",
+ layout.getMixin(ProgressBarMixin.class));
+ assertNotNull(
+ "SetupWizardLayout should have navigation bar mixin",
+ layout.getMixin(NavigationBarMixin.class));
+ }
+
+ private void assertDefaultTemplateInflated(SetupWizardLayout layout) {
+ View decorView = layout.findViewById(R.id.suw_layout_decor);
+ View navbar = layout.findViewById(R.id.suw_layout_navigation_bar);
+ View title = layout.findViewById(R.id.suw_layout_title);
+ assertNotNull("@id/suw_layout_decor_view should not be null", decorView);
+ assertTrue(
+ "@id/suw_layout_navigation_bar should be an instance of NavigationBar",
+ navbar instanceof NavigationBar);
+ assertNotNull("@id/suw_layout_title should not be null", title);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardListLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardListLayoutTest.java
index 5c34fe0..fc18a31 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardListLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SetupWizardListLayoutTest.java
@@ -25,20 +25,18 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;
-import android.support.test.InstrumentationRegistry;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
-
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.SetupWizardLayout;
import com.android.setupwizardlib.SetupWizardListLayout;
import com.android.setupwizardlib.view.NavigationBar;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -47,90 +45,93 @@ import org.junit.runner.RunWith;
@SmallTest
public class SetupWizardListLayoutTest {
- private Context mContext;
-
- @Before
- public void setUp() throws Exception {
- mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(),
- R.style.SuwThemeMaterial_Light);
- }
-
- @Test
- public void testDefaultTemplate() {
- SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
- assertListTemplateInflated(layout);
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ mContext =
+ new ContextThemeWrapper(
+ InstrumentationRegistry.getContext(), R.style.SuwThemeMaterial_Light);
+ }
+
+ @Test
+ public void testDefaultTemplate() {
+ SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
+ assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testAddView() {
+ SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
+ TextView tv = new TextView(mContext);
+ try {
+ layout.addView(tv);
+ fail("Adding view to ListLayout should throw");
+ } catch (UnsupportedOperationException e) {
+ // Expected exception
}
-
- @Test
- public void testAddView() {
- SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
- TextView tv = new TextView(mContext);
- try {
- layout.addView(tv);
- fail("Adding view to ListLayout should throw");
- } catch (UnsupportedOperationException e) {
- // Expected exception
- }
- }
-
- @Test
- public void testInflateFromXml() {
- LayoutInflater inflater = LayoutInflater.from(mContext);
- SetupWizardListLayout layout = (SetupWizardListLayout)
- inflater.inflate(R.layout.test_list_layout, null);
- assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testInflateFromXml() {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ SetupWizardListLayout layout =
+ (SetupWizardListLayout) inflater.inflate(R.layout.test_list_layout, null);
+ assertListTemplateInflated(layout);
+ }
+
+ @Test
+ public void testShowProgressBar() {
+ final SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
+ layout.showProgressBar();
+ assertTrue("Progress bar should be shown", layout.isProgressBarShown());
+ final View progressBar = layout.findViewById(R.id.suw_layout_progress);
+ assertTrue(
+ "Progress bar view should be shown",
+ progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE);
+ }
+
+ @Test
+ public void testDividerInsetLegacy() {
+ SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertListTemplateInflated(layout);
- @Test
- public void testShowProgressBar() {
- final SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
- layout.showProgressBar();
- assertTrue("Progress bar should be shown", layout.isProgressBarShown());
- final View progressBar = layout.findViewById(R.id.suw_layout_progress);
- assertTrue("Progress bar view should be shown",
- progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE);
- }
-
- @Test
- public void testDividerInsetLegacy() {
- SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertListTemplateInflated(layout);
-
- layout.setDividerInset(10);
- assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
+ layout.setDividerInset(10);
+ assertEquals("Divider inset should be 10", 10, layout.getDividerInset());
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
-
- @Test
- public void testDividerInsets() {
- SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
- }
- assertListTemplateInflated(layout);
-
- layout.setDividerInsets(10, 15);
- assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
- assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
-
- final Drawable divider = layout.getDivider();
- assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
- }
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
- private void assertListTemplateInflated(SetupWizardLayout layout) {
- View decorView = layout.findViewById(R.id.suw_layout_decor);
- View navbar = layout.findViewById(R.id.suw_layout_navigation_bar);
- View title = layout.findViewById(R.id.suw_layout_title);
- View list = layout.findViewById(android.R.id.list);
- assertNotNull("@id/suw_layout_decor_view should not be null", decorView);
- assertTrue("@id/suw_layout_navigation_bar should be an instance of NavigationBar",
- navbar instanceof NavigationBar);
- assertNotNull("@id/suw_layout_title should not be null", title);
- assertTrue("@android:id/list should be an instance of ListView", list instanceof ListView);
+ @Test
+ public void testDividerInsets() {
+ SetupWizardListLayout layout = new SetupWizardListLayout(mContext);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ layout.setLayoutDirection(View.LAYOUT_DIRECTION_LTR);
}
+ assertListTemplateInflated(layout);
+
+ layout.setDividerInsets(10, 15);
+ assertEquals("Divider inset start should be 10", 10, layout.getDividerInsetStart());
+ assertEquals("Divider inset end should be 15", 15, layout.getDividerInsetEnd());
+
+ final Drawable divider = layout.getDivider();
+ assertTrue("Divider should be instance of InsetDrawable", divider instanceof InsetDrawable);
+ }
+
+ private void assertListTemplateInflated(SetupWizardLayout layout) {
+ View decorView = layout.findViewById(R.id.suw_layout_decor);
+ View navbar = layout.findViewById(R.id.suw_layout_navigation_bar);
+ View title = layout.findViewById(R.id.suw_layout_title);
+ View list = layout.findViewById(android.R.id.list);
+ assertNotNull("@id/suw_layout_decor_view should not be null", decorView);
+ assertTrue(
+ "@id/suw_layout_navigation_bar should be an instance of NavigationBar",
+ navbar instanceof NavigationBar);
+ assertNotNull("@id/suw_layout_title should not be null", title);
+ assertTrue("@android:id/list should be an instance of ListView", list instanceof ListView);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SimpleInflaterTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SimpleInflaterTest.java
index f4738ca..da39a7b 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SimpleInflaterTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SimpleInflaterTest.java
@@ -20,15 +20,12 @@ import static org.junit.Assert.assertEquals;
import android.content.Context;
import android.content.res.Resources;
+import androidx.annotation.NonNull;
+import android.util.AttributeSet;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-import android.util.AttributeSet;
-
-import androidx.annotation.NonNull;
-
import com.android.setupwizardlib.items.SimpleInflater;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,30 +33,30 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class SimpleInflaterTest {
- @Test
- public void testInflateXml() {
- final Context context = InstrumentationRegistry.getContext();
- TestInflater inflater = new TestInflater(context.getResources());
- final StringBuilder result = inflater.inflate(R.xml.simple_inflater_test);
+ @Test
+ public void testInflateXml() {
+ final Context context = InstrumentationRegistry.getContext();
+ TestInflater inflater = new TestInflater(context.getResources());
+ final StringBuilder result = inflater.inflate(R.xml.simple_inflater_test);
- assertEquals("Parent[null] > Child[foobar]", result.toString());
- }
+ assertEquals("Parent[null] > Child[foobar]", result.toString());
+ }
- private static class TestInflater extends SimpleInflater<StringBuilder> {
+ private static class TestInflater extends SimpleInflater<StringBuilder> {
- protected TestInflater(@NonNull Resources resources) {
- super(resources);
- }
+ protected TestInflater(@NonNull Resources resources) {
+ super(resources);
+ }
- @Override
- protected StringBuilder onCreateItem(String tagName, AttributeSet attrs) {
- final String attribute = attrs.getAttributeValue(null, "myattribute");
- return new StringBuilder(tagName).append("[").append(attribute).append("]");
- }
+ @Override
+ protected StringBuilder onCreateItem(String tagName, AttributeSet attrs) {
+ final String attribute = attrs.getAttributeValue(null, "myattribute");
+ return new StringBuilder(tagName).append("[").append(attribute).append("]");
+ }
- @Override
- protected void onAddChildItem(StringBuilder parent, StringBuilder child) {
- parent.append(" > ").append(child);
- }
+ @Override
+ protected void onAddChildItem(StringBuilder parent, StringBuilder child) {
+ parent.append(" > ").append(child);
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SpanHelperTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SpanHelperTest.java
index 903cf5e..920d7ab 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SpanHelperTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SpanHelperTest.java
@@ -19,13 +19,11 @@ package com.android.setupwizardlib.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
-import android.support.test.filters.SmallTest;
-import android.support.test.runner.AndroidJUnit4;
import android.text.Annotation;
import android.text.SpannableStringBuilder;
-
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
import com.android.setupwizardlib.span.SpanHelper;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,17 +31,17 @@ import org.junit.runner.RunWith;
@SmallTest
public class SpanHelperTest {
- @Test
- public void testReplaceSpan() {
- SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world");
- Annotation oldSpan = new Annotation("key", "value");
- Annotation newSpan = new Annotation("newkey", "newvalue");
- ssb.setSpan(oldSpan, 2, 5, 0 /* flags */);
+ @Test
+ public void testReplaceSpan() {
+ SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world");
+ Annotation oldSpan = new Annotation("key", "value");
+ Annotation newSpan = new Annotation("newkey", "newvalue");
+ ssb.setSpan(oldSpan, 2, 5, 0 /* flags */);
- SpanHelper.replaceSpan(ssb, oldSpan, newSpan);
+ SpanHelper.replaceSpan(ssb, oldSpan, newSpan);
- final Object[] spans = ssb.getSpans(0, ssb.length(), Object.class);
- assertEquals("There should be one span in the builder", 1, spans.length);
- assertSame("The span should be newSpan", newSpan, spans[0]);
- }
+ final Object[] spans = ssb.getSpans(0, ssb.length(), Object.class);
+ assertEquals("There should be one span in the builder", 1, spans.length);
+ assertSame("The span should be newSpan", newSpan, spans[0]);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/StatusBarBackgroundLayoutTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/StatusBarBackgroundLayoutTest.java
index 006e5c4..e0fd49b 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/StatusBarBackgroundLayoutTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/StatusBarBackgroundLayoutTest.java
@@ -24,9 +24,7 @@ import android.graphics.drawable.ShapeDrawable;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
-
import com.android.setupwizardlib.view.StatusBarBackgroundLayout;
-
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -34,46 +32,48 @@ import org.junit.runner.RunWith;
@SmallTest
public class StatusBarBackgroundLayoutTest {
- @Test
- public void testSetStatusBarBackground() {
- final StatusBarBackgroundLayout layout = new StatusBarBackgroundLayout(
- InstrumentationRegistry.getContext());
- final ShapeDrawable drawable = new ShapeDrawable();
- layout.setStatusBarBackground(drawable);
- assertSame("Status bar background drawable should be same as set",
- drawable, layout.getStatusBarBackground());
- }
+ @Test
+ public void testSetStatusBarBackground() {
+ final StatusBarBackgroundLayout layout =
+ new StatusBarBackgroundLayout(InstrumentationRegistry.getContext());
+ final ShapeDrawable drawable = new ShapeDrawable();
+ layout.setStatusBarBackground(drawable);
+ assertSame(
+ "Status bar background drawable should be same as set",
+ drawable,
+ layout.getStatusBarBackground());
+ }
- @Test
- public void testAttachedToWindow() {
- // Attaching to window should request apply window inset
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
- final TestStatusBarBackgroundLayout layout =
- new TestStatusBarBackgroundLayout(InstrumentationRegistry.getContext());
- layout.mRequestApplyInsets = false;
- layout.onAttachedToWindow();
+ @Test
+ public void testAttachedToWindow() {
+ // Attaching to window should request apply window inset
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
+ final TestStatusBarBackgroundLayout layout =
+ new TestStatusBarBackgroundLayout(InstrumentationRegistry.getContext());
+ layout.mRequestApplyInsets = false;
+ layout.onAttachedToWindow();
- assertTrue("Attaching to window should apply window inset", layout.mRequestApplyInsets);
- }
+ assertTrue("Attaching to window should apply window inset", layout.mRequestApplyInsets);
}
+ }
- private static class TestStatusBarBackgroundLayout extends StatusBarBackgroundLayout {
+ private static class TestStatusBarBackgroundLayout extends StatusBarBackgroundLayout {
- boolean mRequestApplyInsets = false;
+ boolean mRequestApplyInsets = false;
- TestStatusBarBackgroundLayout(Context context) {
- super(context);
- }
+ TestStatusBarBackgroundLayout(Context context) {
+ super(context);
+ }
- @Override
- public void onAttachedToWindow() {
- super.onAttachedToWindow();
- }
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ }
- @Override
- public void requestApplyInsets() {
- super.requestApplyInsets();
- mRequestApplyInsets = true;
- }
+ @Override
+ public void requestApplyInsets() {
+ super.requestApplyInsets();
+ mRequestApplyInsets = true;
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
index 98c28f6..1b534e1 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/SystemBarHelperTest.java
@@ -17,7 +17,6 @@
package com.android.setupwizardlib.test;
import static com.google.common.truth.Truth.assertThat;
-
import static org.junit.Assert.assertEquals;
import android.annotation.SuppressLint;
@@ -28,19 +27,17 @@ import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.SystemClock;
+import android.view.ContextThemeWrapper;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
import android.support.test.InstrumentationRegistry;
import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest;
import android.support.test.rule.UiThreadTestRule;
import android.support.test.runner.AndroidJUnit4;
-import android.view.ContextThemeWrapper;
-import android.view.View;
-import android.view.Window;
-import android.view.WindowManager;
-
import com.android.setupwizardlib.test.util.MockWindow;
import com.android.setupwizardlib.util.SystemBarHelper;
-
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -49,241 +46,240 @@ import org.junit.runner.RunWith;
@SmallTest
public class SystemBarHelperTest {
- @Rule
- public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule();
-
- private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
-
- @SuppressLint("InlinedApi")
- private static final int DEFAULT_IMMERSIVE_FLAGS =
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
-
- @SuppressLint("InlinedApi")
- private static final int DIALOG_IMMERSIVE_FLAGS =
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
-
- @UiThreadTest
- @Test
- public void testAddVisibilityFlagView() {
- final View view = createViewWithSystemUiVisibility(0x456);
- SystemBarHelper.addVisibilityFlag(view, 0x1400);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- // Check that result is 0x1456, because 0x1400 | 0x456 = 0x1456.
- assertEquals("View visibility should be 0x1456", 0x1456, view.getSystemUiVisibility());
- }
+ @Rule public UiThreadTestRule mUiThreadTestRule = new UiThreadTestRule();
+
+ private static final int STATUS_BAR_DISABLE_BACK = 0x00400000;
+
+ @SuppressLint("InlinedApi")
+ private static final int DEFAULT_IMMERSIVE_FLAGS =
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
+
+ @SuppressLint("InlinedApi")
+ private static final int DIALOG_IMMERSIVE_FLAGS =
+ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+
+ @UiThreadTest
+ @Test
+ public void testAddVisibilityFlagView() {
+ final View view = createViewWithSystemUiVisibility(0x456);
+ SystemBarHelper.addVisibilityFlag(view, 0x1400);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x1456, because 0x1400 | 0x456 = 0x1456.
+ assertEquals("View visibility should be 0x1456", 0x1456, view.getSystemUiVisibility());
}
-
- @UiThreadTest
- @Test
- public void testRemoveVisibilityFlagView() {
- final View view = createViewWithSystemUiVisibility(0x456);
- SystemBarHelper.removeVisibilityFlag(view, 0x1400);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- // Check that result is 0x56, because 0x456 & ~0x1400 = 0x56.
- assertEquals("View visibility should be 0x56", 0x56, view.getSystemUiVisibility());
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testRemoveVisibilityFlagView() {
+ final View view = createViewWithSystemUiVisibility(0x456);
+ SystemBarHelper.removeVisibilityFlag(view, 0x1400);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x56, because 0x456 & ~0x1400 = 0x56.
+ assertEquals("View visibility should be 0x56", 0x56, view.getSystemUiVisibility());
}
-
- @UiThreadTest
- @Test
- public void testAddVisibilityFlagWindow() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
- SystemBarHelper.addVisibilityFlag(window, 0x1400);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- // Check that result is 0x1456 = 0x1400 | 0x456.
- assertEquals("View visibility should be 0x1456", 0x1456,
- window.getAttributes().systemUiVisibility);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testAddVisibilityFlagWindow() {
+ final Window window = createWindowWithSystemUiVisibility(0x456);
+ SystemBarHelper.addVisibilityFlag(window, 0x1400);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x1456 = 0x1400 | 0x456.
+ assertEquals(
+ "View visibility should be 0x1456", 0x1456, window.getAttributes().systemUiVisibility);
}
-
- @UiThreadTest
- @Test
- public void testRemoveVisibilityFlagWindow() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
- SystemBarHelper.removeVisibilityFlag(window, 0x1400);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- // Check that result is 0x56 = 0x456 & ~0x1400.
- assertEquals("View visibility should be 0x56", 0x56,
- window.getAttributes().systemUiVisibility);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testRemoveVisibilityFlagWindow() {
+ final Window window = createWindowWithSystemUiVisibility(0x456);
+ SystemBarHelper.removeVisibilityFlag(window, 0x1400);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ // Check that result is 0x56 = 0x456 & ~0x1400.
+ assertEquals(
+ "View visibility should be 0x56", 0x56, window.getAttributes().systemUiVisibility);
}
-
- @UiThreadTest
- @Test
- public void testHideSystemBarsWindow() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
- SystemBarHelper.hideSystemBars(window);
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- assertEquals("DEFAULT_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
- DEFAULT_IMMERSIVE_FLAGS | 0x456,
- window.getAttributes().systemUiVisibility);
- assertEquals(
- "DEFAULT_IMMERSIVE_FLAGS should be added to decorView's systemUiVisibility",
- DEFAULT_IMMERSIVE_FLAGS | 0x456,
- window.getDecorView().getSystemUiVisibility());
- assertEquals("Navigation bar should be transparent", window.getNavigationBarColor(), 0);
- assertEquals("Status bar should be transparent", window.getStatusBarColor(), 0);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testHideSystemBarsWindow() {
+ final Window window = createWindowWithSystemUiVisibility(0x456);
+ SystemBarHelper.hideSystemBars(window);
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ assertEquals(
+ "DEFAULT_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
+ DEFAULT_IMMERSIVE_FLAGS | 0x456,
+ window.getAttributes().systemUiVisibility);
+ assertEquals(
+ "DEFAULT_IMMERSIVE_FLAGS should be added to decorView's systemUiVisibility",
+ DEFAULT_IMMERSIVE_FLAGS | 0x456,
+ window.getDecorView().getSystemUiVisibility());
+ assertEquals("Navigation bar should be transparent", window.getNavigationBarColor(), 0);
+ assertEquals("Status bar should be transparent", window.getStatusBarColor(), 0);
}
-
- @UiThreadTest
- @Test
- public void testShowSystemBarsWindow() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
- Context context = new ContextThemeWrapper(
- InstrumentationRegistry.getContext(), android.R.style.Theme);
- SystemBarHelper.showSystemBars(window, context);
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- assertEquals(
- "DEFAULT_IMMERSIVE_FLAGS should be removed from window's systemUiVisibility",
- 0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
- window.getAttributes().systemUiVisibility);
- assertEquals(
- "DEFAULT_IMMERSIVE_FLAGS should be removed from decorView's systemUiVisibility",
- 0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
- window.getDecorView().getSystemUiVisibility());
- assertEquals("Navigation bar should not be transparent",
- window.getNavigationBarColor(), 0xff000000);
- assertEquals("Status bar should not be transparent",
- window.getStatusBarColor(), 0xff000000);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testShowSystemBarsWindow() {
+ final Window window = createWindowWithSystemUiVisibility(0x456);
+ Context context =
+ new ContextThemeWrapper(InstrumentationRegistry.getContext(), android.R.style.Theme);
+ SystemBarHelper.showSystemBars(window, context);
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ assertEquals(
+ "DEFAULT_IMMERSIVE_FLAGS should be removed from window's systemUiVisibility",
+ 0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
+ window.getAttributes().systemUiVisibility);
+ assertEquals(
+ "DEFAULT_IMMERSIVE_FLAGS should be removed from decorView's systemUiVisibility",
+ 0x456 & ~DEFAULT_IMMERSIVE_FLAGS,
+ window.getDecorView().getSystemUiVisibility());
+ assertEquals(
+ "Navigation bar should not be transparent", window.getNavigationBarColor(), 0xff000000);
+ assertEquals("Status bar should not be transparent", window.getStatusBarColor(), 0xff000000);
}
-
- @UiThreadTest
- @Test
- public void testHideSystemBarsNoInfiniteLoop() throws InterruptedException {
- final TestWindow window = new TestWindow(InstrumentationRegistry.getContext(), null);
- final HandlerThread thread = new HandlerThread("SystemBarHelperTest");
- thread.start();
- final Handler handler = new Handler(thread.getLooper());
- handler.post(new Runnable() {
- @Override
- public void run() {
- SystemBarHelper.hideSystemBars(window);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testHideSystemBarsNoInfiniteLoop() throws InterruptedException {
+ final TestWindow window = new TestWindow(InstrumentationRegistry.getContext(), null);
+ final HandlerThread thread = new HandlerThread("SystemBarHelperTest");
+ thread.start();
+ final Handler handler = new Handler(thread.getLooper());
+ handler.post(
+ new Runnable() {
+ @Override
+ public void run() {
+ SystemBarHelper.hideSystemBars(window);
+ }
});
- SystemClock.sleep(500); // Wait for the looper to drain all the messages
- thread.quit();
- // Initial peek + 3 retries = 4 tries total
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- assertEquals("Peek decor view should give up after 4 tries", 4,
- window.peekDecorViewCount);
- }
+ SystemClock.sleep(500); // Wait for the looper to drain all the messages
+ thread.quit();
+ // Initial peek + 3 retries = 4 tries total
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ assertEquals("Peek decor view should give up after 4 tries", 4, window.peekDecorViewCount);
}
-
- @UiThreadTest
- @Test
- public void testHideSystemBarsDialog() {
- final Dialog dialog = new Dialog(InstrumentationRegistry.getContext());
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- final WindowManager.LayoutParams attrs = dialog.getWindow().getAttributes();
- attrs.systemUiVisibility = 0x456;
- dialog.getWindow().setAttributes(attrs);
- }
-
- SystemBarHelper.hideSystemBars(dialog);
- if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- assertEquals("DIALOG_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
- DIALOG_IMMERSIVE_FLAGS | 0x456,
- dialog.getWindow().getAttributes().systemUiVisibility);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testHideSystemBarsDialog() {
+ final Dialog dialog = new Dialog(InstrumentationRegistry.getContext());
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ final WindowManager.LayoutParams attrs = dialog.getWindow().getAttributes();
+ attrs.systemUiVisibility = 0x456;
+ dialog.getWindow().setAttributes(attrs);
}
- @UiThreadTest
- @Test
- public void testSetBackButtonVisibleTrue() {
- final Window window = createWindowWithSystemUiVisibility(STATUS_BAR_DISABLE_BACK | 0x456);
- SystemBarHelper.setBackButtonVisible(window, true);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- assertThat(window.getAttributes().systemUiVisibility)
- .named("window sysUiVisibility")
- .isEqualTo(0x456);
- assertThat(window.getDecorView().getSystemUiVisibility())
- .named("decor view sysUiVisibility")
- .isEqualTo(0x456);
- }
+ SystemBarHelper.hideSystemBars(dialog);
+ if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
+ assertEquals(
+ "DIALOG_IMMERSIVE_FLAGS should be added to window's systemUiVisibility",
+ DIALOG_IMMERSIVE_FLAGS | 0x456,
+ dialog.getWindow().getAttributes().systemUiVisibility);
}
-
- @UiThreadTest
- @Test
- public void testSetBackButtonVisibleFalse() {
- final Window window = createWindowWithSystemUiVisibility(0x456);
- SystemBarHelper.setBackButtonVisible(window, false);
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- assertThat(window.getAttributes().systemUiVisibility)
- .named("window sysUiVisibility")
- .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
- assertThat(window.getDecorView().getSystemUiVisibility())
- .named("decor view sysUiVisibility")
- .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
- }
+ }
+
+ @UiThreadTest
+ @Test
+ public void testSetBackButtonVisibleTrue() {
+ final Window window = createWindowWithSystemUiVisibility(STATUS_BAR_DISABLE_BACK | 0x456);
+ SystemBarHelper.setBackButtonVisible(window, true);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ assertThat(window.getAttributes().systemUiVisibility)
+ .named("window sysUiVisibility")
+ .isEqualTo(0x456);
+ assertThat(window.getDecorView().getSystemUiVisibility())
+ .named("decor view sysUiVisibility")
+ .isEqualTo(0x456);
}
-
- private View createViewWithSystemUiVisibility(int vis) {
- final View view = new View(InstrumentationRegistry.getContext());
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- view.setSystemUiVisibility(vis);
- }
- return view;
+ }
+
+ @UiThreadTest
+ @Test
+ public void testSetBackButtonVisibleFalse() {
+ final Window window = createWindowWithSystemUiVisibility(0x456);
+ SystemBarHelper.setBackButtonVisible(window, false);
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ assertThat(window.getAttributes().systemUiVisibility)
+ .named("window sysUiVisibility")
+ .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
+ assertThat(window.getDecorView().getSystemUiVisibility())
+ .named("decor view sysUiVisibility")
+ .isEqualTo(0x456 | STATUS_BAR_DISABLE_BACK);
}
+ }
- private Window createWindowWithSystemUiVisibility(int vis) {
- final Window window = new TestWindow(InstrumentationRegistry.getContext(),
- createViewWithSystemUiVisibility(vis));
- if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
- WindowManager.LayoutParams attrs = window.getAttributes();
- attrs.systemUiVisibility = vis;
- window.setAttributes(attrs);
- }
- return window;
+ private View createViewWithSystemUiVisibility(int vis) {
+ final View view = new View(InstrumentationRegistry.getContext());
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ view.setSystemUiVisibility(vis);
+ }
+ return view;
+ }
+
+ private Window createWindowWithSystemUiVisibility(int vis) {
+ final Window window =
+ new TestWindow(InstrumentationRegistry.getContext(), createViewWithSystemUiVisibility(vis));
+ if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
+ WindowManager.LayoutParams attrs = window.getAttributes();
+ attrs.systemUiVisibility = vis;
+ window.setAttributes(attrs);
}
+ return window;
+ }
- private static class TestWindow extends MockWindow {
+ private static class TestWindow extends MockWindow {
- private View mDecorView;
- public int peekDecorViewCount = 0;
+ private View mDecorView;
+ public int peekDecorViewCount = 0;
- private int mNavigationBarColor = -1;
- private int mStatusBarColor = -1;
+ private int mNavigationBarColor = -1;
+ private int mStatusBarColor = -1;
- TestWindow(Context context, View decorView) {
- super(context);
- mDecorView = decorView;
- }
+ TestWindow(Context context, View decorView) {
+ super(context);
+ mDecorView = decorView;
+ }
- @Override
- public View getDecorView() {
- return mDecorView;
- }
+ @Override
+ public View getDecorView() {
+ return mDecorView;
+ }
- @Override
- public View peekDecorView() {
- peekDecorViewCount++;
- return mDecorView;
- }
+ @Override
+ public View peekDecorView() {
+ peekDecorViewCount++;
+ return mDecorView;
+ }
- @Override
- public void setNavigationBarColor(int i) {
- mNavigationBarColor = i;
- }
+ @Override
+ public void setNavigationBarColor(int i) {
+ mNavigationBarColor = i;
+ }
- @Override
- public int getNavigationBarColor() {
- return mNavigationBarColor;
- }
+ @Override
+ public int getNavigationBarColor() {
+ return mNavigationBarColor;
+ }
- @Override
- public void setStatusBarColor(int i) {
- mStatusBarColor = i;
- }
+ @Override
+ public void setStatusBarColor(int i) {
+ mStatusBarColor = i;
+ }
- @Override
- public int getStatusBarColor() {
- return mStatusBarColor;
- }
+ @Override
+ public int getStatusBarColor() {
+ return mStatusBarColor;
}
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/util/DrawingTestHelper.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/util/DrawingTestHelper.java
index 6910513..918d63a 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/util/DrawingTestHelper.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/util/DrawingTestHelper.java
@@ -24,69 +24,69 @@ import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.support.test.InstrumentationRegistry;
+import androidx.annotation.StyleRes;
import android.view.View;
import android.view.View.MeasureSpec;
-
-import androidx.annotation.StyleRes;
+import android.support.test.InstrumentationRegistry;
public class DrawingTestHelper {
- /**
- * Creates an activity of which to inflate views and drawables for drawing tests. This method
- * will return an instance of AppCompatActivity which allows testing of drawing behavior
- * injected by support libraries (like drawable tinting) as well.
- */
- public static Activity createCanvasActivity(@StyleRes int theme)
- throws IllegalAccessException, InstantiationException {
- final Context context = InstrumentationRegistry.getTargetContext();
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ /**
+ * Creates an activity of which to inflate views and drawables for drawing tests. This method will
+ * return an instance of AppCompatActivity which allows testing of drawing behavior injected by
+ * support libraries (like drawable tinting) as well.
+ */
+ public static Activity createCanvasActivity(@StyleRes int theme)
+ throws IllegalAccessException, InstantiationException {
+ final Context context = InstrumentationRegistry.getTargetContext();
+ final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- final Intent intent = new Intent(context, DrawingTestActivity.class);
- final Activity activity = instrumentation.newActivity(
- DrawingTestActivity.class,
- context,
- null, /* token */
- new Application(),
- intent,
- new ActivityInfo(),
- "", /* title */
- null, /* parent */
- null, /* id */
- null /* lastNonConfigurationInstance */);
- instrumentation.callActivityOnCreate(activity, null);
- activity.setTheme(theme);
- return activity;
- }
+ final Intent intent = new Intent(context, DrawingTestActivity.class);
+ final Activity activity =
+ instrumentation.newActivity(
+ DrawingTestActivity.class,
+ context,
+ null, /* token */
+ new Application(),
+ intent,
+ new ActivityInfo(),
+ "", /* title */
+ null, /* parent */
+ null, /* id */
+ null /* lastNonConfigurationInstance */);
+ instrumentation.callActivityOnCreate(activity, null);
+ activity.setTheme(theme);
+ return activity;
+ }
- private final int mWidth;
- private final int mHeight;
- private final Canvas mCanvas;
- private final Bitmap mBitmap;
+ private final int mWidth;
+ private final int mHeight;
+ private final Canvas mCanvas;
+ private final Bitmap mBitmap;
- public DrawingTestHelper(int width, int height) {
- mWidth = width;
- mHeight = height;
+ public DrawingTestHelper(int width, int height) {
+ mWidth = width;
+ mHeight = height;
- mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- mCanvas = new Canvas(mBitmap);
- }
+ mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ mCanvas = new Canvas(mBitmap);
+ }
- public void drawView(View view) {
- view.measure(
- MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY),
- MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
- view.layout(0, 0, mWidth, mHeight);
- view.draw(mCanvas);
- }
+ public void drawView(View view) {
+ view.measure(
+ MeasureSpec.makeMeasureSpec(mWidth, MeasureSpec.EXACTLY),
+ MeasureSpec.makeMeasureSpec(mHeight, MeasureSpec.EXACTLY));
+ view.layout(0, 0, mWidth, mHeight);
+ view.draw(mCanvas);
+ }
- public int[] getPixels() {
- int[] out = new int[mWidth * mHeight];
- mBitmap.getPixels(out, 0, mWidth, 0, 0, mWidth, mHeight);
- return out;
- }
+ public int[] getPixels() {
+ int[] out = new int[mWidth * mHeight];
+ mBitmap.getPixels(out, 0, mWidth, 0, 0, mWidth, mHeight);
+ return out;
+ }
- public int getPixel(int x, int y) {
- return mBitmap.getPixel(x, y);
- }
+ public int getPixel(int x, int y) {
+ return mBitmap.getPixel(x, y);
+ }
}
diff --git a/library/test/instrumentation/src/com/android/setupwizardlib/test/util/MockWindow.java b/library/test/instrumentation/src/com/android/setupwizardlib/test/util/MockWindow.java
index 7af20eb..1e096eb 100644
--- a/library/test/instrumentation/src/com/android/setupwizardlib/test/util/MockWindow.java
+++ b/library/test/instrumentation/src/com/android/setupwizardlib/test/util/MockWindow.java
@@ -21,6 +21,7 @@ import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
+import androidx.annotation.NonNull;
import android.view.InputQueue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
@@ -30,252 +31,250 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
-import androidx.annotation.NonNull;
-
public class MockWindow extends Window {
- public MockWindow(Context context) {
- super(context);
- }
-
- @Override
- public void takeSurface(SurfaceHolder.Callback2 callback2) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void takeInputQueue(InputQueue.Callback callback) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean isFloating() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setContentView(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setContentView(View view) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void addContentView(View view, ViewGroup.LayoutParams layoutParams) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public View getCurrentFocus() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @NonNull
- @Override
- public LayoutInflater getLayoutInflater() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setTitle(CharSequence charSequence) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setTitleColor(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void openPanel(int i, KeyEvent keyEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void closePanel(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void togglePanel(int i, KeyEvent keyEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void invalidatePanelMenu(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean performPanelShortcut(int i, int i1, KeyEvent keyEvent, int i2) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean performPanelIdentifierAction(int i, int i1, int i2) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void closeAllPanels() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean performContextMenuIdentifierAction(int i, int i1) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void onConfigurationChanged(Configuration configuration) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setBackgroundDrawable(Drawable drawable) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setFeatureDrawableResource(int i, int i1) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setFeatureDrawableUri(int i, Uri uri) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setFeatureDrawable(int i, Drawable drawable) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setFeatureDrawableAlpha(int i, int i1) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setFeatureInt(int i, int i1) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void takeKeyEvents(boolean b) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean superDispatchKeyEvent(KeyEvent keyEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean superDispatchKeyShortcutEvent(KeyEvent keyEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean superDispatchTouchEvent(MotionEvent motionEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean superDispatchTrackballEvent(MotionEvent motionEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean superDispatchGenericMotionEvent(MotionEvent motionEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public View getDecorView() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public View peekDecorView() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public Bundle saveHierarchyState() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void restoreHierarchyState(Bundle bundle) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- protected void onActive() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setChildDrawable(int i, Drawable drawable) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setChildInt(int i, int i1) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public boolean isShortcutKey(int i, KeyEvent keyEvent) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setVolumeControlStream(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public int getVolumeControlStream() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public int getStatusBarColor() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setStatusBarColor(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public int getNavigationBarColor() {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setNavigationBarColor(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setDecorCaptionShade(int i) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
-
- @Override
- public void setResizingCaptionDrawable(Drawable drawable) {
- throw new UnsupportedOperationException("Unexpected method call on mock");
- }
+ public MockWindow(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void takeSurface(SurfaceHolder.Callback2 callback2) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void takeInputQueue(InputQueue.Callback callback) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean isFloating() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setContentView(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setContentView(View view) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void addContentView(View view, ViewGroup.LayoutParams layoutParams) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public View getCurrentFocus() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @NonNull
+ @Override
+ public LayoutInflater getLayoutInflater() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setTitle(CharSequence charSequence) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setTitleColor(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void openPanel(int i, KeyEvent keyEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void closePanel(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void togglePanel(int i, KeyEvent keyEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void invalidatePanelMenu(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean performPanelShortcut(int i, int i1, KeyEvent keyEvent, int i2) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean performPanelIdentifierAction(int i, int i1, int i2) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void closeAllPanels() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean performContextMenuIdentifierAction(int i, int i1) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration configuration) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setBackgroundDrawable(Drawable drawable) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setFeatureDrawableResource(int i, int i1) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setFeatureDrawableUri(int i, Uri uri) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setFeatureDrawable(int i, Drawable drawable) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setFeatureDrawableAlpha(int i, int i1) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setFeatureInt(int i, int i1) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void takeKeyEvents(boolean b) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean superDispatchKeyEvent(KeyEvent keyEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean superDispatchKeyShortcutEvent(KeyEvent keyEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean superDispatchTouchEvent(MotionEvent motionEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean superDispatchTrackballEvent(MotionEvent motionEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean superDispatchGenericMotionEvent(MotionEvent motionEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public View getDecorView() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public View peekDecorView() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public Bundle saveHierarchyState() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void restoreHierarchyState(Bundle bundle) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ protected void onActive() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setChildDrawable(int i, Drawable drawable) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setChildInt(int i, int i1) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public boolean isShortcutKey(int i, KeyEvent keyEvent) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setVolumeControlStream(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public int getVolumeControlStream() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public int getStatusBarColor() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setStatusBarColor(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public int getNavigationBarColor() {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setNavigationBarColor(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setDecorCaptionShade(int i) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
+
+ @Override
+ public void setResizingCaptionDrawable(Drawable drawable) {
+ throw new UnsupportedOperationException("Unexpected method call on mock");
+ }
}