Search in sources :

Example 16 with FailReason

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);
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) ImageView(android.widget.ImageView) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageView(android.widget.ImageView) View(android.view.View)

Example 17 with FailReason

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);
            }
        }
    };
}
Also used : QAImageException(cn.jeesoft.qa.error.QAImageException) Bitmap(android.graphics.Bitmap) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) FailType(com.nostra13.universalimageloader.core.assist.FailReason.FailType)

Example 18 with FailReason

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) {
        }
    });
}
Also used : Palette(android.support.v7.graphics.Palette) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder) Bitmap(android.graphics.Bitmap) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Example 19 with FailReason

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);
}
Also used : LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) Artist(com.naman14.timber.models.Artist) Palette(android.support.v7.graphics.Palette) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ArtistQuery(com.naman14.timber.lastfmapi.models.ArtistQuery) LastfmArtist(com.naman14.timber.lastfmapi.models.LastfmArtist) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) ArtistInfoListener(com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener) FadeInBitmapDisplayer(com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)

Aggregations

FailReason (com.nostra13.universalimageloader.core.assist.FailReason)19 Bitmap (android.graphics.Bitmap)18 View (android.view.View)17 ImageView (android.widget.ImageView)17 TextView (android.widget.TextView)12 ImageLoadingListener (com.nostra13.universalimageloader.core.assist.ImageLoadingListener)7 RecyclerView (android.support.v7.widget.RecyclerView)6 ImageLoadingListener (com.nostra13.universalimageloader.core.listener.ImageLoadingListener)6 Palette (android.support.v7.graphics.Palette)4 LayoutInflater (android.view.LayoutInflater)4 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)4 Track (io.recom.howabout.category.music.model.Track)4 ProgressBar (android.widget.ProgressBar)3 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)3 HowaboutApplication (io.recom.howabout.HowaboutApplication)3 OnClickListener (android.view.View.OnClickListener)2 InjectView (butterknife.InjectView)2 ActionBar (com.actionbarsherlock.app.ActionBar)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 MaterialDrawableBuilder (net.steamcrafted.materialiconlib.MaterialDrawableBuilder)2