コード例 #1
0
  private void drawScale(final Canvas canvas) {
    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    // On canvas, North is 0 degrees, East is 90 degrees, South is 180 etc.
    // We start the scale somewhere South-West so we need to first rotate the canvas.
    canvas.rotate(mScaleRotation, 0.5f, 0.5f);

    final int totalTicks = mDivisions * mSubdivisions + 1;
    for (int i = 0; i < totalTicks; i++) {
      final float y1 = mScaleRect.top;
      final float y2 = y1 + 0.015f; // height of division
      final float y3 = y1 + 0.045f; // height of subdivision

      final float value = getValueForTick(i);
      final Paint paint = getRangePaint(mScaleStartValue + value);

      float mod = value % mDivisionValue;
      if ((Math.abs(mod - 0) < 0.001) || (Math.abs(mod - mDivisionValue) < 0.001)) {
        // Draw a division tick
        canvas.drawLine(0.5f, y1, 0.5f, y3, paint);
        // Draw the text 0.15 away from the division tick
        drawTextOnCanvasWithMagnifier(canvas, valueString(value), 0.5f, y3 + 0.045f, paint);
      } else {
        // Draw a subdivision tick
        canvas.drawLine(0.5f, y1, 0.5f, y2, paint);
      }
      canvas.rotate(mSubdivisionAngle, 0.5f, 0.5f);
    }
    canvas.restore();
  }
コード例 #2
0
    @Override
    protected void onDraw(Canvas canvas) {
      if (bitmap != null) {
        canvas.drawBitmap(bitmap, null, rect, null);
        float hueInPiInterval = colorHsv[0] / 180f * (float) Math.PI;

        selectedPoint.x =
            rect.left
                + (int)
                    (-FloatMath.cos(hueInPiInterval) * colorHsv[1] * innerRadius + middleSize / 2);
        selectedPoint.y =
            rect.top
                + (int)
                    (-FloatMath.sin(hueInPiInterval) * colorHsv[1] * innerRadius + middleSize / 2);

        canvas.drawLine(
            selectedPoint.x - pointerLength,
            selectedPoint.y,
            selectedPoint.x + pointerLength,
            selectedPoint.y,
            pointerPaint);
        canvas.drawLine(
            selectedPoint.x,
            selectedPoint.y - pointerLength,
            selectedPoint.x,
            selectedPoint.y + pointerLength,
            pointerPaint);
      }
    }
コード例 #3
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float len = 0;
    if (!mRects.isEmpty()) {
      Rect rect = mRects.get(0);
      len = Math.min(rect.width() / 10, MAX_LEN);
    }

    for (Rect rect : mRects) {
      // draw left-top corner
      canvas.drawLine(rect.left, rect.top, rect.left + len, rect.top, mPaint);
      canvas.drawLine(rect.left, rect.top, rect.left, rect.top + len, mPaint);
      // draw right-top corner
      canvas.drawLine(rect.right, rect.top, rect.right - len, rect.top, mPaint);
      canvas.drawLine(rect.right, rect.top, rect.right, rect.top + len, mPaint);
      // draw left-bottom corner
      canvas.drawLine(rect.left, rect.bottom, rect.left, rect.bottom - len, mPaint);
      canvas.drawLine(rect.left, rect.bottom, rect.left + len, rect.bottom, mPaint);
      // draw right-bottom corner
      canvas.drawLine(rect.right, rect.bottom, rect.right, rect.bottom - len, mPaint);
      canvas.drawLine(rect.right, rect.bottom, rect.right - len, rect.bottom, mPaint);
    }
    for (Point pt : mPoints) {
      canvas.drawCircle(pt.x, pt.y, len, mPaint);
    }
    //        Log.i("TAG", String.format("canvas w:%d, h:%d", canvas.getWidth(),
    // canvas.getHeight()));
  }
コード例 #4
0
ファイル: Background.java プロジェクト: lnrtu/android-quill
  private void draw_quad(Canvas c, Transformation t) {
    float spacingMm = 5f;
    int nx, ny;
    float x, x0, x1, y, y0, y1;

    int shade = 0xaa;
    float threshold = 1500;
    if (t.scale < threshold) shade += (int) ((threshold - t.scale) / threshold * (0xff - shade));
    paint.setARGB(0xff, shade, shade, shade);

    paint.setStrokeWidth(0);
    ny = (int) Math.floor((heightMm - 2 * marginMm) / spacingMm);
    nx = (int) Math.floor((widthMm - 2 * marginMm) / spacingMm);
    float marginXMm = (widthMm - nx * spacingMm) / 2;
    float marginYMm = (heightMm - ny * spacingMm) / 2;
    x0 = t.applyX(marginXMm / heightMm);
    x1 = t.applyX((widthMm - marginXMm) / heightMm);
    y0 = t.applyY(marginYMm / heightMm);
    y1 = t.applyY((heightMm - marginYMm) / heightMm);
    for (int i = 0; i <= ny; i++) {
      y = t.applyY((marginYMm + i * spacingMm) / heightMm);
      c.drawLine(x0, y, x1, y, paint);
    }
    for (int i = 0; i <= nx; i++) {
      x = t.applyX((marginXMm + i * spacingMm) / heightMm);
      c.drawLine(x, y0, x, y1, paint);
    }
  }
コード例 #5
0
ファイル: uiGraphics.java プロジェクト: vincfr/PPRZonDroid
  private void drawPlane(Canvas canvas, float GraphicsScaleFactor) {
    canvas.drawCircle(0, 0, (8 * GraphicsScaleFactor), plane);

    canvas.drawLine((-8 * GraphicsScaleFactor), 0, (-16 * GraphicsScaleFactor), 0, plane);
    canvas.drawLine((8 * GraphicsScaleFactor), 0, (16 * GraphicsScaleFactor), 0, plane);
    canvas.drawLine(0, (-8 * GraphicsScaleFactor), 0, (-16 * GraphicsScaleFactor), plane);
  }
コード例 #6
0
  public void drawWin() {
    Paint p = new Paint();

    if (MainActivity.game.getTurn().isX()) p.setColor(getResources().getColor(R.color.win_color));
    else p.setColor(getResources().getColor(R.color.win_color));
    float cellSize = (canvasSize / MainActivity.game.getFieldSize());
    p.setStrokeWidth(cellSize * getFloatValueFromResourses(R.dimen.win_line_width));

    for (int i = 0; i < MainActivity.game.getFieldSize(); i++) {
      for (int j = 0; j < MainActivity.game.getFieldSize(); j++) {
        switch (MainActivity.game.getField()[i][j].getWin()) {
          case 1:
            canvas.drawLine(
                cellSize * (i + 0.5f), cellSize * j, cellSize * (i + 0.5f), cellSize * (j + 1), p);
            break;
          case 2:
            canvas.drawLine(
                cellSize * i, cellSize * (j + 0.5f), cellSize * (i + 1), cellSize * (j + 0.5f), p);
            break;
          case 3:
            canvas.drawLine(cellSize * i, cellSize * j, cellSize * (i + 1), cellSize * (j + 1), p);
            break;
          case 4:
            canvas.drawLine(cellSize * (i + 1), cellSize * j, cellSize * i, cellSize * (j + 1), p);
        }
      }
    }
  }
コード例 #7
0
  public GameFieldView(Context context, AttributeSet attrs) {
    super(context, attrs);
    bitmap = Bitmap.createBitmap(MainActivity.size.x, MainActivity.size.x, Bitmap.Config.ARGB_8888);
    canvas = new Canvas(bitmap);
    mScaleFactor = 1f;
    paint.setColor(getResources().getColor(R.color.gamefield_color));
    paint.setStrokeWidth(
        MainActivity.size.y
            * getFloatValueFromResourses(R.dimen.game_field_line_width)
            / MainActivity.game.getFieldSize());

    canvas.drawRect(
        0, 0, MainActivity.size.x - 2 * margin, MainActivity.size.x - 2 * margin, paint);

    paint.setColor(getResources().getColor(R.color.gamefield_line_color));

    for (int i = 0; i < MainActivity.game.getFieldSize() + 1; i++) {
      canvas.drawLine(
          0,
          i * canvasSize / MainActivity.game.getFieldSize(),
          canvasSize,
          i * canvasSize / MainActivity.game.getFieldSize(),
          paint);
      canvas.drawLine(
          i * canvasSize / MainActivity.game.getFieldSize(),
          0,
          i * canvasSize / MainActivity.game.getFieldSize(),
          canvasSize,
          paint);
    }

    scrollGestureDetector = new GestureDetector(context, new MyGestureListener());
  }
コード例 #8
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (user == null && chat == null && encryptedChat == null) {
      return;
    }

    if (cellLayout == null) {
      requestLayout();
      return;
    }

    if (useSeparator) {
      int h = getMeasuredHeight();
      if (!usePadding) {
        canvas.drawLine(0, h - 1, getMeasuredWidth(), h - 1, linePaint);
      } else {
        canvas.drawLine(
            AndroidUtilities.dp(11),
            h - 1,
            getMeasuredWidth() - AndroidUtilities.dp(11),
            h - 1,
            linePaint);
      }
    }

    if (drawAlpha != 1) {
      canvas.saveLayerAlpha(
          0,
          0,
          canvas.getWidth(),
          canvas.getHeight(),
          (int) (255 * drawAlpha),
          Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    if (cellLayout.drawNameLock) {
      setDrawableBounds(lockDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
      lockDrawable.draw(canvas);
    } else if (cellLayout.drawNameGroup) {
      setDrawableBounds(groupDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
      groupDrawable.draw(canvas);
    } else if (cellLayout.drawNameBroadcast) {
      setDrawableBounds(broadcastDrawable, cellLayout.nameLockLeft, cellLayout.nameLockTop);
      broadcastDrawable.draw(canvas);
    }

    canvas.save();
    canvas.translate(cellLayout.nameLeft, cellLayout.nameTop);
    cellLayout.nameLayout.draw(canvas);
    canvas.restore();

    if (cellLayout.onlineLayout != null) {
      canvas.save();
      canvas.translate(cellLayout.onlineLeft, cellLayout.onlineTop);
      cellLayout.onlineLayout.draw(canvas);
      canvas.restore();
    }

    avatarImage.draw(canvas);
  }
コード例 #9
0
ファイル: patternDraw.java プロジェクト: trideeprath/BICS
    @Override
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      int x = 20;
      int y = 300;
      int dpSize = 3;
      int radius = 40;
      Paint paint = new Paint();
      // Use Color.parseColor to define HTML colors
      paint.setColor(Color.parseColor("#000000"));
      DisplayMetrics dm = getResources().getDisplayMetrics();
      float strokeWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpSize, dm);
      paint.setStrokeWidth(strokeWidth);
      // canvas.drawCircle(x,x, radius, paint);
      // canvas.drawLine(xPositionP1,yPositionP1,xPositionP2,yPositionP2,paint);
      float h = (float) 30.0;
      float x1, y1, x2, y2, x3, y3, x4, y4;
      x1 = xPositionP1;
      y1 = yPositionP1;
      x2 = (xPositionP2 + xPositionP1) / 2;
      y2 = (yPositionP2 + yPositionP1) / 2;

      float phi = (float) Math.atan2(y2 - y1, x2 - x1);
      float angle1 = (float) (phi - Math.PI / 6);
      float angle2 = (float) (phi + Math.PI / 6);

      x3 = (float) (x2 - h * Math.cos(angle1));
      x4 = (float) (x2 - h * Math.cos(angle2));
      y3 = (float) (y2 - h * Math.sin(angle1));
      y4 = (float) (y2 - h * Math.sin(angle2));
      canvas.drawLine(x1, y1, x2, y2, paint);
      canvas.drawLine(x2, y2, x3, y3, paint);
      canvas.drawLine(x2, y2, x4, y4, paint);
    }
コード例 #10
0
ファイル: WaveformView.java プロジェクト: jq/zhong
  /**
   * Our waveform is "painted" as a series of vertical lines, not anti-aliased.
   *
   * <p>But, the Cupcake API only supports the standard resolution and automatically scales
   * everything up by a factor of 1.5 on a high-resolution display, which leaves "gaps" when we try
   * to draw one vertical line per "pixel". (The coordinates are scaled, but the lines are drawn
   * normally.)
   *
   * <p>So, if the density is > 1.0, then we draw two vertical lines instead of one every other
   * time. This solves the problem for a scale factor between 1.0 and 2.0. A future version of
   * Ringdroid will use the 1.6 (Donut) API or later and natively support all resolutions.
   */
  protected void drawWaveformLine(Canvas canvas, int x, int y0, int y1, Paint paint) {
    if (mDensity > 1.0 && (x % 2) == 1) {
      canvas.drawLine(x + 0.5f, y0, x + 0.5f, y1, paint);
    }

    canvas.drawLine(x, y0, x, y1, paint);
  }
コード例 #11
0
ファイル: JoystickView.java プロジェクト: shuwyx/MiniQ
  @Override
  protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);
    centerX = (getWidth()) / 2;
    centerY = (getHeight()) / 2;

    // painting the main circle
    canvas.drawCircle((int) centerX, (int) centerY, joystickRadius, mainCircle);
    // painting the secondary circle
    canvas.drawCircle((int) centerX, (int) centerY, joystickRadius / 2, secondaryCircle);
    // paint lines
    canvas.drawLine(
        (float) centerX,
        (float) centerY,
        (float) centerX,
        (float) (centerY - joystickRadius),
        verticalLine);
    canvas.drawLine(
        (float) (centerX - joystickRadius),
        (float) centerY,
        (float) (centerX + joystickRadius),
        (float) centerY,
        horizontalLine);
    canvas.drawLine(
        (float) centerX,
        (float) (centerY + joystickRadius),
        (float) centerX,
        (float) centerY,
        horizontalLine);

    if (xPosition == 0) xPosition = (int) centerX;
    if (yPosition == 0) yPosition = (int) centerY;
    // painting the move button
    canvas.drawCircle(xPosition, yPosition, buttonRadius, button);
  }
コード例 #12
0
  private void drawDebug(Canvas canvas) {
    float posX = 10;
    float posY = 20;

    Paint paint = new Paint();
    paint.setStrokeWidth(5);
    paint.setStyle(Style.FILL);

    paint.setColor(Color.BLACK);

    canvas.drawCircle(mOrigin.x, mOrigin.y, getWidth(), paint);

    paint.setStrokeWidth(3);
    paint.setColor(Color.RED);
    canvas.drawCircle(mOrigin.x, mOrigin.y, getWidth(), paint);

    paint.setStrokeWidth(5);
    paint.setColor(Color.BLACK);
    canvas.drawLine(mOrigin.x, mOrigin.y, mMovement.x, mMovement.y, paint);

    paint.setStrokeWidth(3);
    paint.setColor(Color.RED);
    canvas.drawLine(mOrigin.x, mOrigin.y, mMovement.x, mMovement.y, paint);

    posY = debugDrawPoint(canvas, "A", mA, Color.RED, posX, posY);
    posY = debugDrawPoint(canvas, "B", mB, Color.GREEN, posX, posY);
    posY = debugDrawPoint(canvas, "C", mC, Color.BLUE, posX, posY);
    posY = debugDrawPoint(canvas, "D", mD, Color.CYAN, posX, posY);
    posY = debugDrawPoint(canvas, "E", mE, Color.YELLOW, posX, posY);
    posY = debugDrawPoint(canvas, "F", mF, Color.LTGRAY, posX, posY);
    posY = debugDrawPoint(canvas, "Mov", mMovement, Color.DKGRAY, posX, posY);
    posY = debugDrawPoint(canvas, "Origin", mOrigin, Color.MAGENTA, posX, posY);

    /**/
  }
コード例 #13
0
ファイル: LineGraphView.java プロジェクト: k9luo/MapNav
  /**
   * Draws the graph itself
   *
   * @param canvas
   */
  private void prepForData(Canvas canvas) {
    canvas.drawLine(0, HEIGHT / 2, WIDTH + AXIS_WIDTH, HEIGHT / 2, graphPaint);
    canvas.drawLine(5 + AXIS_WIDTH, 0, 5 + AXIS_WIDTH, HEIGHT, graphPaint);

    float maxY = 0;

    for (float[] pointArray : points) {
      for (float point : pointArray) {
        if (Math.abs(point) > maxY) maxY = Math.abs(point);
      }
    }

    xScale = (WIDTH) / (points.size() + 1);
    yScale = 40;

    // yScale = (HEIGHT / 2) / maxY;

    canvas.drawText(Float.toString(maxY) + " m/s^2", 0, 10, graphPaint);
    canvas.drawText("-" + Float.toString(maxY) + " m/s^2", 0, HEIGHT, graphPaint);

    for (int i = 0; i < labels.size(); i++) {
      canvas.drawText(labels.get(i) + ":", 0, 30 + i * 20, graphPaint);
      canvas.drawLine(0, 35 + i * 20, AXIS_WIDTH - 20, 35 + i * 20, linePaints.get(i));
    }
  }
コード例 #14
0
  private void drawThirds(Canvas canvas) {
    outlinePaint.setStrokeWidth(1);
    float xThird = (drawRect.right - drawRect.left) / 3;
    float yThird = (drawRect.bottom - drawRect.top) / 3;

    canvas.drawLine(
        drawRect.left + xThird,
        drawRect.top,
        drawRect.left + xThird,
        drawRect.bottom,
        outlinePaint);
    canvas.drawLine(
        drawRect.left + xThird * 2,
        drawRect.top,
        drawRect.left + xThird * 2,
        drawRect.bottom,
        outlinePaint);
    canvas.drawLine(
        drawRect.left, drawRect.top + yThird, drawRect.right, drawRect.top + yThird, outlinePaint);
    canvas.drawLine(
        drawRect.left,
        drawRect.top + yThird * 2,
        drawRect.right,
        drawRect.top + yThird * 2,
        outlinePaint);
  }
コード例 #15
0
 @Override
 protected void onDraw(Canvas canvas) {
   for (int i = 0; i < pos_width_num; i++) {
     canvas.drawLine(
         startx + i * perL,
         starty,
         startx + i * perL,
         starty + perL * (pos_height_num - 1),
         paint);
   }
   for (int i = 0; i < pos_height_num; i++) {
     canvas.drawLine(
         startx,
         starty + i * perL,
         startx + perL * (pos_width_num - 1),
         starty + i * perL,
         paint);
   }
   if (cirX > 0 && cirY > 0) {
     canvas.drawCircle(cirX, cirY, perL / 2, paint);
   }
   if (showText.length() > 0) {
     canvas.drawText(showText, 60, 1000, paint);
   }
   super.onDraw(canvas);
 }
コード例 #16
0
ファイル: LineTool.java プロジェクト: sy1121/thor
  @Override
  public void draw(Canvas canvas) {
    if (mInitialEventCoordinate == null || mCurrentCoordinate == null) {
      return;
    }

    changePaintColor(mCanvasPaint.getColor());

    if (mCanvasPaint.getAlpha() == 0x00) {
      mCanvasPaint.setColor(Color.BLACK);
      canvas.drawLine(
          mInitialEventCoordinate.x,
          mInitialEventCoordinate.y,
          mCurrentCoordinate.x,
          mCurrentCoordinate.y,
          mCanvasPaint);
      mCanvasPaint.setColor(Color.TRANSPARENT);
    } else {
      canvas.drawLine(
          mInitialEventCoordinate.x,
          mInitialEventCoordinate.y,
          mCurrentCoordinate.x,
          mCurrentCoordinate.y,
          mBitmapPaint);
    }
  }
コード例 #17
0
  protected void onDraw(Canvas canvas) {
    mCalendar = Calendar.getInstance();
    super.onDraw(canvas);
    int minute = mCalendar.get(Calendar.MINUTE); // 得到当前分钟数
    int hour = mCalendar.get(Calendar.HOUR); // 得到当前小时数
    int sec = mCalendar.get(Calendar.SECOND); // 得到当前秒数

    float minuteDegree = minute / 60f * 360; // 得到分针旋转的角度
    canvas.save();
    canvas.rotate(minuteDegree, width / 2, height / 2);
    canvas.drawLine(width / 2, height / 2 - 250, width / 2, height / 2 + 40, mPaintMinute);
    canvas.restore();

    float hourDegree = (hour * 60 + minute) / 12f / 60 * 360; // 得到时钟旋转的角度
    canvas.save();
    canvas.rotate(hourDegree, width / 2, height / 2);
    canvas.drawLine(width / 2, height / 2 - 200, width / 2, height / 2 + 30, mPaintHour);
    canvas.restore();

    float secDegree = sec / 60f * 360; // 得到秒针旋转的角度
    canvas.save();
    canvas.rotate(secDegree, width / 2, height / 2);
    canvas.drawLine(width / 2, height / 2 - 300, width / 2, height / 2 + 40, mPaintSec);
    canvas.restore();
  }
コード例 #18
0
  private void drawPageGrid(int w, int h) {
    Bitmap newBackgroundBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
    Canvas newBackgroundCanvas = new Canvas();
    newBackgroundCanvas.setBitmap(newBackgroundBitmap);

    if (mBackgroundBitmap != null) {
      newBackgroundCanvas.drawBitmap(mBackgroundBitmap, 0, 0, null);
    }
    mBackgroundBitmap = newBackgroundBitmap;
    mBackgroundCanvas = newBackgroundCanvas;

    // make the entire canvas page colour
    mBackgroundCanvas.drawPaint(pagePainter);

    // Draw Background Grid
    Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay();
    width = display.getWidth(); // start
    height = display.getHeight(); // end

    for (int i = 0; i < width; i += xpos) {
      mBackgroundCanvas.drawLine(i, 0, i, height, gridPainter);
    }
    for (int i = 0; i < height; i += ypos) {
      mBackgroundCanvas.drawLine(0, i, width, i, gridPainter);
    }
  }
コード例 #19
0
ファイル: HandDraw.java プロジェクト: xiaomochn/TfpVoffLine
 public void drawWordLines(Canvas canvas) {
   Paint paint = new Paint();
   // 换行分隔线颜色透明
   paint.setColor(Color.argb(0, 0, 0, 0));
   for (int i = 0; i < (nLineCount + 1); i++) {
     boolean bSplited = false;
     int y = (nItemHeight + nHeightSpace) * (i + 1);
     int x = 0;
     for (int j = 0; j < pListMaskRect.size(); j++) {
       Rect rectMask = pListMaskRect.get(j);
       if ((((y - nItemHeight - nHeightSpace) >= rectMask.top)
               && ((y - nItemHeight - nHeightSpace) <= rectMask.bottom))
           || ((y >= rectMask.top) && (y <= rectMask.bottom))) {
         canvas.drawLine(x, y, rectMask.left, y, paint);
         x = rectMask.right;
         bSplited = true;
       }
     }
     if (bSplited)
       canvas.drawLine(
           x,
           (nItemHeight + nHeightSpace) * (i + 1),
           GlobalVariables.screenWidth,
           (nItemHeight + nHeightSpace) * (i + 1),
           paint);
     else
       canvas.drawLine(
           0f,
           (nItemHeight + nHeightSpace) * (i + 1),
           GlobalVariables.screenWidth,
           (nItemHeight + nHeightSpace) * (i + 1),
           paint);
   }
 }
コード例 #20
0
    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
      // 移动中心
      canvas.translate(mWidth / 2 - 50, mHeight / 2);
      // 画中心圆
      canvas.drawCircle(0, 0, mCenterRadius, mCenterPaint);
      // 是否显示中心圆外的小圆环
      if (mHighlightCenter || mlittleLightCenter) {
        int c = mCenterPaint.getColor();
        mCenterPaint.setStyle(Paint.Style.STROKE);
        if (mHighlightCenter) {
          mCenterPaint.setAlpha(0xFF);
        } else if (mlittleLightCenter) {
          mCenterPaint.setAlpha(0x90);
        }
        canvas.drawCircle(0, 0, mCenterRadius + mCenterPaint.getStrokeWidth(), mCenterPaint);

        mCenterPaint.setStyle(Paint.Style.FILL);
        mCenterPaint.setColor(c);
      }
      // 画色环
      canvas.drawOval(
          new RectF(-mCircleRadius, -mCircleRadius, mCircleRadius, mCircleRadius), mCirclePaint);
      // 画黑白渐变块
      if (mDownInCircle) {
        mRectColors[1] = mCenterPaint.getColor();
      }
      mRectShader =
          new LinearGradient(
              0, mRectTop, 0, mRectBottom, mRectColors, null, Shader.TileMode.MIRROR);
      mRectPaint.setShader(mRectShader);
      canvas.drawRect(mRectLeft, mRectTop, mRectRight, mRectBottom, mRectPaint);
      float offset = mLinePaint.getStrokeWidth() / 2;
      canvas.drawLine(
          mRectLeft - offset,
          mRectTop - offset * 2,
          mRectLeft - offset,
          mRectBottom + offset * 2,
          mLinePaint); // 左
      canvas.drawLine(
          mRectLeft - offset * 2,
          mRectTop - offset,
          mRectRight + offset * 2,
          mRectTop - offset,
          mLinePaint); // 上
      canvas.drawLine(
          mRectRight + offset,
          mRectTop - offset * 2,
          mRectRight + offset,
          mRectBottom + offset * 2,
          mLinePaint); // 右
      canvas.drawLine(
          mRectLeft - offset * 2,
          mRectBottom + offset,
          mRectRight + offset * 2,
          mRectBottom + offset,
          mLinePaint); // 下
      super.onDraw(canvas);
    }
コード例 #21
0
ファイル: SineView.java プロジェクト: rahulraopune/APIHelp
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub

    super.onDraw(canvas);
    // canvas
    canvas.drawLine(
        canvas.getWidth() / 2 - 200,
        canvas.getHeight() / 2 + 50,
        canvas.getWidth(),
        canvas.getHeight() / 2 + 50,
        red); // xaxis
    canvas.drawLine(
        canvas.getWidth() / 2 - 150,
        canvas.getHeight() / 2 - 800,
        canvas.getWidth() / 2 - 150,
        canvas.getHeight() / 2 + 100,
        red); // yaxis

    for (int i = 0; i <= 720; i++) // curve
    {
      int x = i + (canvas.getWidth() / 2 - 150);
      int y =
          (int) ((canvas.getHeight() / 2 + 50) + ((float) Math.sin(Math.toRadians(2 * i))) * 100);
      canvas.drawPoint(x, y, blue);
    }
  }
コード例 #22
0
 /** 绘制表格 */
 public void onDrawTable(Canvas canvas, int x, int y) {
   // 3.6.2需求多画2行
   for (int i = 0; i < line + 2; i++) {
     for (int j = 0; j < row; j++) {
       if (iGameType.equals("ssq") && isRed && j == 11) {
         p.setColor(Color.GRAY);
         p.setStrokeWidth(1);
         canvas.drawLine(FIRST_WITH + j * WITH + x, 0, FIRST_WITH + j * WITH + x, getHeight(), p);
       }
       if (iGameType.equals("ssq") && isRed && j == 22) {
         p.setColor(Color.GRAY);
         p.setStrokeWidth(1);
         canvas.drawLine(FIRST_WITH + j * WITH + x, 0, FIRST_WITH + j * WITH + x, getHeight(), p);
       }
       if (i % 2 == 0) {
         if (j % 2 == 0) {
           canvas.drawBitmap(bitWhite, FIRST_WITH + j * WITH + x, WITH + i * WITH + y, null);
         } else {
           canvas.drawBitmap(bitGrey, FIRST_WITH + j * WITH + x, WITH + i * WITH + y, null);
         }
       } else {
         if (j % 2 == 0) {
           canvas.drawBitmap(bitGrey, FIRST_WITH + j * WITH + x, WITH + i * WITH + y, null);
         } else {
           canvas.drawBitmap(bitWhite, FIRST_WITH + j * WITH + x, WITH + i * WITH + y, null);
         }
       }
     }
   }
 }
コード例 #23
0
ファイル: UberUnit.java プロジェクト: talah/BBTH
  @Override
  public void drawEffects(Canvas canvas) {
    if (firing) {
      float radius = POWER_CIRCLE_RADIUS * powerLevel / MAX_POWER_LEVEL;
      if (radius > 0f) {
        tempPaint.set(paint);

        paint.setStyle(Style.FILL);
        paint.setColor(Color.GRAY);

        paint.setStrokeWidth(radius);
        canvas.drawLine(getX(), getY(), fireTarget.getX(), fireTarget.getY(), paint);

        canvas.drawCircle(fireTarget.getX(), fireTarget.getY(), radius * .7f, paint);

        paint.setColor(Color.WHITE);
        canvas.drawCircle(getX(), getY(), radius, paint);
        canvas.drawCircle(fireTarget.getX(), fireTarget.getY(), radius * .45f, paint);

        paint.setStrokeWidth(radius * .5f);
        canvas.drawLine(getX(), getY(), fireTarget.getX(), fireTarget.getY(), paint);

        paint.set(tempPaint);
      }
    }
  }
コード例 #24
0
ファイル: uiGraphics.java プロジェクト: vincfr/PPRZonDroid
  private void drawPitch(Canvas canvas) {

    int step = 40; // Pixels per 5 degree step

    canvas.translate(0, (int) (pitch * (step / 5)));
    canvas.rotate(-(int) roll);

    // Draw the background box - FIXME, doesn't yet work - WTF
    // groundGradient.setBounds(-width, 0, width, 2 * height);
    // groundGradient.draw(canvas);

    canvas.drawRect(-width, 0, width, 5 * height /* Go plenty low */, ground);
    canvas.drawRect(-width, -5 * height /* Go plenty high */, width, 0, sky);
    canvas.drawRect(-width, -20, width, 20, whitebar);

    // Draw the vertical grid
    canvas.drawLine(-width, 0, width, 0, white);
    // canvas.f

    for (int i = -step * 20; i < step * 20; i += step) {
      if (i != 0) {
        if (i % (2 * step) == 0) {
          canvas.drawLine(-50, i, 50, i, white);
          canvas.drawText((5 * i / -step) + "", -90, i + 5, white);

        } else canvas.drawLine(-20, i, 20, i, white);
      }
    }
  }
コード例 #25
0
ファイル: Background.java プロジェクト: lnrtu/android-quill
  private void draw_ruled(Canvas c, Transformation t, float lineSpacing, float margin) {

    float spacingMm = lineSpacing;
    float vertLineMm = margin;

    int shade = 0xaa;
    float threshold = 1500;
    if (t.scale < threshold) shade += (int) ((threshold - t.scale) / threshold * (0xff - shade));
    paint.setARGB(0xff, shade, shade, shade);

    paint.setStrokeWidth(0);
    int n = (int) Math.floor((heightMm - 2 * marginMm) / spacingMm) - 2;
    float x0 = t.applyX(marginMm / heightMm);
    float x1 = t.applyX((widthMm - marginMm) / heightMm);
    for (int i = 1; i <= n; i++) {
      float y = t.applyY(((heightMm - n * spacingMm) / 2 + i * spacingMm) / heightMm);
      c.drawLine(x0, y, x1, y, paint);
    }

    // Paint margin
    if (margin > 0.0f) {
      paint.setARGB(0xff, 0xff, shade, shade);
      paint.setStrokeWidth(0);
      float y0 = t.applyY(marginMm / heightMm);
      float y1 = t.applyY((heightMm - marginMm) / heightMm);
      float x = t.applyX(vertLineMm / widthMm);
      c.drawLine(x, y0, x, y1, paint);
    }
  }
コード例 #26
0
    @Override
    protected void onDraw(Canvas canvas) {
      int translatedHue = 255 - (int) (mCurrentHue * 255 / 360);
      // Display all the colors of the hue bar with lines
      for (int x = 0; x < 256; x++) {
        // If this is not the current selected hue, display the actual color
        if (translatedHue != x) {
          mPaint.setColor(mHueBarColors[x]);
          mPaint.setStrokeWidth(1);
        } else // else display a slightly larger black line
        {
          mPaint.setColor(Color.BLACK);
          mPaint.setStrokeWidth(3);
        }
        canvas.drawLine(x + 10, 0, x + 10, 40, mPaint);
      }

      // Display the main field colors using LinearGradient
      for (int x = 0; x < 256; x++) {
        int[] colors = new int[2];
        colors[0] = mMainColors[x];
        colors[1] = Color.BLACK;
        Shader shader = new LinearGradient(0, 50, 0, 306, colors, null, Shader.TileMode.REPEAT);
        mPaint.setShader(shader);
        canvas.drawLine(x + 10, 50, x + 10, 306, mPaint);
      }
      mPaint.setShader(null);

      // Display the circle around the currently selected color in the main field
      if (mCurrentX != 0 && mCurrentY != 0) {
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setColor(Color.BLACK);
        canvas.drawCircle(mCurrentX, mCurrentY, 10, mPaint);
      }

      // Draw a 'button' with the currently selected color
      mPaint.setStyle(Paint.Style.FILL);
      mPaint.setColor(mCurrentColor);
      canvas.drawRect(10, 316, 138, 356, mPaint);

      // Set the text color according to the brightness of the color
      if (Color.red(mCurrentColor) + Color.green(mCurrentColor) + Color.blue(mCurrentColor) < 384)
        mPaint.setColor(Color.WHITE);
      else mPaint.setColor(Color.BLACK);
      // canvas.drawText(getResources().getString(R.string.settings_bg_color_confirm), 74, 340,
      // mPaint);

      // Draw a 'button' with the default color
      mPaint.setStyle(Paint.Style.FILL);
      mPaint.setColor(mDefaultColor);
      canvas.drawRect(138, 316, 266, 356, mPaint);

      // Set the text color according to the brightness of the color
      if (Color.red(mDefaultColor) + Color.green(mDefaultColor) + Color.blue(mDefaultColor) < 384)
        mPaint.setColor(Color.WHITE);
      else mPaint.setColor(Color.BLACK);
      // canvas.drawText(getResources().getString(R.string.settings_default_color_confirm), 202,
      // 340, mPaint);
    }
コード例 #27
0
ファイル: CardsBarGraphic.java プロジェクト: jx-admin/Code2
  private void drawAxis(Canvas canvas) {
    mPaint.setAntiAlias(true);

    // draw y axis
    mPaint.setColor(yAxisColor);
    mPaint.setStrokeWidth(yAxisScale);
    canvas.drawLine(yAxisXPosition, yAxisStartYPosition, yAxisXPosition, yAxisEndYPosition, mPaint);

    // draw x axis
    mPaint.setColor(xAxisColor);
    mPaint.setStrokeWidth(xAxisScale);
    canvas.drawLine(xAxisStartXPosition, xAxisYPosition, xAxisEndXPosition, xAxisYPosition, mPaint);

    // draw average line
    int y =
        (int) (averageWithdrawal / maximumWithdrawal * (yAxisEndYPosition - yAxisStartYPosition));
    y = yAxisEndYPosition - 1 - y;
    canvas.drawLine(yAxisXPosition, y, xAxisEndXPosition, y, mPaint);

    textPaint.setAntiAlias(true);
    textPaint.setTypeface(Typeface.SERIF);
    textPaint.setColor(Color.BLACK);

    // draw the second title
    textPaint.setTextAlign(Paint.Align.LEFT);
    textPaint.setTextSize(titleSecondSize);
    canvas.drawText(averageText, titleSecondSize, titleSecondY, textPaint);

    // draw the y axis valus
    textPaint.setTextAlign(Paint.Align.RIGHT);
    textPaint.setTextSize(yPaintScale);
    int x = yAxisXPosition - 2 * yAxisScale;
    y = yAxisEndYPosition;
    for (int i = 0, count = yValues.size(); i < count; i++) {
      canvas.drawText(yValues.get(i), x, y, textPaint);
      y -= yCellLength;
    }

    // draw the x axis values
    textPaint.setTextAlign(Paint.Align.LEFT);
    textPaint.setTextSize(xPaintScale);
    x = yAxisXPosition + xCellLength;
    for (int count = dataList.size(), i = count - 1; i >= 0; i--) {

      // draw the vertical line
      canvas.drawLine(x, yAxisStartYPosition, x, yAxisEndYPosition, mPaint);

      mpath.reset();
      String temp = convertDateFormat(dataList.get(i).getLastUpdate());
      String[] strs = temp.split(" ");
      mpath.moveTo(x - yPaintScale / 2, yAxisEndYPosition + 2 * yPaintScale);
      mpath.lineTo(x + 3 * yPaintScale, yAxisEndYPosition);

      canvas.drawTextOnPath(strs[0], mpath, 0, 0, textPaint);
      canvas.drawTextOnPath(strs[1], mpath, 0, yPaintScale, textPaint);

      x += xCellLength;
    }
  }
コード例 #28
0
  private void drawBrokenLine(
      float startX, float startY, float stopX, float stopY, float endX, Canvas canvas) {
    // 连接线
    canvas.drawLine(startX, startY, stopX, stopY, getLabelLinePaint());

    // 转折线
    canvas.drawLine(stopX, stopY, endX, stopY, getLabelLinePaint());
  }
コード例 #29
0
ファイル: BoardView.java プロジェクト: bart9h/AngryPipes
 private void drawLock(float x, float y, boolean simple, Canvas canvas, Paint paint) { //
   if (simple) return;
   paint.setAlpha(0x60);
   canvas.drawLine(x - 5, y - 5, x + 5, y - 5, paint);
   canvas.drawLine(x + 5, y - 5, x + 5, y + 5, paint);
   canvas.drawLine(x + 5, y + 5, x - 5, y + 5, paint);
   canvas.drawLine(x - 5, y + 5, x - 5, y - 5, paint);
 } //
コード例 #30
0
 /** 画十字及坐标信息 */
 private void drawCrosshairsAndText(int x, int y, Paint paint, int ptr, int id, Canvas c) {
   c.drawLine(0, y, width, y, paint);
   c.drawLine(x, 0, x, height, paint);
   int textY = 15 + 20 * ptr;
   c.drawText("x" + ptr + "=" + x, 15, textY, textPaint);
   c.drawText("y" + ptr + "=" + y, 75, textY, textPaint);
   c.drawText("id" + ptr + "=" + id, width - 55, textY, textPaint);
 }