Search in sources :

Example 6 with SimpleTarget

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

the class GlideTest method removeFromManagers_afterRequestManagerRemoved_clearsRequest.

@Test
public void removeFromManagers_afterRequestManagerRemoved_clearsRequest() {
    target = requestManager.load(mockUri("content://uri")).into(new SimpleTarget<Drawable>() {

        @Override
        public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
        // Do nothing.
        }
    });
    Request request = Preconditions.checkNotNull(target.getRequest());
    requestManager.onDestroy();
    requestManager.clear(target);
    assertThat(target.getRequest()).isNull();
    assertThat(request.isCancelled()).isTrue();
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) NonNull(android.support.annotation.NonNull) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) Transition(com.bumptech.glide.request.transition.Transition) Request(com.bumptech.glide.request.Request) Nullable(android.support.annotation.Nullable) Test(org.junit.Test)

Example 7 with SimpleTarget

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

the class MediaSessionManager method updateMediaSessionArtwork.

private void updateMediaSessionArtwork(MediaMetadataCompat.Builder metaData) {
    QueueItem currentQueueItem = queueManager.getCurrentQueueItem();
    if (currentQueueItem != null) {
        disposables.add(Completable.defer(() -> Completable.fromAction(() -> Glide.with(context).load(currentQueueItem.getSong().getAlbum()).asBitmap().override(1024, 1024).into(new SimpleTarget<Bitmap>() {

            @Override
            public void onResourceReady(Bitmap bitmap, GlideAnimation<? super Bitmap> glideAnimation) {
                if (bitmap != null) {
                    metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap);
                }
                try {
                    mediaSession.setMetadata(metaData.build());
                } catch (NullPointerException e) {
                    metaData.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, null);
                    mediaSession.setMetadata(metaData.build());
                }
            }

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                mediaSession.setMetadata(metaData.build());
            }
        }))).subscribeOn(AndroidSchedulers.mainThread()).subscribe());
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) QueueItem(com.simplecity.amp_library.ui.screens.queue.QueueItem) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Example 8 with SimpleTarget

use of com.bumptech.glide.request.target.SimpleTarget in project android by nextcloud.

the class UserInfoActivity method setHeaderImage.

private void setHeaderImage() {
    if (getStorageManager().getCapability(user.getAccountName()).getServerBackground() != null) {
        ImageView backgroundImageView = findViewById(R.id.userinfo_background);
        if (backgroundImageView != null) {
            String background = getStorageManager().getCapability(user.getAccountName()).getServerBackground();
            int primaryColor = ThemeColorUtils.primaryColor(getAccount(), false, this);
            if (URLUtil.isValidUrl(background)) {
                // background image
                SimpleTarget target = new SimpleTarget<Drawable>() {

                    @Override
                    public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
                        Drawable[] drawables = { new ColorDrawable(primaryColor), resource };
                        LayerDrawable layerDrawable = new LayerDrawable(drawables);
                        backgroundImageView.setImageDrawable(layerDrawable);
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        Drawable[] drawables = { new ColorDrawable(primaryColor), ResourcesCompat.getDrawable(getResources(), R.drawable.background, null) };
                        LayerDrawable layerDrawable = new LayerDrawable(drawables);
                        backgroundImageView.setImageDrawable(layerDrawable);
                    }
                };
                Glide.with(this).load(background).centerCrop().placeholder(R.drawable.background).error(R.drawable.background).crossFade().into(target);
            } else {
                // plain color
                backgroundImageView.setImageDrawable(new ColorDrawable(primaryColor));
            }
        }
    }
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ImageView(android.widget.ImageView) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Example 9 with SimpleTarget

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

the class AlbumTagEditorActivity method getImageFromLastFM.

@Override
protected void getImageFromLastFM() {
    String albumTitleStr = albumTitle.getText().toString();
    String albumArtistNameStr = albumArtist.getText().toString();
    if (albumArtistNameStr.trim().equals("") || albumTitleStr.trim().equals("")) {
        Toast.makeText(this, getResources().getString(R.string.album_or_artist_empty), Toast.LENGTH_SHORT).show();
        return;
    }
    lastFMRestClient.getApiService().getAlbumInfo(albumTitleStr, albumArtistNameStr, null).enqueue(new Callback<LastFmAlbum>() {

        @Override
        public void onResponse(Call<LastFmAlbum> call, Response<LastFmAlbum> response) {
            LastFmAlbum lastFmAlbum = response.body();
            if (lastFmAlbum.getAlbum() != null) {
                String url = LastFMUtil.getLargestAlbumImageUrl(lastFmAlbum.getAlbum().getImage());
                if (!TextUtils.isEmpty(url) && url.trim().length() > 0) {
                    Glide.with(AlbumTagEditorActivity.this).load(url).asBitmap().transcode(new BitmapPaletteTranscoder(AlbumTagEditorActivity.this), BitmapPaletteWrapper.class).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(R.drawable.default_album_art).into(new SimpleTarget<BitmapPaletteWrapper>() {

                        @Override
                        public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            e.printStackTrace();
                            Toast.makeText(AlbumTagEditorActivity.this, e.toString(), Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
                            albumArtBitmap = ImageUtil.resizeBitmap(resource.getBitmap(), 2048);
                            setImageBitmap(albumArtBitmap, PhonographColorUtil.getColor(resource.getPalette(), ATHUtil.resolveColor(AlbumTagEditorActivity.this, R.attr.defaultFooterColor)));
                            deleteAlbumArt = false;
                            dataChanged();
                            setResult(RESULT_OK);
                        }
                    });
                    return;
                }
            }
            toastLoadingFailed();
        }

        @Override
        public void onFailure(Call<LastFmAlbum> call, Throwable t) {
            toastLoadingFailed();
        }

        private void toastLoadingFailed() {
            Toast.makeText(AlbumTagEditorActivity.this, R.string.could_not_download_album_cover, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) LastFmAlbum(com.kabouzeid.gramophone.lastfm.rest.model.LastFmAlbum) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) BitmapPaletteTranscoder(com.kabouzeid.gramophone.glide.palette.BitmapPaletteTranscoder)

Example 10 with SimpleTarget

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

the class PlayingNotificationImpl24 method update.

@Override
public synchronized void update() {
    stopped = false;
    final Song song = service.getCurrentSong();
    final boolean isPlaying = service.isPlaying();
    final int playButtonResId = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
    Intent action = new Intent(service, MainActivity.class);
    action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    final PendingIntent clickIntent = PendingIntent.getActivity(service, 0, action, 0);
    final ComponentName serviceName = new ComponentName(service, MusicService.class);
    Intent intent = new Intent(MusicService.ACTION_QUIT);
    intent.setComponent(serviceName);
    final PendingIntent deleteIntent = PendingIntent.getService(service, 0, intent, 0);
    final int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
    service.runOnUiThread(() -> SongGlideRequest.Builder.from(Glide.with(service), song).checkIgnoreMediaStore(service).generatePalette(service).build().into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {

        @Override
        public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
            Palette palette = resource.getPalette();
            update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(Color.TRANSPARENT)));
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            update(null, Color.TRANSPARENT);
        }

        void update(Bitmap bitmap, int color) {
            if (bitmap == null)
                bitmap = BitmapFactory.decodeResource(service.getResources(), R.drawable.default_album_art);
            NotificationCompat.Action playPauseAction = new NotificationCompat.Action(playButtonResId, service.getString(R.string.action_play_pause), retrievePlaybackAction(ACTION_TOGGLE_PAUSE));
            NotificationCompat.Action previousAction = new NotificationCompat.Action(R.drawable.ic_skip_previous_white_24dp, service.getString(R.string.action_previous), retrievePlaybackAction(ACTION_REWIND));
            NotificationCompat.Action nextAction = new NotificationCompat.Action(R.drawable.ic_skip_next_white_24dp, service.getString(R.string.action_next), retrievePlaybackAction(ACTION_SKIP));
            NotificationCompat.Builder builder = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_notification).setSubText(song.albumName).setLargeIcon(bitmap).setContentIntent(clickIntent).setDeleteIntent(deleteIntent).setContentTitle(song.title).setContentText(song.artistName).setOngoing(isPlaying).setShowWhen(false).addAction(previousAction).addAction(playPauseAction).addAction(nextAction);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder.setStyle(new MediaStyle().setMediaSession(service.getMediaSession().getSessionToken()).setShowActionsInCompactView(0, 1, 2)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
                if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil.getInstance(service).coloredNotification())
                    builder.setColor(color);
            }
            if (stopped)
                // notification has been stopped before loading was finished
                return;
            updateNotifyModeAndPostNotification(builder.build());
        }
    }));
}
Also used : Palette(androidx.palette.graphics.Palette) MediaStyle(androidx.media.app.NotificationCompat.MediaStyle) BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap) NotificationCompat(androidx.core.app.NotificationCompat) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent)

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