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();
}
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());
}
}
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));
}
}
}
}
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();
}
});
}
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());
}
}));
}
Aggregations