diff options
author | Maurice Lam <yukl@google.com> | 2015-10-08 16:24:01 -0700 |
---|---|---|
committer | Maurice Lam <yukl@google.com> | 2015-10-08 16:33:11 -0700 |
commit | c5bf1cb9cb52f95f862eedb8d4f2c71c1ff1a79f (patch) | |
tree | 70fe20af65a473492deb073ab4898b527d58dffb /library | |
parent | 5bf291fde3dfd64f264d525534730514a279c8fc (diff) | |
download | setupwizard-c5bf1cb9cb52f95f862eedb8d4f2c71c1ff1a79f.tar.gz |
[SuwLib] Single-line item
Hide the summary TextView if summary is not set, so that the title
will be centered vertically.
Change-Id: Idbc5f35f7ce48a7338eb0b7061ef5d02b74b7b65
Diffstat (limited to 'library')
4 files changed, 34 insertions, 3 deletions
diff --git a/library/eclair-mr1/res/layout/suw_items_text.xml b/library/eclair-mr1/res/layout/suw_items_text.xml index 89a4894..065c14e 100644 --- a/library/eclair-mr1/res/layout/suw_items_text.xml +++ b/library/eclair-mr1/res/layout/suw_items_text.xml @@ -43,6 +43,7 @@ android:gravity="start" android:textAlignment="viewStart" android:textAppearance="?attr/textAppearanceListItemSmall" + android:visibility="gone" tools:ignore="UnusedAttribute" /> </LinearLayout> diff --git a/library/main/src/com/android/setupwizardlib/items/Item.java b/library/main/src/com/android/setupwizardlib/items/Item.java index 9c6832a..d6af65d 100644 --- a/library/main/src/com/android/setupwizardlib/items/Item.java +++ b/library/main/src/com/android/setupwizardlib/items/Item.java @@ -82,7 +82,13 @@ public class Item { // TODO: Show icon if defined TextView label = (TextView) view.findViewById(R.id.suw_items_title); label.setText(getTitle()); - TextView summary = (TextView) view.findViewById(R.id.suw_items_summary); - summary.setText(getSummary()); + TextView summaryView = (TextView) view.findViewById(R.id.suw_items_summary); + CharSequence summary = getSummary(); + if (summary != null && summary.length() > 0) { + summaryView.setText(summary); + summaryView.setVisibility(View.VISIBLE); + } else { + summaryView.setVisibility(View.GONE); + } } } diff --git a/library/platform/res/layout-v21/suw_items_text.xml b/library/platform/res/layout-v21/suw_items_text.xml index cda5487..ca6c742 100644 --- a/library/platform/res/layout-v21/suw_items_text.xml +++ b/library/platform/res/layout-v21/suw_items_text.xml @@ -36,6 +36,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:textAlignment="viewStart" - android:textAppearance="?android:attr/textAppearanceListItemSmall" /> + android:textAppearance="?android:attr/textAppearanceListItemSmall" + android:visibility="gone" /> </LinearLayout> diff --git a/library/test/src/com/android/setupwizardlib/test/ItemTest.java b/library/test/src/com/android/setupwizardlib/test/ItemTest.java index e6bf94e..c739d99 100644 --- a/library/test/src/com/android/setupwizardlib/test/ItemTest.java +++ b/library/test/src/com/android/setupwizardlib/test/ItemTest.java @@ -44,6 +44,17 @@ public class ItemTest extends AndroidTestCase { mSummaryView.getText().toString()); } + @SmallTest + public void testSingleLineItem() { + Item item = new SingleLineTestItem(mContext); + View view = createLayout(); + + item.onBindView(view); + + assertEquals("Title should be \"TestTitle\"", "TestTitle", mTitleView.getText().toString()); + assertEquals("Summary should be gone", View.GONE, mSummaryView.getVisibility()); + } + private ViewGroup createLayout() { ViewGroup root = new FrameLayout(mContext); @@ -73,4 +84,16 @@ public class ItemTest extends AndroidTestCase { return "TestSummary"; } } + + private static class SingleLineTestItem extends Item { + + public SingleLineTestItem(Context context) { + super(context, null); + } + + @Override + public CharSequence getTitle() { + return "TestTitle"; + } + } } |