use of com.nostra13.universalimageloader.core.assist.FailReason in project QuickAndroid by ImKarl.
the class DefaultImage method load.
/**
* 加载图片
* @param view 将图片显示到该控件
* @param url
*/
@Override
public void load(final View view, String url) {
url = checkImageUri(url);
if (view instanceof ImageView) {
load((ImageView) view, url);
return;
}
getImageLoader().loadImage(url, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View viewNull) {
showLoading(view);
}
@Override
public void onLoadingFailed(String imageUri, View viewNull, FailReason failReason) {
showLoadfail(view);
}
@SuppressWarnings("deprecation")
@Override
public void onLoadingComplete(String imageUri, View viewNull, Bitmap loadedImage) {
if (loadedImage == null) {
onLoadingFailed(imageUri, viewNull, new FailReason(FailType.UNKNOWN, new NullPointerException("'bitmap' is NULL.")));
return;
}
view.setBackgroundDrawable(new BitmapDrawable(view.getResources(), loadedImage));
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
showLoadfail(view);
}
});
}
use of com.nostra13.universalimageloader.core.assist.FailReason in project QuickAndroid by ImKarl.
the class DefaultImage method createQAImageLoadingListener.
/**
* 创建图片加载监听器
* @param view
* @param listener
* @return
*/
@SuppressWarnings("rawtypes")
private QAImageLoadingListener createQAImageLoadingListener(View view, final QAImageCallback listener) {
return new QAImageLoadingListener<View>(view) {
@Override
public void onLoadingCancelled(View view, String imageUri) {
if (listener != null) {
listener.onCancel(imageUri, view);
}
}
@Override
public void onLoadingComplete(View view, String imageUri, Bitmap loadedImage) {
if (listener != null) {
listener.onSuccess(imageUri, view, loadedImage);
}
}
@Override
public void onLoadingFailed(View view, String imageUri, FailReason failReason) {
if (listener != null) {
FailType type = failReason.getType();
int code = QAException.CODE_UNKNOW;
if (type == FailType.IO_ERROR) {
code = QAException.CODE_IO_FILE;
} else if (type == FailType.DECODING_ERROR) {
code = QAException.CODE_DECODE;
} else if (type == FailType.NETWORK_DENIED) {
code = QAException.CODE_NETWORK;
} else if (type == FailType.OUT_OF_MEMORY) {
code = QAException.CODE_OOM;
} else if (type == FailType.UNKNOWN) {
code = QAException.CODE_UNKNOW;
}
QAImageException exception = new QAImageException(code, failReason.getCause());
listener.onFail(imageUri, view, exception);
}
}
@Override
public void onLoadingStarted(View view, String imageUri) {
if (listener != null) {
listener.onStart(imageUri, view);
}
}
};
}
use of com.nostra13.universalimageloader.core.assist.FailReason in project Timber by naman14.
the class AlbumDetailFragment method setAlbumart.
private void setAlbumart() {
ImageLoader.getInstance().displayImage(TimberUtils.getAlbumArtUri(albumID).toString(), albumArt, new DisplayImageOptions.Builder().cacheInMemory(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).build(), new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
loadFailed = true;
MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(context).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
fab.setImageDrawable(builder.build());
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
try {
new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
Palette.Swatch swatch = palette.getVibrantSwatch();
if (swatch != null) {
primaryColor = swatch.getRgb();
collapsingToolbarLayout.setContentScrimColor(primaryColor);
if (getActivity() != null)
ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
} else {
Palette.Swatch swatchMuted = palette.getMutedSwatch();
if (swatchMuted != null) {
primaryColor = swatchMuted.getRgb();
collapsingToolbarLayout.setContentScrimColor(primaryColor);
if (getActivity() != null)
ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
}
}
MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setSizeDp(30);
if (primaryColor != -1) {
builder.setColor(TimberUtils.getBlackWhiteColor(primaryColor));
ATEUtils.setFabBackgroundTint(fab, primaryColor);
fab.setImageDrawable(builder.build());
} else {
if (context != null) {
ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
builder.setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
fab.setImageDrawable(builder.build());
}
}
}
});
} catch (Exception ignored) {
}
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
});
}
use of com.nostra13.universalimageloader.core.assist.FailReason in project Timber by naman14.
the class ArtistAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ItemHolder itemHolder, int i) {
final Artist localItem = arraylist.get(i);
itemHolder.name.setText(localItem.name);
String albumNmber = TimberUtils.makeLabel(mContext, R.plurals.Nalbums, localItem.albumCount);
String songCount = TimberUtils.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount);
itemHolder.albums.setText(TimberUtils.makeCombinedString(mContext, albumNmber, songCount));
LastFmClient.getInstance(mContext).getArtistInfo(new ArtistQuery(localItem.name), new ArtistInfoListener() {
@Override
public void artistInfoSucess(LastfmArtist artist) {
if (artist != null && artist.mArtwork != null) {
if (isGrid) {
ImageLoader.getInstance().displayImage(artist.mArtwork.get(2).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build(), new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
if (isGrid && loadedImage != null) {
new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
int color = palette.getVibrantColor(Color.parseColor("#66000000"));
itemHolder.footer.setBackgroundColor(color);
Palette.Swatch swatch = palette.getVibrantSwatch();
int textColor;
if (swatch != null) {
textColor = getOpaqueColor(swatch.getTitleTextColor());
} else
textColor = Color.parseColor("#ffffff");
itemHolder.name.setTextColor(textColor);
itemHolder.albums.setTextColor(textColor);
}
});
}
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
if (isGrid) {
itemHolder.footer.setBackgroundColor(0);
if (mContext != null) {
int textColorPrimary = Config.textColorPrimary(mContext, Helpers.getATEKey(mContext));
itemHolder.name.setTextColor(textColorPrimary);
itemHolder.albums.setTextColor(textColorPrimary);
}
}
}
});
} else {
ImageLoader.getInstance().displayImage(artist.mArtwork.get(1).mUrl, itemHolder.artistImage, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisk(true).showImageOnFail(R.drawable.ic_empty_music2).resetViewBeforeLoading(true).displayer(new FadeInBitmapDisplayer(400)).build());
}
}
}
@Override
public void artistInfoFailed() {
}
});
if (TimberUtils.isLollipop())
itemHolder.artistImage.setTransitionName("transition_artist_art" + i);
}
Aggregations