android.text.StaticLayout#getLineBottom ( )源码实例Demo

下面列出了android.text.StaticLayout#getLineBottom ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TelePlus-Android   文件: LetterDrawable.java
public void setTitle(String title) {
    stringBuilder.setLength(0);
    if (title != null && title.length() > 0) {
        stringBuilder.append(title.substring(0, 1));
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
源代码2 项目: Telegram   文件: TextSelectionHelper.java
@Override
protected int getLineHeight() {
    if (selectedView == null) {
        return 0;
    } else {
        arrayList.clear();
        selectedView.fillTextLayoutBlocks(arrayList);
        int index = startPeek ? startViewChildPosition : endViewChildPosition;
        if (index < 0 || index >= arrayList.size()) {
            return 0;
        }
        StaticLayout layout = arrayList.get(index).getLayout();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < layout.getLineCount(); i++) {
            int h = layout.getLineBottom(i) - layout.getLineTop(i);
            if (h < min) min = h;
        }
        return min;
    }
}
 
源代码3 项目: Telegram-FOSS   文件: TextSelectionHelper.java
@Override
protected int getLineHeight() {
    if (selectedView != null && selectedView.getMessageObject() != null) {
        MessageObject object = selectedView.getMessageObject();
        StaticLayout layout = null;
        if (isDescription) {
            layout = selectedView.getDescriptionlayout();
        } else if (selectedView.hasCaptionLayout()) {
            layout = selectedView.getCaptionLayout();
        } else if (object.textLayoutBlocks != null) {
            layout = object.textLayoutBlocks.get(0).textLayout;
        }
        if (layout == null) {
            return 0;
        }
        int lineHeight = layout.getLineBottom(0) - layout.getLineTop(0);
        return lineHeight;
    }
    return 0;
}
 
源代码4 项目: Telegram-FOSS   文件: TextSelectionHelper.java
@Override
protected int getLineHeight() {
    if (selectedView == null) {
        return 0;
    } else {
        arrayList.clear();
        selectedView.fillTextLayoutBlocks(arrayList);
        int index = startPeek ? startViewChildPosition : endViewChildPosition;
        if (index < 0 || index >= arrayList.size()) {
            return 0;
        }
        StaticLayout layout = arrayList.get(index).getLayout();
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < layout.getLineCount(); i++) {
            int h = layout.getLineBottom(i) - layout.getLineTop(i);
            if (h < min) min = h;
        }
        return min;
    }
}
 
源代码5 项目: Telegram   文件: LinkPath.java
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) {
    currentLayout = layout;
    currentLine = layout.getLineForOffset(start);
    lastTop = -1;
    heightOffset = yOffset;
    if (Build.VERSION.SDK_INT >= 28) {
        int lineCount = layout.getLineCount();
        if (lineCount > 0) {
            lineHeight = layout.getLineBottom(lineCount - 1) - layout.getLineTop(lineCount - 1);
        }
    }
}
 
源代码6 项目: SmartChart   文件: BannerTextView.java
private int getHeightS() {
    TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
    textPaint.setTextSize(getTextSize());
    StaticLayout staticLayout = new StaticLayout(textList.get(currentPosition), textPaint, getWidth() - getPaddingLeft() - getPaddingRight(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false);
    int height = staticLayout.getHeight();
    if (staticLayout.getLineCount() > getMaxLines()) {
        int lineCount = staticLayout.getLineCount();
        height = staticLayout.getLineBottom(getMaxLines() - 1);
    }
    return height;
}
 
源代码7 项目: zone-sdk   文件: TextViewLinkActivity.java
private void roateSpan() {
        TextView tv_rotate_img_span = (TextView) findViewById(R.id.tv_rotate_img_span);
        ImageView img_rotate = (ImageView) findViewById(R.id.img_rotate);
        Drawable drawable = getResources().getDrawable(R.drawable.icon);
//        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.setBounds(0, 0, 200, 200);
        img_rotate.setImageDrawable(drawable);

        ViewGroup.LayoutParams lp = img_rotate.getLayoutParams();
        lp.width = 200;
        lp.height = 200;
        img_rotate.setLayoutParams(lp);

        //这个可以在oncreate的时候测量出来
        StaticLayout sl = new StaticLayout("aa", tv_rotate_img_span.getPaint(),
                100, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
        int lineHeight = sl.getLineBottom(0) - sl.getLineTop(0);// 比 tv_rotate_img_span.getLineHeight() 这个好 因为每行高刚度可能不一致

        int affectLine = 0;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            if (i * lineHeight > 200 + 20) {
                affectLine = i - 1;
                break;
            }
        }

        SpannableString msp = new SpannableString("可是现在我已不是在天上翱翔的小鸟,在地上奔跑的动物了,因为我长大了,已经五年级了,大家都在努力地学习,谁都不想输给别人,每个人都在奋发图强,“学习如逆水行舟,不进则退”。这句话在我耳边回荡,难道我们就不应该有一个孩子应该有的童真吗?难道我已经失去了吗?难道现在我们所有的孩子都应该抓住学习这根攀山绳吗?为什么我们不?");
        tv_rotate_img_span.setText(msp);
        tv_rotate_img_span.setGravity(Gravity.LEFT);

        msp.setSpan(new ImageRotate(affectLine), 0, msp.length() - 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tv_rotate_img_span.setText(msp);
    }
 
源代码8 项目: Telegram   文件: TextSelectionHelper.java
protected int[] offsetToCord(int offset) {
    fillLayoutForOffset(offset, layoutBlock);

    StaticLayout layout = layoutBlock.layout;
    if (layout == null || offset > layout.getText().length()) {
        return tmpCoord;
    }
    int line = layout.getLineForOffset(offset);
    tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset);
    tmpCoord[1] = layout.getLineBottom(line);
    tmpCoord[1] += layoutBlock.yOffset;
    return tmpCoord;
}
 
源代码9 项目: Telegram-FOSS   文件: TextSelectionHelper.java
protected int[] offsetToCord(int offset) {
    fillLayoutForOffset(offset, layoutBlock);

    StaticLayout layout = layoutBlock.layout;
    if (layout == null || offset > layout.getText().length()) {
        return tmpCoord;
    }
    int line = layout.getLineForOffset(offset);
    tmpCoord[0] = (int) (layout.getPrimaryHorizontal(offset) + layoutBlock.xOffset);
    tmpCoord[1] = layout.getLineBottom(line);
    tmpCoord[1] += layoutBlock.yOffset;
    return tmpCoord;
}
 
源代码10 项目: Telegram-FOSS   文件: LinkPath.java
public void setCurrentLayout(StaticLayout layout, int start, float yOffset) {
    currentLayout = layout;
    currentLine = layout.getLineForOffset(start);
    lastTop = -1;
    heightOffset = yOffset;
    if (Build.VERSION.SDK_INT >= 28) {
        int lineCount = layout.getLineCount();
        if (lineCount > 0) {
            lineHeight = layout.getLineBottom(lineCount - 1) - layout.getLineTop(lineCount - 1);
        }
    }
}
 
源代码11 项目: TelePlus-Android   文件: SharedLinkCell.java
@Override
protected void onDraw(Canvas canvas) {
    if (titleLayout != null) {
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout2 != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y);
        descriptionLayout2.draw(canvas);
        canvas.restore();
    }

    if (!linkLayout.isEmpty()) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
        int offset = 0;
        for (int a = 0; a < linkLayout.size(); a++) {
            StaticLayout layout = linkLayout.get(a);
            if (layout.getLineCount() > 0) {
                canvas.save();
                canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset);
                if (pressedLink == a) {
                    canvas.drawPath(urlPath, Theme.linkSelectionPaint);
                }
                layout.draw(canvas);
                canvas.restore();
                offset += layout.getLineBottom(layout.getLineCount() - 1);
            }
        }
    }

    letterDrawable.draw(canvas);
    if (drawLinkImageView) {
        linkImageView.draw(canvas);
    }

    if (needDivider) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint);
        }
    }
}
 
源代码12 项目: TelePlus-Android   文件: AvatarDrawable.java
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }

    drawBrodcast = isBroadcast;
    savedMessages = 0;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
源代码13 项目: Telegram-FOSS   文件: AvatarDrawable.java
public void setInfo(int id, String firstName, String lastName, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }
    needApplyColorAccent = id == 5; // Tinting manually set blue color

    avatarType = AVATAR_TYPE_NORMAL;
    drawDeleted = false;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
源代码14 项目: TelePlus-Android   文件: SharedLinkCell.java
@Override
protected void onDraw(Canvas canvas) {
    if (titleLayout != null) {
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout2 != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y);
        descriptionLayout2.draw(canvas);
        canvas.restore();
    }

    if (!linkLayout.isEmpty()) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
        int offset = 0;
        for (int a = 0; a < linkLayout.size(); a++) {
            StaticLayout layout = linkLayout.get(a);
            if (layout.getLineCount() > 0) {
                canvas.save();
                canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset);
                if (pressedLink == a) {
                    canvas.drawPath(urlPath, Theme.linkSelectionPaint);
                }
                layout.draw(canvas);
                canvas.restore();
                offset += layout.getLineBottom(layout.getLineCount() - 1);
            }
        }
    }

    letterDrawable.draw(canvas);
    if (drawLinkImageView) {
        linkImageView.draw(canvas);
    }

    if (needDivider) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint);
        }
    }
}
 
源代码15 项目: TelePlus-Android   文件: AvatarDrawable.java
public void setInfo(int id, String firstName, String lastName, boolean isBroadcast, String custom) {
    if (isProfile) {
        color = getProfileColorForId(id);
    } else {
        color = getColorForId(id);
    }

    drawBrodcast = isBroadcast;
    savedMessages = 0;

    if (firstName == null || firstName.length() == 0) {
        firstName = lastName;
        lastName = null;
    }

    stringBuilder.setLength(0);
    if (custom != null) {
        stringBuilder.append(custom);
    } else {
        if (firstName != null && firstName.length() > 0) {
            stringBuilder.appendCodePoint(firstName.codePointAt(0));
        }
        if (lastName != null && lastName.length() > 0) {
            Integer lastch = null;
            for (int a = lastName.length() - 1; a >= 0; a--) {
                if (lastch != null && lastName.charAt(a) == ' ') {
                    break;
                }
                lastch = lastName.codePointAt(a);
            }
            if (Build.VERSION.SDK_INT > 17) {
                stringBuilder.append("\u200C");
            }
            stringBuilder.appendCodePoint(lastch);
        } else if (firstName != null && firstName.length() > 0) {
            for (int a = firstName.length() - 1; a >= 0; a--) {
                if (firstName.charAt(a) == ' ') {
                    if (a != firstName.length() - 1 && firstName.charAt(a + 1) != ' ') {
                        if (Build.VERSION.SDK_INT > 17) {
                            stringBuilder.append("\u200C");
                        }
                        stringBuilder.appendCodePoint(firstName.codePointAt(a + 1));
                        break;
                    }
                }
            }
        }
    }

    if (stringBuilder.length() > 0) {
        String text = stringBuilder.toString().toUpperCase();
        try {
            textLayout = new StaticLayout(text, namePaint, AndroidUtilities.dp(100), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
            if (textLayout.getLineCount() > 0) {
                textLeft = textLayout.getLineLeft(0);
                textWidth = textLayout.getLineWidth(0);
                textHeight = textLayout.getLineBottom(0);
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
    } else {
        textLayout = null;
    }
}
 
源代码16 项目: no-player   文件: SubtitlePainter.java
@SuppressWarnings("PMD.NPathComplexity")  // TODO break this method up
private void drawTextLayout(Canvas canvas) {
    StaticLayout layout = textLayout;
    if (layout == null) {
        // Nothing to draw.
        return;
    }

    int saveCount = canvas.save();
    canvas.translate(textLeft, textTop);

    if (Color.alpha(windowColor) > 0) {
        paint.setColor(windowColor);
        canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(),
                paint);
    }

    if (Color.alpha(backgroundColor) > 0) {
        paint.setColor(backgroundColor);
        float previousBottom = layout.getLineTop(0);
        int lineCount = layout.getLineCount();
        for (int i = 0; i < lineCount; i++) {
            lineBounds.left = layout.getLineLeft(i) - textPaddingX;
            lineBounds.right = layout.getLineRight(i) + textPaddingX;
            lineBounds.top = previousBottom;
            lineBounds.bottom = layout.getLineBottom(i);
            previousBottom = lineBounds.bottom;
            canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
        }
    }

    if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
        textPaint.setStrokeJoin(Join.ROUND);
        textPaint.setStrokeWidth(outlineWidth);
        textPaint.setColor(edgeColor);
        textPaint.setStyle(Style.FILL_AND_STROKE);
        layout.draw(canvas);
    } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
        textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
    } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
            || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
        boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
        int colorUp = raised ? Color.WHITE : edgeColor;
        int colorDown = raised ? edgeColor : Color.WHITE;
        float offset = shadowRadius / 2;
        textPaint.setColor(foregroundColor);
        textPaint.setStyle(Style.FILL);
        textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
        layout.draw(canvas);
        textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
    }

    textPaint.setColor(foregroundColor);
    textPaint.setStyle(Style.FILL);
    layout.draw(canvas);
    textPaint.setShadowLayer(0, 0, 0, 0);

    canvas.restoreToCount(saveCount);
}
 
源代码17 项目: K-Sonic   文件: SubtitlePainter.java
private void drawTextLayout(Canvas canvas) {
  StaticLayout layout = textLayout;
  if (layout == null) {
    // Nothing to draw.
    return;
  }

  int saveCount = canvas.save();
  canvas.translate(textLeft, textTop);

  if (Color.alpha(windowColor) > 0) {
    paint.setColor(windowColor);
    canvas.drawRect(-textPaddingX, 0, layout.getWidth() + textPaddingX, layout.getHeight(),
        paint);
  }

  if (Color.alpha(backgroundColor) > 0) {
    paint.setColor(backgroundColor);
    float previousBottom = layout.getLineTop(0);
    int lineCount = layout.getLineCount();
    for (int i = 0; i < lineCount; i++) {
      lineBounds.left = layout.getLineLeft(i) - textPaddingX;
      lineBounds.right = layout.getLineRight(i) + textPaddingX;
      lineBounds.top = previousBottom;
      lineBounds.bottom = layout.getLineBottom(i);
      previousBottom = lineBounds.bottom;
      canvas.drawRoundRect(lineBounds, cornerRadius, cornerRadius, paint);
    }
  }

  if (edgeType == CaptionStyleCompat.EDGE_TYPE_OUTLINE) {
    textPaint.setStrokeJoin(Join.ROUND);
    textPaint.setStrokeWidth(outlineWidth);
    textPaint.setColor(edgeColor);
    textPaint.setStyle(Style.FILL_AND_STROKE);
    layout.draw(canvas);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_DROP_SHADOW) {
    textPaint.setShadowLayer(shadowRadius, shadowOffset, shadowOffset, edgeColor);
  } else if (edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED
      || edgeType == CaptionStyleCompat.EDGE_TYPE_DEPRESSED) {
    boolean raised = edgeType == CaptionStyleCompat.EDGE_TYPE_RAISED;
    int colorUp = raised ? Color.WHITE : edgeColor;
    int colorDown = raised ? edgeColor : Color.WHITE;
    float offset = shadowRadius / 2f;
    textPaint.setColor(foregroundColor);
    textPaint.setStyle(Style.FILL);
    textPaint.setShadowLayer(shadowRadius, -offset, -offset, colorUp);
    layout.draw(canvas);
    textPaint.setShadowLayer(shadowRadius, offset, offset, colorDown);
  }

  textPaint.setColor(foregroundColor);
  textPaint.setStyle(Style.FILL);
  layout.draw(canvas);
  textPaint.setShadowLayer(0, 0, 0, 0);

  canvas.restoreToCount(saveCount);
}
 
源代码18 项目: MixtureTextView   文件: MixtureTextView.java
private void cacuLineHeight()
{
    layout = new StaticLayout("爱我中华", mTextPaint, 0, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0f, false);
    mLineHeight = layout.getLineBottom(0) - layout.getLineTop(0);
}
 
源代码19 项目: Telegram   文件: TextSelectionHelper.java
@Override
protected int getCharOffsetFromCord(int x, int y, int offsetX, int offsetY, ArticleSelectableView view, boolean maybe) {
    if (view == null) {
        return -1;
    }

    int line = -1;
    x -= offsetX;
    y -= offsetY;

    arrayList.clear();
    view.fillTextLayoutBlocks(arrayList);

    int childIndex;
    if (maybe) {
        childIndex = maybeTextIndex;
    } else {
        childIndex = startPeek ? startViewChildPosition : endViewChildPosition;
    }
    StaticLayout layout = arrayList.get(childIndex).getLayout();
    if (x < 0) {
        x = 1;
    }
    if (y < 0) {
        y = 1;
    }
    if (x > layout.getWidth()) {
        x = layout.getWidth();
    }
    if (y > layout.getLineBottom(layout.getLineCount() - 1)) {
        y = (int) (layout.getLineBottom(layout.getLineCount() - 1) - 1);
    }

    for (int i = 0; i < layout.getLineCount(); i++) {
        if (y > layout.getLineTop(i) && y < layout.getLineBottom(i)) {
            line = i;
            break;
        }
    }
    if (line >= 0) {
        return layout.getOffsetForHorizontal(line, x);
    }

    return -1;
}
 
源代码20 项目: Telegram   文件: SharedLinkCell.java
@Override
protected void onDraw(Canvas canvas) {
    if (titleLayout != null) {
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY);
        titleLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY);
        descriptionLayout.draw(canvas);
        canvas.restore();
    }

    if (descriptionLayout2 != null) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        canvas.save();
        canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), description2Y);
        descriptionLayout2.draw(canvas);
        canvas.restore();
    }

    if (!linkLayout.isEmpty()) {
        descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
        int offset = 0;
        for (int a = 0; a < linkLayout.size(); a++) {
            StaticLayout layout = linkLayout.get(a);
            if (layout.getLineCount() > 0) {
                canvas.save();
                canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY + offset);
                if (pressedLink == a) {
                    canvas.drawPath(urlPath, Theme.linkSelectionPaint);
                }
                layout.draw(canvas);
                canvas.restore();
                offset += layout.getLineBottom(layout.getLineCount() - 1);
            }
        }
    }

    letterDrawable.draw(canvas);
    if (drawLinkImageView) {
        linkImageView.draw(canvas);
    }

    if (needDivider) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint);
        }
    }
}