Search in sources :

Example 1 with SimpleTarget

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

the class PlayerFragment method trackInfoChanged.

@Override
public void trackInfoChanged(@Nullable Song song) {
    if (song == null)
        return;
    if (isExpanded && !snowfallView.isSnowing()) {
        snowfallView.letItSnow();
    } else {
        snowfallView.removeSnow();
    }
    String totalTimeString = StringUtils.makeTimeString(this.getActivity(), song.duration / 1000);
    if (!TextUtils.isEmpty(totalTimeString)) {
        if (totalTime != null) {
            totalTime.setText(totalTimeString);
        }
    }
    if (track != null) {
        track.setText(song.name);
        track.setSelected(true);
    }
    if (album != null) {
        album.setText(String.format("%s | %s", song.artistName, song.albumName));
    }
    if (isLandscape) {
        toolbar.setTitle(song.name);
        toolbar.setSubtitle(String.format("%s | %s", song.artistName, song.albumName));
        target = Glide.with(this).load(song).diskCacheStrategy(DiskCacheStrategy.SOURCE).bitmapTransform(new BlurTransformation(getContext(), 15, 4)).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(song.name, true)).thumbnail(Glide.with(this).load(this.song).bitmapTransform(new BlurTransformation(getContext(), 15, 4))).crossFade(600).into(backgroundView);
        this.song = song;
    } else {
        backgroundView.setImageDrawable(null);
        toolbar.setTitle(null);
        toolbar.setSubtitle(null);
    }
    if (SettingsManager.getInstance().getUsePalette()) {
        // noinspection unchecked
        Glide.with(this).load(song).asBitmap().transcode(new PaletteBitmapTranscoder(getContext()), PaletteBitmap.class).override(250, 250).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<PaletteBitmap>() {

            @Override
            public void onResourceReady(PaletteBitmap resource, GlideAnimation<? super PaletteBitmap> glideAnimation) {
                if (!isAdded() || getContext() == null) {
                    return;
                }
                Palette.Swatch swatch = resource.palette.getDarkMutedSwatch();
                if (swatch != null) {
                    if (SettingsManager.getInstance().getUsePalette()) {
                        if (SettingsManager.getInstance().getUsePaletteNowPlayingOnly()) {
                            animateColors(currentColor, swatch.getRgb(), color -> invalidateColors(color));
                        } else {
                            // Set Aesthetic colors globally, based on the current Palette swatch
                            disposables.add(Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(integer -> animateColors(integer, swatch.getRgb(), color -> {
                                if (getContext() != null && isAdded()) {
                                    Aesthetic aesthetic = Aesthetic.get(getContext()).colorPrimary(color).colorStatusBarAuto();
                                    if (SettingsManager.getInstance().getTintNavBar()) {
                                        aesthetic = aesthetic.colorNavigationBar(color);
                                    }
                                    aesthetic.apply();
                                }
                            })));
                        }
                    }
                } else {
                    // Failed to generate the dark muted swatch, fall back to the primary theme colour.
                    Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
                }
            }

            @Override
            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                super.onLoadFailed(e, errorDrawable);
                Aesthetic.get(getContext()).colorPrimary().take(1).subscribe(primaryColor -> animateColors(currentColor, primaryColor, color -> invalidateColors(color)));
            }
        });
    }
}
Also used : PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) ImageView(android.widget.ImageView) SeekBarStopChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStopChangeEvent) FavoriteActionBarView(com.simplecity.amp_library.ui.views.FavoriteActionBarView) Drawable(android.graphics.drawable.Drawable) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) PaletteBitmapTranscoder(com.simplecity.amp_library.glide.palette.PaletteBitmapTranscoder) RepeatingImageButton(com.simplecity.amp_library.ui.views.RepeatingImageButton) View(android.view.View) ArgbEvaluator(android.animation.ArgbEvaluator) Schedulers(io.reactivex.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) ShuffleButton(com.simplecity.amp_library.ui.views.ShuffleButton) Unbinder(butterknife.Unbinder) Log(android.util.Log) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) LogUtils(com.simplecity.amp_library.utils.LogUtils) PlayPauseView(com.simplecity.amp_library.ui.views.PlayPauseView) SeekBarProgressChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarProgressChangeEvent) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) SnowfallView(com.simplecity.amp_library.ui.views.SnowfallView) SeekBarStartChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarStartChangeEvent) Util(com.afollestad.aesthetic.Util) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Palette(android.support.v7.graphics.Palette) ButterKnife(butterknife.ButterKnife) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) StringUtils(com.simplecity.amp_library.utils.StringUtils) MenuItem(android.view.MenuItem) Inject(javax.inject.Inject) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SuppressLint(android.annotation.SuppressLint) SeekBarChangeEvent(com.jakewharton.rxbinding2.widget.SeekBarChangeEvent) Flowable(io.reactivex.Flowable) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) UnsafeConsumer(com.simplecity.amp_library.rx.UnsafeConsumer) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TaggerDialog(com.simplecity.amp_library.tagger.TaggerDialog) BackpressureStrategy(io.reactivex.BackpressureStrategy) LayoutInflater(android.view.LayoutInflater) Target(com.bumptech.glide.request.target.Target) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) TextUtils(android.text.TextUtils) Color(android.graphics.Color) TimeUnit(java.util.concurrent.TimeUnit) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) PlayerView(com.simplecity.amp_library.ui.views.PlayerView) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap) Glide(com.bumptech.glide.Glide) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Toolbar(android.support.v7.widget.Toolbar) MusicService(com.simplecity.amp_library.playback.MusicService) PlayerPresenter(com.simplecity.amp_library.ui.presenters.PlayerPresenter) DataManager(com.simplecity.amp_library.utils.DataManager) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) RepeatButton(com.simplecity.amp_library.ui.views.RepeatButton) Collections(java.util.Collections) RxSeekBar(com.jakewharton.rxbinding2.widget.RxSeekBar) ValueAnimator(android.animation.ValueAnimator) RxSharedPreferences(com.f2prateek.rx.preferences2.RxSharedPreferences) BlurTransformation(com.jp.wasabeef.glide.transformations.BlurTransformation) Aesthetic(com.afollestad.aesthetic.Aesthetic) Drawable(android.graphics.drawable.Drawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) PaletteBitmap(com.simplecity.amp_library.glide.palette.PaletteBitmap)

Example 2 with SimpleTarget

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

the class MineFragment method refreshUserInfo.

private void refreshUserInfo(final UserBean user) {
    if (user == null) {
        return;
    }
    mBinding.setUser(user);
    Observable.timer(0, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Observer<Long>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            Log.w(TAG, "onError:" + e.toString());
        }

        @Override
        public void onNext(Long aLong) {
            Glide.with(getContext()).load(user.getProfile_image_url()).asBitmap().into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    Bitmap bitmap = FastBlurUtil.toBlur(resource, 10, 1);
                    mBinding.ivTopBg.setImageBitmap(bitmap);
                }
            });
        }
    });
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Example 3 with SimpleTarget

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

the class App method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    sApp = this;
    AutoJs.initInstance(this);
    GlobalKeyObserver.init();
    Drawables.setDefaultImageLoader(new ImageLoader() {

        @Override
        public void loadInto(ImageView imageView, Uri uri) {
            Glide.with(App.this).load(uri).into(imageView);
        }

        @Override
        public void loadIntoBackground(View view, Uri uri) {
            Glide.with(App.this).load(uri).into(new SimpleTarget<Drawable>() {

                @Override
                public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                    view.setBackground(resource);
                }
            });
        }

        @Override
        public Drawable load(View view, Uri uri) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void load(View view, Uri uri, DrawableCallback drawableCallback) {
            Glide.with(App.this).load(uri).into(new SimpleTarget<Drawable>() {

                @Override
                public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                    drawableCallback.onLoaded(resource);
                }
            });
        }

        @Override
        public void load(View view, Uri uri, BitmapCallback bitmapCallback) {
            Glide.with(App.this).asBitmap().load(uri).into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                    bitmapCallback.onLoaded(resource);
                }
            });
        }
    });
}
Also used : SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) Drawable(android.graphics.drawable.Drawable) Transition(com.bumptech.glide.request.transition.Transition) ImageView(android.widget.ImageView) ImageLoader(com.stardust.autojs.core.ui.inflater.ImageLoader) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View)

Example 4 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 5 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)

Aggregations

SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)24 GlideAnimation (com.bumptech.glide.request.animation.GlideAnimation)18 Drawable (android.graphics.drawable.Drawable)17 Bitmap (android.graphics.Bitmap)16 ColorDrawable (android.graphics.drawable.ColorDrawable)6 ImageView (android.widget.ImageView)6 View (android.view.View)5 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 LayerDrawable (android.graphics.drawable.LayerDrawable)4 Nullable (android.support.annotation.Nullable)4 Palette (android.support.v7.graphics.Palette)4 Target (com.bumptech.glide.request.target.Target)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)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 Uri (android.net.Uri)2