From 24edeb52bc6202ca98fb80f2f30e4a38dc6ab43b Mon Sep 17 00:00:00 2001 From: cgspine Date: Wed, 27 Mar 2019 17:06:12 +0800 Subject: [PATCH] paragraph space for ellipsize end --- .../qmui/qqface/QMUIQQFaceCompiler.java | 9 ++-- .../qmuiteam/qmui/qqface/QMUIQQFaceView.java | 42 ++++++++----------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceCompiler.java b/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceCompiler.java index e8c2acf5..8ef830a0 100644 --- a/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceCompiler.java +++ b/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceCompiler.java @@ -60,7 +60,7 @@ public class QMUIQQFaceCompiler { mQQFaceManager = manager; } - public int getSpecialBoundsMaxHeight(){ + public int getSpecialBoundsMaxHeight() { return mQQFaceManager.getSpecialDrawableMaxHeight(); } @@ -363,8 +363,11 @@ public class QMUIQQFaceCompiler { } else if (element.getType() == ElementType.NEXTLINE) { mNewLineCount++; } else if (element.getType() == ElementType.SPAN) { - mQQFaceCount += element.getChildList().getQQFaceCount(); - mNewLineCount += element.getChildList().getNewLineCount(); + ElementList childList = element.getChildList(); + if (childList != null) { + mQQFaceCount += element.getChildList().getQQFaceCount(); + mNewLineCount += element.getChildList().getNewLineCount(); + } } mElements.add(element); } diff --git a/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceView.java b/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceView.java index d3e4553e..13528c96 100644 --- a/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceView.java +++ b/qmui/src/main/java/com/qmuiteam/qmui/qqface/QMUIQQFaceView.java @@ -92,6 +92,7 @@ public class QMUIQQFaceView extends View { private TextUtils.TruncateAt mEllipsize = TextUtils.TruncateAt.END; private boolean mIsNeedEllipsize = false; private int mNeedDrawLine = 0; + private int mParagraphShowCount = 0; private int mQQFaceSizeAddon = 0; // 可以让QQ表情高度比字体高度小一点或大一点 private QQFaceViewListener mListener; private int mMaxWidth = Integer.MAX_VALUE; @@ -312,6 +313,9 @@ public class QMUIQQFaceView extends View { } } + /** + * @param paragraphSpace only support for NO Ellipse or Ellipse End + */ public void setParagraphSpace(int paragraphSpace) { if (mParagraphSpace != paragraphSpace) { mParagraphSpace = paragraphSpace; @@ -580,6 +584,7 @@ public class QMUIQQFaceView extends View { protected int calculateLinesAndContentWidth(int limitWidth) { if (limitWidth <= (getPaddingRight() + getPaddingLeft()) || isElementEmpty()) { mLines = 0; + mParagraphShowCount = 0; mLastCalLines = 0; mLastCalContentWidth = 0; return mLastCalContentWidth; @@ -706,6 +711,13 @@ public class QMUIQQFaceView extends View { mCurrentCalLine++; setContentCalMaxWidth(mCurrentCalWidth); mCurrentCalWidth = widthStart; + if (mEllipsize == null) { + mParagraphShowCount++; + } else if (mEllipsize == TextUtils.TruncateAt.END) { + if (mCurrentCalLine <= mMaxLine) { + mParagraphShowCount++; + } + } } private void measureText(CharSequence text, int widthStart, int widthEnd) { @@ -752,6 +764,7 @@ public class QMUIQQFaceView extends View { Log.i(TAG, "widthSize = " + widthSize + "; heightSize = " + heightSize); mLines = 0; + mParagraphShowCount = 0; int width, height; switch (widthMode) { case AT_MOST: @@ -785,7 +798,7 @@ public class QMUIQQFaceView extends View { if (mNeedDrawLine < 2) { height += mNeedDrawLine * mFontHeight; } else { - height += (mNeedDrawLine - 1) * (mFontHeight + mLineSpace) + mFontHeight; + height += (mNeedDrawLine - 1) * (mFontHeight + mLineSpace) + mFontHeight + mParagraphShowCount * mParagraphSpace; } break; case MeasureSpec.UNSPECIFIED: @@ -796,7 +809,7 @@ public class QMUIQQFaceView extends View { if (mNeedDrawLine < 2) { height += mNeedDrawLine * mFontHeight; } else { - height += (mNeedDrawLine - 1) * (mFontHeight + mLineSpace) + mFontHeight; + height += (mNeedDrawLine - 1) * (mFontHeight + mLineSpace) + mFontHeight + mParagraphShowCount * mParagraphSpace; } break; case MeasureSpec.EXACTLY: @@ -812,27 +825,6 @@ public class QMUIQQFaceView extends View { + (System.currentTimeMillis() - start)); } -// private int getParagraphCount(){ -// if(mElementList == null || mElementList.getElements() == null || mElementList.getElements().isEmpty()){ -// return 0; -// } -// List elementList = mElementList.getElements(); -// int paragraphCount = 0; -// for(int i = 0; i < elementList.size(); i++){ -// QMUIQQFaceCompiler.Element element = elementList.get(i); -// if(i == elementList.size() - 1){ -// if(element.getType() != QMUIQQFaceCompiler.ElementType.NEXTLINE){ -// paragraphCount ++; -// } -// }else{ -// if(element.getType() == QMUIQQFaceCompiler.ElementType.NEXTLINE){ -// paragraphCount++; -// } -// } -// } -// return paragraphCount; -// } - @Override protected void onDraw(Canvas canvas) { if (mJumpHandleMeasureAndDraw || mOriginText == null || mLines == 0 || isElementEmpty()) { @@ -922,10 +914,10 @@ public class QMUIQQFaceView extends View { } /** - * 控制段落切换 + * control for paragraph space if mEllipsize == null || mEllipsize == TextUtils.TruncateAt.END */ private void toNewDrawLine(int startLeft, boolean paragraph, int usefulWidth) { - int addOn = (paragraph ? mParagraphSpace : 0) + mLineSpace; + int addOn = (paragraph && (mEllipsize == null || mEllipsize == TextUtils.TruncateAt.END) ? mParagraphSpace : 0) + mLineSpace; mCurrentDrawLine++; if (mIsNeedEllipsize) { if (mEllipsize == TextUtils.TruncateAt.START) {