From bbc139188a4ac90cb9371e2b823821063d96f273 Mon Sep 17 00:00:00 2001 From: Mario Bertschler Date: Wed, 5 Jul 2017 12:03:24 -0700 Subject: Only draw double shadows of BubbleTextView if both shadow color's alpha value is non-zero. Bug: 63331170 Change-Id: Ia9f06c1d6fb217d264cece805826faf123e9d5f3 Signed-off-by: Mario Bertschler --- .../views/DoubleShadowBubbleTextView.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/com/android/launcher3') diff --git a/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java b/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java index c0b5fe156..c8203f7f2 100644 --- a/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java +++ b/src/com/android/launcher3/views/DoubleShadowBubbleTextView.java @@ -23,6 +23,7 @@ import android.graphics.Color; import android.graphics.Region; import android.support.v4.graphics.ColorUtils; import android.util.AttributeSet; +import android.widget.TextView; import com.android.launcher3.BubbleTextView; import com.android.launcher3.R; @@ -50,13 +51,12 @@ public class DoubleShadowBubbleTextView extends BubbleTextView { @Override public void onDraw(Canvas canvas) { - // If text is transparent, don't draw any shadow - int alpha = Color.alpha(getCurrentTextColor()); - if (alpha == 0) { - getPaint().clearShadowLayer(); + // If text is transparent or shadow alpha is 0, don't draw any shadow + if (mShadowInfo.skipDoubleShadow(this)) { super.onDraw(canvas); return; } + int alpha = Color.alpha(getCurrentTextColor()); // We enhance the shadow by drawing the shadow twice getPaint().setShadowLayer(mShadowInfo.ambientShadowBlur, 0, 0, @@ -97,5 +97,25 @@ public class DoubleShadowBubbleTextView extends BubbleTextView { keyShadowColor = a.getColor(R.styleable.ShadowInfo_keyShadowColor, 0); a.recycle(); } + + public boolean skipDoubleShadow(TextView textView) { + int textAlpha = Color.alpha(textView.getCurrentTextColor()); + int keyShadowAlpha = Color.alpha(keyShadowColor); + int ambientShadowAlpha = Color.alpha(ambientShadowColor); + if (textAlpha == 0 || (keyShadowAlpha == 0 && ambientShadowAlpha == 0)) { + textView.getPaint().clearShadowLayer(); + return true; + } else if (ambientShadowAlpha > 0) { + textView.getPaint().setShadowLayer(ambientShadowBlur, 0, 0, + ColorUtils.setAlphaComponent(ambientShadowColor, textAlpha)); + return true; + } else if (keyShadowAlpha > 0) { + textView.getPaint().setShadowLayer(keyShadowBlur, 0.0f, keyShadowOffset, + ColorUtils.setAlphaComponent(keyShadowColor, textAlpha)); + return true; + } else { + return false; + } + } } } -- cgit v1.2.3