diff --git a/library/gingerbread/res/values/styles.xml b/library/gingerbread/res/values/styles.xml index 3399178..d9930f4 100644 --- a/library/gingerbread/res/values/styles.xml +++ b/library/gingerbread/res/values/styles.xml @@ -109,6 +109,7 @@ @dimen/suw_items_glif_icon_divider_inset @dimen/suw_items_glif_text_divider_inset start + @style/SuwGlifIcon @style/SuwItemContainer.Description.Glif @style/SuwItemTitle.GlifDescription @color/suw_list_item_icon_color_dark @@ -144,6 +145,7 @@ @dimen/suw_items_glif_icon_divider_inset @dimen/suw_items_glif_text_divider_inset start + @style/SuwGlifIcon @style/SuwItemContainer.Description.Glif @style/SuwItemTitle.GlifDescription @color/suw_list_item_icon_color_light diff --git a/library/main/res/layout/suw_glif_blank_template_content.xml b/library/main/res/layout/suw_glif_blank_template_content.xml index ed81126..6d864cd 100644 --- a/library/main/res/layout/suw_glif_blank_template_content.xml +++ b/library/main/res/layout/suw_glif_blank_template_content.xml @@ -21,6 +21,11 @@ android:layout_height="match_parent" android:orientation="vertical"> + + + + + + + - + @@ -104,6 +105,7 @@ + diff --git a/library/main/src/com/android/setupwizardlib/GlifLayout.java b/library/main/src/com/android/setupwizardlib/GlifLayout.java index dd0963b..e1d9d70 100644 --- a/library/main/src/com/android/setupwizardlib/GlifLayout.java +++ b/library/main/src/com/android/setupwizardlib/GlifLayout.java @@ -141,6 +141,11 @@ public class GlifLayout extends TemplateLayout { inflateFooter(footer); } + final int stickyHeader = a.getResourceId(R.styleable.SuwGlifLayout_suwStickyHeader, 0); + if (stickyHeader != 0) { + inflateStickyHeader(stickyHeader); + } + mLayoutFullscreen = a.getBoolean(R.styleable.SuwGlifLayout_suwLayoutFullscreen, true); a.recycle(); @@ -168,17 +173,31 @@ public class GlifLayout extends TemplateLayout { /** * Sets the footer of the layout, which is at the bottom of the content area outside the - * scrolling container. The footer can only be inflated once per layout. + * scrolling container. The footer can only be inflated once per instance of this layout. * * @param footer The layout to be inflated as footer. * @return The root of the inflated footer view. */ public View inflateFooter(@LayoutRes int footer) { - ViewStub footerStub = (ViewStub) findManagedViewById(R.id.suw_layout_footer); + ViewStub footerStub = findManagedViewById(R.id.suw_layout_footer); footerStub.setLayoutResource(footer); return footerStub.inflate(); } + /** + * Sets the sticky header (i.e. header that doesn't scroll) of the layout, which is at the top + * of the content area outside of the scrolling container. The header can only be inflated once + * per instance of this layout. + * + * @param header The layout to be inflated as the header. + * @return The root of the inflated header view. + */ + public View inflateStickyHeader(@LayoutRes int header) { + ViewStub stickyHeaderStub = findManagedViewById(R.id.suw_layout_sticky_header); + stickyHeaderStub.setLayoutResource(header); + return stickyHeaderStub.inflate(); + } + public ScrollView getScrollView() { final View view = findManagedViewById(R.id.suw_scroll_view); return view instanceof ScrollView ? (ScrollView) view : null; diff --git a/library/main/src/com/android/setupwizardlib/TemplateLayout.java b/library/main/src/com/android/setupwizardlib/TemplateLayout.java index 771592f..bd430db 100644 --- a/library/main/src/com/android/setupwizardlib/TemplateLayout.java +++ b/library/main/src/com/android/setupwizardlib/TemplateLayout.java @@ -103,7 +103,7 @@ public class TemplateLayout extends FrameLayout { * by this view but not currently added to the view hierarchy. e.g. recycler view or list view * headers that are not currently shown. */ - public View findManagedViewById(int id) { + public T findManagedViewById(int id) { return findViewById(id); } diff --git a/library/platform/res/values-v23/styles.xml b/library/platform/res/values-v23/styles.xml index 61a75fb..2f06636 100644 --- a/library/platform/res/values-v23/styles.xml +++ b/library/platform/res/values-v23/styles.xml @@ -108,6 +108,7 @@ @dimen/suw_items_glif_icon_divider_inset @dimen/suw_items_glif_text_divider_inset start + @style/SuwGlifIcon @style/SuwItemContainer.Description.Glif @style/SuwItemTitle.GlifDescription @color/suw_list_item_icon_color_dark @@ -140,6 +141,7 @@ @dimen/suw_items_glif_icon_divider_inset @dimen/suw_items_glif_text_divider_inset start + @style/SuwGlifIcon @style/SuwItemContainer.Description.Glif @style/SuwItemTitle.GlifDescription @color/suw_list_item_icon_color_light diff --git a/library/recyclerview/res/layout/suw_glif_recycler_template_content.xml b/library/recyclerview/res/layout/suw_glif_recycler_template_content.xml index e8d209b..c16f85a 100644 --- a/library/recyclerview/res/layout/suw_glif_recycler_template_content.xml +++ b/library/recyclerview/res/layout/suw_glif_recycler_template_content.xml @@ -23,6 +23,11 @@ android:layout_height="match_parent" android:orientation="vertical"> + + T findManagedViewById(int id) { final View header = mRecyclerMixin.getHeader(); if (header != null) { - final View view = header.findViewById(id); + final T view = header.findViewById(id); if (view != null) { return view; } diff --git a/library/recyclerview/src/com/android/setupwizardlib/SetupWizardRecyclerLayout.java b/library/recyclerview/src/com/android/setupwizardlib/SetupWizardRecyclerLayout.java index 5ff825d..c5b5afc 100644 --- a/library/recyclerview/src/com/android/setupwizardlib/SetupWizardRecyclerLayout.java +++ b/library/recyclerview/src/com/android/setupwizardlib/SetupWizardRecyclerLayout.java @@ -127,10 +127,10 @@ public class SetupWizardRecyclerLayout extends SetupWizardLayout { } @Override - public View findManagedViewById(int id) { + public T findManagedViewById(int id) { final View header = mRecyclerMixin.getHeader(); if (header != null) { - final View view = header.findViewById(id); + final T view = header.findViewById(id); if (view != null) { return view; } diff --git a/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java b/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java index 360dfe2..e07d5fa 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/GlifLayoutTest.java @@ -267,6 +267,47 @@ public class GlifLayoutTest { assertNotNull(layout.findViewById(android.R.id.text1)); } + @Test + public void inflateStickyHeader_shouldAddViewToLayout() { + GlifLayout layout = new GlifLayout(mContext); + + final View view = layout.inflateStickyHeader(android.R.layout.simple_list_item_1); + assertEquals(android.R.id.text1, view.getId()); + assertNotNull(layout.findViewById(android.R.id.text1)); + } + + @Config(qualifiers = "sw600dp") + @Test + public void inflateStickyHeader_whenOnTablets_shouldAddViewToLayout() { + inflateStickyHeader_shouldAddViewToLayout(); + } + + @Test + public void inflateStickyHeader_whenInXml_shouldAddViewToLayout() { + GlifLayout layout = new GlifLayout( + mContext, + Robolectric.buildAttributeSet() + .addAttribute(R.attr.suwStickyHeader, "@android:layout/simple_list_item_1") + .build()); + + assertNotNull(layout.findViewById(android.R.id.text1)); + } + + @Test + public void inflateStickyHeader_whenOnBlankTemplate_shouldAddViewToLayout() { + GlifLayout layout = new GlifLayout(mContext, R.layout.suw_glif_blank_template); + + final View view = layout.inflateStickyHeader(android.R.layout.simple_list_item_1); + assertEquals(android.R.id.text1, view.getId()); + assertNotNull(layout.findViewById(android.R.id.text1)); + } + + @Config(qualifiers = "sw600dp") + @Test + public void inflateStickyHeader_whenOnBlankTemplateTablet_shouldAddViewToLayout() { + inflateStickyHeader_whenOnBlankTemplate_shouldAddViewToLayout(); + } + @Config(sdk = { VERSION_CODES.M, Config.NEWEST_SDK }) @Test public void createFromXml_shouldSetLayoutFullscreen_whenLayoutFullscreenIsNotSet() {