当前位置: 首页>>代码示例>>Java>>正文


Java Paint.breakText方法代码示例

本文整理汇总了Java中android.graphics.Paint.breakText方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.breakText方法的具体用法?Java Paint.breakText怎么用?Java Paint.breakText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.breakText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end,
                 float x, int top, int y, int bottom, @NonNull Paint paint) {
    float textWidth = paint.measureText(text, start, end);

    if (x + (int) Math.ceil(textWidth) < mClipRect.right) {
        //text fits
        canvas.drawText(text, start, end, x, y, paint);
    } else {
        float ellipsisWidth = paint.measureText("\u2026");
        // move 'end' to the ellipsis point
        end = start + paint.breakText(text, start, end, true,
                mClipRect.right - x - ellipsisWidth, null);
        canvas.drawText(text, start, end, x, y, paint);
        canvas.drawText("\u2026", x + paint.measureText(text, start, end), y, paint);
    }
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:18,代码来源:EllipsizeLineSpan.java

示例2: loadPages

import android.graphics.Paint; //导入方法依赖的package包/类
public static SparseArray<ArrayList<String>> loadPages(String source, Paint textPaint, int visibleHeight, int visibleWidth, int intervalSize, int paragraphSize) {
    SparseArray<ArrayList<String>> pageArray = new SparseArray<>();
    List<String> lines = new ArrayList<>();
    if (source != null && source.length() > 0) {
        String[] split = source.split("\n");
        //剩余高度
        int rHeight = visibleHeight + intervalSize + paragraphSize;
        for (String paragraph : split) {
            boolean hasContent=false;
            //如果只有换行符,那么就不执行
            if (StringUtils.isBlank(paragraph)) continue;
            //重置段落
            paragraph = StringUtils.halfToFull("  " + paragraph + "\n");
            paragraph = StringUtils.trimBeforeReplace(paragraph, "  ");
            while (paragraph.length() > 0) {


                //测量一行占用的字节数
                int count = textPaint.breakText(paragraph, true, visibleWidth, null);
                String subStr = paragraph.substring(0, count);
                String trim = subStr.trim();
                if (trim.length()>0&&!trim.equals("\n") && !trim.equals("\r\n")&&!StringUtils.isBlank(trim)) {
                    //重置剩余距离
                    rHeight -= (textPaint.getTextSize() + intervalSize);

                    //达到行数要求,创建Page
                    if (rHeight < 0) {
                        //创建Page
                        pageArray.put(pageArray.size(), new ArrayList<>(lines));
                        //重置Lines
                        lines.clear();
                        rHeight = visibleHeight;
                        continue;
                    }
                    //将一行字节,存储到lines中
                    lines.add(subStr);
                    hasContent=true;
                }


                //裁剪
                paragraph = paragraph.substring(count);
            }

            if (lines.size() > 0&&hasContent) {
                rHeight -= paragraphSize;
            }
        }

        if (lines.size() != 0) {
            pageArray.put(pageArray.size(), new ArrayList<>(lines));
            //重置Lines
            lines.clear();

        }
    }
    return pageArray;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:59,代码来源:StringAdapter.java

示例3: drawLegend

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Draws the chart legend.
 * 
 * @param canvas the canvas to paint to
 * @param renderer the series renderer
 * @param titles the titles to go to the legend
 * @param left the left X value of the area to draw to
 * @param right the right X value of the area to draw to
 * @param y the y value of the area to draw to
 * @param width the width of the area to draw to
 * @param height the height of the area to draw to
 * @param legendSize the legend size
 * @param paint the paint to be used for drawing
 * @param calculate if only calculating the legend size
 * 
 * @return the legend height
 */
protected int drawLegend(Canvas canvas, DefaultRenderer renderer, String[] titles, int left,
    int right, int y, int width, int height, int legendSize, Paint paint, boolean calculate) {
  float size = 32;
  if (renderer.isShowLegend()) {
    float currentX = left;
    float currentY = y + height - legendSize + size;
    paint.setTextAlign(Align.LEFT);
    paint.setTextSize(renderer.getLegendTextSize());
    int sLength = Math.min(titles.length, renderer.getSeriesRendererCount());
    for (int i = 0; i < sLength; i++) {
      SimpleSeriesRenderer r = renderer.getSeriesRendererAt(i);
      final float lineSize = getLegendShapeWidth(i);
      if (r.isShowLegendItem()) {
        String text = titles[i];
        if (titles.length == renderer.getSeriesRendererCount()) {
          paint.setColor(r.getColor());
        } else {
          paint.setColor(Color.LTGRAY);
        }
        float[] widths = new float[text.length()];
        paint.getTextWidths(text, widths);
        float sum = 0;
        for (float value : widths) {
          sum += value;
        }
        float extraSize = lineSize + 10 + sum;
        float currentWidth = currentX + extraSize;

        if (i > 0 && getExceed(currentWidth, renderer, right, width)) {
          currentX = left;
          currentY += renderer.getLegendTextSize();
          size += renderer.getLegendTextSize();
          currentWidth = currentX + extraSize;
        }
        if (getExceed(currentWidth, renderer, right, width)) {
          float maxWidth = right - currentX - lineSize - 10;
          if (isVertical(renderer)) {
            maxWidth = width - currentX - lineSize - 10;
          }
          int nr = paint.breakText(text, true, maxWidth, widths);
          text = text.substring(0, nr) + "...";
        }
        if (!calculate) {
          drawLegendShape(canvas, r, currentX, currentY, i, paint);
          drawString(canvas, text, currentX + lineSize + 5, currentY + 5, paint);
        }
        currentX += extraSize;
      }
    }
  }
  return Math.round(size + renderer.getLegendTextSize());
}
 
开发者ID:sdrausty,项目名称:buildAPKsApps,代码行数:70,代码来源:AbstractChart.java

示例4: extractWrappedLines

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Recursive method, takes a list of words and concatenates them in order and with spaces in between each word, up to a maximum line width of widthAvailable,
 * further lines are added to linesSoFar until all the wordsStillToWrap have been processed.
 *
 * @param linesSoFar
 * @param wordsStillToWrap
 * @param widthAvailable
 * @param paint            if null we will wrap based on number of charactersAvailable
 * @param leftToRight
 */
private static void extractWrappedLines(List<String> linesSoFar, List<String> wordsStillToWrap, float widthAvailable, Paint paint, int charactersAvailable, boolean leftToRight) {

    if (wordsStillToWrap.size() > 0) {

        //start by assuming all the words still to wrap will wrap into one line
        String nextLineAttempt = flattenWordsAddingSpaces(wordsStillToWrap);

        int charactersThatFit;

        if (paint == null) {
            charactersThatFit = nextLineAttempt.length() < charactersAvailable ? nextLineAttempt.length() : charactersAvailable;
        } else {
            charactersThatFit = paint.breakText(nextLineAttempt, leftToRight, widthAvailable, null);
        }


        if (charactersThatFit == nextLineAttempt.length()) { //we're done

            linesSoFar.add(nextLineAttempt);
            wordsStillToWrap.clear();

        } else { //just get the next line, then pass the remaining words to the method again recursively

            List<String> wordsForNextLine = new ArrayList<String>();

            int charactersUsed = -1;//to take into account that there is no space before the first word in a line

            while (wordsStillToWrap.size() > 0 && charactersUsed + 1 + wordsStillToWrap.get(0).length() <= charactersThatFit) {

                wordsForNextLine.add(wordsStillToWrap.get(0));
                charactersUsed += (1 + wordsStillToWrap.get(0).length());
                wordsStillToWrap.remove(0);
            }

            if (charactersUsed < 1) {//the next word must be very large so we need to take what we can off the front of it

                String massiveWord = wordsStillToWrap.get(0);

                if (charactersThatFit == 0) {//just in case
                    charactersThatFit = 1;
                }

                wordsForNextLine.add(massiveWord.substring(0, charactersThatFit));
                wordsStillToWrap.remove(0);

                if (massiveWord.length() > charactersThatFit) {
                    wordsStillToWrap.add(0, massiveWord.substring(charactersThatFit, massiveWord.length()));
                }
            }

            linesSoFar.add(flattenWordsAddingSpaces(wordsForNextLine));

            extractWrappedLines(linesSoFar, wordsStillToWrap, widthAvailable, paint, charactersAvailable, leftToRight);

        }
    }
}
 
开发者ID:erdo,项目名称:asaf-project,代码行数:68,代码来源:MonospacedTextWrappingUtils.java


注:本文中的android.graphics.Paint.breakText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。