Пример #1
0
  /**
   * Renders the plot onto a canvas. Used by both main thread to draw directly onto the View's
   * canvas as well as by background draw to render onto a Bitmap buffer. At the end of the day this
   * is the main entry for a plot's "heavy lifting".
   *
   * @param canvas
   */
  protected synchronized void renderOnCanvas(Canvas canvas) {
    try {
      // any series interested in synchronizing with plot should
      // implement PlotListener.onBeforeDraw(...) and do a read lock from within its
      // invocation.  This is the entry point into that call:
      notifyListenersBeforeDraw(canvas);
      try {
        // need to completely erase what was on the canvas before redrawing, otherwise
        // some odd aliasing artifacts begin to build up around the edges of aa'd entities
        // over time.
        canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        if (backgroundPaint != null) {
          drawBackground(canvas, displayDims.marginatedRect);
        }

        layoutManager.draw(canvas);

        if (getBorderPaint() != null) {
          drawBorder(canvas, displayDims.marginatedRect);
        }
      } catch (PlotRenderException e) {
        Log.e(TAG, "Exception while rendering Plot.", e);
      } catch (Exception e) {
        Log.e(TAG, "Exception while rendering Plot.", e);
      }
    } finally {
      isIdle = true;
      // any series interested in synchronizing with plot should
      // implement PlotListener.onAfterDraw(...) and do a read unlock from within that
      // invocation. This is the entry point for that invocation.
      notifyListenersAfterDraw(canvas);
    }
  }
Пример #2
0
    public void onDraw(Canvas canvas) {
      // 검정색 배경으로 지운다. 빈 화면이면 지우기만 하고 리턴
      canvas.drawColor(Color.BLACK);
      if (status == BLANK) {
        return;
      }

      // 도형 목록을 순회하면서 도형 정보대로 출력한다.
      int idx;
      for (idx = 0; idx < arShape.size(); idx++) {
        Paint Pnt = new Paint();
        Pnt.setAntiAlias(true);
        Pnt.setColor(arShape.get(idx).color);

        Rect rt = arShape.get(idx).rt;
        switch (arShape.get(idx).what) {
          case Shape.RECT:
            canvas.drawRect(rt, Pnt);
            break;
          case Shape.CIRCLE:
            canvas.drawCircle(
                rt.left + rt.width() / 2, rt.top + rt.height() / 2, rt.width() / 2, Pnt);
            break;
          case Shape.TRIANGLE:
            Path path = new Path();
            path.moveTo(rt.left + rt.width() / 2, rt.top);
            path.lineTo(rt.left, rt.bottom);
            path.lineTo(rt.right, rt.bottom);
            canvas.drawPath(path, Pnt);
            break;
        }
      }
    }
Пример #3
0
  @Override
  protected void onDraw(Canvas canvas) {
    canvas.drawColor(Color.LTGRAY);

    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

    canvas.drawPath(mPath, mPaint);
  }
Пример #4
0
 void myDraw() {
   float width, height;
   width = getMeasuredWidth();
   height = getMeasuredHeight();
   canvas = holder.lockCanvas();
   canvas.drawColor(Color.GREEN);
   canvas.drawPath(path, paint);
   holder.unlockCanvasAndPost(canvas);
 }
Пример #5
0
    public void onDraw(Canvas canvas) {
      canvas.drawColor(Color.LTGRAY);
      Paint Pnt = new Paint();
      String str = "Custom Font Test";

      Pnt.setAntiAlias(true);
      Pnt.setTypeface(mFont);
      Pnt.setTextSize(30);
      canvas.drawText(str, 10, 40, Pnt);
    }
Пример #6
0
  public void mDraw() {

    mCanvas = mHolder.lockCanvas(); // 获得画布对象,开始对画布画画

    mCanvas.drawColor(++i); // 设置画布颜色为黑色

    canvasMethod(mCanvas); // 调用自定义的方法,主要是在传进去的画布对象上画画

    mHolder.unlockCanvasAndPost(mCanvas); // 把画布显示在屏幕上
  }
Пример #7
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);
  }
Пример #8
0
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawColor(
          (props.containsKeyAndNotNull(TiC.PROPERTY_BACKGROUND_COLOR))
              ? TiConvert.toColor(props, TiC.PROPERTY_BACKGROUND_COLOR)
              : TiConvert.toColor("transparent"));

      canvas.drawBitmap(tiBitmap, 0, 0, tiBitmapPaint);

      canvas.drawPath(tiPath, tiPaint);
    }
  public Bitmap toBitmap(int bgcolor) {
    Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, mConfig);
    Canvas canvas = new Canvas(bitmap);

    if (bgcolor != Color.TRANSPARENT) {
      canvas.drawColor(bgcolor);
    }

    drawTo(canvas, 0, 0, null, false);
    return bitmap;
  }
Пример #10
0
 public void onDraw(Canvas canvas) {
   canvas.drawColor(Color.LTGRAY);
   Paint Pnt = new Paint();
   int y = 1;
   Pnt.setAntiAlias(true);
   Pnt.setTextSize(30);
   Pnt.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
   canvas.drawText("Font:Default", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL));
   canvas.drawText("Font:Default Bold", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
   canvas.drawText("Font:Monospace", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
   canvas.drawText("Font:Sans Serif", 10, y++ * 40, Pnt);
   Pnt.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL));
   canvas.drawText("Font:Serif", 10, y++ * 40, Pnt);
 }
Пример #11
0
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawColor(Color.WHITE);

      canvas.drawPicture(mPicture);

      canvas.drawPicture(mPicture, new RectF(0, 100, getWidth(), 200));

      mDrawable.setBounds(0, 200, getWidth(), 300);
      mDrawable.draw(canvas);

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      mPicture.writeToStream(os);
      InputStream is = new ByteArrayInputStream(os.toByteArray());
      canvas.translate(0, 300);
      canvas.drawPicture(Picture.createFromStream(is));
    }
Пример #12
0
  /**
   * 画整体chart图
   *
   * @param translatX chart图偏移量
   */
  public void refreshChart(int translatX) {
    synchronized (holder) {
      translationChart(translatX);

      if (holder != null) {
        Canvas canvas = holder.lockCanvas();
        if (canvas != null) {
          canvas.drawColor(backColor);
          drawGridLine(canvas);
          drawChartLine(canvas);
          drawLimitRect(canvas);
          drawAxesLine(canvas);
          drawYValueText(canvas);
          holder.unlockCanvasAndPost(canvas);
        }
      }
    }
  }
Пример #13
0
    @Override
    protected void onDraw(Canvas canvas) {
      canvas.drawColor(Color.WHITE);

      drawArcs(canvas, mBigOval, mUseCenters[mBigIndex], mPaints[mBigIndex]);

      for (int i = 0; i < 4; i++) {
        drawArcs(canvas, mOvals[i], mUseCenters[i], mPaints[i]);
      }

      mSweep += SWEEP_INC;
      if (mSweep > 360) {
        mSweep -= 360;
        mStart += START_INC;
        if (mStart >= 360) {
          mStart -= 360;
        }
        mBigIndex = (mBigIndex + 1) % mOvals.length;
      }
      invalidate();
    }
Пример #14
0
  public void onDraw(Canvas canvas) {
    canvas.drawColor(Color.TRANSPARENT);
    paint.reset();
    paint.setAntiAlias(true);
    float midX, midY, radius, innerRadius;
    path.reset();

    float currentAngle = 270;
    float currentSweep;
    int totalValue = 0;
    float padding = 2;

    midX = getWidth() / 2;
    midY = getHeight() / 2;
    if (midX < midY) {
      radius = midX;
    } else {
      radius = midY;
    }
    radius -= padding;
    innerRadius = radius - thickness;

    for (PieSlice slice : slices) {
      totalValue += slice.getValue();
    }

    int count = 0;
    for (PieSlice slice : slices) {
      Path p = new Path();
      paint.setColor(slice.getColor());
      currentSweep = (slice.getValue() / totalValue) * (360);
      p.arcTo(
          new RectF(midX - radius, midY - radius, midX + radius, midY + radius),
          currentAngle + padding,
          currentSweep - padding);
      p.arcTo(
          new RectF(midX - innerRadius, midY - innerRadius, midX + innerRadius, midY + innerRadius),
          (currentAngle + padding) + (currentSweep - padding),
          -(currentSweep - padding));
      p.close();

      slice.setPath(p);
      slice.setRegion(
          new Region(
              (int) (midX - radius),
              (int) (midY - radius),
              (int) (midX + radius),
              (int) (midY + radius)));
      canvas.drawPath(p, paint);

      if (indexSelected == count && listener != null) {
        path.reset();
        paint.setColor(slice.getColor());
        paint.setColor(Color.parseColor("#33B5E5"));
        paint.setAlpha(100);

        if (slices.size() > 1) {
          path.arcTo(
              new RectF(
                  midX - radius - (padding * 2),
                  midY - radius - (padding * 2),
                  midX + radius + (padding * 2),
                  midY + radius + (padding * 2)),
              currentAngle,
              currentSweep + padding);
          path.arcTo(
              new RectF(
                  midX - innerRadius + (padding * 2),
                  midY - innerRadius + (padding * 2),
                  midX + innerRadius - (padding * 2),
                  midY + innerRadius - (padding * 2)),
              currentAngle + currentSweep + padding,
              -(currentSweep + padding));
          path.close();
        } else {
          path.addCircle(midX, midY, radius + padding, Direction.CW);
        }

        canvas.drawPath(path, paint);
        paint.setAlpha(255);
      }

      currentAngle = currentAngle + currentSweep;

      count++;
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawColor(Color.TRANSPARENT);

    int startCircleX = 0, startCircleY = 0;
    if (isTouched) { // 触摸状态

      startCircleX = startPoint.x + curRadius;
      startCircleY = startPoint.y - curRadius;
      // 绘制原来的圆形(触摸移动的时候半径会不断变化)
      canvas.drawCircle(startCircleX, startCircleY, curRadius, paint);
      // 绘制手指跟踪的圆形
      int endCircleX = endPoint.x;
      int endCircleY = endPoint.y;
      canvas.drawCircle(endCircleX, endCircleY, originRadius, paint);

      if (!isArrivedMaxMoved) { // 没有达到拉伸最大值
        path.reset();
        double sin = triangle.deltaY / triangle.hypotenuse;
        double cos = triangle.deltaX / triangle.hypotenuse;

        // A点
        path.moveTo(
            (float) (startCircleX - curRadius * sin), (float) (startCircleY - curRadius * cos));
        // B点
        path.lineTo(
            (float) (startCircleX + curRadius * sin), (float) (startCircleY + curRadius * cos));
        // C点
        path.quadTo(
            (startCircleX + endCircleX) / 2,
            (startCircleY + endCircleY) / 2,
            (float) (endCircleX + originRadius * sin),
            (float) (endCircleY + originRadius * cos));
        // D点
        path.lineTo(
            (float) (endCircleX - originRadius * sin), (float) (endCircleY - originRadius * cos));
        // A点
        path.quadTo(
            (startCircleX + endCircleX) / 2,
            (startCircleY + endCircleY) / 2,
            (float) (startCircleX - curRadius * sin),
            (float) (startCircleY - curRadius * cos));
        canvas.drawPath(path, paint);
      }

      // 绘制文字
      float textH = -textFontMetrics.ascent - textFontMetrics.descent;
      canvas.drawText(text, endCircleX, endCircleY + textH / 2, textPaint);

    } else { // 非触摸状态
      if (curRadius > 0) {
        startCircleX = curRadius;
        startCircleY = originHeight - curRadius;
        canvas.drawCircle(startCircleX, startCircleY, curRadius, paint);
        if (curRadius == originRadius) { // 只有在恢复正常的情况下才显示文字
          // 绘制文字
          float textH = -textFontMetrics.ascent - textFontMetrics.descent;
          canvas.drawText(text, startCircleX, startCircleY + textH / 2, textPaint);
        }
      }
    }
    //        Logger.d(TAG, "circleX: " + startCircleX + ", circleY: " + startCircleY + ",
    // curRadius: " + curRadius);
  }