/**
* Copyright 2013 Joan Zapata
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.mydownloadmanger.adapter.quickadpter;
import com.nostra13.universalimageloader.core.ImageLoader;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.util.Linkify;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
//import com.squareup.picasso.Picasso;
//import com.squareup.picasso.RequestCreator;
/**
* Allows an abstraction of the ViewHolder pattern.<br>
* <br>
* <p/>
* <b>Usage</b>
* <p/>
*
* <pre>
* return BaseAdapterHelper.get(context, convertView, parent, R.layout.item)
* .setText(R.id.tvName, contact.getName())
* .setText(R.id.tvEmails, contact.getEmails().toString())
* .setText(R.id.tvNumbers, contact.getNumbers().toString()).getView();
* </pre>
*/
public class BaseAdapterHelper
{
/** Views indexed with their IDs */
private final SparseArray<View> views;
private final Context context;
private int position;
private View convertView;
public int layoutId;
/**
* Package private field to retain the associated user object and detect a
* change
*/
Object associatedObject;
protected BaseAdapterHelper(Context context, ViewGroup parent,
int layoutId, int position)
{
this.context = context;
this.position = position;
this.layoutId = layoutId;
this.views = new SparseArray<View>();
convertView = LayoutInflater.from(context) //
.inflate(layoutId, parent, false);
convertView.setTag(this);
}
/**
* This method is the only entry point to get a BaseAdapterHelper.
*
* @param context
* The current context.
* @param convertView
* The convertView arg passed to the getView() method.
* @param parent
* The parent arg passed to the getView() method.
* @return A BaseAdapterHelper instance.
*/
public static BaseAdapterHelper get(Context context, View convertView,
ViewGroup parent, int layoutId)
{
return get(context, convertView, parent, layoutId, -1);
}
/** This method is package private and should only be used by QuickAdapter. */
static BaseAdapterHelper get(Context context, View convertView,
ViewGroup parent, int layoutId, int position)
{
if (convertView == null)
{
return new BaseAdapterHelper(context, parent, layoutId, position);
}
// Retrieve the existing helper and update its position
BaseAdapterHelper existingHelper = (BaseAdapterHelper) convertView
.getTag();
if (existingHelper.layoutId != layoutId)
{
return new BaseAdapterHelper(context, parent, layoutId, position);
}
existingHelper.position = position;
return existingHelper;
}
/**
* This method allows you to retrieve a view and perform custom operations
* on it, not covered by the BaseAdapterHelper.<br/>
* If you think it's a common use case, please consider creating a new issue
* at https://github.com/JoanZapata/base-adapter-helper/issues.
*
* @param viewId
* The id of the view you want to retrieve.
*/
public <T extends View> T getView(int viewId)
{
return retrieveView(viewId);
}
@SuppressWarnings("unchecked")
protected <T extends View> T retrieveView(int viewId)
{
View view = views.get(viewId);
if (view == null)
{
view = convertView.findViewById(viewId);
views.put(viewId, view);
}
return (T) view;
}
/**
* Will set the text of a TextView.
*
* @param viewId
* The view id.
* @param value
* The text to put in the text view.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setText(int viewId, String value)
{
TextView view = retrieveView(viewId);
view.setText(value);
return this;
}
public BaseAdapterHelper setText(int viewId, int value)
{
TextView view = retrieveView(viewId);
view.setText(value);
return this;
}
/**
* Will set the image of an ImageView from a resource id.
*
* @param viewId
* The view id.
* @param imageResId
* The image resource id.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setImageResource(int viewId, int imageResId)
{
ImageView view = retrieveView(viewId);
view.setImageResource(imageResId);
return this;
}
/**
* Will set background color of a view.
*
* @param viewId
* The view id.
* @param color
* A color, not a resource id.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setBackgroundColor(int viewId, int color)
{
View view = retrieveView(viewId);
view.setBackgroundColor(color);
return this;
}
/**
* Will set background of a view.
*
* @param viewId
* The view id.
* @param backgroundRes
* A resource to use as a background.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setBackgroundRes(int viewId, int backgroundRes)
{
View view = retrieveView(viewId);
view.setBackgroundResource(backgroundRes);
return this;
}
/**
* Will set text color of a TextView.
*
* @param viewId
* The view id.
* @param textColor
* The text color (not a resource id).
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setTextColor(int viewId, int textColor)
{
TextView view = retrieveView(viewId);
view.setTextColor(textColor);
return this;
}
/**
* Will set text color of a TextView.
*
* @param viewId
* The view id.
* @param textColorRes
* The text color resource id.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setTextColorRes(int viewId, int textColorRes)
{
TextView view = retrieveView(viewId);
view.setTextColor(context.getResources().getColor(textColorRes));
return this;
}
/**
* Will set the image of an ImageView from a drawable.
*
* @param viewId
* The view id.
* @param drawable
* The image drawable.
* @return The BaseAdapterHelper for chaining.
*/
public BaseAdapterHelper setImageDrawable(int viewId, Drawable drawable)
{
ImageView view = retrieveView(viewId);
view.setImageDrawable(drawable);
return this;
}
/**
* Will download an image from a URL and put it in an ImageView.<br/>
* It uses Square's Picasso library to download the image asynchronously and
* put the result into the ImageView.<br/>
* Picasso manages recycling of views in a ListView.<br/>
* If you need more control over the Picasso settings, use
* {BaseAdapterHelper#setImageBuilder}.
*
* @param viewId
* The view id.
* @param imageUrl
* The image URL.
* @ret
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mydownloadmanger.zip (91个子文件)
mydownloadmanger
gradlew.bat 2KB
gradlew 5KB
gradle.properties 953B
app
proguard-rules.pro 967B
src
test
java
com
example
mydownloadmanger
ExampleUnitTest.java 422B
main
res
mipmap-xxxhdpi
ic_launcher.png 10KB
ic_launcher_round.png 14KB
drawable
ic_launcher_round.png 6KB
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 4KB
values
colors.xml 214B
strings.xml 411B
styles.xml 1KB
dimens.xml 70B
mipmap-xxhdpi
ic_launcher.png 8KB
ic_launcher_round.png 10KB
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
ic_launcher_round.png 6KB
layout
activity_download_detail.xml 844B
fragment_load_listview.xml 408B
activity_start.xml 444B
loaditem.xml 2KB
activity_main.xml 1KB
fragment_load_recycleview.xml 463B
xml
file_paths.xml 503B
assets
apkurl.xml 3KB
java
com
example
mydownloadmanger
LoadRecycleViewFragment.java 2KB
LoadListViewQucikAdapterFragment.java 2KB
LoadListViewBaseAdapterFragment.java 2KB
FileProvider7.java 3KB
AnrBlocktUtil.java 3KB
MainActivity.java 3KB
download
DownloadInfo.java 3KB
DownLoadManager.java 12KB
BaseLoadTask.java 740B
ThreadPoolManager.java 918B
DownloadUtil.java 5KB
adapter
LoadBaseAdapter.java 9KB
LoadRecycleViewAdapter.java 8KB
quickadpter
EnhancedQuickAdapter.java 3KB
BaseAdapterHelper.java 16KB
MultiItemTypeSupport.java 218B
BaseQuickAdapter.java 8KB
QuickAdapter.java 3KB
AbsAdapter.java 726B
LoadQucikAdapter.java 7KB
MyApplication.java 3KB
BaseActivity.java 6KB
StartActivity.java 2KB
DownloadDetailActivity.java 7KB
ApkUrlParser.java 2KB
AndroidManifest.xml 2KB
app.iml 10KB
.gitignore 8B
mydownloadmanger.iml 9KB
build.gradle 806B
libs
universal-image-loader-1.9.4-with-sources.jar 284KB
gradle
wrapper
gradle-wrapper.jar 52KB
gradle-wrapper.properties 234B
.idea
gradle.xml 626B
runConfigurations.xml 564B
misc.xml 2KB
copyright
profiles_settings.xml 76B
modules.xml 369B
compiler.xml 686B
workspace.xml 147KB
libraries
support_annotations_25_3_1.xml 541B
support_v4_25_3_1.xml 404B
support_vector_drawable_25_3_1.xml 621B
transition_25_1_1.xml 582B
permission_1_1_0.xml 587B
recyclerview_v7_25_1_1.xml 597B
alertdialog_1_0_1.xml 602B
support_core_utils_25_3_1.xml 606B
animated_vector_drawable_25_3_1.xml 624B
hamcrest_core_1_3.xml 508B
design_25_1_1.xml 570B
junit_4_12.xml 459B
support_compat_25_3_1.xml 594B
support_core_ui_25_3_1.xml 597B
appcompat_v7_25_3_1.xml 588B
support_media_compat_25_3_1.xml 612B
universal_image_loader_1_9_4_with_sources.xml 285B
support_fragment_25_3_1.xml 600B
local.properties 574B
config.gradle 0B
mydownloadmanger.iml 870B
settings.gradle 16B
build.gradle 632B
共 91 条
- 1
资源评论
- 陌小雨Babylove2017-12-08不错好好好
- sliencefun2018-08-19做法很值得借鉴。
杨贱贱
- 粉丝: 3
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功