summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2016-06-21 00:37:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-06-21 00:37:08 +0000
commit50e31a5e909a65cf6457dd80b9c9150a6e76b6a7 (patch)
treee225e35eecee26187645502d9d7d50fd5bf897d6
parent96da2eaca4b1a5876a7787394a5dd686d5129d6f (diff)
parentb6fb8bb15f4c6b08eb7f875c21df1005a8679594 (diff)
downloadsetupwizard-50e31a5e909a65cf6457dd80b9c9150a6e76b6a7.tar.gz
Merge "[SuwLib] Allow peeking progress bar" into ub-setupwizard-ceridwen
-rw-r--r--library/main/src/com/android/setupwizardlib/GlifLayout.java49
-rw-r--r--library/test/src/com/android/setupwizardlib/test/GlifLayoutTest.java14
2 files changed, 51 insertions, 12 deletions
diff --git a/library/main/src/com/android/setupwizardlib/GlifLayout.java b/library/main/src/com/android/setupwizardlib/GlifLayout.java
index c3202ad..3d79da5 100644
--- a/library/main/src/com/android/setupwizardlib/GlifLayout.java
+++ b/library/main/src/com/android/setupwizardlib/GlifLayout.java
@@ -234,28 +234,53 @@ public class GlifLayout extends TemplateLayout {
}
public void setProgressBarShown(boolean shown) {
- final View progressBar = findManagedViewById(R.id.suw_layout_progress);
if (shown) {
- if (progressBar != null) {
- progressBar.setVisibility(View.VISIBLE);
- } else {
- final ViewStub progressBarStub =
- (ViewStub) findManagedViewById(R.id.suw_layout_progress_stub);
- if (progressBarStub != null) {
- progressBarStub.inflate();
- }
- }
- setProgressBarColor(mPrimaryColor);
+ View progressBar = getProgressBar();
+ progressBar.setVisibility(View.VISIBLE);
} else {
+ View progressBar = peekProgressBar();
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}
}
+ /**
+ * Gets the progress bar in the layout. If the progress bar has not been used before, it will be
+ * installed (i.e. inflated from its view stub).
+ *
+ * @return The progress bar of this layout. May be null only if the template used doesn't have a
+ * progress bar built-in.
+ */
+ private ProgressBar getProgressBar() {
+ final View progressBar = peekProgressBar();
+ if (progressBar == null) {
+ final ViewStub progressBarStub =
+ (ViewStub) findManagedViewById(R.id.suw_layout_progress_stub);
+ if (progressBarStub != null) {
+ progressBarStub.inflate();
+ }
+ setProgressBarColor(mPrimaryColor);
+ }
+ return peekProgressBar();
+ }
+
+ /**
+ * Gets the progress bar in the layout only if it has been installed.
+ * {@link #setProgressBarShown(boolean)} should be called before this to ensure the progress bar
+ * is set up correctly.
+ *
+ * @return The progress bar of this layout, or null if the progress bar is not installed. The
+ * null case can happen either if {@link #setProgressBarShown(boolean)} with true was
+ * not called before this, or if the template does not contain a progress bar.
+ */
+ public ProgressBar peekProgressBar() {
+ return (ProgressBar) findManagedViewById(R.id.suw_layout_progress);
+ }
+
private void setProgressBarColor(ColorStateList color) {
if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
- final ProgressBar bar = (ProgressBar) findManagedViewById(R.id.suw_layout_progress);
+ final ProgressBar bar = peekProgressBar();
if (bar != null) {
bar.setIndeterminateTintList(color);
}
diff --git a/library/test/src/com/android/setupwizardlib/test/GlifLayoutTest.java b/library/test/src/com/android/setupwizardlib/test/GlifLayoutTest.java
index 1ae620d..24351da 100644
--- a/library/test/src/com/android/setupwizardlib/test/GlifLayoutTest.java
+++ b/library/test/src/com/android/setupwizardlib/test/GlifLayoutTest.java
@@ -114,6 +114,20 @@ public class GlifLayoutTest extends InstrumentationTestCase {
}
}
+ @SmallTest
+ public void testPeekProgressBarNull() {
+ GlifLayout layout = new GlifLayout(mContext);
+ assertNull("PeekProgressBar should return null initially", layout.peekProgressBar());
+ }
+
+ @SmallTest
+ public void testPekkProgressBar() {
+ GlifLayout layout = new GlifLayout(mContext);
+ layout.setProgressBarShown(true);
+ assertNotNull("Peek progress bar should return the bar after setProgressBarShown(true)",
+ layout.peekProgressBar());
+ }
+
private void assertDefaultTemplateInflated(GlifLayout layout) {
View title = layout.findViewById(R.id.suw_layout_title);
assertNotNull("@id/suw_layout_title should not be null", title);