|
7 | 7 | import android.util.SparseArray;
|
8 | 8 | import android.view.View;
|
9 | 9 | import android.view.ViewGroup;
|
| 10 | +import android.view.ViewParent; |
10 | 11 | import android.widget.FrameLayout;
|
11 | 12 | import android.widget.FrameLayout.LayoutParams;
|
12 | 13 |
|
|
15 | 16 | * usage:<br>
|
16 | 17 | * //if set true, logs will print into logcat<br>
|
17 | 18 | * Gloading.debug(trueOrFalse);<br>
|
| 19 | + * |
18 | 20 | * //init the default loading status view creator ({@link Adapter})<br>
|
19 | 21 | * Gloading.initDefault(adapter);<br>
|
| 22 | + * |
20 | 23 | * //wrap an activity. return the holder<br>
|
21 | 24 | * Holder holder = Gloading.getDefault().wrap(activity);<br>
|
| 25 | + * |
22 | 26 | * //wrap an activity and set retry task. return the holder<br>
|
23 | 27 | * Holder holder = Gloading.getDefault().wrap(activity).withRetry(retryTask);<br>
|
| 28 | + * |
| 29 | + * //wrap a view and set retry task. return the holder<br> |
| 30 | + * Holder holder = Gloading.getDefault().wrap(view).withRetry(retryTask);<br> |
| 31 | + * |
| 32 | + * //cover a view which relatives to another view within a parent of RelativeLayout or ConstraintLayout parent |
| 33 | + * Holder holder = Gloading.getDefault().cover(view).withRetry(retryTask);<br> |
24 | 34 | * <br>
|
25 | 35 | * holder.showLoading() //show loading status view by holder<br>
|
26 | 36 | * holder.showLoadSuccess() //show load success status view by holder (frequently, hide gloading)<br>
|
@@ -132,6 +142,23 @@ public Holder wrap(View view) {
|
132 | 142 | return new Holder(mAdapter, view.getContext(), wrapper);
|
133 | 143 | }
|
134 | 144 |
|
| 145 | + /** |
| 146 | + * loadingStatusView shows cover the view with the same LayoutParams object |
| 147 | + * this method is useful with RelativeLayout and ConstraintLayout |
| 148 | + * @param view the view which needs show loading status |
| 149 | + * @return Holder |
| 150 | + */ |
| 151 | + public Holder cover(View view) { |
| 152 | + ViewParent parent = view.getParent(); |
| 153 | + if (parent == null) { |
| 154 | + throw new RuntimeException("view has no parent to show gloading as cover!"); |
| 155 | + } |
| 156 | + ViewGroup viewGroup = (ViewGroup) parent; |
| 157 | + FrameLayout wrapper = new FrameLayout(view.getContext()); |
| 158 | + viewGroup.addView(wrapper, view.getLayoutParams()); |
| 159 | + return new Holder(mAdapter, view.getContext(), wrapper); |
| 160 | + } |
| 161 | + |
135 | 162 | /**
|
136 | 163 | * Gloading holder<br>
|
137 | 164 | * create by {@link Gloading#wrap(Activity)} or {@link Gloading#wrap(View)}<br>
|
|
0 commit comments