Back to project page Shutterbug.
The source code is released under:
* Copyright (c) 2012, Applidium * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met...
If you think the Android project Shutterbug listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.applidium.shutterbug; /*from w w w . j a v a 2 s . c om*/ import android.R; import android.content.Context; import android.graphics.Bitmap; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.widget.ImageView; import com.applidium.shutterbug.utils.ShutterbugManager; import com.applidium.shutterbug.utils.ShutterbugManager.ShutterbugManagerListener; public class FetchableImageView extends ImageView implements ShutterbugManagerListener { public interface FetchableImageViewListener { void onImageFetched(Bitmap bitmap, String url); void onImageFailure(String url); } private FetchableImageViewListener mListener; public FetchableImageView(Context context, AttributeSet attrs) { super(context, attrs); } public FetchableImageViewListener getListener() { return mListener; } public void setListener(FetchableImageViewListener listener) { mListener = listener; } public void setImage(String url) { setImage(url, new ColorDrawable(getContext().getResources().getColor(R.color.transparent))); } public void setImage(String url, int desiredHeight, int desiredWidth) { setImage(url, new ColorDrawable(getContext().getResources().getColor(R.color.transparent)), desiredHeight, desiredWidth); } public void setImage(String url, int placeholderDrawableId) { setImage(url, getContext().getResources().getDrawable(placeholderDrawableId)); } public void setImage(String url, Drawable placeholderDrawable) { setImage(url, placeholderDrawable, -1, -1); } public void setImage(String url, Drawable placeholderDrawable, int desiredHeight, int desiredWidth) { final ShutterbugManager manager = ShutterbugManager.getSharedImageManager(getContext()); manager.cancel((ShutterbugManagerListener) this); setImageDrawable(placeholderDrawable); if (url != null) { manager.download(url, (ShutterbugManagerListener) this, desiredHeight, desiredWidth); } } public void cancelCurrentImageLoad() { ShutterbugManager.getSharedImageManager(getContext()).cancel((ShutterbugManagerListener) this); } @Override public void onImageSuccess(ShutterbugManager imageManager, Bitmap bitmap, String url) { setImageBitmap(bitmap); requestLayout(); if (mListener != null) { mListener.onImageFetched(bitmap, url); } } @Override public void onImageFailure(ShutterbugManager imageManager, String url) { if (mListener != null) { mListener.onImageFailure(url); } } }