Add suwFooter attribute to GlifLayout
Add the suwFooter attribute so custom footer layouts can be easily added, in conjunction with <aapt:attr> tag. Test: ./gradlew connectedAndroidTest test Bug: 36009807 Change-Id: Id7d937486451e34bdc30775a0f5f3dfcde47598f
This commit is contained in:
parent
925f4b24fc
commit
48c121912f
|
@ -88,9 +88,10 @@
|
|||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SuwGlifLayout">
|
||||
<attr name="suwColorPrimary" />
|
||||
<attr name="suwBackgroundPatterned" format="boolean" />
|
||||
<attr name="suwBackgroundBaseColor" format="color" />
|
||||
<attr name="suwColorPrimary" />
|
||||
<attr name="suwFooter" format="reference" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SuwStatusBarBackgroundLayout">
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.util.AttributeSet;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewStub;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
@ -123,6 +124,11 @@ public class GlifLayout extends TemplateLayout {
|
|||
a.getBoolean(R.styleable.SuwGlifLayout_suwBackgroundPatterned, true);
|
||||
setBackgroundPatterned(backgroundPatterned);
|
||||
|
||||
final int footer = a.getResourceId(R.styleable.SuwGlifLayout_suwFooter, 0);
|
||||
if (footer != 0) {
|
||||
inflateFooter(footer);
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
|
@ -142,6 +148,19 @@ public class GlifLayout extends TemplateLayout {
|
|||
return super.findContainer(containerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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);
|
||||
footerStub.setLayoutResource(footer);
|
||||
return footerStub.inflate();
|
||||
}
|
||||
|
||||
public ScrollView getScrollView() {
|
||||
final View view = findManagedViewById(R.id.suw_scroll_view);
|
||||
return view instanceof ScrollView ? (ScrollView) view : null;
|
||||
|
|
|
@ -49,6 +49,7 @@ import com.android.setupwizardlib.view.StatusBarBackgroundLayout;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SuwLibRobolectricTestRunner.class)
|
||||
|
@ -224,6 +225,32 @@ public class GlifLayoutTest {
|
|||
layout.getMixin(ProgressBarMixin.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInflateFooter() {
|
||||
GlifLayout layout = new GlifLayout(mContext);
|
||||
|
||||
final View view = layout.inflateFooter(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 testInflateFooterTablet() {
|
||||
testInflateFooter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFooterXml() {
|
||||
GlifLayout layout = new GlifLayout(
|
||||
mContext,
|
||||
Robolectric.buildAttributeSet()
|
||||
.addAttribute(R.attr.suwFooter, "@android:layout/simple_list_item_1")
|
||||
.build());
|
||||
|
||||
assertNotNull(layout.findViewById(android.R.id.text1));
|
||||
}
|
||||
|
||||
private Drawable getPhoneBackground(GlifLayout layout) {
|
||||
final StatusBarBackgroundLayout patternBg =
|
||||
(StatusBarBackgroundLayout) layout.findManagedViewById(R.id.suw_pattern_bg);
|
||||
|
|
Loading…
Reference in a new issue