Esempio n. 1
0
    /** draw graph without animation */
    private void drawGraphRegionWithoutAnimation(GraphCanvasWrapper graphCanvas) {

      boolean isDrawRegion = mLineGraphVO.isDrawRegion();

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        for (int j = 0; j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              regionPath.moveTo(x, 0);
              regionPath.lineTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              regionPath.lineTo(x, y);
            }
          }
        }

        if (isDrawRegion) {
          regionPath.lineTo(x, 0);
          regionPath.lineTo(0, 0);

          Paint pBg = new Paint();
          pBg.setFlags(Paint.ANTI_ALIAS_FLAG);
          pBg.setAntiAlias(true); // text anti alias
          pBg.setFilterBitmap(true); // bitmap anti alias
          pBg.setStyle(Style.FILL);
          pBg.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
          graphCanvas.getCanvas().drawPath(regionPath, pBg);
        }
      }
    }
Esempio n. 2
0
    /** draw graph without animation */
    private void drawGraphWithoutAnimation(GraphCanvasWrapper graphCanvas) {

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath linePath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        Bitmap icon = arrIcon.get(i);

        for (int j = 0; j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.moveTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.lineTo(x, y);
            }

            if (icon == null) {
              graphCanvas.drawCircle(x, y, 4, pCircle);
            } else {
              graphCanvas.drawBitmapIcon(icon, x, y, null);
            }
          }
        }

        graphCanvas.getCanvas().drawPath(linePath, p);
      }
    }
Esempio n. 3
0
    /** draw graph with animation */
    private void drawGraphWithAnimation(GraphCanvasWrapper graphCanvas) {
      // for draw animation
      float prev_x = 0;
      float prev_y = 0;

      float next_x = 0;
      float next_y = 0;

      float value = 0;
      float mode = 0;

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath linePath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        Bitmap icon = arrIcon.get(i);
        value = anim / 1;
        mode = anim % 1;

        for (int j = 0; j < value + 1; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              linePath.moveTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              if (j > value && mode != 0) {
                next_x = x - prev_x;
                next_y = y - prev_y;

                linePath.lineTo(prev_x + next_x * mode, prev_y + next_y * mode);
              } else {
                linePath.lineTo(x, y);
              }
            }

            if (icon == null) {
              graphCanvas.drawCircle(x, y, 4, pCircle);
            } else {
              graphCanvas.drawBitmapIcon(icon, x, y, null);
            }
            prev_x = x;
            prev_y = y;
          }
        }

        graphCanvas.getCanvas().drawPath(linePath, p);
      }
    }
Esempio n. 4
0
    /** draw graph with animation */
    private void drawGraphRegionWithAnimation(GraphCanvasWrapper graphCanvas) {
      // for draw animation
      float prev_x = 0;
      float prev_y = 0;

      float next_x = 0;
      float next_y = 0;

      int value = 0;
      float mode = 0;

      boolean isDrawRegion = mLineGraphVO.isDrawRegion();

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        value = (int) (anim / 1);
        mode = anim % 1;

        boolean isFinish = false;
        for (int j = 0; j <= value + 1; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              regionPath.moveTo(x, 0);
              regionPath.lineTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              if (j > value) {
                next_x = x - prev_x;
                next_y = y - prev_y;
                regionPath.lineTo(prev_x + next_x * mode, prev_y + next_y * mode);
              } else {
                regionPath.lineTo(x, y);
              }
            }

            prev_x = x;
            prev_y = y;
          }
        }
        isFinish = true;

        if (isDrawRegion) {
          float x_bg = prev_x + next_x * mode;
          if (x_bg >= xLength) {
            x_bg = xLength;
          }
          regionPath.lineTo(x_bg, 0);
          regionPath.lineTo(0, 0);

          Paint pBg = new Paint();
          pBg.setFlags(Paint.ANTI_ALIAS_FLAG);
          pBg.setAntiAlias(true); // text anti alias
          pBg.setFilterBitmap(true); // bitmap anti alias
          pBg.setStyle(Style.FILL);
          pBg.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
          graphCanvas.getCanvas().drawPath(regionPath, pBg);
        }
      }
    }
Esempio n. 5
0
    @Override
    public void run() {
      Canvas canvas = null;
      GraphCanvasWrapper graphCanvasWrapper = null;
      Log.e(TAG, "height = " + height);
      Log.e(TAG, "width = " + width);

      setPaint();
      isAnimation();
      isDrawRegion();

      animStartTime = System.currentTimeMillis();

      while (isRun) {

        // draw only on dirty mode
        if (!isDirty) {
          try {
            Thread.sleep(100);
          } catch (InterruptedException e1) {
            e1.printStackTrace();
          }
          continue;
        }

        canvas = mHolder.lockCanvas();
        graphCanvasWrapper =
            new GraphCanvasWrapper(
                canvas,
                width,
                height,
                mLineGraphVO.getPaddingLeft(),
                mLineGraphVO.getPaddingBottom());

        try {
          Thread.sleep(0000);
        } catch (InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        calcTimePass();

        synchronized (mHolder) {
          synchronized (touchLock) {
            try {
              // bg color
              canvas.drawColor(Color.WHITE);
              if (bg != null) {
                canvas.drawBitmap(bg, 0, 0, null);
              }

              // x coord dot line
              drawBaseLine(graphCanvasWrapper);

              // y coord
              graphCanvasWrapper.drawLine(0, 0, 0, chartYLength, pBaseLine);

              // x coord
              graphCanvasWrapper.drawLine(0, 0, chartXLength, 0, pBaseLine);

              // x, y coord mark
              drawXMark(graphCanvasWrapper);
              drawYMark(graphCanvasWrapper);

              // x, y coord text
              drawXText(graphCanvasWrapper);
              drawYText(graphCanvasWrapper);

              // Graph
              drawGraphRegion(graphCanvasWrapper);
              drawGraph(graphCanvasWrapper);

              drawGraphName(canvas);

              //							isDirty = false;

            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              if (graphCanvasWrapper.getCanvas() != null) {
                mHolder.unlockCanvasAndPost(graphCanvasWrapper.getCanvas());
              }
            }
          }
        }
      }
    }