Search in sources :

Example 11 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project Phonograph by kabouzeid.

the class MusicService method updateMediaSessionMetaData.

private void updateMediaSessionMetaData() {
    final Song song = getCurrentSong();
    if (song.id == -1) {
        mediaSession.setMetadata(null);
        return;
    }
    final MediaMetadataCompat.Builder metaData = new MediaMetadataCompat.Builder().putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.artistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, song.artistName).putString(MediaMetadataCompat.METADATA_KEY_ALBUM, song.albumName).putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.title).putLong(MediaMetadataCompat.METADATA_KEY_DURATION, song.duration).putLong(MediaMetadataCompat.METADATA_KEY_TRACK_NUMBER, getPosition() + 1).putLong(MediaMetadataCompat.METADATA_KEY_YEAR, song.year).putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        metaData.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, getPlayingQueue().size());
    }
    if (PreferenceUtil.getInstance(this).albumArtOnLockscreen()) {
        final Point screenSize = Util.getScreenSize(MusicService.this);
        final BitmapRequestBuilder<?, Bitmap> request = SongGlideRequest.Builder.from(Glide.with(MusicService.this), song).checkIgnoreMediaStore(MusicService.this).asBitmap().build();
        if (PreferenceUtil.getInstance(this).blurredAlbumArt()) {
            request.transform(new BlurTransformation.Builder(MusicService.this).build());
        }
        runOnUiThread(new Runnable() {

            @Override
            public void run() {
                request.into(new SimpleTarget<Bitmap>(screenSize.x, screenSize.y) {

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        super.onLoadFailed(e, errorDrawable);
                        mediaSession.setMetadata(metaData.build());
                    }

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, copy(resource));
                        mediaSession.setMetadata(metaData.build());
                    }
                });
            }
        });
    } else {
        mediaSession.setMetadata(metaData.build());
    }
}
Also used : MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) BitmapRequestBuilder(com.bumptech.glide.BitmapRequestBuilder) Drawable(android.graphics.drawable.Drawable) Point(android.graphics.Point) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap)

Example 12 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project Rocket by mozilla-tw.

the class TabTrayAdapter method loadCachedFavicon.

private void loadCachedFavicon(final Session tab, final TabViewHolder holder) {
    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
    Bitmap favicon = tab.getFavicon();
    FaviconModel model = new FaviconModel(tab.getUrl(), DimenUtils.getFavIconType(holder.itemView.getResources(), favicon), favicon);
    requestManager.load(model).apply(options).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            loadGeneratedFavicon(tab, holder);
            return true;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            return false;
        }
    }).into(new SimpleTarget<Drawable>() {

        @Override
        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
            updateFavicon(holder, resource);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable)

Example 13 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemHolder itemHolder, final int i) {
    final Playlist localItem = arraylist.get(i);
    itemHolder.title.setText(localItem.name);
    itemHolder.songcount.setText(ListenerUtil.makeLabel(mContext, R.plurals.Nsongs, localItem.songCount));
    itemHolder.subtitle1.setVisibility(View.GONE);
    itemHolder.divider.setVisibility(View.GONE);
    PlaylistSongLoader.getSongsInPlaylist(mContext, localItem.id).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<List<Song>>() {

        @Override
        public void call(List<Song> playlistsongs) {
            String uri = "";
            long firstAlbumID = -1;
            if (playlistsongs.size() != 0) {
                firstAlbumID = playlistsongs.get(0).albumId;
                uri = ListenerUtil.getAlbumArtUri(firstAlbumID).toString();
            }
            itemHolder.playlistArt.setTag(R.string.playlistArt, firstAlbumID);
            Glide.with(itemHolder.itemView.getContext()).load(uri).asBitmap().placeholder(ATEUtil.getDefaultAlbumDrawable(mContext)).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    if (isGrid) {
                        itemHolder.footer.setBackgroundColor(ATEUtil.getThemeAlbumDefaultPaletteColor(mContext));
                    }
                    itemHolder.playlistArt.setImageDrawable(ATEUtil.getDefaultAlbumDrawable(mContext));
                    itemHolder.title.setTextColor(ATEUtil.getThemeTextColorPrimary(mContext));
                    itemHolder.songcount.setTextColor(ATEUtil.getThemeTextColorSecondly(mContext));
                    itemHolder.popupMenu.setColorFilter(mContext.getResources().getColor(R.color.background_floating_material_dark));
                }

                @Override
                public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    if (isGrid) {
                        new Palette.Builder(resource).generate(new Palette.PaletteAsyncListener() {

                            @Override
                            public void onGenerated(Palette palette) {
                                Palette.Swatch swatch = ColorUtil.getMostPopulousSwatch(palette);
                                if (swatch != null) {
                                    int color = swatch.getRgb();
                                    itemHolder.footer.setBackgroundColor(color);
                                    int detailColor = swatch.getTitleTextColor();
                                    itemHolder.playlistArt.setImageBitmap(resource);
                                    itemHolder.title.setTextColor(ColorUtil.getOpaqueColor(detailColor));
                                    itemHolder.songcount.setTextColor(detailColor);
                                    itemHolder.popupMenu.setColorFilter(detailColor);
                                }
                            }
                        });
                    } else {
                        itemHolder.playlistArt.setImageBitmap(resource);
                    }
                }
            });
        }
    });
    if (ListenerUtil.isLollipop())
        itemHolder.playlistArt.setTransitionName("transition_album_art" + i);
    setOnPopupMenuListener(itemHolder, i);
}
Also used : Palette(android.support.v7.graphics.Palette) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Playlist(io.hefuyi.listener.mvp.model.Playlist) Song(io.hefuyi.listener.mvp.model.Song) Bitmap(android.graphics.Bitmap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project Shuttle by timusus.

the class MusicService method buildNotification.

private Notification buildNotification() {
    final boolean isPlaying = isPlaying();
    if (mNotification == null) {
        Intent intent = new Intent(BuildConfig.APPLICATION_ID + (ShuttleUtils.isTablet() ? ".TABLET_PLAYBACK_VIEWER" : ".PLAYBACK_VIEWER"));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(MusicService.this, 0, intent, 0);
        Notification.Builder builder = new Notification.Builder(this);
        builder.setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(contentIntent).setPriority(Notification.PRIORITY_MAX);
        if (ShuttleUtils.hasJellyBeanMR1()) {
            builder.setShowWhen(false);
        }
        if (ShuttleUtils.hasLollipop()) {
            builder.setVisibility(Notification.VISIBILITY_PUBLIC);
        }
        if (ShuttleUtils.hasNougat()) {
            builder.setStyle(new Notification.DecoratedCustomViewStyle());
        }
        mNotification = builder.build();
    }
    boolean invertIconsAndText = SettingsManager.getInstance().invertNotificationIcons() && ShuttleUtils.hasLollipop();
    int baseLayoutResId = invertIconsAndText ? R.layout.notification_template_base_inverse : R.layout.notification_template_base;
    int baseBigLayoutResId = invertIconsAndText ? R.layout.notification_template_big_base_inverse : R.layout.notification_template_big_base;
    if (ShuttleUtils.hasNougat()) {
        baseLayoutResId = invertIconsAndText ? R.layout.notification_template_base_v24_inverse : R.layout.notification_template_base_v24;
        baseBigLayoutResId = invertIconsAndText ? R.layout.notification_template_big_base_v24_inverse : R.layout.notification_template_big_base_v24;
    }
    RemoteViews contentView = new RemoteViews(getPackageName(), baseLayoutResId);
    RemoteViews bigContentView = new RemoteViews(getPackageName(), baseBigLayoutResId);
    String artistName = getArtistName();
    String albumName = getAlbumName();
    String trackName = getSongName();
    if (artistName != null && albumName != null) {
        contentView.setTextViewText(R.id.text, String.format("%s | %s", artistName, albumName));
        bigContentView.setTextViewText(R.id.text, String.format("%s | %s", artistName, albumName));
    }
    if (trackName != null) {
        contentView.setTextViewText(R.id.title, trackName);
        bigContentView.setTextViewText(R.id.title, trackName);
    }
    contentView.setImageViewBitmap(R.id.pause, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_pause_white));
    contentView.setImageViewBitmap(R.id.next, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_skip_white));
    contentView.setImageViewBitmap(R.id.prev, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_prev_white));
    bigContentView.setImageViewBitmap(R.id.pause, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_pause_white));
    bigContentView.setImageViewBitmap(R.id.next, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_skip_white));
    bigContentView.setImageViewBitmap(R.id.prev, DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_prev_white));
    PendingIntent pendingIntent = retrievePlaybackAction(ServiceCommand.PREV_ACTION);
    bigContentView.setOnClickPendingIntent(R.id.prev, pendingIntent);
    pendingIntent = retrievePlaybackAction(ServiceCommand.TOGGLE_PAUSE_ACTION);
    contentView.setOnClickPendingIntent(R.id.pause, pendingIntent);
    bigContentView.setOnClickPendingIntent(R.id.pause, pendingIntent);
    pendingIntent = retrievePlaybackAction(ServiceCommand.NEXT_ACTION);
    contentView.setOnClickPendingIntent(R.id.next, pendingIntent);
    bigContentView.setOnClickPendingIntent(R.id.next, pendingIntent);
    pendingIntent = retrievePlaybackAction(ServiceCommand.PREV_ACTION);
    contentView.setOnClickPendingIntent(R.id.prev, pendingIntent);
    bigContentView.setOnClickPendingIntent(R.id.prev, pendingIntent);
    pendingIntent = retrievePlaybackAction(ServiceCommand.STOP_ACTION);
    contentView.setOnClickPendingIntent(R.id.close, pendingIntent);
    bigContentView.setOnClickPendingIntent(R.id.close, pendingIntent);
    doOnMainThread(() -> Glide.with(MusicService.this).load(getAlbum()).asBitmap().diskCacheStrategy(DiskCacheStrategy.ALL).override(600, 600).placeholder(GlideUtils.getPlaceHolderDrawable(albumName, false)).into(new SimpleTarget<Bitmap>() {

        @Override
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
            if (resource != null) {
                contentView.setImageViewBitmap(R.id.icon, resource);
                bigContentView.setImageViewBitmap(R.id.icon, resource);
            }
            mNotificationManager.notify(NOTIFICATION_ID, mNotification);
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            super.onLoadFailed(e, errorDrawable);
            contentView.setImageViewBitmap(R.id.icon, GlideUtils.drawableToBitmap(errorDrawable));
            bigContentView.setImageViewBitmap(R.id.icon, GlideUtils.drawableToBitmap(errorDrawable));
            mNotificationManager.notify(NOTIFICATION_ID, mNotification);
        }
    }));
    mNotification.contentView = contentView;
    try {
        mNotification.bigContentView = bigContentView;
    } catch (NoSuchFieldError ignored) {
    }
    if (ShuttleUtils.hasAndroidLPreview()) {
        mNotification.contentView.setImageViewBitmap(R.id.pause, !isPlaying ? DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_play_white) : DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_pause_white));
    } else {
        mNotification.contentView.setImageViewResource(R.id.pause, !isPlaying ? R.drawable.ic_play_white : R.drawable.ic_pause_white);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        try {
            if (mNotification.bigContentView != null) {
                if (ShuttleUtils.hasAndroidLPreview()) {
                    mNotification.bigContentView.setImageViewBitmap(R.id.pause, !isPlaying ? DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_play_white) : DrawableUtils.getTintedNotificationDrawable(this, R.drawable.ic_pause_white));
                } else {
                    mNotification.bigContentView.setImageViewResource(R.id.pause, !isPlaying ? R.drawable.ic_play_white : R.drawable.ic_pause_white);
                }
            }
        } catch (NoSuchFieldError ignored) {
        }
    }
    return mNotification;
}
Also used : Drawable(android.graphics.drawable.Drawable) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) Notification(android.app.Notification) SuppressLint(android.annotation.SuppressLint) SQLiteException(android.database.sqlite.SQLiteException) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) PendingIntent(android.app.PendingIntent)

Example 15 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project Notes by Elder-Wu.

the class GlideFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_glide, container, false);
    ImageView imageView = (ImageView) rootView.findViewById(R.id.image);
    Glide.with(getContext()).load("http://pic.qiantucdn.com/58pic/18/31/50/70T58PIC4Xi_1024.jpg").diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).crossFade().into(imageView);
    final ImageView imageView2 = (ImageView) rootView.findViewById(R.id.image2);
    imageView2.postDelayed(new Runnable() {

        @Override
        public void run() {
            Glide.with(getContext()).load((String) null).transform(new RoundTransform(getContext(), imageView2.getMeasuredWidth(), 10)).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).fallback(new ColorDrawable(Color.GREEN)).listener(new RequestListener<String, GlideDrawable>() {

                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    return false;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    Logger.d(model);
                    return false;
                }
            }).into(new SimpleTarget<GlideDrawable>() {

                @Override
                public void onResourceReady(final GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
                    Observable.timer(5, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<Long>() {

                        @Override
                        public void call(Long aLong) {
                            imageView2.setImageDrawable(new ColorDrawable(Color.DKGRAY));
                        }
                    });
                }
            });
        }
    }, 2000);
    return rootView;
}
Also used : GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) ImageView(android.widget.ImageView) View(android.view.View) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) ImageView(android.widget.ImageView) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) Nullable(android.support.annotation.Nullable)

Aggregations

SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)25 Drawable (android.graphics.drawable.Drawable)18 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)18 Bitmap (android.graphics.Bitmap)17 ColorDrawable (android.graphics.drawable.ColorDrawable)6 ImageView (android.widget.ImageView)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)5 View (android.view.View)5 Target (com.bumptech.glide.request.target.Target)5 LayerDrawable (android.graphics.drawable.LayerDrawable)4 Nullable (android.support.annotation.Nullable)4 RequestListener (com.bumptech.glide.request.RequestListener)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 Palette (android.support.v7.graphics.Palette)3 ViewGroup (android.view.ViewGroup)3 TextDrawable (com.owncloud.android.ui.TextDrawable)3 MenuSimpleTarget (com.owncloud.android.utils.svg.MenuSimpleTarget)3 PendingIntent (android.app.PendingIntent)2 SQLiteException (android.database.sqlite.SQLiteException)2