@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO: 16/3/29
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);

    int heightMode = MeasureSpec.getMode(heightMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    int width;
    int height;

    if (widthMode == MeasureSpec.EXACTLY) {
      width = widthSize;
    } else {
      mPaint.setTextSize(mTitleSize);
      mPaint.getTextBounds(mTitleText, 0, mTitleText.length(), mBound);
      float textWidth = mBound.width();
      int desired = (int) (getPaddingLeft() + textWidth + getPaddingRight());
      width = desired;
    }

    if (heightMode == MeasureSpec.EXACTLY) {
      height = heightSize;
    } else {
      mPaint.setTextSize(mTitleSize);
      mPaint.getTextBounds(mTitleText, 0, mTitleText.length(), mBound);
      float textHeight = mBound.height();
      int desired = (int) (getPaddingTop() + textHeight + getPaddingBottom());
      height = desired;
    }

    setMeasuredDimension(width, height);
  }
Beispiel #2
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int fWidth;
    int fHeight;
    int wSize = MeasureSpec.getSize(widthMeasureSpec);
    int wMode = MeasureSpec.getMode(widthMeasureSpec);
    int hSize = MeasureSpec.getSize(heightMeasureSpec);
    int hMode = MeasureSpec.getMode(heightMeasureSpec);
    if (wMode == MeasureSpec.EXACTLY) {
      fWidth = wSize;
    } else {
      mPaint.setTextSize(mTextSize);
      mPaint.getTextBounds(mInt, 0, mInt.length(), mBound);
      int tepWidth = (int) (getPaddingLeft() + mBound.width() + getPaddingRight());
      fWidth = tepWidth;
    }
    if (hMode == MeasureSpec.EXACTLY) {
      fHeight = hSize;
    } else {

      mPaint.setTextSize(mTextSize);
      mPaint.getTextBounds(mInt, 0, mInt.length(), mBound);
      int tepHeight = getPaddingTop() + mBound.height() + getPaddingBottom();
      fHeight = tepHeight;
    }
    radius = Math.max(fHeight, fWidth) / 2;
    setMeasuredDimension(radius * 2, radius * 2);
  }
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mapView == null || mapView.isClickable()) {
      return;
    }

    if (doMeasureMode) {
      int cWidth = canvas.getWidth();
      canvas.drawPath(measurePath, measurePaint);
      int upper = 70;
      int delta = 5;
      measureTextPaint.getTextBounds(distanceString, 0, distanceString.length(), rect);
      int textWidth = rect.width();
      int textHeight = rect.height();
      int x = cWidth / 2 - textWidth / 2;
      canvas.drawText(distanceString, x, upper, measureTextPaint);
      String distanceText = String.valueOf((int) measuredDistance);
      // String distanceText = distanceText((int) measuredDistance, imperial, nautical);
      measureTextPaint.getTextBounds(distanceText, 0, distanceText.length(), rect);
      textWidth = rect.width();
      x = cWidth / 2 - textWidth / 2;
      canvas.drawText(distanceText, x, upper + delta + textHeight, measureTextPaint);
      if (GPLog.LOG_HEAVY)
        GPLog.addLogEntry(this, "Drawing measure path text: " + upper); // $NON-NLS-1$
    } else if (doInfoMode) {
      canvas.drawRect(rect, infoRectPaintFill);
      canvas.drawRect(rect, infoRectPaintStroke);
    }
  }
  private void calculateTextLocation() {
    if (mCenterPoint == null) return;

    double step = Math.PI / 6;
    double angle = -Math.PI / 3;
    float x, y;

    mPaint.setTextSize(mTextSize);
    mPaint.setTypeface(mTypeface);
    mPaint.setTextAlign(Paint.Align.CENTER);

    if (m24Hour) {
      for (int i = 0; i < 12; i++) {
        mPaint.getTextBounds(TICKS[i], 0, TICKS[i].length(), mRect);
        if (i == 0) mSecondInnerRadius = mInnerRadius - mSelectionRadius - mRect.height();

        x = mCenterPoint.x + (float) Math.cos(angle) * mSecondInnerRadius;
        y = mCenterPoint.y + (float) Math.sin(angle) * mSecondInnerRadius;

        mLocations[i * 2] = x;
        mLocations[i * 2 + 1] = y + mRect.height() / 2f;

        angle += step;
      }

      for (int i = 12; i < TICKS.length; i++) {
        x = mCenterPoint.x + (float) Math.cos(angle) * mInnerRadius;
        y = mCenterPoint.y + (float) Math.sin(angle) * mInnerRadius;

        mPaint.getTextBounds(TICKS[i], 0, TICKS[i].length(), mRect);
        mLocations[i * 2] = x;
        mLocations[i * 2 + 1] = y + mRect.height() / 2f;

        angle += step;
      }
    } else {
      for (int i = 0; i < 12; i++) {
        x = mCenterPoint.x + (float) Math.cos(angle) * mInnerRadius;
        y = mCenterPoint.y + (float) Math.sin(angle) * mInnerRadius;

        mPaint.getTextBounds(TICKS[i], 0, TICKS[i].length(), mRect);
        mLocations[i * 2] = x;
        mLocations[i * 2 + 1] = y + mRect.height() / 2f;

        angle += step;
      }

      for (int i = 24; i < TICKS.length; i++) {
        x = mCenterPoint.x + (float) Math.cos(angle) * mInnerRadius;
        y = mCenterPoint.y + (float) Math.sin(angle) * mInnerRadius;

        mPaint.getTextBounds(TICKS[i], 0, TICKS[i].length(), mRect);
        mLocations[i * 2] = x;
        mLocations[i * 2 + 1] = y + mRect.height() / 2f;

        angle += step;
      }
    }
  }
 protected void onDraw(Canvas paramCanvas) {
   // today round
   if (mIsToday) {
     Paint painta = new Paint();
     painta.setStyle(Paint.Style.STROKE);
     painta.setColor(Color.BLACK);
     painta.setAntiAlias(true);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 5, getMeasuredHeight() / 5, painta);
     Paint paintb = new Paint();
     paintb.setColor(Color.GRAY);
     paintb.setAntiAlias(true);
     paintb.setAlpha(50);
     paramCanvas.drawRoundRect(rt, getMeasuredWidth() / 6, getMeasuredWidth() / 6, paintb);
   }
   // solar text
   Paint paint1 = new Paint();
   paint1.setAntiAlias(true);
   paint1.setFakeBoldText(true);
   paint1.setTextSize(getMeasuredWidth() / 2);
   if (mDay.mIsWeekEnd) {
     paint1.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint1.setColor(Color.BLACK);
   }
   Rect text = new Rect();
   paint1.getTextBounds(mDay.mSolarDay, 0, mDay.mSolarDay.length(), text);
   int w = getMeasuredWidth();
   int w1 = text.width();
   float fw = (w - w1) / 2;
   float fh = getMeasuredHeight() / 2 + 1;
   paramCanvas.drawText(mDay.mSolarDay, fw, fh, paint1);
   // lunar text
   Paint paint2 = new Paint();
   paint2.setAntiAlias(true);
   paint2.setTextSize(getMeasuredWidth() / 4);
   if (mDay.mIsFestival) {
     paint2.setColor(ECalendarActivity.mHolidayColor);
   } else {
     paint2.setColor(Color.BLACK);
   }
   paint2.getTextBounds(mDay.mLunarDay, 0, mDay.mLunarDay.length(), text);
   w1 = text.width();
   fw = (w - w1) / 2;
   fh = getMeasuredHeight() / 2 + 2 + text.height();
   paramCanvas.drawText(mDay.mLunarDay, fw, fh, paint2);
   if (mDay.mHasDiary) {
     Paint pd = new Paint();
     pd.setStyle(Paint.Style.STROKE);
     pd.setColor(ECalendarActivity.mHolidayColor);
     pd.setStrokeWidth(2);
     Rect rect = paramCanvas.getClipBounds();
     RectF rt = new RectF(rect);
     rt.inset(getMeasuredWidth() / 12, getMeasuredHeight() / 12);
     paramCanvas.drawLine(rt.left + rt.width() / 4, rt.top, rt.right - rt.width() / 4, rt.top, pd);
   }
 }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    paint.setStrokeWidth(0);
    paint.setTextSize(25);
    Rect bounds = new Rect();
    float bottom = 0;
    paint.setARGB(255, 255, 255, 255);
    if (searched == null) return;
    for (Match m : searched) {
      float start = bottom;
      String s = "Match 216498464";
      canvas.drawLine(5, bottom, getWidth() - 5, bottom, paint);
      paint.getTextBounds(s.toUpperCase(), 0, s.length(), bounds);
      paint.setARGB(255, 255, 255, 255);
      s = "Match " + m.getMatchNum();
      canvas.drawText(s, 10, bottom + bounds.height() + 5, paint);
      bottom = bottom + bounds.height() + 10;

      s = "123654987";
      paint.getTextBounds(s.toUpperCase(), 0, s.length(), bounds);
      paint.setARGB(255, 255, 0, 0);
      canvas.drawRoundRect(
          new RectF(getWidth() / 4 - 5, bottom, getWidth(), bottom + bounds.height() + 10),
          6,
          6,
          paint);
      paint.setARGB(255, 255, 255, 255);
      bottom = bottom + bounds.height() + 10;
      s = m.getRedTeam()[0].getNumber() + "";
      canvas.drawText(s, getWidth() / 4, bottom - 5, paint);
      s = m.getRedTeam()[1].getNumber() + "";
      canvas.drawText(s, getWidth() / 2, bottom - 5, paint);
      s = m.getRedTeam()[2].getNumber() + "";
      canvas.drawText(s, getWidth() / 4 * 3, bottom - 5, paint);

      paint.setARGB(255, 0, 0, 255);
      canvas.drawRoundRect(
          new RectF(getWidth() / 4 - 5, bottom, getWidth(), bottom + bounds.height() + 10),
          6,
          6,
          paint);
      paint.setARGB(255, 255, 255, 255);
      bottom = bottom + bounds.height() + 10;
      canvas.drawText(s, getWidth() / 4, bottom - 5, paint);
      s = m.getBlueTeam()[0].getNumber() + "";
      canvas.drawText(s, getWidth() / 2, bottom - 5, paint);
      s = m.getBlueTeam()[1].getNumber() + "";
      canvas.drawText(s, getWidth() / 4 * 3, bottom - 5, paint);
      s = m.getBlueTeam()[2].getNumber() + "";
      bottom += 5;
    }
    height = Math.round(bottom + 1);
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

    int height = 0;
    if (mBitmap != null) {
      height += mBitmap.getHeight();
      bx = ((right - left) - mBitmap.getWidth()) / 2;
    }
    if (message != null) {
      Rect bounds = new Rect();
      mPaint.getTextBounds(message, 0, message.length() - 1, bounds);
      int tw = bounds.right - bounds.left;
      int th = bounds.bottom - bounds.top;
      height += th;
      tx = ((right - left) - tw) / 2;
    }

    by = (bottom - top - height) / 2;
    if (mBitmap != null) {
      ty = by + mBitmap.getHeight();
    } else {
      ty = by;
    }
    if (message != null) {
      ty += (-mPaint.ascent());
    }
  }
  private static Bitmap drawText(String text, String imagePath) {

    // Create bitmap and canvas to draw to
    Bitmap b = ImageLoader.getInstance().loadImageSync("file://" + imagePath);
    Bitmap bitmap = b.copy(Bitmap.Config.RGB_565, true);

    Canvas canvas = new Canvas(bitmap);
    // new antialised Paint
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // text color - #3D3D3D
    paint.setColor(Color.rgb(61, 61, 61));
    // text size in pixels
    paint.setTextSize(20);
    // text shadow
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    // draw text to the Canvas center
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;

    canvas.drawText(text, x, y, paint);

    return bitmap;
  }
Beispiel #9
0
 /** 计算最大len的Text的宽高度 */
 private void measureTextWidthHeight() {
   Rect rect = new Rect();
   for (int i = 0; i < adapter.getItemsCount(); i++) {
     String s1 = getContentText(adapter.getItem(i));
     paintCenterText.getTextBounds(s1, 0, s1.length(), rect);
     int textWidth = rect.width();
     if (textWidth > maxTextWidth) {
       maxTextWidth = textWidth;
     }
     paintCenterText.getTextBounds("\u661F\u671F", 0, 2, rect); // 星期
     int textHeight = rect.height();
     if (textHeight > maxTextHeight) {
       maxTextHeight = textHeight;
     }
   }
 }
 @Override
 public int getSize(
     Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
   paint.getTextBounds(mText, 0, mText.length(), mRect);
   mRect.inset(-1, -1);
   return (int) (paint.measureText(mText) + 0.5);
 }
  /**
   * Create a skeleton FontMap for the requested font. This will allow the developer to query text
   * length, and height. Creation of models and textures is done later during the draw cycle.
   */
  public GLFontMap generateFontMap(
      final Typeface _typeface, final int _size, final String _charsToMap, int _spacing) {
    final Paint paint = new Paint();
    paint.setTypeface(_typeface);
    paint.setTextSize((float) _size);

    final int length = _charsToMap.length();
    float increment = 0;
    final char[] c = new char[1];
    final Glyph[] glyphs = new GLGlyph[length];

    for (int i = 0; i < length; i++) {
      c[0] = _charsToMap.charAt(i);
      final float start = increment + (i * _spacing);
      final float advance = paint.measureText(c, 0, 1);

      glyphs[i] = new GLGlyph(c[0], start, advance);
      // System.out.println( "Index: " + i + " Glyph: " + glyphs[i] ) ;
      increment += advance;
    }

    // Create a GLFontMap and wrap it around a FontMap
    final Rect bounds = new Rect();
    paint.getTextBounds(_charsToMap, 0, length, bounds);
    return new GLFontMap(new FontMap(glyphs, null, bounds.height()));
  }
Beispiel #12
0
 private void e() {
   Rect rect = new Rect();
   for (int i1 = 0; i1 < arrayList.size(); i1++) {
     String s1 = (String) arrayList.get(i1);
     paintB.getTextBounds(s1, 0, s1.length(), rect);
     int j1 = rect.width();
     if (j1 > g) {
       g = j1;
     }
     paintB.getTextBounds("\u661F\u671F", 0, 2, rect);
     j1 = rect.height();
     if (j1 > h) {
       h = j1;
     }
   }
 }
  /**
   * @param textview
   * @return
   */
  private String adjustTextLength(TextView tv) {
    if (tv == null) {
      return "";
    }
    String input = tv.getText().toString();
    String result = input;
    String newtext = input;
    int lastSpaceIndex = 0;
    ViewGroup.LayoutParams lp = (ViewGroup.LayoutParams) tv.getLayoutParams();
    Paint p = tv.getPaint();
    Rect bound = new Rect();
    p.getTextBounds(input, 0, input.length() - 1, bound);
    float textHeight = p.getTextSize();
    float multiLine = (((lp.height - tv.getPaddingTop() - tv.getPaddingBottom()) / textHeight));
    float availableW = (lp.width - tv.getPaddingLeft() - tv.getPaddingRight()) * (multiLine + 0.2f);

    do {

      newtext = (String) TextUtils.ellipsize(result, tv.getPaint(), availableW, TruncateAt.END);
      if (!newtext.equals(result)) {
        lastSpaceIndex = newtext.lastIndexOf(" ");
        if (lastSpaceIndex > 0) {
          result = newtext.substring(0, lastSpaceIndex) + "...";
        } else {
          break;
        }
      } else {
        break;
      }
    } while (false);

    GKIMLog.lf(null, 0, TAG + "=>adjust title from: " + input + " to: " + result);
    tv.setText(result);
    return result;
  }
Beispiel #14
0
 /** 设置绘制刮奖文案信息的画笔属性 */
 private void setTextPaint() {
   mTextPaint.setColor(Color.DKGRAY);
   mTextPaint.setStyle(Style.FILL);
   mTextPaint.setTextSize(mTextSize);
   // 获取画笔绘制文本的宽高
   mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
 }
    /**
     * initializes all size dependent variables sets stroke width and text size of all involved
     * paints YES! i think the method name is appropriate
     */
    private void initSizeBasedStuff() {
      mCircleSize = Math.min(getMeasuredWidth(), getMeasuredHeight());
      mTextPaint.setTextSize(mCircleSize / 2f);

      float strokeWidth = mCircleSize / STROKE_WITH;
      mFrontPaint.setStrokeWidth(strokeWidth);
      mBackPaint.setStrokeWidth(strokeWidth);

      // calculate rectangle for drawArc calls
      int pLeft = getPaddingLeft();
      mRectLeft =
          new RectF(
              pLeft + strokeWidth / 2.0f,
              0 + strokeWidth / 2.0f,
              mCircleSize - strokeWidth / 2.0f + pLeft,
              mCircleSize - strokeWidth / 2.0f);

      // calculate Y position for text
      Rect bounds = new Rect();
      mTextPaint.getTextBounds("99", 0, "99".length(), bounds);
      mTextX = mCircleSize / 2.0f + getPaddingLeft();
      // the +1dp at end of formula balances out rounding issues.works out on all resolutions
      mTextY =
          mCircleSize / 2.0f
              + (bounds.bottom - bounds.top) / 2.0f
              - strokeWidth / 2.0f
              + getResources().getDisplayMetrics().density;
    }
 private Rect getBounds(BatteryTracker tracker, int level) {
   Rect bounds = new Rect();
   boolean unknownStatus = tracker.status == BatteryManager.BATTERY_STATUS_UNKNOWN;
   String levelTxt = getLevel(unknownStatus ? -1 : level);
   mBackPaint.getTextBounds(levelTxt, 0, levelTxt.length(), bounds);
   return bounds;
 }
Beispiel #17
0
  public static Bitmap drawTextToBitmap(Context context, int resId, String text) {
    Resources resources = context.getResources();

    Bitmap bitmap = BitmapFactory.decodeResource(resources, resId);

    Bitmap.Config bitmapConfig = bitmap.getConfig();
    // set default bitmap config if none
    if (bitmapConfig == null) {
      bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }
    // resource bitmaps are immutable,
    // so we need to convert it to mutable one
    bitmap = bitmap.copy(bitmapConfig, true);

    // new antialised Paint
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // text color
    paint.setColor(colors900[random.nextInt(colors900.length)]);
    // text size in pixels
    paint.setTextSize((int) (30 * resources.getDisplayMetrics().density));
    // text shadow
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    // draw text to the Canvas center
    Rect bounds = new Rect();
    paint.getTextBounds(text, 0, text.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) / 2;

    new Canvas(bitmap).drawText(text, x, y, paint);

    return bitmap;
  }
Beispiel #18
0
  public TimeBar(Context context, Listener listener) {
    super(context);
    this.listener = Utils.checkNotNull(listener);

    showTimes = true;
    showScrubber = true;

    progressBar = new Rect();
    playedBar = new Rect();

    progressPaint = new Paint();
    progressPaint.setColor(0xFF808080);
    playedPaint = new Paint();
    playedPaint.setColor(0xFFFFFFFF);

    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    float textSizeInPx = metrics.density * TEXT_SIZE_IN_DP;
    timeTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    timeTextPaint.setColor(0xFFCECECE);
    timeTextPaint.setTextSize(textSizeInPx);
    timeTextPaint.setTextAlign(Paint.Align.CENTER);

    timeBounds = new Rect();
    timeTextPaint.getTextBounds("0:00:00", 0, 7, timeBounds);

    scrubber = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_knob);
    scrubberPadding = (int) (metrics.density * SCRUBBER_PADDING_IN_DP);

    vPaddingInPx = (int) (metrics.density * V_PADDING_IN_DP);
  }
Beispiel #19
0
 private int getTextWidth(String text) {
   Paint p = new Paint();
   Rect bounds = new Rect();
   p.setTextSize(50);
   p.getTextBounds(text, 0, text.length(), bounds);
   return bounds.width();
 }
Beispiel #20
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO Auto-generated method stub
    int width;
    int height;

    width = MeasureSpec.getSize(widthMeasureSpec);

    // 獲取刻度數字高度
    mTextPaint.getTextBounds(mCalibrationArray[0] + "", 0, 1, mTextBounds);
    // 20默認豎線高度
    int topheight = Math.max(mTextBounds.height() + VERTICALLINEHEIGHT, mBitmap.getHeight());
    height = topheight + mBarHeight + mBitmap.getHeight();
    setMeasuredDimension(width, height);

    // 初始下游標繪製的rect
    mCursorBottomDstRect.set(0, height - mBitmap.getHeight(), mBitmap.getWidth(), height);
    // 初始上游標繪製的rect
    mCursorTopDstRect.set(
        width - mBitmap.getWidth(),
        height - 2 * mBitmap.getHeight() - mBarHeight,
        width,
        height - mBitmap.getHeight() - mBarHeight);
    // 計算bar的寬度
    mBarWidth = MeasureSpec.getSize(widthMeasureSpec) - mBitmap.getWidth();
  }
Beispiel #21
0
  // methods
  public ModeStatus(CommonActivity parent, Screen screen) {
    super(parent, screen);

    this.state = parent.getMainState();

    sMode = parent.getString(R.string.label_ui_mode);
    vecModes = parent.getResources().getStringArray(R.array.status_ui_modes);

    // paint
    mTextModeValue.setAntiAlias(true);
    mTextModeValue.setColor(style.iTextColor2);
    mTextModeValue.setTextSize(style.fTextSize1);
    mTextModeValue.setTextAlign(Paint.Align.LEFT);
    mTextModeValue.setTextSkewX(fTextSkew);

    mBarFrame.setColor(style.iBarFrame);
    mBarFrame.setAlpha(128);

    mBackground.setAntiAlias(true);
    mBackground.setColor(style.iBackgroundColor);

    // get default height
    mTextModeValue.getTextBounds(sMode, 0, sMode.length(), rtTextMode);

    this.bAlwaysVisible = true;

    updateWidth();

    // watch state object for UI mode change
    state.addObserver(this);
  }
  public void onDraw(Canvas canvas, int measuredWidth, int measuredHeight) {
    if (!visual || text == null) {
      return;
    }

    float actualDistance = distance + height / 2;
    calcOffset(actualDistance, measuredWidth, measuredHeight);

    rectPaint.setColor(backgroundColor);
    if (alpha != 0) {
      rectPaint.setAlpha(alpha);
    }
    rectPaint.setStrokeWidth(height);

    rectPath.reset();
    rectPath.moveTo(startPosX, startPosY);
    rectPath.lineTo(endPosX, endPosY);
    canvas.drawPath(rectPath, rectPaint);

    textPaint.setTextSize(textSize);
    textPaint.setColor(textColor);
    textPaint.getTextBounds(text, 0, text.length(), textBound);

    canvas.drawTextOnPath(
        text,
        rectPath,
        (1.4142135f * actualDistance) / 2 - textBound.width() / 2,
        textBound.height() / 2,
        textPaint);
  }
Beispiel #23
0
    public void chooseHeight(
        CharSequence text,
        int start,
        int end,
        int spanstartv,
        int v,
        Paint.FontMetricsInt fm,
        TextPaint paint) {
      int size = mSize;
      if (paint != null) {
        size *= paint.density;
      }

      if (fm.bottom - fm.top < size) {
        fm.top = fm.bottom - size;
        fm.ascent = fm.ascent - size;
      } else {
        if (sProportion == 0) {
          /*
           * Calculate what fraction of the nominal ascent the height
           * of a capital letter actually is, so that we won't reduce
           * the ascent to less than that unless we absolutely have
           * to.
           */

          Paint p = new Paint();
          p.setTextSize(100);
          Rect r = new Rect();
          p.getTextBounds("ABCDEFG", 0, 7, r);

          sProportion = (r.top) / p.ascent();
        }

        int need = (int) Math.ceil(-fm.top * sProportion);

        if (size - fm.descent >= need) {
          /*
           * It is safe to shrink the ascent this much.
           */

          fm.top = fm.bottom - size;
          fm.ascent = fm.descent - size;
        } else if (size >= need) {
          /*
           * We can't show all the descent, but we can at least show
           * all the ascent.
           */

          fm.top = fm.ascent = -need;
          fm.bottom = fm.descent = fm.top + size;
        } else {
          /*
           * Show as much of the ascent as we can, and no descent.
           */

          fm.top = fm.ascent = -size;
          fm.bottom = fm.descent = 0;
        }
      }
    }
Beispiel #24
0
  private void calc() {
    textSize = mHTextView.getTextSize();
    paint.setTextSize(textSize);

    for (int i = 0; i < mText.length(); i++) {
      gaps[i] = paint.measureText(mText.charAt(i) + "");
    }

    oldPaint.setTextSize(textSize);

    for (int i = 0; i < mOldText.length(); i++) {
      oldGaps[i] = oldPaint.measureText(mOldText.charAt(i) + "");
    }

    oldStartX = (mHTextView.getWidth() - oldPaint.measureText(mOldText.toString())) / 2f;

    startX = (mHTextView.getWidth() - paint.measureText(mText.toString())) / 2f;
    startY = (int) ((mHTextView.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));

    differentList.clear();
    differentList.addAll(CharacterUtils.diff(mOldText, mText));

    Rect bounds = new Rect();
    paint.getTextBounds(mText.toString(), 0, mText.length(), bounds);
    upDistance = bounds.height();
  }
 private void initaitePaint() {
   mTextPaint = new Paint();
   mTextPaint.setTextSize(mTextSize);
   mTextPaint.setColor(0xff555555);
   mTextPaint.setAntiAlias(true);
   // 得到text绘制范围
   mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
 }
Beispiel #26
0
  public void setLevel(int level) {
    this.level = level;
    Rect bounds = new Rect();
    String l = "" + level;
    paintText.getTextBounds(l, 0, l.length(), bounds);

    fw = bounds.width();
  }
Beispiel #27
0
  /**
   * Gets the the intrinsic width of the underlying drawable object. Returns -1 if it has no
   * intrinsic width, such as with a solid color.
   *
   * @return The intrinsic width as an {@code int} value.
   */
  @Override
  public int getIntrinsicWidth() {
    if (mText != null && mFillPaint != null) {
      mFillPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
      return mTextBounds.width();
    }

    return super.getIntrinsicWidth();
  }
Beispiel #28
0
  private void measureBaseSize() {
    mPaint.setTextSize(mTextSize);
    mPaint.setTypeface(mTypeface);
    mDayBaseWidth = mPaint.measureText("88", 0, 2) + mDayPadding * 2;

    Rect bounds = new Rect();
    mPaint.getTextBounds("88", 0, 2, bounds);
    mDayBaseHeight = bounds.height();
  }
Beispiel #29
0
 /**
  * Like getPackedStringDimensions except adds extra space to accommodate all characters that can
  * be drawn regardless of whether or not they exist in text. This ensures a more uniform
  * appearance for things that have dynamic text.
  *
  * @param text
  * @param paint
  * @return
  */
 public static Rect getStringDimensions(String text, Paint paint) {
   Rect size = new Rect();
   if (text == null || text.length() == ZERO) {
     return null;
   }
   paint.getTextBounds(text, ZERO, text.length(), size);
   size.bottom = size.top + (int) getFontHeight(paint);
   return size;
 }
 @Override
 protected synchronized void onDraw(Canvas canvas) {
   // First draw the regular progress bar, then custom draw our text
   super.onDraw(canvas);
   Rect bounds = new Rect();
   textPaint.getTextBounds(text, 0, text.length(), bounds);
   int x = getWidth() / 2 - bounds.centerX();
   int y = getHeight() / 2 - bounds.centerY();
   canvas.drawText(text, x, y, textPaint);
 }