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


Java Paint.getTextWidths方法代码示例

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


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

示例1: a

import android.graphics.Paint; //导入方法依赖的package包/类
public int a(Paint paint, int i, int i2, float[] fArr) {
    int i3 = 0;
    if (!TextUtils.isEmpty(this.text)) {
        int i4 = i + i2;
        if (i4 > this.text.length()) {
            i4 = this.text.length();
        }
        if (i < i4) {
            Typeface d = d(paint);
            if ((this.useDefaultFont || !this.useHanyiColorFont) && (paint instanceof ETPaint)) {
                paint = ((ETPaint) paint).a();
            }
            i3 = paint.getTextWidths(this.text, i, i4, fArr);
            if (d != null) {
                paint.setTypeface(d);
            }
        }
    }
    return i3;
}
 
开发者ID:xieyangxuejun,项目名称:CommentView,代码行数:21,代码来源:TextCell.java

示例2: getTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
public int getTextWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }
    }
    return iRet;
}
 
开发者ID:wmuqing,项目名称:timePicker,代码行数:13,代码来源:WheelView.java

示例3: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
                   @Nullable Paint.FontMetricsInt fm) {
    paint.getTextWidths(MEASURE_NUMBER_CHARS, mNumberWidths);
    float mw = 0.f;
    char ld = '0';
    for (int i = MEASURE_NUMBER_CHARS.length() - 1; i >= 0; --i) {
        if (mNumberWidths[i] > mw) {
            mNumberWidths[i] = mw;
            ld = MEASURE_NUMBER_CHARS.charAt(i);
        }
    }
    CharSequence s = text.subSequence(start - mPreOffset, start);
    String rs = sMatchNumbersRegex.matcher(s).replaceAll(String.valueOf(ld));
    return (int) (paint.measureText(rs) - paint.measureText(s, 0, s.length()));
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:17,代码来源:FixedWidthTimestampSpan.java

示例4: getTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
private int getTextWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }
    }
    return iRet;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ShoppingView.java

示例5: measure

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void measure(char[] charArray, int start, int end,
		byte[] wideAttribute, Paint paint, int charWidth) {
	paint.getTextWidths(charArray, start, end, mWidths);
	final int N = end - start;
	for (int i = 0; i < N; i++)
		wideAttribute[i] = (byte) (((int) mWidths[i] != charWidth) ?
				AndroidCharacter.EAST_ASIAN_WIDTH_WIDE :
				AndroidCharacter.EAST_ASIAN_WIDTH_NARROW);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:EastAsianWidth.java

示例6: getTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
public int getTextWidth(Paint paint, String str) {//计算文字宽度
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }
    }
    return iRet;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:WheelView.java

示例7: obtainTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
private int obtainTextWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil(widths[j]);
        }
    }
    return iRet;
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:13,代码来源:WheelView.java

示例8: getTextWidth

import android.graphics.Paint; //导入方法依赖的package包/类
public static int getTextWidth(Paint paint, String str) {
    int iRet = 0;
    if (str != null && str.length() > 0) {
        int len = str.length();
        float[] widths = new float[len];
        paint.getTextWidths(str, widths);
        for (int j = 0; j < len; j++) {
            iRet += (int) Math.ceil((double) widths[j]);
        }
    }
    return iRet;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:13,代码来源:ViewUtils.java

示例9: 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

示例10: drawTextRange

import android.graphics.Paint; //导入方法依赖的package包/类
public void drawTextRange(Canvas canvas, String text, RectF textRect, Paint textPaint, int color, int shadowColor) {
    Paint.FontMetrics fm = textPaint.getFontMetrics();
    // 计算行高
    //float textHeight = (int) (Math.ceil(fm.descent - fm.ascent));
    float textHeight = fm.bottom - fm.top - 8;
    float rectHeight = textRect.height();
    if (textHeight > rectHeight)
        return;
    // 字体宽度
    float widthText = textPaint.measureText(text);
    float rectWidth = textRect.width() * scaleImg;
    // 行数
    float line = widthText / rectWidth;
    float baseline = ((textRect.bottom + textRect.top) * scaleImg - fm.bottom - fm.top) / 2;
    if (line <= 1) {
        textPaint.setColor(shadowColor);
        canvas.drawText(text, textRect.centerX() * scaleImg - 2, baseline, textPaint);
        canvas.drawText(text, textRect.centerX() * scaleImg + 2, baseline, textPaint);
        canvas.drawText(text, textRect.centerX() * scaleImg, baseline + 2, textPaint);
        canvas.drawText(text, textRect.centerX() * scaleImg, baseline - 2, textPaint);
        textPaint.setColor(color);
        canvas.drawText(text, textRect.centerX() * scaleImg, baseline, textPaint);
    } else {
        baseline -= (textHeight / 2 + 12);
        float[] widths = new float[text.length()];
        textPaint.getTextWidths(text, widths);
        int newline = formatFloatToInt(line);
        // 计算基线
        //float contentHeight = newline * textHeight;
        //if (contentHeight < rectHeight) {
        //    baseline = textRect.top + (rectHeight - contentHeight) / 2 + textHeight;
        //}
        float baseWidth = 0;
        // idline为行数
        for (int index = 0, idline = 0, lastindex = 0; index < widths.length; index++) {
            // 本行宽度
            float temp = (baseWidth + widths[index]);
            float dis = rectWidth - temp;
            if (index + 1 != widths.length) {
                if (dis >= (widths[index + 1])) {
                    baseWidth = temp;
                    continue;
                }
                textPaint.setColor(shadowColor);
                canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg) - 2, baseline + idline * textHeight, textPaint);
                canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg) + 2, baseline + idline * textHeight, textPaint);
                canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight + 2, textPaint);
                canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight - 2, textPaint);
                textPaint.setColor(color);
                canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight, textPaint);

                baseWidth = 0;
                lastindex = index + 1;
                idline++;
                if ((baseline + idline * textHeight) > (textRect.bottom * scaleImg)) {
                    break;
                }
                continue;
            }

            if ((baseline + idline * textHeight) > (textRect.bottom * scaleImg)) {
                break;
            }
            textPaint.setColor(shadowColor);
            canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg) - 2, baseline + idline * textHeight, textPaint);
            canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg) + 2, baseline + idline * textHeight, textPaint);
            canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight + 2, textPaint);
            canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight - 2, textPaint);
            textPaint.setColor(color);
            canvas.drawText(text, lastindex, index + 1, (textRect.centerX() * scaleImg), baseline + idline * textHeight, textPaint);
        }
    }
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:74,代码来源:MergeFactory.java


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