@Override
  public void onDrawIndicator(Canvas canvas) {
    int height = mPageIndicator.getHeight();

    for (int i = 0; i < mPageIndicator.getTotalPages(); i++) {
      if (i == mPageIndicator.getActualPosition() + 1) {
        int x = mConversionUtils.getPixelsFromDp(4) + mConversionUtils.getPixelsFromDp(16 * i);

        canvas.save();
        canvas.rotate(90 * mPageIndicator.getPositionOffset(), x, height / 2);
      } else if (i == mPageIndicator.getActualPosition()) {
        int x = mConversionUtils.getPixelsFromDp(4) + mConversionUtils.getPixelsFromDp(16 * i);

        canvas.save();
        canvas.rotate(90 + (90 * mPageIndicator.getPositionOffset()), x, height / 2);
      } else {
        canvas.save();
      }
      int x = mConversionUtils.getPixelsFromDp(0) + mConversionUtils.getPixelsFromDp(16 * i);
      int twoDp = mConversionUtils.getPixelsFromDp(3);
      int sixDp = mConversionUtils.getPixelsFromDp(5);
      int heightDp = mConversionUtils.getPixelsFromDp(8);
      canvas.drawRect(x, twoDp, x + heightDp, sixDp, mPaint);
      canvas.restore();
    }
  }
  private void drawScale(Canvas canvas) {
    canvas.drawOval(scaleRect, scalePaint);

    canvas.rotate(210, 0.5f, 0.5f);

    canvas.save(Canvas.MATRIX_SAVE_FLAG);
    for (int i = 0; i < totalNicks; ++i) {
      float y1 = scaleRect.top;
      float y2 = y1 - 0.075f;

      double tempi = i;
      double tempNicks = totalNicks;

      Double green = (tempi / tempNicks) * 255;
      Double red = (1 - (tempi / tempNicks)) * 255;
      Integer igreen = (int) Math.round(green);
      Integer ired = (int) Math.round(red);

      scalePaint.setColor(Color.rgb(ired, igreen, 0));
      canvas.drawLine(0.5f, y1, 0.5f, y2, scalePaint);

      canvas.rotate(degreesPerNick, 0.5f, 0.5f);
    }
    canvas.restore();
  }
  private void drawEdges(Canvas canvas) {

    if (mEdgeGlowLeft != null) {
      if (!mEdgeGlowLeft.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight();

        canvas.rotate(-90);
        canvas.translate(-height / 1.5f, 0);
        mEdgeGlowLeft.setSize((int) (height / 2.5f), height / 5);

        if (mEdgeGlowLeft.draw(canvas)) {
          invalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
      if (!mEdgeGlowRight.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight();

        canvas.translate(getScrollX() + width, height / 3f);
        canvas.rotate(90);
        mEdgeGlowRight.setSize((int) (height / 2.5f), height / 5);
        if (mEdgeGlowRight.draw(canvas)) {
          invalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
  private void drawEdges(Canvas canvas) {

    if (mEdgeGlowLeft != null) {

      final int width = getWidth();
      final int height = getHeight() - getPaddingTop() - getPaddingBottom();

      if (!mEdgeGlowLeft.isFinished()) {
        final int restoreCount = canvas.save();

        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), 0);
        mEdgeGlowLeft.setSize(height, width);
        if (mEdgeGlowLeft.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }

      if (!mEdgeGlowRight.isFinished()) {
        final int restoreCount = canvas.save();

        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), -(mTouchX + width));
        mEdgeGlowRight.setSize(height, width);

        if (mEdgeGlowRight.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
    private void drawRightTopArc(Canvas canvas) {
      canvas.save();

      canvas.translate(0, -radius * 3); // the center of the circle in the rightTop
      canvas.drawArc(oval, -22.5f, -135, true, arcPaint);

      arcPaint.setStyle(Paint.Style.STROKE);
      arcPaint.setColor(Color.WHITE);
      canvas.drawArc(
          oval, -22.5f, -135, false,
          arcPaint); // @param useCenter: useCenter If true, include the center of the oval in the
                     // arc, and close it if it is being stroked. This will draw a wedge

      // ======== draw arc text ==========
      canvas.save();
      canvas.rotate(-135 / 2); // 到正中间

      for (int i = 0; i < 135; i += 33.75) { // 33.75 * 4 = 135;
        canvas.save();
        canvas.rotate(i);
        canvas.drawText("Item", 0, -width * 5 / 32, textPaint);
        canvas.restore();
      }

      canvas.restore();
      // ======== draw arc text ==========

      canvas.restore();
    }
  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();
  }
  private void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) {
    final QuadPoint c = tileBox.getCenterPixelPoint();
    synchronized (this) {
      if (bufferBitmap != null && !bufferBitmap.isRecycled()) {
        canvas.save();
        canvas.rotate(tileBox.getRotate(), c.x, c.y);
        drawBasemap(canvas);
        canvas.restore();
      }
    }

    for (int i = 0; i < layers.size(); i++) {
      try {
        OsmandMapLayer layer = layers.get(i);
        canvas.save();
        // rotate if needed
        if (!layer.drawInScreenPixels()) {
          canvas.rotate(tileBox.getRotate(), c.x, c.y);
        }
        layer.onDraw(canvas, tileBox, drawSettings);
        canvas.restore();
      } catch (IndexOutOfBoundsException e) {
        // skip it
      }
    }
    if (showMapPosition) {
      canvas.drawCircle(c.x, c.y, 3 * dm.density, paintCenter);
      canvas.drawCircle(c.x, c.y, 7 * dm.density, paintCenter);
    }
  }
  /** Draws the overscroll edge glow effect on the left and right sides of the horizontal list */
  private void drawEdgeGlow(Canvas canvas) {
    if (mEdgeGlowLeft != null && !mEdgeGlowLeft.isFinished() && isEdgeGlowEnabled()) {
      // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the left
      // side.
      final int restoreCount = canvas.save();
      final int height = getHeight();

      canvas.rotate(-90, 0, 0);
      canvas.translate(-height + getPaddingBottom(), 0);

      mEdgeGlowLeft.setSize(getRenderHeight(), getRenderWidth());
      if (mEdgeGlowLeft.draw(canvas)) {
        invalidate();
      }

      canvas.restoreToCount(restoreCount);
    } else if (mEdgeGlowRight != null && !mEdgeGlowRight.isFinished() && isEdgeGlowEnabled()) {
      // The Edge glow is meant to come from the top of the screen, so rotate it to draw on the
      // right side.
      final int restoreCount = canvas.save();
      final int width = getWidth();

      canvas.rotate(90, 0, 0);
      canvas.translate(getPaddingTop(), -width);
      mEdgeGlowRight.setSize(getRenderHeight(), getRenderWidth());
      if (mEdgeGlowRight.draw(canvas)) {
        invalidate();
      }

      canvas.restoreToCount(restoreCount);
    }
  }
    @Override
    public void onDraw(Canvas canvas, Rect bounds) {
      is24Hour = df.is24HourFormat(context);
      seconds = getSeconds();
      cal = Calendar.getInstance();
      width = bounds.width() / 2;
      height = bounds.height() / 2;

      canvas.drawRect(0, 0, width * 2, height * 2, mBackgroundPaint);

      if (!ambientMode) {
        canvas.drawRect(0, height + 45, width * 2, height * 2, mTilePaint);
        if (seconds - 447 > -620) {
          canvas.drawBitmap(scale, seconds - 447, height + 60, mScalePaint);
        } else {
          canvas.drawBitmap(scale, seconds + 753, height + 60, mScalePaint);
        }
        canvas.drawBitmap(scale, seconds + 153, height + 60, mScalePaint);

        canvas.rotate(45, width, height);
        canvas.drawRect(width + 15, height + 15, width + 45, height + 45, mArrowPaint);
        canvas.rotate(-45, width, height);
        canvas.drawRect(width - 30, height + 15, width + 30, height + 45, mBorderPaint);
      }

      canvas.drawText(getHours(), HOUR_X, HOUR_MINUTE_Y, mHourPaint);
      canvas.drawText(getMinutes(), MINUTE_X, HOUR_MINUTE_Y, mMinutePaint);
      canvas.drawText(getDate(), width - mDatePaint.getStrokeWidth() / 2, DATE_Y, mDatePaint);
      canvas.drawText(getAmPm(), TIME_X, TIME_Y, mTimePaint);
      if (battery) {
        canvas.drawText(batteryLevel, BATTERY_X, TIME_Y, mBatteryPaint);
      }
    }
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int count = mPagesCount;
    if (count == 0) {
      return;
    }
    float cx = canvas.getWidth() >> 1;
    float cy = canvas.getHeight() >> 1;
    int totalCount = 2 * count - 1;
    int halfCount = totalCount / 2;
    float itemWithOffset = mIndicatorElementSize + mIndicatorElementSpacing;
    float halfItemWithOffset = mIndicatorElementSize / 2 + mIndicatorElementSpacing;
    float halfSize = mIndicatorElementSize / 2f;
    float halfSpacing = mIndicatorElementSpacing / 2f;
    float startX = cx - halfCount * (mIndicatorElementSize + mIndicatorElementSpacing);
    float top = cy - halfSize;
    float bottom = cy + halfSize;
    // if we have odd elements - need to set indicators in center
    if (totalCount % 2 != 0) {
      startX -= halfSize + halfSpacing;
    }

    int i;
    for (i = 0; i < totalCount; i++) {
      // skip empty spaces
      if (i % 2 != 0) {
        continue;
      }
      float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * i;
      float right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      mRenderer.draw(canvas, mElementBounds, mIndicatorPaint, false);
    }

    // multiply on 2 because there are spaces between elements
    float activeItemOffset = (mSelectedPosition + mScrolledOffset) * 2;
    float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * activeItemOffset;
    float right = left + mIndicatorElementSize;
    mElementBounds.set(left, top, right, bottom);

    canvas.clipRect(mClipBounds);

    canvas.save();
    canvas.rotate(ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
    mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
    canvas.restore();

    if (mIsInfiniteScroll && mSelectedPosition == mPagesCount - 1) { // isInfinite && isEnd
      activeItemOffset = (1f - mScrolledOffset) * 2;
      left = mClipBounds.left - itemWithOffset * activeItemOffset + halfItemWithOffset;
      right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      canvas.save();
      canvas.rotate(
          ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
      mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
      canvas.restore();
    }
  }
  public void setWindSpeedDirection(int direction) {
    // ----Point for the triangle indicator-------
    Point a = new Point(x, y - (int) ((height / 2) - textSize));
    Point b = new Point(x - (height / 17), y);
    Point c = new Point(x + (height / 17), y);

    Path path = new Path();
    path.moveTo(a.x, a.y);
    path.lineTo(b.x, b.y);
    path.lineTo(c.x, c.y);
    path.lineTo(a.x, a.y);
    path.close();

    // Red Brush for the painting
    Paint redBrush = new Paint(Paint.ANTI_ALIAS_FLAG);
    redBrush.setColor(Color.RED);
    redBrush.setStrokeWidth(3f);

    if (currentDegrees != direction) {
      // matrix.postRotate(currentDegrees++,x,y);
      mCanvas.rotate(currentDegrees++, x, y);
    } else {
      finishAnimation = true;
      mCanvas.rotate(direction, x, y);
    }
    mCanvas.drawPath(path, redBrush);
    mCanvas.restore();
  }
  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();
  }
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);
    if (leftGlow != null) {
      final int scrollX = getScrollX();
      if (!leftGlow.isFinished()) {
        final int restoreCount = canvas.save();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(270);
        canvas.translate(-height + getPaddingTop(), Math.min(0, scrollX));
        leftGlow.setSize(height, getWidth());
        if (leftGlow.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
      if (!rightGlow.isFinished()) {
        final int restoreCount = canvas.save();
        final int width = getWidth();
        final int height = getHeight() - getPaddingTop() - getPaddingBottom();

        canvas.rotate(90);
        canvas.translate(-getPaddingTop(), -(Math.max(getScrollRange(), scrollX) + width));
        rightGlow.setSize(height, width);
        if (rightGlow.draw(canvas)) {
          postInvalidate();
        }
        canvas.restoreToCount(restoreCount);
      }
    }
  }
  public Bearings(final Activity a) {
    sensorManager = (SensorManager) a.getSystemService(Context.SENSOR_SERVICE);

    // If cache not created, create it!
    if (bitmapsRotated.isEmpty()) {
      final Bitmap bearingBitmap =
          BitmapFactory.decodeResource(a.getResources(), R.drawable.bearing);

      if (bearingBitmap != null) {
        final Canvas bearingCanvas = new Canvas();
        final Paint bearingPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
        for (int i = 0; i < N_OF_CACHE_BITMAPS; i++) {
          final Bitmap b =
              Bitmap.createBitmap(
                  bearingBitmap.getWidth(), bearingBitmap.getHeight(), Bitmap.Config.ARGB_8888);

          final float direction = DEGREES_PER_BITMAP * i - 180;
          bearingCanvas.setBitmap(b);
          bearingCanvas.rotate(
              direction, bearingBitmap.getWidth() / 2, bearingBitmap.getHeight() / 2);
          bearingCanvas.drawBitmap(bearingBitmap, 0, 0, bearingPaint);
          bearingCanvas.rotate(
              -direction, bearingBitmap.getWidth() / 2, bearingBitmap.getHeight() / 2);

          bitmapsRotated.add(b);
        }
      }
    }
  }
  @Override
  public void draw(Canvas canvas, Matrix matrix, float currentZoom, float currentRotateDegrees) {
    canvas.save();
    if (this.isVisible && this.currentPosition != null) {
      float goal[] = {currentPosition.x, currentPosition.y};
      matrix.mapPoints(goal);

      canvas.drawCircle(goal[0], goal[1], defaultLocationCircleRadius, locationPaint);

      if (currentMode == MODE_COMPASS) {
          /*
          for (int i = 0; i < 360 / COMPASS_DELTA_ANGLE; i++)
          {
              canvas.save();
              canvas.rotate(COMPASS_DELTA_ANGLE * i, goal[0], goal[1]);

              if (i % (90 / COMPASS_DELTA_ANGLE) == 0)
              {
                  canvas.drawLine(goal[0], goal[1] - compassRadius + compassLocationCircleRadius, goal[0], goal[1] - compassRadius + compassLocationCircleRadius - compassLineLength, compassLinePaint);
              }
              else
              {
                  canvas.drawCircle(goal[0], goal[1] - compassRadius, compassLocationCircleRadius, new Paint());
              }
              canvas.restore();
          }*/
        if (compassIndicatorArrowBitmap != null) {
          canvas.save();
          canvas.rotate(this.compassIndicatorArrowRotateDegree, goal[0], goal[1]);
          canvas.drawBitmap(
              compassIndicatorArrowBitmap,
              goal[0] - compassIndicatorArrowBitmap.getWidth() / 2,
              goal[1] - defaultLocationCircleRadius - compassIndicatorGap,
              new Paint());
          canvas.restore();
          /*
          if (360 - (this.compassIndicatorArrowRotateDegree - this.compassIndicatorCircleRotateDegree) > 180)
          {
              canvas.drawArc(new RectF(goal[0] - compassRadius, goal[1] - compassRadius, goal[0] + compassRadius, goal[1] + compassRadius), -90 + this.compassIndicatorCircleRotateDegree, (this.compassIndicatorArrowRotateDegree - this.compassIndicatorCircleRotateDegree), false,
                      indicatorArcPaint);
          }
          else
          {
              canvas.drawArc(new RectF(goal[0] - compassRadius, goal[1] - compassRadius, goal[0] + compassRadius, goal[1] + compassRadius), -90 + this.compassIndicatorArrowRotateDegree, 360 - (this.compassIndicatorArrowRotateDegree - this.compassIndicatorCircleRotateDegree), false,
                      indicatorArcPaint);
          }*/

        }
        canvas.save();
        canvas.rotate(compassIndicatorCircleRotateDegree, goal[0], goal[1]);
        // canvas.drawCircle(goal[0], goal[1] - compassRadius, compassIndicatorCircleRadius,
        // indicatorCirclePaint);
        canvas.restore();
      }
    }
    canvas.restore();
  }
Exemple #16
0
 /**
  * Transform the canvas such as it can handle both HORIZONTAL and VERTICAL orientations.
  *
  * @param canvas the canvas to paint to
  * @param angle the angle of rotation
  * @param inverse if the inverse transform needs to be applied
  */
 private void transform(Canvas canvas, float angle, boolean inverse) {
   if (inverse) {
     canvas.scale(1 / mScale, mScale);
     canvas.translate(mTranslate, -mTranslate);
     canvas.rotate(-angle, mCenter.x, mCenter.y);
   } else {
     canvas.rotate(angle, mCenter.x, mCenter.y);
     canvas.translate(-mTranslate, mTranslate);
     canvas.scale(mScale, 1 / mScale);
   }
 }
Exemple #17
0
 @Override
 public void draw(Canvas canvas) {
   if (topDown) {
     canvas.translate(getHeight(), 0);
     canvas.rotate(90);
   } else {
     canvas.translate(0, getWidth());
     canvas.rotate(-90);
   }
   canvas.clipRect(0, 0, getWidth(), getHeight(), android.graphics.Region.Op.REPLACE);
   super.draw(canvas);
 }
Exemple #18
0
 /**
  * The graphical representation of a text, to handle both HORIZONTAL and VERTICAL orientations and
  * extra rotation angles.
  *
  * @param canvas the canvas to paint to
  * @param text the text to be rendered
  * @param x the X axis location of the text
  * @param y the Y axis location of the text
  * @param paint the paint to be used for drawing
  * @param extraAngle the array of points to be used for drawing the series
  */
 protected void drawText(
     Canvas canvas, String text, float x, float y, Paint paint, int extraAngle) {
   int angle = -mRenderer.getOrientation().getAngle() + extraAngle;
   if (angle != 0) {
     // canvas.scale(1 / mScale, mScale);
     canvas.rotate(angle, x, y);
   }
   canvas.drawText(text, x, y, paint);
   if (angle != 0) {
     canvas.rotate(-angle, x, y);
     // canvas.scale(mScale, 1 / mScale);
   }
 }
 private void drawShadow(Canvas canvas) {
   float f = -mCornerRadius - mShadowSize;
   float f1 = mCornerRadius + (float) mInsetShadow + mRawShadowSize / 2.0F;
   int i;
   boolean flag;
   int j;
   if (mCardBounds.width() - 2.0F * f1 > 0.0F) {
     i = 1;
   } else {
     i = 0;
   }
   if (mCardBounds.height() - 2.0F * f1 > 0.0F) {
     flag = true;
   } else {
     flag = false;
   }
   j = canvas.save();
   canvas.translate(mCardBounds.left + f1, mCardBounds.top + f1);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (i != 0) {
     canvas.drawRect(0.0F, f, mCardBounds.width() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(j);
   j = canvas.save();
   canvas.translate(mCardBounds.right - f1, mCardBounds.bottom - f1);
   canvas.rotate(180F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (i != 0) {
     float f2 = mCardBounds.width();
     float f3 = -mCornerRadius;
     canvas.drawRect(0.0F, f, f2 - 2.0F * f1, mShadowSize + f3, mEdgeShadowPaint);
   }
   canvas.restoreToCount(j);
   i = canvas.save();
   canvas.translate(mCardBounds.left + f1, mCardBounds.bottom - f1);
   canvas.rotate(270F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (flag) {
     canvas.drawRect(0.0F, f, mCardBounds.height() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(i);
   i = canvas.save();
   canvas.translate(mCardBounds.right - f1, mCardBounds.top + f1);
   canvas.rotate(90F);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (flag) {
     canvas.drawRect(0.0F, f, mCardBounds.height() - 2.0F * f1, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(i);
 }
Exemple #20
0
 protected void drawAxesLabels(Canvas canvas) {
   canvas.drawText(
       mXAxisLabel,
       mLeftPadding + graphWidth / 2 - mAxisLabelPaint.measureText(mXAxisLabel) / 2,
       mTopPadding + graphHeight + mBottomPadding - mXAxisLabelOffset,
       mAxisLabelPaint);
   canvas.rotate(-90, 0, 0);
   canvas.drawText(
       mYAxisLabel,
       -(mTopPadding + graphHeight / 2 + mAxisLabelPaint.measureText(mYAxisLabel) / 2),
       mAxisLabelPaint.getTextSize() + mYAxisLabelOffset,
       mAxisLabelPaint);
   canvas.rotate(90, 0, 0);
 }
 private void drawShadow(Canvas canvas) {
   final float edgeShadowTop = -mCornerRadius - mShadowSize;
   final float inset = mCornerRadius + mInsetShadow + mRawShadowSize / 2;
   final boolean drawHorizontalEdges = mCardBounds.width() - 2 * inset > 0;
   final boolean drawVerticalEdges = mCardBounds.height() - 2 * inset > 0;
   // LT
   int saved = canvas.save();
   canvas.translate(mCardBounds.left + inset, mCardBounds.top + inset);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawHorizontalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.width() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // RB
   saved = canvas.save();
   canvas.translate(mCardBounds.right - inset, mCardBounds.bottom - inset);
   canvas.rotate(180f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawHorizontalEdges) {
     canvas.drawRect(
         0,
         edgeShadowTop,
         mCardBounds.width() - 2 * inset,
         -mCornerRadius + mShadowSize,
         mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // LB
   saved = canvas.save();
   canvas.translate(mCardBounds.left + inset, mCardBounds.bottom - inset);
   canvas.rotate(270f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawVerticalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
   // RT
   saved = canvas.save();
   canvas.translate(mCardBounds.right - inset, mCardBounds.top + inset);
   canvas.rotate(90f);
   canvas.drawPath(mCornerShadowPath, mCornerShadowPaint);
   if (drawVerticalEdges) {
     canvas.drawRect(
         0, edgeShadowTop, mCardBounds.height() - 2 * inset, -mCornerRadius, mEdgeShadowPaint);
   }
   canvas.restoreToCount(saved);
 }
  @Override
  public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    final boolean isRtl = isLayoutRtl();
    // Interpolated widths of arrow bars
    final float arrowSize = lerp(mBarSize, mTopBottomArrowSize, mProgress);
    final float middleBarSize = lerp(mBarSize, mMiddleArrowSize, mProgress);
    // Interpolated size of middle bar
    final float middleBarCut = lerp(0, mBarThickness / 2, mProgress);
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(isRtl ? 180 : 0, isRtl ? 0 : 180, mProgress);
    final float topBottomBarOffset = lerp(mBarGap + mBarThickness, 0, mProgress);
    mPath.rewind();

    final float arrowEdge = -middleBarSize / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + middleBarCut, 0);
    mPath.rLineTo(middleBarSize - middleBarCut, 0);

    final float arrowWidth = Math.round(arrowSize * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowSize * Math.sin(rotation));

    // top bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // bottom bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);
    mPath.moveTo(0, 0);
    mPath.close();

    canvas.save();
    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    if (mSpin) {
      canvas.rotate(
          canvasRotate * ((mVerticalMirror ^ isRtl) ? -1 : 1), bounds.centerX(), bounds.centerY());
    } else if (isRtl) {
      canvas.rotate(-180, bounds.centerX(), bounds.centerY());
    }
    canvas.translate(bounds.centerX(), bounds.centerY());
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
  }
  /*
   * (non-Javadoc)
   *
   * @see android.view.View#onDraw(android.graphics.Canvas)
   */
  @Override
  protected void onDraw(final Canvas canvas) {

    // All of our positions are using our internal coordinate system.
    // Instead of translating
    // them we let Canvas do the work for us.
    canvas.translate(mTranslationOffsetX, mTranslationOffsetY);

    final float progressRotation = getCurrentRotation();

    // draw the background
    if (!mOverrdraw) {
      canvas.drawArc(mCircleBounds, 270, -(360 - progressRotation), false, mBackgroundColorPaint);
    }

    // draw the progress or a full circle if overdraw is true
    canvas.drawArc(
        mCircleBounds, 270, mOverrdraw ? 360 : progressRotation, false, mProgressColorPaint);

    // draw the marker at the correct rotated position
    if (mIsMarkerEnabled) {
      final float markerRotation = getMarkerRotation();

      canvas.save();
      canvas.rotate(markerRotation - 90);
      canvas.drawLine(
          (float) (mThumbPosX + mThumbRadius / 2 * 1.4),
          mThumbPosY,
          (float) (mThumbPosX - mThumbRadius / 2 * 1.4),
          mThumbPosY,
          mMarkerColorPaint);
      canvas.restore();
    }

    if (isThumbEnabled()) {
      // draw the thumb square at the correct rotated position
      canvas.save();
      canvas.rotate(progressRotation - 90);
      // rotate the square by 45 degrees
      canvas.rotate(45, mThumbPosX, mThumbPosY);
      mSquareRect.left = mThumbPosX - mThumbRadius / 3;
      mSquareRect.right = mThumbPosX + mThumbRadius / 3;
      mSquareRect.top = mThumbPosY - mThumbRadius / 3;
      mSquareRect.bottom = mThumbPosY + mThumbRadius / 3;
      canvas.drawRect(mSquareRect, mThumbColorPaint);
      canvas.restore();
    }
  }
 public final void draw(Canvas paramCanvas) {
   Rect localRect = getBounds();
   int i = paramCanvas.save();
   paramCanvas.rotate(this.mRotation, localRect.exactCenterX(), localRect.exactCenterY());
   Ring localRing = this.mRing;
   RectF localRectF = localRing.mTempBounds;
   localRectF.set(localRect);
   localRectF.inset(localRing.mStrokeInset, localRing.mStrokeInset);
   float f1 = 360.0F * (localRing.mStartTrim + localRing.mRotation);
   float f2 = 360.0F * (localRing.mEndTrim + localRing.mRotation) - f1;
   localRing.mPaint.setColor(localRing.mCurrentColor);
   paramCanvas.drawArc(localRectF, f1, f2, false, localRing.mPaint);
   if (localRing.mShowArrow) {
     if (localRing.mArrow != null) {
       break label427;
     }
     localRing.mArrow = new Path();
     localRing.mArrow.setFillType(Path.FillType.EVEN_ODD);
   }
   for (; ; ) {
     float f3 = (int) localRing.mStrokeInset / 2 * localRing.mArrowScale;
     float f4 = (float) (localRing.mRingCenterRadius * Math.cos(0.0D) + localRect.exactCenterX());
     float f5 = (float) (localRing.mRingCenterRadius * Math.sin(0.0D) + localRect.exactCenterY());
     localRing.mArrow.moveTo(0.0F, 0.0F);
     localRing.mArrow.lineTo(localRing.mArrowWidth * localRing.mArrowScale, 0.0F);
     localRing.mArrow.lineTo(
         localRing.mArrowWidth * localRing.mArrowScale / 2.0F,
         localRing.mArrowHeight * localRing.mArrowScale);
     localRing.mArrow.offset(f4 - f3, f5);
     localRing.mArrow.close();
     localRing.mArrowPaint.setColor(localRing.mCurrentColor);
     paramCanvas.rotate(f1 + f2 - 5.0F, localRect.exactCenterX(), localRect.exactCenterY());
     paramCanvas.drawPath(localRing.mArrow, localRing.mArrowPaint);
     if (localRing.mAlpha < 255) {
       localRing.mCirclePaint.setColor(localRing.mBackgroundColor);
       localRing.mCirclePaint.setAlpha(255 - localRing.mAlpha);
       paramCanvas.drawCircle(
           localRect.exactCenterX(),
           localRect.exactCenterY(),
           localRect.width() / 2,
           localRing.mCirclePaint);
     }
     paramCanvas.restoreToCount(i);
     return;
     label427:
     localRing.mArrow.reset();
   }
 }
  @Override
  public void draw(Canvas canvas, Paint paint) {
    float circleSpacing = 12;
    float x = getWidth() / 2;
    float y = getHeight() / 2;

    // draw fill circle
    canvas.save();
    canvas.translate(x, y);
    canvas.scale(scaleFloat1, scaleFloat1);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(0, 0, x / 2.5f, paint);

    canvas.restore();

    canvas.translate(x, y);
    canvas.scale(scaleFloat2, scaleFloat2);
    canvas.rotate(degrees);

    paint.setStrokeWidth(3);
    paint.setStyle(Paint.Style.STROKE);

    // draw two arc
    float[] startAngles = new float[] {225, 45};
    for (int i = 0; i < 2; i++) {
      RectF rectF =
          new RectF(-x + circleSpacing, -y + circleSpacing, x - circleSpacing, y - circleSpacing);
      canvas.drawArc(rectF, startAngles[i], 90, false, paint);
    }
  }
    private void drawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds) {
      if (mShowArrow) {
        if (mArrow == null) {
          mArrow = new Path();
          mArrow.setFillType(Path.FillType.EVEN_ODD);
        } else {
          mArrow.reset();
        }

        // Adjust the position of the triangle so that it is inset as
        // much as the arc, but also centered on the arc.
        float inset = (int) mStrokeInset / 2 * mArrowScale;
        float x = (float) (mRingCenterRadius * Math.cos(0) + bounds.exactCenterX());
        float y = (float) (mRingCenterRadius * Math.sin(0) + bounds.exactCenterY());

        // Update the path each time. This works around an issue in SKIA
        // where concatenating a rotation matrix to a scale matrix
        // ignored a starting negative rotation. This appears to have
        // been fixed as of API 21.
        mArrow.moveTo(0, 0);
        mArrow.lineTo(mArrowWidth * mArrowScale, 0);
        mArrow.lineTo((mArrowWidth * mArrowScale / 2), (mArrowHeight * mArrowScale));
        mArrow.offset(x - inset, y);
        mArrow.close();
        // draw a triangle
        mArrowPaint.setColor(mColors[mColorIndex]);
        c.rotate(
            startAngle + sweepAngle - ARROW_OFFSET_ANGLE,
            bounds.exactCenterX(),
            bounds.exactCenterY());
        c.drawPath(mArrow, mArrowPaint);
      }
    }
Exemple #27
0
  @Override
  public void drawChassis(Canvas canvas) {
    canvas.save();

    canvas.translate(getX(), getY());

    canvas.rotate(MathUtils.toDegrees(getHeading()) + 90);
    canvas.drawLines(outline, paint);
    canvas.drawCircle(0f, 0f, 5f, paint);

    canvas.restore();

    if (!firing) {
      float radius = POWER_CIRCLE_RADIUS * powerLevel / MAX_POWER_LEVEL;
      if (radius > 0) {
        tempPaint.set(paint);

        paint.setStyle(Style.FILL);
        paint.setColor(Color.GRAY);
        canvas.drawCircle(getX(), getY(), radius, paint);

        paint.set(tempPaint);
      }
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    // the sizes of the ViewGroup
    circleHeight = getHeight();
    circleWidth = getWidth();

    if (imageOriginal != null) {
      // Scaling the size of the background image
      if (imageScaled == null) {
        matrix = new Matrix();
        float sx = (((radius + childWidth / 4) * 2) / (float) imageOriginal.getWidth());
        float sy = (((radius + childWidth / 4) * 2) / (float) imageOriginal.getHeight());
        matrix.postScale(sx, sy);
        imageScaled =
            Bitmap.createBitmap(
                imageOriginal,
                0,
                0,
                imageOriginal.getWidth(),
                imageOriginal.getHeight(),
                matrix,
                false);
      }

      if (imageScaled != null) {
        // Move the background to the center
        int cx = (circleWidth - imageScaled.getWidth()) / 2;
        int cy = (circleHeight - imageScaled.getHeight()) / 2;

        Canvas g = canvas;
        canvas.rotate(0, circleWidth / 2, circleHeight / 2);
        g.drawBitmap(imageScaled, cx, cy, null);
      }
    }
  }
 @Override
 public void draw(Canvas canvas) {
   canvas.save();
   canvas.rotate(rotation, drawableArea.exactCenterX(), drawableArea.exactCenterY());
   canvas.drawPath(glyphPath, glyphPaint);
   canvas.restore();
 }
  @Override
  public void draw(Canvas canvas) {
    super.draw(canvas);
    int totalW = getWidth();
    int totalH = getHeight();
    // rotate canvas first
    canvas.rotate(45, totalW / 2, totalH / 2);

    totalW /= 1.2;
    totalH /= 1.4;
    mMaxLeftRectWidth = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;

    RectF leftRect = new RectF();
    if (mLeftRectGrowMode) {
      leftRect.left = 0;
      leftRect.right = leftRect.left + mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    } else {
      leftRect.right = (totalW + CONST_LEFT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
      leftRect.left = leftRect.right - mLeftRectWidth;
      leftRect.top = (totalH + CONST_RIGHT_RECT_W) / 2;
      leftRect.bottom = leftRect.top + CONST_RECT_WEIGHT;
    }

    canvas.drawRoundRect(leftRect, CONST_RADIUS, CONST_RADIUS, mPaint);

    RectF rightRect = new RectF();
    rightRect.bottom = (totalH + CONST_RIGHT_RECT_W) / 2 + CONST_RECT_WEIGHT - 1;
    rightRect.left = (totalW + CONST_LEFT_RECT_W) / 2;
    rightRect.right = rightRect.left + CONST_RECT_WEIGHT;
    rightRect.top = rightRect.bottom - mRightRectWidth;
    canvas.drawRoundRect(rightRect, CONST_RADIUS, CONST_RADIUS, mPaint);
  }