Пример #1
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;
        }
      }
    }
Пример #2
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);
    }
  }