Exemplo n.º 1
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    if (showcaseX < 0 || showcaseY < 0 || isRedundant) {
      super.dispatchDraw(canvas);
      return;
    }

    // Draw the semi-transparent background
    canvas.drawColor(backColor);

    // Draw to the scale specified
    Matrix mm = new Matrix();
    mm.postScale(scaleMultiplier, scaleMultiplier, showcaseX, showcaseY);
    canvas.setMatrix(mm);

    // Erase the area for the ring
    canvas.drawCircle(showcaseX, showcaseY, showcaseRadius, mEraser);

    boolean recalculateText = makeVoidedRect() || mAlteredText;
    mAlteredText = false;

    showcase.setBounds(voidedArea);
    showcase.draw(canvas);

    canvas.setMatrix(new Matrix());

    if (!TextUtils.isEmpty(mTitleText) || !TextUtils.isEmpty(mSubText)) {
      if (recalculateText)
        mBestTextPosition = getBestTextPosition(canvas.getWidth(), canvas.getHeight());

      if (!TextUtils.isEmpty(mTitleText)) {
        // TODO: use a dynamic detail layout
        canvas.drawText(mTitleText, mBestTextPosition[0], mBestTextPosition[1], mPaintTitle);
      }

      if (!TextUtils.isEmpty(mSubText)) {
        canvas.save();
        if (recalculateText)
          mDynamicDetailLayout =
              new DynamicLayout(
                  mSubText,
                  mPaintDetail,
                  ((Number) mBestTextPosition[2]).intValue(),
                  Layout.Alignment.ALIGN_NORMAL,
                  1.2f,
                  1.0f,
                  true);
        canvas.translate(mBestTextPosition[0], mBestTextPosition[1] + 12 * metricScale);
        mDynamicDetailLayout.draw(canvas);
        canvas.restore();
      }
    }

    super.dispatchDraw(canvas);
  }
  // ==============================================================================
  public final int[] renderGlyph(
      char glyph, Paint paint, android.graphics.Matrix matrix, Rect bounds) {
    Path p = new Path();
    paint.getTextPath(String.valueOf(glyph), 0, 1, 0.0f, 0.0f, p);

    RectF boundsF = new RectF();
    p.computeBounds(boundsF, true);
    matrix.mapRect(boundsF);

    boundsF.roundOut(bounds);
    bounds.left--;
    bounds.right++;

    final int w = bounds.width();
    final int h = bounds.height();

    Bitmap bm = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);

    Canvas c = new Canvas(bm);
    matrix.postTranslate(-bounds.left, -bounds.top);
    c.setMatrix(matrix);
    c.drawPath(p, paint);

    final int sizeNeeded = w * h;
    if (cachedRenderArray.length < sizeNeeded) cachedRenderArray = new int[sizeNeeded];

    bm.getPixels(cachedRenderArray, 0, w, 0, 0, w, h);
    bm.recycle();
    return cachedRenderArray;
  }
Exemplo n.º 3
0
    @Override
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);

      if (Build.VERSION.SDK_INT < 11) {
        mTransform.set(canvas.getMatrix());
        mTransform.preRotate(mRotation, mPivot.x, mPivot.y);
        canvas.setMatrix(mTransform);
      }

      for (Item it : mData) {
        mPiePaint.setShader(it.mItemShader);
        cSlicePaint.setShader(it.cSliceShader);
        //                Log.d(TAG, "mBounds: " +mBounds);
        canvas.drawArc(mBounds, 360 - it.mEndAngle, it.mEndAngle - it.mStartAngle, true, mPiePaint);
        Log.d(TAG, "Item Being Built: " + it.mLabel);
        Log.d(TAG, "RectF: " + it.cSliceBounds);
        Log.d(TAG, "StartAngle> " + it.mStartAngle + " EndAngle> " + it.mEndAngle);
        canvas.drawArc(
            it.cSliceBounds, 360 - it.mEndAngle, it.mEndAngle - it.mStartAngle, true, cSlicePaint);
        //                Log.d(TAG, "StartAngle> "+it.mStartAngle+" EndAngle> "+it.mEndAngle);
      }
    }