Search in sources :

Example 6 with Palette

use of androidx.palette.graphics.Palette in project Phonograph by kabouzeid.

the class AppWidgetCard method performUpdate.

/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_card);
    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();
    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
    }
    // Set correct drawable for pause state
    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, true))));
    // Set prev/next button drawables
    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
    // Link actions buttons to intents
    linkButtons(service, appWidgetView);
    if (imageSize == 0)
        imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
    if (cardRadius == 0f)
        cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
    // Load the album cover async and push the update on completion
    service.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(service), song).checkIgnoreMediaStore(service).generatePalette(service).build().centerCrop().into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {

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

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    super.onLoadFailed(e, errorDrawable);
                    update(null, MaterialValueHelper.getSecondaryTextColor(service, true));
                }

                private void update(@Nullable Bitmap bitmap, int color) {
                    // Set correct drawable for pause state
                    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
                    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));
                    // Set prev/next button drawables
                    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
                    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));
                    final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
                    final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
                    appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
                    pushUpdate(service, appWidgetIds, appWidgetView);
                }
            });
        }
    });
}
Also used : Palette(androidx.palette.graphics.Palette) BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) RemoteViews(android.widget.RemoteViews) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap)

Example 7 with Palette

use of androidx.palette.graphics.Palette 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)

Example 8 with Palette

use of androidx.palette.graphics.Palette in project Timber by naman14.

the class AlbumDetailFragment method setAlbumart.

private void setAlbumart() {
    ImageUtils.loadAlbumArtIntoView(album.id, albumArt, new ImageLoadingListener() {

        @Override
        public void onLoadingStarted(String imageUri, View view) {
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            loadFailed = true;
            MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(context).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
            ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
            fab.setImageDrawable(builder.build());
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            try {
                new Palette.Builder(loadedImage).generate(new Palette.PaletteAsyncListener() {

                    @Override
                    public void onGenerated(Palette palette) {
                        Palette.Swatch swatch = palette.getVibrantSwatch();
                        if (swatch != null) {
                            primaryColor = swatch.getRgb();
                            collapsingToolbarLayout.setContentScrimColor(primaryColor);
                            if (getActivity() != null)
                                ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
                        } else {
                            Palette.Swatch swatchMuted = palette.getMutedSwatch();
                            if (swatchMuted != null) {
                                primaryColor = swatchMuted.getRgb();
                                collapsingToolbarLayout.setContentScrimColor(primaryColor);
                                if (getActivity() != null)
                                    ATEUtils.setStatusBarColor(getActivity(), Helpers.getATEKey(getActivity()), primaryColor);
                            }
                        }
                        if (getActivity() != null) {
                            MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.SHUFFLE).setSizeDp(30);
                            if (primaryColor != -1) {
                                builder.setColor(TimberUtils.getBlackWhiteColor(primaryColor));
                                ATEUtils.setFabBackgroundTint(fab, primaryColor);
                                fab.setImageDrawable(builder.build());
                            } else {
                                if (context != null) {
                                    ATEUtils.setFabBackgroundTint(fab, Config.accentColor(context, Helpers.getATEKey(context)));
                                    builder.setColor(TimberUtils.getBlackWhiteColor(Config.accentColor(context, Helpers.getATEKey(context))));
                                    fab.setImageDrawable(builder.build());
                                }
                            }
                        }
                    }
                });
            } catch (Exception ignored) {
            }
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
        }
    });
}
Also used : Palette(androidx.palette.graphics.Palette) Bitmap(android.graphics.Bitmap) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder)

Example 9 with Palette

use of androidx.palette.graphics.Palette 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).showImageOnLoading(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).showImageOnLoading(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(androidx.palette.graphics.Palette) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.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)

Example 10 with Palette

use of androidx.palette.graphics.Palette in project Phonograph by kabouzeid.

the class AppWidgetClassic method performUpdate.

/**
 * Update all active widget instances by pushing changes
 */
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
    final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_classic);
    final boolean isPlaying = service.isPlaying();
    final Song song = service.getCurrentSong();
    // Set the titles and artwork
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
        appWidgetView.setTextViewText(R.id.title, song.title);
        appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
    }
    // Link actions buttons to intents
    linkButtons(service, appWidgetView);
    if (imageSize == 0)
        imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_classic_image_size);
    if (cardRadius == 0f)
        cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
    // Load the album cover async and push the update on completion
    final Context appContext = service.getApplicationContext();
    service.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(appContext), song).checkIgnoreMediaStore(appContext).generatePalette(service).build().centerCrop().into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {

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

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    super.onLoadFailed(e, errorDrawable);
                    update(null, MaterialValueHelper.getSecondaryTextColor(appContext, true));
                }

                private void update(@Nullable Bitmap bitmap, int color) {
                    // Set correct drawable for pause state
                    int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
                    appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));
                    // Set prev/next button drawables
                    appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
                    appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));
                    final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
                    final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
                    appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
                    pushUpdate(appContext, appWidgetIds, appWidgetView);
                }
            });
        }
    });
}
Also used : Context(android.content.Context) Palette(androidx.palette.graphics.Palette) BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) RemoteViews(android.widget.RemoteViews) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap)

Aggregations

Bitmap (android.graphics.Bitmap)11 Palette (androidx.palette.graphics.Palette)11 View (android.view.View)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)5 Drawable (android.graphics.drawable.Drawable)4 BitmapPaletteWrapper (com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper)4 Song (com.kabouzeid.gramophone.model.Song)4 FailReason (com.nostra13.universalimageloader.core.assist.FailReason)4 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)4 Context (android.content.Context)3 RemoteViews (android.widget.RemoteViews)3 Nullable (androidx.annotation.Nullable)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 PendingIntent (android.app.PendingIntent)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1