Search in sources :

Example 26 with Palette

use of android.support.v7.graphics.Palette in project PhotoNoter by yydcdut.

the class Utils method getPaletteColor.

public static int getPaletteColor(Bitmap bitmap) {
    Palette.Builder builder = Palette.from(bitmap);
    Palette palette = builder.generate();
    Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();
    if (vibrantSwatch == null) {
        Palette.Swatch lightVibrant = palette.getLightVibrantSwatch();
        if (lightVibrant == null) {
            Palette.Swatch darkVibrant = palette.getDarkVibrantSwatch();
            if (darkVibrant == null) {
                Palette.Swatch mutedSwatch = palette.getMutedSwatch();
                if (mutedSwatch == null) {
                    Palette.Swatch lightMuted = palette.getMutedSwatch();
                    if (lightMuted == null) {
                        Palette.Swatch darkMuted = palette.getDarkMutedSwatch();
                        if (darkMuted == null) {
                            return Color.WHITE;
                        } else {
                            return darkMuted.getRgb();
                        }
                    } else {
                        return lightMuted.getRgb();
                    }
                } else {
                    return mutedSwatch.getRgb();
                }
            } else {
                return darkVibrant.getRgb();
            }
        } else {
            return lightVibrant.getRgb();
        }
    } else {
        return vibrantSwatch.getRgb();
    }
}
Also used : Palette(android.support.v7.graphics.Palette)

Example 27 with Palette

use of android.support.v7.graphics.Palette in project apps-android-wikipedia by wikimedia.

the class FacePostprocessor method process.

@Override
public void process(Bitmap destBitmap, Bitmap sourceBitmap) {
    if (listener.get() == null) {
        return;
    }
    if (isBitmapEligibleForImageProcessing(sourceBitmap)) {
        copyWithWhiteBackground(destBitmap, sourceBitmap);
        Bitmap testBmp = new565ScaledBitmap(sourceBitmap);
        Palette colorPalette = Palette.from(testBmp).generate();
        PointF facePos = null;
        try {
            facePos = detectFace(testBmp);
        } catch (OutOfMemoryError e) {
            L.logRemoteErrorIfProd(e);
        }
        int defaultColor = ContextCompat.getColor(WikipediaApp.getInstance(), R.color.base30);
        listener.get().onImageLoaded(destBitmap.getHeight(), facePos, extractMainColor(colorPalette, defaultColor));
    } else {
        listener.get().onImageFailed();
    }
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap) PointF(android.graphics.PointF) Paint(android.graphics.Paint)

Example 28 with Palette

use of android.support.v7.graphics.Palette in project TicktockMusic by Lauzy.

the class TickNotification method buildNotification.

private Notification buildNotification(MusicService musicService) {
    PendingIntent playIntent = createAction(musicService, MusicService.ACTION_PLAY);
    PendingIntent pauseIntent = createAction(musicService, MusicService.ACTION_PAUSE);
    PendingIntent previousIntent = createAction(musicService, MusicService.ACTION_LAST);
    PendingIntent nextIntent = createAction(musicService, MusicService.ACTION_NEXT);
    PendingIntent contentIntent = PendingIntent.getActivity(musicService, 0, new Intent(musicService, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    boolean isPlaying = musicService.getPlaybackState().getState() == PlaybackState.STATE_PLAYING;
    MediaSession session = musicService.getMediaSession();
    MediaController controller = session.getController();
    if (controller.getMetadata() != null) {
        MediaDescription description = controller.getMetadata().getDescription();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(musicService);
        builder.setContentTitle(description.getTitle()).setSmallIcon(R.drawable.ic_notification).setShowWhen(false).setOngoing(isPlaying).setContentIntent(contentIntent).setLargeIcon(description.getIconBitmap()).setContentTitle(description.getTitle()).setContentText(description.getSubtitle()).addAction(R.drawable.ic_skip_previous_notify, "", previousIntent).addAction(isPlaying ? R.drawable.ic_pause : R.drawable.ic_play, "", isPlaying ? pauseIntent : playIntent).addAction(R.drawable.ic_skip_next_notify, "", nextIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(0, 1, 2));
        if (description.getIconBitmap() != null) {
            Palette palette = Palette.from(description.getIconBitmap()).generate();
            int color = palette.getDominantColor(ThemeHelper.getThemeColorResId(musicService.getApplicationContext()));
            builder.setColor(color);
        }
        return builder.build();
    }
    return null;
}
Also used : Palette(android.support.v7.graphics.Palette) MediaController(android.media.session.MediaController) MediaDescription(android.media.MediaDescription) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) MainActivity(com.freedom.lauzy.ticktockmusic.ui.activity.MainActivity) MediaSession(android.media.session.MediaSession) NotificationCompat(android.support.v7.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 29 with Palette

use of android.support.v7.graphics.Palette in project MusicLake by caiyonglong.

the class PlayControlsPresenter method updateNowPlayingCard.

@Override
public void updateNowPlayingCard() {
    Log.d(TAG, "updateNowPlayingCard" + mProgress);
    Music music = PlayManager.getPlayingMusic();
    if (music == null || PlayManager.getPlayList().size() == 0) {
        Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.default_cover);
        mView.setAlbumArt(bitmap);
        mView.setTitle(mContext.getResources().getString(R.string.app_name));
        mView.setArtist("");
        mView.updatePanelLayout(false);
        return;
    } else {
        mView.updatePanelLayout(true);
    }
    final String title = PlayManager.getSongName();
    final String artist = PlayManager.getSongArtist();
    if (TextUtils.isEmpty(title) && TextUtils.isEmpty(artist)) {
        mView.setTitle(mContext.getResources().getString(R.string.app_name));
        mView.setArtist("");
    } else {
        mView.setTitle(title);
        mView.setArtist(artist);
    }
    String picUrl = CoverLoader.getInstance().getCoverUriByMusic(music);
    // 设置音乐来源
    mView.setOtherInfo(music.getTypeName(false));
    // 获取当前歌曲状态
    AppRepository.getMusicInfo(mContext, music).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(music1 -> mView.updateFavorite(music1.isLove()));
    if (!isPlayPauseClick && !activity.isFinishing()) {
        loadLyric();
        GlideApp.with(mContext).asBitmap().load(picUrl != null ? picUrl : CoverLoader.getInstance().getCoverUriByRandom()).error(CoverLoader.getInstance().getCoverUriByRandom()).diskCacheStrategy(DiskCacheStrategy.ALL).into(new SimpleTarget<Bitmap>() {

            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                mView.setAlbumArt(resource);
                mView.setAlbumArt(ImageUtils.createBlurredImageFromBitmap(resource, mContext, 12));
                new Palette.Builder(resource).generate(palette -> mView.setPalette(palette));
            }
        });
    }
    isPlayPauseClick = false;
    mHandler.post(updateProgress);
}
Also used : GlideApp(com.cyl.musiclake.api.GlideApp) Context(android.content.Context) Palette(android.support.v7.graphics.Palette) LogUtil(com.cyl.musiclake.utils.LogUtil) FileUtils(com.cyl.musiclake.utils.FileUtils) R(com.cyl.musiclake.R) BitmapFactory(android.graphics.BitmapFactory) MusicApi(com.cyl.musiclake.api.MusicApi) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SuppressLint(android.annotation.SuppressLint) CoverLoader(com.cyl.musiclake.utils.CoverLoader) Handler(android.os.Handler) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) PlayControlsContract(com.cyl.musiclake.ui.music.local.contract.PlayControlsContract) MetaChangedEvent(com.cyl.musiclake.event.MetaChangedEvent) Log(android.util.Log) PlayManager(com.cyl.musiclake.service.PlayManager) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Music(com.cyl.musiclake.bean.Music) TextUtils(android.text.TextUtils) AppRepository(com.cyl.musiclake.data.source.AppRepository) ImageUtils(com.cyl.musiclake.utils.ImageUtils) StatusChangedEvent(com.cyl.musiclake.event.StatusChangedEvent) Disposable(io.reactivex.disposables.Disposable) Bitmap(android.graphics.Bitmap) Transition(com.bumptech.glide.request.transition.Transition) Observer(io.reactivex.Observer) RxBus(com.cyl.musiclake.RxBus) Activity(android.app.Activity) Bitmap(android.graphics.Bitmap) Music(com.cyl.musiclake.bean.Music)

Aggregations

Palette (android.support.v7.graphics.Palette)25 Bitmap (android.graphics.Bitmap)18 Drawable (android.graphics.drawable.Drawable)7 ImageView (android.widget.ImageView)7 TextView (android.widget.TextView)6 View (android.view.View)5 Intent (android.content.Intent)4 TextUtils (android.text.TextUtils)4 BindView (butterknife.BindView)4 Context (android.content.Context)3 Bundle (android.os.Bundle)3 RecyclerView (android.support.v7.widget.RecyclerView)3 Toolbar (android.support.v7.widget.Toolbar)3 SuppressLint (android.annotation.SuppressLint)2 Activity (android.app.Activity)2 Color (android.graphics.Color)2 Uri (android.net.Uri)2 Nullable (android.support.annotation.Nullable)2 ContextCompat (android.support.v4.content.ContextCompat)2 Pair (android.support.v4.util.Pair)2