[SuwLib] Fix showProgressBar for RecyclerLayout
Fix show and hide progress bar for RecyclerLayout by introducing findManagedViewById method in SetupWizardLayout, so that it can find progress bar even if it is not currently laid out in the view hierarchy. Also added setProgressBarShown(boolean) to make the interface consistent with GlifLayout. Change-Id: Icc44d91e2d6030b210304ad81c158be67b7050f1
This commit is contained in:
parent
3885d8491a
commit
ec9d8c8aa8
|
@ -50,9 +50,8 @@ public class SetupWizardRecyclerLayout extends SetupWizardLayout {
|
|||
|
||||
private RecyclerView.Adapter mAdapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private View mHeader;
|
||||
|
||||
private TextView mHeaderTextView;
|
||||
private View mDecorationView;
|
||||
private DividerItemDecoration mDividerDecoration;
|
||||
private Drawable mDefaultDivider;
|
||||
private Drawable mDivider;
|
||||
|
@ -138,9 +137,7 @@ public class SetupWizardRecyclerLayout extends SetupWizardLayout {
|
|||
mRecyclerView = recyclerView;
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
if (mRecyclerView instanceof HeaderRecyclerView) {
|
||||
final View header = ((HeaderRecyclerView) mRecyclerView).getHeader();
|
||||
mHeaderTextView = (TextView) header.findViewById(R.id.suw_layout_title);
|
||||
mDecorationView = header.findViewById(R.id.suw_layout_decor);
|
||||
mHeader = ((HeaderRecyclerView) mRecyclerView).getHeader();
|
||||
}
|
||||
mDividerDecoration = DividerItemDecoration.getDefault(getContext());
|
||||
mRecyclerView.addItemDecoration(mDividerDecoration);
|
||||
|
@ -155,21 +152,14 @@ public class SetupWizardRecyclerLayout extends SetupWizardLayout {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected TextView getHeaderTextView() {
|
||||
if (mHeaderTextView != null) {
|
||||
return mHeaderTextView;
|
||||
} else {
|
||||
return super.getHeaderTextView();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected View getDecorationView() {
|
||||
if (mDecorationView != null) {
|
||||
return mDecorationView;
|
||||
} else {
|
||||
return super.getDecorationView();
|
||||
protected View findManagedViewById(int id) {
|
||||
if (mHeader != null) {
|
||||
final View view = mHeader.findViewById(id);
|
||||
if (view != null) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return super.findViewById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.view.ContextThemeWrapper;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.setupwizardlib.SetupWizardPreferenceLayout;
|
||||
|
||||
|
@ -89,9 +88,9 @@ public class SetupWizardPreferenceLayoutTest extends InstrumentationTestCase {
|
|||
|
||||
if (layout instanceof TestLayout) {
|
||||
assertNotNull("Header text view should not be null",
|
||||
((TestLayout) layout).getHeaderTextView());
|
||||
((TestLayout) layout).findManagedViewById(R.id.suw_layout_title));
|
||||
assertNotNull("Decoration view should not be null",
|
||||
((TestLayout) layout).getDecorationView());
|
||||
((TestLayout) layout).findManagedViewById(R.id.suw_layout_decor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -103,13 +102,8 @@ public class SetupWizardPreferenceLayoutTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TextView getHeaderTextView() {
|
||||
return super.getHeaderTextView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDecorationView() {
|
||||
return super.getDecorationView();
|
||||
public View findManagedViewById(int id) {
|
||||
return super.findManagedViewById(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import android.view.ContextThemeWrapper;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.setupwizardlib.SetupWizardRecyclerLayout;
|
||||
|
||||
|
@ -113,7 +112,9 @@ public class SetupWizardRecyclerLayoutTest extends InstrumentationTestCase {
|
|||
|
||||
if (layout instanceof TestLayout) {
|
||||
assertNotNull("Header text view should not be null",
|
||||
((TestLayout) layout).getHeaderTextView());
|
||||
((TestLayout) layout).findManagedViewById(R.id.suw_layout_title));
|
||||
assertNotNull("Decoration view should not be null",
|
||||
((TestLayout) layout).findManagedViewById(R.id.suw_layout_decor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,8 +126,9 @@ public class SetupWizardRecyclerLayoutTest extends InstrumentationTestCase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TextView getHeaderTextView() {
|
||||
return super.getHeaderTextView();
|
||||
public View findManagedViewById(int id) {
|
||||
return super.findManagedViewById(id);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,12 +174,12 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
}
|
||||
|
||||
public NavigationBar getNavigationBar() {
|
||||
final View view = findViewById(R.id.suw_layout_navigation_bar);
|
||||
final View view = findManagedViewById(R.id.suw_layout_navigation_bar);
|
||||
return view instanceof NavigationBar ? (NavigationBar) view : null;
|
||||
}
|
||||
|
||||
public ScrollView getScrollView() {
|
||||
final View view = findViewById(R.id.suw_bottom_scroll_view);
|
||||
final View view = findManagedViewById(R.id.suw_bottom_scroll_view);
|
||||
return view instanceof ScrollView ? (ScrollView) view : null;
|
||||
}
|
||||
|
||||
|
@ -194,33 +194,25 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
}
|
||||
}
|
||||
|
||||
protected TextView getHeaderTextView() {
|
||||
return (TextView) findViewById(R.id.suw_layout_title);
|
||||
}
|
||||
|
||||
public void setHeaderText(int title) {
|
||||
final TextView titleView = getHeaderTextView();
|
||||
final TextView titleView = (TextView) findManagedViewById(R.id.suw_layout_title);
|
||||
if (titleView != null) {
|
||||
titleView.setText(title);
|
||||
}
|
||||
}
|
||||
|
||||
public void setHeaderText(CharSequence title) {
|
||||
final TextView titleView = getHeaderTextView();
|
||||
final TextView titleView = (TextView) findManagedViewById(R.id.suw_layout_title);
|
||||
if (titleView != null) {
|
||||
titleView.setText(title);
|
||||
}
|
||||
}
|
||||
|
||||
public CharSequence getHeaderText() {
|
||||
final TextView titleView = getHeaderTextView();
|
||||
final TextView titleView = (TextView) findManagedViewById(R.id.suw_layout_title);
|
||||
return titleView != null ? titleView.getText() : null;
|
||||
}
|
||||
|
||||
protected View getDecorationView() {
|
||||
return findViewById(R.id.suw_layout_decor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the illustration of the layout. The drawable will be applied as is, and the bounds will
|
||||
* be set as implemented in {@link com.android.setupwizardlib.view.Illustration}. To create
|
||||
|
@ -230,7 +222,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
* @param drawable The drawable specifying the illustration.
|
||||
*/
|
||||
public void setIllustration(Drawable drawable) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view instanceof Illustration) {
|
||||
final Illustration illustration = (Illustration) view;
|
||||
illustration.setIllustration(drawable);
|
||||
|
@ -247,7 +239,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
* @param horizontalTile Resource ID of the horizontally repeating tile for tablet layout.
|
||||
*/
|
||||
public void setIllustration(int asset, int horizontalTile) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view instanceof Illustration) {
|
||||
final Illustration illustration = (Illustration) view;
|
||||
final Drawable illustrationDrawable = getIllustration(asset, horizontalTile);
|
||||
|
@ -256,7 +248,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
}
|
||||
|
||||
private void setIllustration(Drawable asset, Drawable horizontalTile) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view instanceof Illustration) {
|
||||
final Illustration illustration = (Illustration) view;
|
||||
final Drawable illustrationDrawable = getIllustration(asset, horizontalTile);
|
||||
|
@ -272,7 +264,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
* @see com.android.setupwizardlib.view.Illustration#setAspectRatio(float)
|
||||
*/
|
||||
public void setIllustrationAspectRatio(float aspectRatio) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view instanceof Illustration) {
|
||||
final Illustration illustration = (Illustration) view;
|
||||
illustration.setAspectRatio(aspectRatio);
|
||||
|
@ -290,7 +282,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
* @param paddingTop The top padding in pixels.
|
||||
*/
|
||||
public void setDecorPaddingTop(int paddingTop) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view != null) {
|
||||
view.setPadding(view.getPaddingLeft(), paddingTop, view.getPaddingRight(),
|
||||
view.getPaddingBottom());
|
||||
|
@ -302,7 +294,7 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
* a bitmap tile and you want it to repeat, use {@link #setBackgroundTile(int)} instead.
|
||||
*/
|
||||
public void setLayoutBackground(Drawable background) {
|
||||
final View view = getDecorationView();
|
||||
final View view = findManagedViewById(R.id.suw_layout_decor);
|
||||
if (view != null) {
|
||||
//noinspection deprecation
|
||||
view.setBackgroundDrawable(background);
|
||||
|
@ -361,28 +353,52 @@ public class SetupWizardLayout extends TemplateLayout {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link android.view.View#findViewById(int)}, but may include views that are managed
|
||||
* by this view but not currently added to the view hierarchy. e.g. recycler view or list view
|
||||
* headers that are not currently shown.
|
||||
*/
|
||||
protected View findManagedViewById(int id) {
|
||||
return findViewById(id);
|
||||
}
|
||||
|
||||
public boolean isProgressBarShown() {
|
||||
final View progressBar = findViewById(R.id.suw_layout_progress);
|
||||
final View progressBar = findManagedViewById(R.id.suw_layout_progress);
|
||||
return progressBar != null && progressBar.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public void showProgressBar() {
|
||||
final View progressBar = findViewById(R.id.suw_layout_progress);
|
||||
/**
|
||||
* Sets whether the progress bar below the header text is shown or not. The progress bar is
|
||||
* a lazily inflated ViewStub, which means the progress bar will not actually be part of the
|
||||
* view hierarchy until the first time this is set to {@code true}.
|
||||
*/
|
||||
public void setProgressBarShown(boolean shown) {
|
||||
final View progressBar = findManagedViewById(R.id.suw_layout_progress);
|
||||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
final ViewStub progressBarStub = (ViewStub) findViewById(R.id.suw_layout_progress_stub);
|
||||
progressBar.setVisibility(shown ? View.VISIBLE : View.GONE);
|
||||
} else if (shown) {
|
||||
final ViewStub progressBarStub =
|
||||
(ViewStub) findManagedViewById(R.id.suw_layout_progress_stub);
|
||||
if (progressBarStub != null) {
|
||||
progressBarStub.inflate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setProgressBarShown(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void showProgressBar() {
|
||||
setProgressBarShown(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setProgressBarShown(boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void hideProgressBar() {
|
||||
final View progressBar = findViewById(R.id.suw_layout_progress);
|
||||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
setProgressBarShown(false);
|
||||
}
|
||||
|
||||
/* Misc */
|
||||
|
|
Loading…
Reference in a new issue