예제 #1
0
  private void updateHUD() {
    // TODO Line wrap!

    HUD.eraseColor(Color.TRANSPARENT);
    float textHeight = paint.getFontSpacing();
    int rowsOnScreen = (int) (hudHeight / textHeight);
    float baseLine = hudHeight - Math.max(0, rowsOnScreen - lines.size()) * textHeight;
    log(
        "updateHUD",
        "textHeight = %.2f, rowsOnScreen = %d, lines.size() = %d, baseLine = %.2f",
        textHeight,
        rowsOnScreen,
        lines.size(),
        baseLine);
    int written = 0;
    for (String line : lines) {
      canvas.drawText(line, textXOffset, baseLine - textHeight + textYOffset, paint);
      written += 1;
      baseLine -= textHeight;
      if (baseLine < textHeight) {
        break;
      }
    }
    for (int index = lines.size() - 1; index > written; --index) {
      lines.remove(index);
    }

    setMainTexture();
  }
예제 #2
0
  protected void drawAxes(Canvas canvas) {
    float textHoriOffset;
    float textVertOffset = -(2 * mAxesPaint.getTextSize() - mAxesPaint.getFontSpacing()) / 2;

    Path axesPath = new Path();
    axesPath.moveTo(mLeftPadding, mTopPadding - mGridlinesPaint.getStrokeWidth() / 2);
    axesPath.lineTo(mLeftPadding, mTopPadding + graphHeight);
    axesPath.lineTo(
        mLeftPadding + graphWidth + mGridlinesPaint.getStrokeWidth() / 2,
        mTopPadding + graphHeight);
    mAxesPaint.setStyle(Paint.Style.STROKE);
    mAxesPaint.setAntiAlias(false);
    canvas.drawPath(axesPath, mAxesPaint);
    mAxesPaint.setAntiAlias(mAxesPaintAntiAlias);
    mAxesPaint.setStyle(Paint.Style.FILL);

    for (int i = 0; i < mYAxisLabels.length; i++) {
      textHoriOffset = mAxesPaint.measureText(mYAxisLabels[i]) + mGridlineLabelHoriSpacing;
      canvas.drawText(
          mYAxisLabels[i],
          mLeftPadding - textHoriOffset,
          mTopPadding - textVertOffset + (1.00f - mYAxisLabelPositions[i]) * graphHeight,
          mAxesPaint);
    }

    textVertOffset =
        (2 * mAxesPaint.getTextSize() - mAxesPaint.getFontSpacing()) + mGridlineLabelVertSpacing;

    for (int i = 0; i < mXAxisLabels.length; i++) {
      textHoriOffset = mAxesPaint.measureText(mXAxisLabels[i]) / 2;
      canvas.drawText(
          mXAxisLabels[i],
          mLeftPadding - textHoriOffset + mXAxisLabelPositions[i] * graphWidth,
          mTopPadding + graphHeight + textVertOffset,
          mAxesPaint);
    }
  }
예제 #3
0
  private void init(AttributeSet attrs) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DialpadKey);
    try {
      number = a.getString(R.styleable.DialpadKey_number);
      letters = a.getString(R.styleable.DialpadKey_letters);
    } finally {
      a.recycle();
    }

    // boolean mdpi = ScreenUtil.densityDpi <= DisplayMetrics.DENSITY_MEDIUM;// less or equal than
    // 160dpi

    digitPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    digitPaint.setFakeBoldText(false);
    digitPaint.setColor(Color.parseColor("#000000"));
    digitPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.text_size_37sp));
    digitFM = digitPaint.getFontMetrics();

    charPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    charPaint.setFakeBoldText(false);
    charPaint.setColor(Color.parseColor("#000000"));
    charPaint.setTextSize(getResources().getDimensionPixelSize(R.dimen.text_size_12sp));
    charFM = charPaint.getFontMetrics();

    numberW = Math.round(digitPaint.measureText(number));
    /*Rect rect = new Rect();
    digitPaint.getTextBounds(number,0,number.length(),rect);
    numberH = rect.height();*/
    numberH = Math.round(digitFM.bottom - digitFM.top);

    if (!TextUtils.isEmpty(letters)) {
      lettersW = Math.round(charPaint.measureText(letters));
      /*rect.setEmpty();
      charPaint.getTextBounds(letters,0,letters.length(),rect);
      lettersH = rect.height();*/
      lettersH = Math.round(charFM.bottom - charFM.top);
    }

    gap = getResources().getDimensionPixelSize(R.dimen.gap_4dp);
    int size = numberH + (lettersH > 0 ? (lettersH + gap) : 0);
    // int size = Math.round((0 - digitFM.top) + gap + lettersH + (digitFM.ascent - digitFM.top +
    // ));
    measureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
    Log.i("DialpadKey", "size : " + size + ",spacing :  " + digitPaint.getFontSpacing());
    Log.i("DialpadKey digit fontmetrics ", fontMetricsInfo(digitFM));
    Log.i("DialpadKey char fontmetrics ", fontMetricsInfo(charFM));
  }
예제 #4
0
  private void setFontSize(int size, boolean persist) {

    setFontFace();

    if (size < MIN_FONT_SIZE) size = MIN_FONT_SIZE;
    else if (size > MAX_FONT_SIZE) size = MAX_FONT_SIZE;

    font_text_size = size;

    fore.setTextSize(font_text_size);

    if (persist) {
      if (Preferences.isScreenPortraitOrientation())
        Preferences.setPortraitFontSize(font_text_size);
      else Preferences.setLandscapeFontSize(font_text_size);
    }

    char_height = (int) Math.ceil(fore.getFontSpacing());
    char_width = (int) fore.measureText("X", 0, 1);
    // Log.d("Crawl","setSizeFont "+fore.measureText("X", 0, 1));
  }
예제 #5
0
  @Override
  protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);

    if (mData == null) {

      boolean hasText = !TextUtils.isEmpty(mNoDataText);
      boolean hasDescription = !TextUtils.isEmpty(mNoDataTextDescription);
      float line1height = hasText ? Utils.calcTextHeight(mInfoPaint, mNoDataText) : 0.f;
      float line2height =
          hasDescription ? Utils.calcTextHeight(mInfoPaint, mNoDataTextDescription) : 0.f;
      float lineSpacing =
          (hasText && hasDescription) ? (mInfoPaint.getFontSpacing() - line1height) : 0.f;

      // if no data, inform the user

      float y = (getHeight() - (line1height + lineSpacing + line2height)) / 2.f + line1height;

      if (hasText) {
        canvas.drawText(mNoDataText, getWidth() / 2, y, mInfoPaint);

        if (hasDescription) {
          y = y + line1height + lineSpacing;
        }
      }

      if (hasDescription) {
        canvas.drawText(mNoDataTextDescription, getWidth() / 2, y, mInfoPaint);
      }
      return;
    }

    if (!mOffsetsCalculated) {

      calculateOffsets();
      mOffsetsCalculated = true;
    }
  }