From c8906fce1a28d877b9120873dd38a3070cb3a4bd Mon Sep 17 00:00:00 2001 From: Eugen Martynov Date: Tue, 26 Nov 2019 00:17:42 +0100 Subject: [PATCH] Restore texture functionality --- .../core/util/CollapsingTextHelper.java | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/io/plaidapp/core/util/CollapsingTextHelper.java b/core/src/main/java/io/plaidapp/core/util/CollapsingTextHelper.java index b06873b01..132b96f1c 100644 --- a/core/src/main/java/io/plaidapp/core/util/CollapsingTextHelper.java +++ b/core/src/main/java/io/plaidapp/core/util/CollapsingTextHelper.java @@ -74,6 +74,7 @@ public final class CollapsingTextHelper { private CharSequence mText; private CharSequence mTextToDraw; private boolean mIsRtl; + private boolean mUseTexture; private Bitmap mExpandedTitleTexture; private Paint mTexturePaint; private float mTextureAscent; @@ -117,21 +118,35 @@ public void draw(Canvas canvas) { if (mTextToDraw != null && mDrawTitle) { float x = mCurrentDrawX; float y = mCurrentDrawY; + final boolean drawTexture = mUseTexture && mExpandedTitleTexture != null; final float ascent; final float descent; // Update the TextPaint to the current text size mTextPaint.setTextSize(mCurrentTextSize); - ascent = mTextPaint.ascent() * mScale; - descent = mTextPaint.descent() * mScale; + if (drawTexture) { + ascent = mTextureAscent * mScale; + descent = mTextureDescent * mScale; + } else { + ascent = mTextPaint.ascent() * mScale; + descent = mTextPaint.descent() * mScale; + } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mCurrentBounds.left, y + ascent, mCurrentBounds.right, y + descent, DEBUG_DRAW_PAINT); } + if (drawTexture) { + y += ascent; + } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } - canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); + if (drawTexture) { + // If we should use a texture, draw it instead of text + canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); + } else { + canvas.drawText(mTextToDraw, 0, mTextToDraw.length(), x, y, mTextPaint); + } } canvas.restoreToCount(saveCount); } @@ -459,6 +474,12 @@ private void setInterpolatedTextSize(final float textSize) { } mIsRtl = calculateIsRtl(mTextToDraw); } + // Use our texture if the scale isn't 1.0 + mUseTexture = mScale != 1f; + if (mUseTexture) { + // Make sure we have an expanded texture if needed + ensureExpandedTexture(); + } ViewCompat.postInvalidateOnAnimation(mView); }