Android图片上传下载小框架

时间:2016-07-19 13:11:32
【文件属性】:

文件名称:Android图片上传下载小框架

文件大小:8KB

文件格式:ZIP

更新时间:2016-07-19 13:11:32

Android 图片 上传下载 框架

package com.loopj.android.image; import android.content.Context; import android.graphics.Bitmap; import android.util.AttributeSet; import android.widget.ImageView; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class SmartImageView extends ImageView { private static final int LOADING_THREADS = 4; private static ExecutorService threadPool = Executors.newFixedThreadPool(LOADING_THREADS); private SmartImageTask currentTask; public SmartImageView(Context context) { super(context); } public SmartImageView(Context context, AttributeSet attrs) { super(context, attrs); } public SmartImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } // Helpers to set image by URL public void setImageUrl(String url) { setImage(new WebImage(url)); } public void setImageUrl(String url, SmartImageTask.OnCompleteListener completeListener) { setImage(new WebImage(url), completeListener); } public void setImageUrl(String url, final Integer fallbackResource) { setImage(new WebImage(url), fallbackResource); } public void setImageUrl(String url, final Integer fallbackResource, SmartImageTask.OnCompleteListener completeListener) { setImage(new WebImage(url), fallbackResource, completeListener); } public void setImageUrl(String url, final Integer fallbackResource, final Integer loadingResource) { setImage(new WebImage(url), fallbackResource, loadingResource); } public void setImageUrl(String url, final Integer fallbackResource, final Integer loadingResource, SmartImageTask.OnCompleteListener completeListener) { setImage(new WebImage(url), fallbackResource, loadingResource, completeListener); } // Helpers to set image by contact address book id public void setImageContact(long contactId) { setImage(new ContactImage(contactId)); } public void setImageContact(long contactId, final Integer fallbackResource) { setImage(new ContactImage(contactId), fallbackResource); } public void setImageContact(long contactId, final Integer fallbackResource, final Integer loadingResource) { setImage(new ContactImage(contactId), fallbackResource, fallbackResource); } // Set image using SmartImage object public void setImage(final SmartImage image) { setImage(image, null, null, null); } public void setImage(final SmartImage image, final SmartImageTask.OnCompleteListener completeListener) { setImage(image, null, null, completeListener); } public void setImage(final SmartImage image, final Integer fallbackResource) { setImage(image, fallbackResource, fallbackResource, null); } public void setImage(final SmartImage image, final Integer fallbackResource, SmartImageTask.OnCompleteListener completeListener) { setImage(image, fallbackResource, fallbackResource, completeListener); } public void setImage(final SmartImage image, final Integer fallbackResource, final Integer loadingResource) { setImage(image, fallbackResource, loadingResource, null); } public void setImage(final SmartImage image, final Integer fallbackResource, final Integer loadingResource, final SmartImageTask.OnCompleteListener completeListener) { // Set a loading resource if(loadingResource != null){ setImageResource(loadingResource); } // Cancel any existing tasks for this image view if(currentTask != null) { currentTask.cancel(); currentTask = null; } // Set up the new task currentTask = new SmartImageTask(getContext(), image); currentTask.setOnCompleteHandler(new SmartImageTask.OnCompleteHandler() { @Override public void onComplete(Bitmap bitmap) { if(bitmap != null) { setImageBitmap(bitmap); } else { // Set fallback resource if(fallbackResource != null) { setImageResource(fallbackResource); } } if(completeListener != null){ completeListener.onComplete(); } } }); // Run the task in a threadpool threadPool.execute(currentTask); } public static void cancelAllTasks() { threadPool.shutdownNow(); threadPool = Executors.newFixedThreadPool(LOADING_THREADS); } }


【文件预览】:
android-smart-image-view-master
----build.xml(2KB)
----src()
--------com()
----.gitignore(61B)
----README.md(824B)

网友评论

  • 很好,很有借鉴意义
  • 不错 就是要得积分有点多啊
  • 很好用,很适合
  • 看不大懂,不过还是感谢
  • as的项目,我用的eclipse
  • 这个框架 看不懂啊
  • 至少明白了图片缓存该怎么弄了
  • 至少明白了图片缓存该怎么弄了
  • 至少明白了图片缓存该怎么弄了