Search in sources :

Example 6 with SimpleImageLoadingListener

use of com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener in project Android-Universal-Image-Loader by nostra13.

the class UILWidgetProvider method updateAppWidget.

static void updateAppWidget(Context context, final AppWidgetManager appWidgetManager, final int appWidgetId) {
    final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
    // 70 - approximate size of ImageView in widget
    ImageSize minImageSize = new ImageSize(70, 70);
    ImageLoader.getInstance().loadImage(IMAGES[0], minImageSize, displayOptions, new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            views.setImageViewBitmap(R.id.image_left, loadedImage);
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    });
    ImageLoader.getInstance().loadImage(IMAGES[1], minImageSize, displayOptions, new SimpleImageLoadingListener() {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            views.setImageViewBitmap(R.id.image_right, loadedImage);
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    });
}
Also used : SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) ImageSize(com.nostra13.universalimageloader.core.assist.ImageSize) View(android.view.View)

Example 7 with SimpleImageLoadingListener

use of com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener 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

Bitmap (android.graphics.Bitmap)7 View (android.view.View)7 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)6 ImageView (android.widget.ImageView)5 Palette (android.support.v7.graphics.Palette)4 RecyclerView (android.support.v7.widget.RecyclerView)4 TextView (android.widget.TextView)4 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)4 Handler (android.os.Handler)2 ArtistInfoListener (com.naman14.timber.lastfmapi.callbacks.ArtistInfoListener)2 ArtistQuery (com.naman14.timber.lastfmapi.models.ArtistQuery)2 LastfmArtist (com.naman14.timber.lastfmapi.models.LastfmArtist)2 Artist (com.naman14.timber.models.Artist)2 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)2 FadeInBitmapDisplayer (com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer)2 RemoteViews (android.widget.RemoteViews)1 InjectView (butterknife.InjectView)1 Album (com.naman14.timber.models.Album)1 Playlist (com.naman14.timber.models.Playlist)1 TimelyView (com.naman14.timber.timely.TimelyView)1