1111import android .view .View ;
1212import android .view .ViewGroup ;
1313import android .view .animation .AlphaAnimation ;
14- import android .widget .Adapter ;
15- import android .widget .AdapterView ;
16- import android .widget .Checkable ;
17- import android .widget .CompoundButton ;
18- import android .widget .ImageView ;
19- import android .widget .ProgressBar ;
20- import android .widget .RatingBar ;
21- import android .widget .TextView ;
14+ import android .widget .*;
2215
2316/**
2417 * Allows an abstraction of the ViewHolder pattern.<br>
@@ -61,12 +54,12 @@ protected AdapterHelper(Context context, ViewGroup parent, int layoutRes, int po
6154 }
6255
6356 /**
64- * This method is the only entry point to get a BaseAdapterHelper .
57+ * This method is the only entry point to get a AdapterHelper .
6558 *
6659 * @param context The current context.
6760 * @param convertView The convertView arg passed to the getView() method.
6861 * @param parent The parent arg passed to the getView() method.
69- * @return A BaseAdapterHelper instance.
62+ * @return A AdapterHelper instance.
7063 */
7164 public static AdapterHelper get (Context context , View convertView , ViewGroup parent , int layoutRes ) {
7265 return get (context , convertView , parent , layoutRes , -1 );
@@ -88,7 +81,7 @@ protected static AdapterHelper get(Context context, View convertView, ViewGroup
8881
8982 /**
9083 * This method allows you to retrieve a view and perform custom
91- * operations on it, not covered by the BaseAdapterHelper .<br/>
84+ * operations on it, not covered by the AdapterHelper .<br/>
9285 * If you think it's a common use case, please consider creating
9386 * a new issue at https://github.com/JoanZapata/base-adapter-helper/issues.
9487 *
@@ -103,7 +96,7 @@ public <T extends View> T getView(int viewId) {
10396 *
10497 * @param viewId The view id.
10598 * @param value The text to put in the text view.
106- * @return The BaseAdapterHelper for chaining.
99+ * @return The AdapterHelper for chaining.
107100 */
108101 public AdapterHelper setText (int viewId , CharSequence value ) {
109102 TextView view = retrieveView (viewId );
@@ -116,34 +109,20 @@ public AdapterHelper setText(int viewId, CharSequence value) {
116109 *
117110 * @param viewId The view id.
118111 * @param imageResId The image resource id.
119- * @return The BaseAdapterHelper for chaining.
112+ * @return The AdapterHelper for chaining.
120113 */
121114 public AdapterHelper setImageResource (int viewId , int imageResId ) {
122115 ImageView view = retrieveView (viewId );
123116 view .setImageResource (imageResId );
124117 return this ;
125118 }
126119
127- /**
128- * Will download an image from a URL or load an image from a path and put it in an ImageView.<br/>
129- * Modified by liyujiang at 2015.08.01
130- *
131- * @param viewId The view id.
132- * @param imageUri The image URL.
133- * @return The BaseAdapterHelper for chaining.
134- */
135- public AdapterHelper setImageUri (int viewId , String imageUri ) {
136- ImageView view = retrieveView (viewId );
137- //ImageLoader.getInstance(context).loadBitmap(imageUri, view);
138- return this ;
139- }
140-
141120 /**
142121 * Will set background color of a view.
143122 *
144123 * @param viewId The view id.
145124 * @param color A color, not a resource id.
146- * @return The BaseAdapterHelper for chaining.
125+ * @return The AdapterHelper for chaining.
147126 */
148127 public AdapterHelper setBackgroundColor (int viewId , int color ) {
149128 View view = retrieveView (viewId );
@@ -156,7 +135,7 @@ public AdapterHelper setBackgroundColor(int viewId, int color) {
156135 *
157136 * @param viewId The view id.
158137 * @param backgroundRes A resource to use as a background.
159- * @return The BaseAdapterHelper for chaining.
138+ * @return The AdapterHelper for chaining.
160139 */
161140 public AdapterHelper setBackgroundResource (int viewId , int backgroundRes ) {
162141 View view = retrieveView (viewId );
@@ -169,7 +148,7 @@ public AdapterHelper setBackgroundResource(int viewId, int backgroundRes) {
169148 *
170149 * @param viewId The view id.
171150 * @param textColor The text color (not a resource id).
172- * @return The BaseAdapterHelper for chaining.
151+ * @return The AdapterHelper for chaining.
173152 */
174153 public AdapterHelper setTextColor (int viewId , int textColor ) {
175154 TextView view = retrieveView (viewId );
@@ -182,7 +161,7 @@ public AdapterHelper setTextColor(int viewId, int textColor) {
182161 *
183162 * @param viewId The view id.
184163 * @param textColorRes The text color resource id.
185- * @return The BaseAdapterHelper for chaining.
164+ * @return The AdapterHelper for chaining.
186165 */
187166 public AdapterHelper setTextColorResource (int viewId , int textColorRes ) {
188167 TextView view = retrieveView (viewId );
@@ -195,7 +174,7 @@ public AdapterHelper setTextColorResource(int viewId, int textColorRes) {
195174 *
196175 * @param viewId The view id.
197176 * @param drawable The image drawable.
198- * @return The BaseAdapterHelper for chaining.
177+ * @return The AdapterHelper for chaining.
199178 */
200179 public AdapterHelper setImageDrawable (int viewId , Drawable drawable ) {
201180 ImageView view = retrieveView (viewId );
@@ -212,6 +191,35 @@ public AdapterHelper setImageBitmap(int viewId, Bitmap bitmap) {
212191 return this ;
213192 }
214193
194+ /**
195+ * Will download an image from a URL or load an image from a path and put it in an ImageView.<br/>
196+ * Modified by liyujiang at 2015.08.01
197+ *
198+ * @param viewId The view id.
199+ * @param imageUrl The image URL.
200+ * @return The AdapterHelper for chaining.
201+ */
202+ public AdapterHelper setImageUri (int viewId , String imageUrl ) {
203+ ImageView view = retrieveView (viewId );
204+ //ImageLoader.getInstance(context).loadBitmap(imageUrl, view);
205+ return this ;
206+ }
207+
208+ /**
209+ * Add by liyujiang at 2015.08.01
210+ *
211+ * @param viewId
212+ * @param imageUrl
213+ * @param maxWidth
214+ * @param maxHeight
215+ * @return
216+ */
217+ public AdapterHelper setImageUri (int viewId , String imageUrl , int maxWidth , int maxHeight ) {
218+ ImageView view = retrieveView (viewId );
219+ //ImageLoader.getInstance(context).loadBitmap(imageUrl, view, maxWidth, maxHeight);
220+ return this ;
221+ }
222+
215223 /**
216224 * Add an action to set the alpha of a view. Can be called multiple times.
217225 * Alpha between 0-1.
@@ -231,7 +239,7 @@ public AdapterHelper setAlpha(int viewId, float value) {
231239 *
232240 * @param viewId The view id.
233241 * @param visible True for VISIBLE, false for GONE.
234- * @return The BaseAdapterHelper for chaining.
242+ * @return The AdapterHelper for chaining.
235243 */
236244 public AdapterHelper setVisible (int viewId , boolean visible ) {
237245 View view = retrieveView (viewId );
@@ -243,7 +251,7 @@ public AdapterHelper setVisible(int viewId, boolean visible) {
243251 * Add links into a TextView.
244252 *
245253 * @param viewId The id of the TextView to linkify.
246- * @return The BaseAdapterHelper for chaining.
254+ * @return The AdapterHelper for chaining.
247255 */
248256 public AdapterHelper linkify (int viewId ) {
249257 TextView view = retrieveView (viewId );
@@ -287,7 +295,7 @@ public AdapterHelper setTypeface(Typeface typeface, int... viewIds) {
287295 *
288296 * @param viewId The view id.
289297 * @param progress The progress.
290- * @return The BaseAdapterHelper for chaining.
298+ * @return The AdapterHelper for chaining.
291299 */
292300 public AdapterHelper setProgress (int viewId , int progress ) {
293301 ProgressBar view = retrieveView (viewId );
@@ -301,7 +309,7 @@ public AdapterHelper setProgress(int viewId, int progress) {
301309 * @param viewId The view id.
302310 * @param progress The progress.
303311 * @param max The max value of a ProgressBar.
304- * @return The BaseAdapterHelper for chaining.
312+ * @return The AdapterHelper for chaining.
305313 */
306314 public AdapterHelper setProgress (int viewId , int progress , int max ) {
307315 ProgressBar view = retrieveView (viewId );
@@ -315,7 +323,7 @@ public AdapterHelper setProgress(int viewId, int progress, int max) {
315323 *
316324 * @param viewId The view id.
317325 * @param max The max value of a ProgressBar.
318- * @return The BaseAdapterHelper for chaining.
326+ * @return The AdapterHelper for chaining.
319327 */
320328 public AdapterHelper setMax (int viewId , int max ) {
321329 ProgressBar view = retrieveView (viewId );
@@ -328,7 +336,7 @@ public AdapterHelper setMax(int viewId, int max) {
328336 *
329337 * @param viewId The view id.
330338 * @param rating The rating.
331- * @return The BaseAdapterHelper for chaining.
339+ * @return The AdapterHelper for chaining.
332340 */
333341 public AdapterHelper setRating (int viewId , float rating ) {
334342 RatingBar view = retrieveView (viewId );
@@ -342,7 +350,7 @@ public AdapterHelper setRating(int viewId, float rating) {
342350 * @param viewId The view id.
343351 * @param rating The rating.
344352 * @param max The range of the RatingBar to 0...max.
345- * @return The BaseAdapterHelper for chaining.
353+ * @return The AdapterHelper for chaining.
346354 */
347355 public AdapterHelper setRating (int viewId , float rating , int max ) {
348356 RatingBar view = retrieveView (viewId );
@@ -356,7 +364,7 @@ public AdapterHelper setRating(int viewId, float rating, int max) {
356364 *
357365 * @param viewId The view id.
358366 * @param listener The on click listener;
359- * @return The BaseAdapterHelper for chaining.
367+ * @return The AdapterHelper for chaining.
360368 */
361369 public AdapterHelper setOnClickListener (int viewId , View .OnClickListener listener ) {
362370 View view = retrieveView (viewId );
@@ -369,7 +377,7 @@ public AdapterHelper setOnClickListener(int viewId, View.OnClickListener listene
369377 *
370378 * @param viewId The view id.
371379 * @param listener The on touch listener;
372- * @return The BaseAdapterHelper for chaining.
380+ * @return The AdapterHelper for chaining.
373381 */
374382 public AdapterHelper setOnTouchListener (int viewId , View .OnTouchListener listener ) {
375383 View view = retrieveView (viewId );
@@ -382,7 +390,7 @@ public AdapterHelper setOnTouchListener(int viewId, View.OnTouchListener listene
382390 *
383391 * @param viewId The view id.
384392 * @param listener The on long click listener;
385- * @return The BaseAdapterHelper for chaining.
393+ * @return The AdapterHelper for chaining.
386394 */
387395 public AdapterHelper setOnLongClickListener (int viewId , View .OnLongClickListener listener ) {
388396 View view = retrieveView (viewId );
@@ -409,7 +417,7 @@ public AdapterHelper setOnCheckedChangeListener(int viewId, CompoundButton.OnChe
409417 *
410418 * @param viewId The view id.
411419 * @param tag The tag;
412- * @return The BaseAdapterHelper for chaining.
420+ * @return The AdapterHelper for chaining.
413421 */
414422 public AdapterHelper setTag (int viewId , Object tag ) {
415423 View view = retrieveView (viewId );
@@ -423,7 +431,7 @@ public AdapterHelper setTag(int viewId, Object tag) {
423431 * @param viewId The view id.
424432 * @param key The key of tag;
425433 * @param tag The tag;
426- * @return The BaseAdapterHelper for chaining.
434+ * @return The AdapterHelper for chaining.
427435 */
428436 public AdapterHelper setTag (int viewId , int key , Object tag ) {
429437 View view = retrieveView (viewId );
@@ -436,11 +444,16 @@ public AdapterHelper setTag(int viewId, int key, Object tag) {
436444 *
437445 * @param viewId The view id.
438446 * @param checked The checked status;
439- * @return The BaseAdapterHelper for chaining.
447+ * @return The AdapterHelper for chaining.
440448 */
441449 public AdapterHelper setChecked (int viewId , boolean checked ) {
442- Checkable view = retrieveView (viewId );
443- view .setChecked (checked );
450+ View view = retrieveView (viewId );
451+ // FIXME: 2015/10/26 View²»ÄÜÇ¿ÖÆ×ª»»ÎªCheckable, thanks https://github.com/Flywhiter
452+ if (view instanceof CompoundButton ) {
453+ ((CompoundButton ) view ).setChecked (checked );
454+ } else if (view instanceof CheckedTextView ) {
455+ ((CheckedTextView ) view ).setChecked (checked );
456+ }
444457 return this ;
445458 }
446459
@@ -449,7 +462,7 @@ public AdapterHelper setChecked(int viewId, boolean checked) {
449462 *
450463 * @param viewId The view id.
451464 * @param adapter The adapter;
452- * @return The BaseAdapterHelper for chaining.
465+ * @return The AdapterHelper for chaining.
453466 */
454467 public AdapterHelper setAdapter (int viewId , Adapter adapter ) {
455468 AdapterView view = retrieveView (viewId );
@@ -472,7 +485,7 @@ public View getView() {
472485 */
473486 public int getPosition () {
474487 if (position == -1 ) {
475- throw new IllegalStateException ("Use BaseAdapterHelper constructor " +
488+ throw new IllegalStateException ("Use AdapterHelper constructor " +
476489 "with position if you need to retrieve the position." );
477490 }
478491 return position ;
0 commit comments