Jun_27.md

2018-06-27  本文已影响0人  深蓝Yearth

今日任务


Que 0x01 mUpdateColors

private final OnGetTintInfo mUpdateColors = new OnGetTintInfo() {
        public void onGetTintInfo(int listType, long albumId, TintInfo tintInfo) {
            BackgroundFadeController.this.mEdgeLightningColors = new int[]{tintInfo.gradientColorA, tintInfo.gradientColorB};
            BackgroundFadeController.this.updateEdgeAnimation(BackgroundFadeController.this.mIsPlaying);
        }
    };

Que 0x02 mUpdateColorsAfterRotation

private final Runnable mUpdateColorsAfterRotation = new Runnable() {
        public void run() {
            if (BackgroundFadeController.sActivityCount == 0) {
                BackgroundFadeController.this.stopEdgeLightning();
            }
        }
    };

Que 0x03 static {}

static {
        sAppEdgeEffectInfo.setStrokeAlpha(0.8f);
        sAppEdgeEffectInfo.setRotateDuration(3000);
    }

Que 0x04 BackgroundFadeController

public BackgroundFadeController(Activity activity, com.samsung.android.app.music.common.mediainfo.observer.MediaChangeObservable mediaChangeObservable, MediaChangeObservable coreMediaChangeObservable) {
        this.mActivity = activity;
        this.mAlphaMask = (ImageView) activity.findViewById(R.id.blur_alpha_mask);
        if (this.mAlphaMask != null) {
            this.mNonPlayingColor = ContextCompat.getColor(activity, R.color.blur_alpha_mask);
            this.mPlayingColor = ContextCompat.getColor(activity, R.color.blur_alpha_mask_playing);
            this.mMediaChangeObservable = mediaChangeObservable;
            this.mCoreMediaChangeObservable = coreMediaChangeObservable;
            mediaChangeObservable.registerMediaChangeObserver(this);
        } else {
            this.mNonPlayingColor = 0;
            this.mPlayingColor = 0;
            this.mMediaChangeObservable = null;
            this.mCoreMediaChangeObservable = null;
        }
        this.mIsFirstMeta = true;
        sAppEdgeEffectInfo.setStrokeWidth(activity.getResources().getDimension(R.dimen.edge_lightning_stroke_width));
    }

Que 0x05 isLockScreen

private boolean isLockScreen() {
        return this.mActivity instanceof LockScreenActivity;
    }

Que 0x06 onMetaChanged

public void onMetaChanged(Meta m, PlayState s) {
        iLog.d(LOG_TAG, "onMetaChanged() called with: mIsFirstMeta = [" + this.mIsFirstMeta + "]");
        if (this.mIsFirstMeta) {
            this.mIsFirstMeta = false;
            updateFadeState(s.isPlaying, false);
        }
        this.mIsPlaying = s.isPlaying;
        updateColors(m.listType, m.albumId);
    }

Que 0x07 onPlayStateChanged

public void onPlayStateChanged(PlayState s) {
        iLog.d(LOG_TAG, "onPlayStateChanged() called with: s.isPlaying = [" + s.isPlaying + "]");
        if (this.mIsPlaying != s.isPlaying) {
            this.mIsPlaying = s.isPlaying;
            updateFadeState(s.isPlaying, true);
            if (s.isPlaying) {
                Meta currentMeta = this.mMediaChangeObservable.getCurrentMeta();
                updateColors(currentMeta.listType, currentMeta.albumId);
                return;
            }
            stopEdgeLightning();
        }
    }

Que 0x08 updateFadeState

private void updateFadeState(boolean isPlaying, boolean animation) {
        int startColor;
        int endColor;
        ColorDrawable color;
        iLog.d(LOG_TAG, "updateFadeState() called with: isPlaying = [" + isPlaying + "], animation = [" + animation + "]");
        if (isPlaying) {
            startColor = this.mNonPlayingColor;
            endColor = this.mPlayingColor;
        } else {
            startColor = this.mPlayingColor;
            endColor = this.mNonPlayingColor;
        }
        Drawable d = this.mAlphaMask.getDrawable();
        if (d instanceof ColorDrawable) {
            color = (ColorDrawable) d.mutate();
        } else {
            color = new ColorDrawable(startColor);
            this.mAlphaMask.setImageDrawable(color);
        }
        if (animation) {
            ValueAnimator alphaAnimation = ValueAnimator.ofArgb(new int[]{startColor, endColor}).setDuration(266);
            alphaAnimation.setInterpolator(InterpolatorSet.SINE_IN_OUT_33);
            alphaAnimation.addUpdateListener(new AnimatorUpdateListener() {
                public void onAnimationUpdate(ValueAnimator animation) {
                    color.setColor(((Integer) animation.getAnimatedValue()).intValue());
                    BackgroundFadeController.this.mAlphaMask.invalidateDrawable(color);
                }
            });
            alphaAnimation.start();
            return;
        }
        color.setColor(endColor);
        this.mAlphaMask.invalidateDrawable(color);
    }

Que 0x09 checkEdgeLightningStopCondition

private boolean checkEdgeLightningStopCondition(boolean isPlaying) {
        if (isPlaying) {
            if ((!isLockScreen() && UiUtils.isInMultiWindowMode(this.mActivity)) || DesktopModeManagerCompat.isDesktopMode()) {
                return true;
            }
        } else if (isLockScreen() || UiUtils.isInMultiWindowMode(this.mActivity)) {
            return true;
        }
        return false;
    }

Que 0x0A stopEdgeLightning

private void stopEdgeLightning() {
        if (sEdgeLightingController != null) {
            sEdgeLightingController.stopApplication();
        }
        sIsEdgeAnimationPlaying = false;
    }

Que 0x0B updateEdgeAnimation

private void updateEdgeAnimation(boolean isPlaying) {
        if (sEdgeLightingController == null) {
            synchronized (sEdgeLightningLock) {
                if (sEdgeLightingController == null) {
                    sEdgeLightingController = new EdgeLightingDialog(this.mActivity.getApplicationContext());
                }
            }
        }
        if (checkEdgeLightningStopCondition(isPlaying)) {
            stopEdgeLightning();
            return;
        }
        iLog.d(LOG_TAG, "updateEdgeAnimation() called with: isPlaying = [" + isPlaying + "]");
        if (isPlaying && this.mEdgeLightningColors != null) {
            if (!sIsEdgeAnimationPlaying || !Arrays.equals(this.mEdgeLightningColors, sCurrentEdgeLightningColors)) {
                sCurrentEdgeLightningColors = this.mEdgeLightningColors;
                sAppEdgeEffectInfo.setEffectColors(this.mEdgeLightningColors);
                sEdgeLightingController.startApplication(sAppEdgeEffectInfo);
                sIsEdgeAnimationPlaying = true;
            }
        }
    }

Que 0x0C updateColors

private void updateColors(int listType, long albumId) {
        TintColorCache.getInstance().getColor(this.mActivity, listType, albumId, this.mUpdateColors);
    }

Que 0x0D 总结

如图所示:

123123123123.png
上一篇 下一篇

猜你喜欢

热点阅读