FileDocCategorySizeDatePackage
NotificationTemplateViewWrapper.javaAPI DocAndroid 5.1 API9936Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar

NotificationTemplateViewWrapper

public class NotificationTemplateViewWrapper extends NotificationViewWrapper
Wraps a notification view inflated from a template.

Fields Summary
private final android.graphics.ColorMatrix
mGrayscaleColorMatrix
private final android.graphics.PorterDuffColorFilter
mIconColorFilter
private final int
mIconDarkAlpha
private final int
mIconBackgroundDarkColor
private final android.view.animation.Interpolator
mLinearOutSlowInInterpolator
private int
mIconBackgroundColor
private com.android.systemui.ViewInvertHelper
mInvertHelper
private android.widget.ImageView
mIcon
protected android.widget.ImageView
mPicture
private boolean
mIconForceGraysaleWhenDark
Whether the icon needs to be forced grayscale when in dark mode.
Constructors Summary
protected NotificationTemplateViewWrapper(android.content.Context ctx, android.view.View view)


         
        super(view);
        mIconDarkAlpha = ctx.getResources().getInteger(R.integer.doze_small_icon_alpha);
        mIconBackgroundDarkColor =
                ctx.getResources().getColor(R.color.doze_small_icon_background_color);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(ctx,
                android.R.interpolator.linear_out_slow_in);
        resolveViews();
    
Methods Summary
protected voidfadeGrayscale(android.widget.ImageView target, boolean dark, long delay)

        startIntensityAnimation(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                updateGrayscaleMatrix((float) animation.getAnimatedValue());
                target.setColorFilter(new ColorMatrixColorFilter(mGrayscaleColorMatrix));
            }
        }, dark, delay, new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (!dark) {
                    target.setColorFilter(null);
                }
            }
        });
    
private voidfadeIconAlpha(android.widget.ImageView target, boolean dark, long delay)

        startIntensityAnimation(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float t = (float) animation.getAnimatedValue();
                target.setImageAlpha((int) (255 * (1f - t) + mIconDarkAlpha * t));
            }
        }, dark, delay, null /* listener */);
    
private voidfadeIconColorFilter(android.widget.ImageView target, boolean dark, long delay)

        startIntensityAnimation(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                updateIconColorFilter(target, (Float) animation.getAnimatedValue());
            }
        }, dark, delay, null /* listener */);
    
private static intinterpolateColor(int source, int target, float t)

        int aSource = Color.alpha(source);
        int rSource = Color.red(source);
        int gSource = Color.green(source);
        int bSource = Color.blue(source);
        int aTarget = Color.alpha(target);
        int rTarget = Color.red(target);
        int gTarget = Color.green(target);
        int bTarget = Color.blue(target);
        return Color.argb(
                (int) (aSource * (1f - t) + aTarget * t),
                (int) (rSource * (1f - t) + rTarget * t),
                (int) (gSource * (1f - t) + gTarget * t),
                (int) (bSource * (1f - t) + bTarget * t));
    
public voidnotifyContentUpdated()

        super.notifyContentUpdated();

        // Reinspect the notification.
        resolveViews();
    
private intresolveBackgroundColor(android.widget.ImageView icon)

        if (icon != null && icon.getBackground() != null) {
            ColorFilter filter = icon.getBackground().getColorFilter();
            if (filter instanceof PorterDuffColorFilter) {
                return ((PorterDuffColorFilter) filter).getColor();
            }
        }
        return 0;
    
private android.widget.ImageViewresolveIcon(android.widget.ImageView largeIcon, android.widget.ImageView rightIcon)

        return largeIcon != null && largeIcon.getBackground() != null ? largeIcon
                : rightIcon != null && rightIcon.getVisibility() == View.VISIBLE ? rightIcon
                : null;
    
private android.widget.ImageViewresolvePicture(android.widget.ImageView largeIcon)

        return largeIcon != null && largeIcon.getBackground() == null
                ? largeIcon
                : null;
    
private voidresolveViews()

        View mainColumn = mView.findViewById(com.android.internal.R.id.notification_main_column);
        mInvertHelper = mainColumn != null
                ? new ViewInvertHelper(mainColumn, NotificationPanelView.DOZE_ANIMATION_DURATION)
                : null;
        ImageView largeIcon = (ImageView) mView.findViewById(com.android.internal.R.id.icon);
        ImageView rightIcon = (ImageView) mView.findViewById(com.android.internal.R.id.right_icon);
        mIcon = resolveIcon(largeIcon, rightIcon);
        mPicture = resolvePicture(largeIcon);
        mIconBackgroundColor = resolveBackgroundColor(mIcon);

        // If the icon already has a color filter, we assume that we already forced the icon to be
        // white when we created the notification.
        mIconForceGraysaleWhenDark = mIcon != null && mIcon.getDrawable().getColorFilter() != null;
    
public voidsetDark(boolean dark, boolean fade, long delay)

        if (mInvertHelper != null) {
            if (fade) {
                mInvertHelper.fade(dark, delay);
            } else {
                mInvertHelper.update(dark);
            }
        }
        if (mIcon != null) {
            if (fade) {
                fadeIconColorFilter(mIcon, dark, delay);
                fadeIconAlpha(mIcon, dark, delay);
                if (!mIconForceGraysaleWhenDark) {
                    fadeGrayscale(mIcon, dark, delay);
                }
            } else {
                updateIconColorFilter(mIcon, dark);
                updateIconAlpha(mIcon, dark);
                if (!mIconForceGraysaleWhenDark) {
                    updateGrayscale(mIcon, dark);
                }
            }
        }
        setPictureGrayscale(dark, fade, delay);
    
protected voidsetPictureGrayscale(boolean grayscale, boolean fade, long delay)

        if (mPicture != null) {
            if (fade) {
                fadeGrayscale(mPicture, grayscale, delay);
            } else {
                updateGrayscale(mPicture, grayscale);
            }
        }
    
private voidstartIntensityAnimation(ValueAnimator.AnimatorUpdateListener updateListener, boolean dark, long delay, Animator.AnimatorListener listener)

        float startIntensity = dark ? 0f : 1f;
        float endIntensity = dark ? 1f : 0f;
        ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity);
        animator.addUpdateListener(updateListener);
        animator.setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION);
        animator.setInterpolator(mLinearOutSlowInInterpolator);
        animator.setStartDelay(delay);
        if (listener != null) {
            animator.addListener(listener);
        }
        animator.start();
    
protected voidupdateGrayscale(android.widget.ImageView target, boolean dark)

        if (dark) {
            updateGrayscaleMatrix(1f);
            target.setColorFilter(new ColorMatrixColorFilter(mGrayscaleColorMatrix));
        } else {
            target.setColorFilter(null);
        }
    
private voidupdateGrayscaleMatrix(float intensity)

        mGrayscaleColorMatrix.setSaturation(1 - intensity);
    
private voidupdateIconAlpha(android.widget.ImageView target, boolean dark)

        target.setImageAlpha(dark ? mIconDarkAlpha : 255);
    
private voidupdateIconColorFilter(android.widget.ImageView target, boolean dark)

        updateIconColorFilter(target, dark ? 1f : 0f);
    
private voidupdateIconColorFilter(android.widget.ImageView target, float intensity)

        int color = interpolateColor(mIconBackgroundColor, mIconBackgroundDarkColor, intensity);
        mIconColorFilter.setColor(color);
        Drawable background = target.getBackground();

        // The background might be null for legacy notifications. Also, the notification might have
        // been modified during the animation, so background might be null here.
        if (background != null) {
            background.mutate().setColorFilter(mIconColorFilter);
        }