Beispiel #1
0
  public void init(HTextView hTextView, AttributeSet attrs, int defStyle) {
    mHTextView = hTextView;

    mText = "";
    mOldText = "";

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(textColor);
    paint.setStyle(Paint.Style.FILL);

    oldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    oldPaint.setColor(textColor);
    oldPaint.setStyle(Paint.Style.FILL);

    backPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    backPaint.setColor(((ColorDrawable) mHTextView.getBackground()).getColor());
    backPaint.setStyle(Paint.Style.FILL);

    metrics = new DisplayMetrics();
    WindowManager windowManger =
        (WindowManager) hTextView.getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManger.getDefaultDisplay().getMetrics(metrics);

    textSize = hTextView.getTextSize();

    sparkBitmap = BitmapFactory.decodeResource(hTextView.getResources(), R.drawable.fire);
  }
Beispiel #2
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();
  }