@Override
  protected void drawCallout(Canvas canvas, NMapView mapView, boolean shadow, long when) {

    adjustTextBounds(mapView);

    stepAnimations(canvas, mapView, when);

    // Draw inner info window
    canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mInnerPaint);

    // Draw border for info window
    canvas.drawRoundRect(mTempRectF, CALLOUT_ROUND_RADIUS_X, CALLOUT_ROUND_RADIUS_Y, mBorderPaint);

    // Draw bottom tag
    if (CALLOUT_TAG_WIDTH > 0 && CALLOUT_TAG_HEIGHT > 0) {
      float x = mTempRectF.centerX();
      float y = mTempRectF.bottom;

      Path path = mPath;
      path.reset();

      path.moveTo(x - CALLOUT_TAG_WIDTH, y);
      path.lineTo(x, y + CALLOUT_TAG_HEIGHT);
      path.lineTo(x + CALLOUT_TAG_WIDTH, y);
      path.close();

      canvas.drawPath(path, mInnerPaint);
      canvas.drawPath(path, mBorderPaint);
    }

    //  Draw title
    canvas.drawText(mOverlayItem.getTitle(), mOffsetX, mOffsetY, mTextPaint);
  }
  @Override
  protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawPath(path, fillPaint);
    canvas.drawPath(path, strokePaint);
  }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
   if (IsPaint) canvas.drawPath(mPath, mPaint);
   else canvas.drawPath(mPath, mEraserPaint);
 }
  @Override
  protected void onDraw(Canvas canvas) {
    int save;

    if (!mPathValid) {
      generatePath();
    }

    final float primaryLeftPoint = mHoriz.convertToPoint(mPrimaryLeft);
    final float primaryRightPoint = mHoriz.convertToPoint(mPrimaryRight);

    if (mEstimateVisible) {
      save = canvas.save();
      canvas.clipRect(0, 0, getWidth(), getHeight());
      canvas.drawPath(mPathEstimate, mPaintEstimate);
      canvas.restoreToCount(save);
    }

    save = canvas.save();
    canvas.clipRect(0, 0, primaryLeftPoint, getHeight());
    canvas.drawPath(mPathFill, mPaintFillSecondary);
    canvas.restoreToCount(save);

    save = canvas.save();
    canvas.clipRect(primaryRightPoint, 0, getWidth(), getHeight());
    canvas.drawPath(mPathFill, mPaintFillSecondary);
    canvas.restoreToCount(save);

    save = canvas.save();
    canvas.clipRect(primaryLeftPoint, 0, primaryRightPoint, getHeight());
    canvas.drawPath(mPathFill, mPaintFill);
    canvas.drawPath(mPathStroke, mPaintStroke);
    canvas.restoreToCount(save);
  }
 @Override
 public boolean onTouch(View v, MotionEvent event) {
   float x = event.getX();
   float y = event.getY();
   switch (event.getAction()) {
     case MotionEvent.ACTION_DOWN:
       path.reset();
       path.moveTo(x, y);
       x1 = x;
       y1 = y;
       break;
     case MotionEvent.ACTION_MOVE:
       path.quadTo(x1, y1, x, y);
       x1 = x;
       y1 = y;
       canvas.drawPath(path, paint);
       path.reset();
       path.moveTo(x, y);
       break;
     case MotionEvent.ACTION_UP:
       if (x == x1 && y == y1) y1 = y1 + 1;
       path.quadTo(x1, y1, x, y);
       canvas.drawPath(path, paint);
       path.reset();
       break;
   }
   ImageView iv = (ImageView) this.findViewById(R.id.imageView1);
   iv.setImageBitmap(bitmap);
   return true;
 }
  private void redo() {
    try {
      if (redoPathList.size() > 0) {
        HistoryItem item_t = redoPathList.get(redoPathList.size() - 1);
        undoPathList.add(item_t);
        redoPathList.remove(redoPathList.size() - 1);

        if (item_t.getType() == HistoryItem.TYPE_PATH) {
          mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint());
        } else if (item_t.getType() == HistoryItem.TYPE_TEXT) {
          mCacheCanvas.drawText(
              item_t.getText(),
              item_t.getTextStartPoint().x,
              item_t.getTextStartPoint().y,
              item_t.getPaint());
        } else if (item_t.getType() == HistoryItem.TYPE_ERASER) {
          item_t.getPaint().setXfermode(new PorterDuffXfermode(Mode.DST_IN));
          mCacheCanvas.drawPath(item_t.getPath(), item_t.getPaint());
        }
        handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 @Override
 public void draw(Canvas canvas) {
   /// small indent
   // canvas.translate(0, 3 * scaleCoefficient);
   canvas.drawPath(pathForTurn, paintRouteDirection);
   canvas.drawPath(pathForTurn, paintBlack);
 }
  private void drawSpring(Canvas canvas, int springDelta) {
    mPath.reset();
    mPath.moveTo(0, 0);
    mPath.lineTo(0, PULL_HEIGHT);
    mPath.quadTo(mWidth / 2, PULL_HEIGHT - springDelta, mWidth, PULL_HEIGHT);
    mPath.lineTo(mWidth, 0);
    canvas.drawPath(mPath, mBackPaint);

    int curH = PULL_HEIGHT - springDelta / 2;

    if (curH > PULL_HEIGHT - PULL_DELTA / 2) {
      int leftX = (int) (mWidth / 2 - 2 * mRadius + getSprRatio() * mRadius);
      mPath.reset();
      mPath.moveTo(leftX, curH);
      mPath.quadTo(mWidth / 2, curH - mRadius * getSprRatio() * 2, mWidth - leftX, curH);
      canvas.drawPath(mPath, mBallPaint);
    } else {
      canvas.drawArc(
          new RectF(mWidth / 2 - mRadius, curH - mRadius, mWidth / 2 + mRadius, curH + mRadius),
          180,
          180,
          true,
          mBallPaint);
    }
  }
Example #9
0
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);

    float x =
        (mDrawRect.width() - mThumbRadius * 2) * mThumbPosition + mDrawRect.left + mThumbRadius;
    if (mIsRtl) x = 2 * mDrawRect.centerX() - x;
    float y = mDrawRect.centerY();

    getTrackPath(x, y, mThumbRadius);
    mPaint.setColor(
        ColorUtil.getMiddleColor(getTrackColor(false), getTrackColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(mTrackPath, mPaint);

    if (mShadowSize > 0) {
      int saveCount = canvas.save();
      canvas.translate(x, y + mShadowOffset);
      canvas.drawPath(mShadowPath, mShadowPaint);
      canvas.restoreToCount(saveCount);
    }

    mPaint.setColor(
        ColorUtil.getMiddleColor(getThumbColor(false), getThumbColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(x, y, mThumbRadius, mPaint);
  }
Example #10
0
  private void drawPointerArrow(Canvas canvas) {

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    double tipAngle = (colorHSV[2] - 0.5f) * Math.PI;
    double leftAngle = tipAngle + Math.PI / 96;
    double rightAngle = tipAngle - Math.PI / 96;

    double tipAngleX = Math.cos(tipAngle) * outerWheelRadius;
    double tipAngleY = Math.sin(tipAngle) * outerWheelRadius;
    double leftAngleX = Math.cos(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double leftAngleY = Math.sin(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleX = Math.cos(rightAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleY = Math.sin(rightAngle) * (outerWheelRadius + arrowPointerSize);

    arrowPointerPath.reset();
    arrowPointerPath.moveTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);
    arrowPointerPath.lineTo((float) leftAngleX + centerX, (float) leftAngleY + centerY);
    arrowPointerPath.lineTo((float) rightAngleX + centerX, (float) rightAngleY + centerY);
    arrowPointerPath.lineTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);

    valuePointerArrowPaint.setColor(Color.HSVToColor(colorHSV));
    valuePointerArrowPaint.setStyle(Style.FILL);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);

    valuePointerArrowPaint.setStyle(Style.STROKE);
    valuePointerArrowPaint.setStrokeJoin(Join.ROUND);
    valuePointerArrowPaint.setColor(Color.BLACK);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);
  }
 @Override
 public void draw(Canvas canvas) {
   float w = 72 * scaleCoefficient / miniCoeff;
   // to change color immediately when needed
   if (lanes != null && lanes.length > 0) {
     canvas.save();
     // canvas.translate((int) (16 * scaleCoefficient), 0);
     for (int i = 0; i < lanes.length; i++) {
       int turnType;
       if ((lanes[i] & 1) == 1) {
         paintRouteDirection.setColor(
             imminent
                 ? ctx.getResources().getColor(R.color.nav_arrow_imminent)
                 : ctx.getResources().getColor(R.color.nav_arrow));
         turnType = TurnType.getPrimaryTurn(lanes[i]);
       } else {
         paintRouteDirection.setColor(ctx.getResources().getColor(R.color.nav_arrow_distant));
         turnType = TurnType.getPrimaryTurn(lanes[i]);
       }
       Path p = getPathFromTurnType(paths, turnType, laneStraight, scaleCoefficient / miniCoeff);
       canvas.drawPath(p, paintBlack);
       canvas.drawPath(p, paintRouteDirection);
       canvas.translate(w, 0);
     }
     canvas.restore();
   }
 }
Example #12
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.translate(this.getWidth() / 2, this.getHeight() / 2);

    canvas.drawPath(mCirclePath, mCirclePaint);
    canvas.drawPath(mCircleProgressPath, mCircleProgressGlowPaint);
    canvas.drawPath(mCircleProgressPath, mCircleProgressPaint);

    canvas.drawPath(mCirclePath, mCircleFillPaint);

    canvas.drawCircle(
        mPointerPositionXY[0],
        mPointerPositionXY[1],
        mPointerRadius + mPointerHaloWidth,
        mPointerHaloPaint);
    canvas.drawCircle(mPointerPositionXY[0], mPointerPositionXY[1], mPointerRadius, mPointerPaint);
    if (mUserIsMovingPointer) {
      canvas.drawCircle(
          mPointerPositionXY[0],
          mPointerPositionXY[1],
          mPointerRadius + mPointerHaloWidth + (mPointerHaloBorderWidth / 2f),
          mPointerHaloBorderPaint);
    }
  }
Example #13
0
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawPath(bPath, bPaint);
   fPath.reset();
   fPath.addCircle(radius + offset * position, radius, radius, Path.Direction.CCW);
   canvas.drawPath(fPath, fPaint);
 }
Example #14
0
  private void drawPolygon(
      BinaryMapDataObject obj,
      RenderingRuleSearchRequest render,
      Canvas canvas,
      RenderingContext rc,
      TagValuePair pair) {
    if (render == null || pair == null) {
      return;
    }
    float xText = 0;
    float yText = 0;
    int zoom = rc.zoom;
    Path path = null;

    // rc.main.color = Color.rgb(245, 245, 245);
    render.setInitialTagValueZoom(pair.tag, pair.value, zoom, obj);
    boolean rendered = render.search(RenderingRulesStorage.POLYGON_RULES);
    if (!rendered || !updatePaint(render, paint, 0, true, rc)) {
      return;
    }
    rc.visible++;
    int len = obj.getPointsLength();
    for (int i = 0; i < obj.getPointsLength(); i++) {

      PointF p = calcPoint(obj, i, rc);
      xText += p.x;
      yText += p.y;
      if (path == null) {
        path = new Path();
        path.moveTo(p.x, p.y);
      } else {
        path.lineTo(p.x, p.y);
      }
    }
    int[][] polygonInnerCoordinates = obj.getPolygonInnerCoordinates();
    if (polygonInnerCoordinates != null && path != null) {
      path.setFillType(FillType.EVEN_ODD);
      for (int j = 0; j < polygonInnerCoordinates.length; j++) {
        for (int i = 0; i < polygonInnerCoordinates[j].length; i += 2) {
          PointF p =
              calcPoint(polygonInnerCoordinates[j][i], polygonInnerCoordinates[j][i + 1], rc);
          if (i == 0) {
            path.moveTo(p.x, p.y);
          } else {
            path.lineTo(p.x, p.y);
          }
        }
      }
    }

    if (path != null && len > 0) {
      canvas.drawPath(path, paint);
      if (updatePaint(render, paint, 1, false, rc)) {
        canvas.drawPath(path, paint);
      }
      textRenderer.renderText(obj, render, rc, pair, xText / len, yText / len, null, null);
    }
  }
Example #15
0
  private void drawDebugIndicator(Canvas canvas) {
    DEBUG_PAINT.setColor(WHITE);
    Path path = getTrianglePath(new Point(0, 0), (int) (16 * density));
    canvas.drawPath(path, DEBUG_PAINT);

    DEBUG_PAINT.setColor(loadedFrom.debugColor);
    path = getTrianglePath(new Point(0, 0), (int) (15 * density));
    canvas.drawPath(path, DEBUG_PAINT);
  }
Example #16
0
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Translate the canvas to account for the view padding
    canvas.translate(mCanvasXPadding, mCanvasYPadding);

    // Outside box
    mCacheRectF.set(0, 0, mWidth, mHeight);
    canvas.drawRect(mCacheRectF, mStrokeColor);

    final float centerY = mHeight / 2;
    final float ticMargin = mHeight / mScrollToRange;
    final int start = (int) (mScrollTo - mScrollToRange / 2);
    final int end = (int) (mScrollTo + mScrollToRange / 2);
    final float ticStart = mHandedness == Handedness.LEFT ? mWidth : 0;
    final float ticEnd =
        mHandedness == Handedness.LEFT ? ticStart - mTicWidth : ticStart + mTicWidth;
    final float textStart =
        mHandedness == Handedness.LEFT ? mWidth - mTextHorizontalMargin : mTextHorizontalMargin;
    final float textOffset = mStrokeColor.getTextSize() / 2 + mTextVerticalMargin;

    for (int a = start; a <= end; a++) {
      if (a % 5 == 0) {
        float lineHeight = centerY - ticMargin * (a - mScrollTo);
        canvas.drawLine(ticStart, lineHeight, ticEnd, lineHeight, mStrokeColor);
        canvas.drawText(String.valueOf(a), textStart, lineHeight + textOffset, mStrokeColor);
      }
    }

    // Arrow with current speed
    final int borderWidth = Math.round(mArrowStrokeColor.getStrokeWidth());
    final float arrowStickX, arrowBaseX, arrowPointX;
    if (mHandedness == Handedness.LEFT) {
      arrowStickX = -borderWidth;
      arrowBaseX = mWidth - mArrowHeight / 4 - borderWidth;
      arrowPointX = mWidth - borderWidth;
    } else {
      arrowStickX = mWidth + borderWidth;
      arrowBaseX = mArrowHeight / 4 + borderWidth;
      arrowPointX = borderWidth;
    }

    final float arrowStartY = centerY - mArrowHeight / 2;
    final float arrowEndY = centerY + mArrowHeight / 2;

    mCachePath.reset();
    Path arrow = mCachePath;
    arrow.moveTo(arrowStickX, arrowStartY);
    arrow.lineTo(arrowBaseX, arrowStartY);
    arrow.lineTo(arrowPointX, centerY);
    arrow.lineTo(arrowBaseX, arrowEndY);
    arrow.lineTo(arrowStickX, arrowEndY);
    canvas.drawPath(arrow, mArrowBgColor);
    canvas.drawPath(arrow, mArrowStrokeColor);
    canvas.drawText(String.valueOf((int) mScrollTo), textStart, centerY + textOffset, mStrokeColor);
  }
 @Override
 public void draw(Canvas canvas) {
   paint.setColor(ColorUtils.getColor("#BDBDBD"));
   canvas.drawPath(path1, paint);
   paint.setColor(Color.WHITE);
   canvas.drawPath(path2, paint);
   paint.setColor(ColorUtils.getColor("#7EC0EE"));
   canvas.drawPath(path3, paint);
 }
Example #18
0
 @Override
 public void draw(Canvas canvas) {
   Rect bounds = getBounds();
   paint.setColor(COLOR_LIGHT);
   int width = bounds.width() - STROKE_WIDTH;
   int height = bounds.height() - STROKE_WIDTH;
   canvas.drawPath(createLightPath(width, height), paint);
   paint.setColor(COLOR_DARK);
   canvas.drawPath(createDarkPath(width, height), paint);
 }
Example #19
0
  // Creates icons for markers
  public Bitmap create_marker_icon(String AcColorX, String MarkerName, float GraphicsScaleFactor) {

    int w = (int) (34 * GraphicsScaleFactor); // 24
    int h = (int) (54 * GraphicsScaleFactor);
    Bitmap.Config conf = Bitmap.Config.ARGB_4444; // see other conf types
    Bitmap bmp =
        Bitmap.createBitmap(
            w, h, conf); // this creates a MUTABLE bitmapAircraftData[IndexOfAc].AC_Color
    Canvas canvas = new Canvas(bmp);

    Paint p = new Paint();
    p.setColor(get_color(AcColorX));
    p.setStyle(Paint.Style.FILL);
    p.setAntiAlias(true);

    Path MarkerPath = new Path();
    MarkerPath.moveTo((w / 2), (6 * h / 16)); // point 1
    MarkerPath.lineTo((7 * w / 16), (5 * h / 16)); // point 2
    MarkerPath.lineTo((2 * w / 8), (5 * h / 16)); // point 3
    MarkerPath.lineTo((2 * w / 8), (2)); // point 4  (2*h/8)
    MarkerPath.lineTo((6 * w / 8), (2)); // point 5
    MarkerPath.lineTo((6 * w / 8), (5 * h / 16)); // point 6
    MarkerPath.lineTo((9 * w / 16), (5 * h / 16)); // point 7

    MarkerPath.close();

    // border
    canvas.drawPath(MarkerPath, p);
    Paint black = new Paint();
    black.setColor(Color.BLACK);
    black.setStyle(Paint.Style.STROKE);
    black.setStrokeWidth(2f);
    black.setAntiAlias(true);
    canvas.drawPath(MarkerPath, black);

    // Text

    black.setTextAlign(Paint.Align.CENTER);
    black.setStrokeWidth(3f * GraphicsScaleFactor);
    black.setTextSize(8f * GraphicsScaleFactor);

    // for DEBUG
    // canvas.drawRect(0,0,w,h,black);

    p.setStyle(Paint.Style.STROKE);
    p.setTextAlign(Paint.Align.CENTER);
    p.setTextSize(8f * GraphicsScaleFactor);
    p.setStrokeWidth(1f * GraphicsScaleFactor);

    canvas.drawText(MarkerName, (w / 2), (7 * h / 32), black);
    canvas.drawText(MarkerName, (w / 2), (7 * h / 32), p);

    return bmp;
  }
Example #20
0
  private void eraseArea(byte[] packetData) {
    try {
      int penWidthNum = myConvertByteArrToInt_bigend(packetData, 4);
      int penColorNum = myConvertByteArrToInt_bigend(packetData, 8);
      int eraserWidth = myConvertByteArrToInt_bigend(packetData, 12);
      int eraserHeight = myConvertByteArrToInt_bigend(packetData, 16);
      int nums = myConvertByteArrToInt_bigend(packetData, 20);

      int BYTES_PER_COORDINATE = 2;
      for (int i = 0; i < nums / 4; i++) {
        int x =
            xCoordinateMap(
                myConvertByteArrToShort_bigend(packetData, 24 + i * 2 * BYTES_PER_COORDINATE));
        int y =
            yCoordinateMap(
                myConvertByteArrToShort_bigend(
                    packetData, 24 + i * 2 * BYTES_PER_COORDINATE + BYTES_PER_COORDINATE));
        int x1, y1, x2, y2;
        x1 = x - (eraserWidth / 2 + penWidthNum);
        y1 = y - (eraserHeight / 2 + penWidthNum);
        x2 = x + (eraserWidth / 2 + penWidthNum);
        y2 = y + (eraserHeight / 2 + penWidthNum);
        if (i == 0) {
          mPath = new Path();
          mPath.addRect(x1, y1, x2, y2, Direction.CW);

          mPaint = getAPaint();
          mPaint.setStrokeWidth(penWidthMap.get(penWidthNum));
          mPaint.setColor(penColorMap.get(penColorNum));
          mPaint.setStyle(Style.FILL_AND_STROKE);
          mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));

          HistoryItem item = new HistoryItem(HistoryItem.TYPE_PATH, mPaint, mPath, null, null);
          undoPathList.add(item); //

          mCacheCanvas.drawPath(mPath, mPaint);
        } else {
          mPath.addRect(x1, y1, x2, y2, Direction.CW);
          mPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
          mCacheCanvas.drawPath(mPath, mPaint);
        }
        handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE);

        if (!((ClassWorkActivity) mContext).isScreenLocked()) {
          break;
        }
      } // end of for

    } catch (Exception e) {
      e.printStackTrace();
      Logg.e(TAG, "erase error");
    }
  }
 @Override
 public void onDraw(Canvas canvas) {
   mPaint.setShader(mShader);
   mPaint.setStyle(Paint.Style.FILL);
   int sc = canvas.save();
   canvas.drawPath(mPath, mPaint);
   mPaint.setShader(null);
   mPaint.setStyle(Paint.Style.STROKE);
   canvas.drawPath(mPath, mPaint);
   canvas.restoreToCount(sc);
   canvas.clipPath(mPath);
 }
  private void drawArrow(Canvas c) {
    int height = getHeight();
    int width = getWidth();

    // Create a buffer around the arrow so when it rotates it doesn't get clipped by view edge
    final float BUFFER = width / 5;

    // Height of the cutout in the bottom of the triangle that makes it an arrow (0=triangle)
    final float CUTOUT_HEIGHT = getHeight() / 5;

    float x1, y1; // Tip of arrow
    x1 = width / 2;
    y1 = BUFFER;

    float x2, y2; // lower left
    x2 = BUFFER;
    y2 = height - BUFFER;

    float x3, y3; // cutout in arrow bottom
    x3 = width / 2;
    y3 = height - CUTOUT_HEIGHT - BUFFER;

    float x4, y4; // lower right
    x4 = width - BUFFER;
    y4 = height - BUFFER;

    Path path = new Path();
    path.setFillType(Path.FillType.EVEN_ODD);
    path.moveTo(x1, y1);
    path.lineTo(x2, y2);
    path.lineTo(x3, y3);
    path.lineTo(x4, y4);
    path.lineTo(x1, y1);
    path.close();

    float direction = mHeading - mBearingToStop;
    // Make sure value is between 0-360
    direction = MathUtils.mod(direction, 360.0f);

    // Rotate arrow around center point
    Matrix matrix = new Matrix();
    matrix.postRotate((float) -direction, width / 2, height / 2);
    path.transform(matrix);

    c.drawPath(path, mArrowPaint);
    c.drawPath(path, mArrowFillPaint);

    // Update content description, so screen readers can announce direction to stop
    String[] spokenDirections = getResources().getStringArray(R.array.spoken_compass_directions);
    String directionName = spokenDirections[MathUtils.getHalfWindIndex(direction)];
    setContentDescription(directionName);
  }
  private void createCompassRosePicture() {
    // Paint design of north triangle (it's common to paint north in red color)
    final Paint northPaint = new Paint();
    northPaint.setColor(0xFFA00000);
    northPaint.setAntiAlias(true);
    northPaint.setStyle(Style.FILL);
    northPaint.setAlpha(220);

    // Paint design of south triangle (black)
    final Paint southPaint = new Paint();
    southPaint.setColor(Color.BLACK);
    southPaint.setAntiAlias(true);
    southPaint.setStyle(Style.FILL);
    southPaint.setAlpha(220);

    // Create a little white dot in the middle of the compass rose
    final Paint centerPaint = new Paint();
    centerPaint.setColor(Color.WHITE);
    centerPaint.setAntiAlias(true);
    centerPaint.setStyle(Style.FILL);
    centerPaint.setAlpha(220);

    // final int picBorderWidthAndHeight = (int) ((mCompassRadius + 5) * 2 * mScale);
    final int picBorderWidthAndHeight = (int) ((mCompassRadius + 5) * 2);
    final int center = picBorderWidthAndHeight / 2;

    final Canvas canvas =
        mCompassRose.beginRecording(picBorderWidthAndHeight, picBorderWidthAndHeight);

    // Blue triangle pointing north
    final Path pathNorth = new Path();
    pathNorth.moveTo(center, center - (mCompassRadius - 3) * mScale);
    pathNorth.lineTo(center + 4 * mScale, center);
    pathNorth.lineTo(center - 4 * mScale, center);
    pathNorth.lineTo(center, center - (mCompassRadius - 3) * mScale);
    pathNorth.close();
    canvas.drawPath(pathNorth, northPaint);

    // Red triangle pointing south
    final Path pathSouth = new Path();
    pathSouth.moveTo(center, center + (mCompassRadius - 3) * mScale);
    pathSouth.lineTo(center + 4 * mScale, center);
    pathSouth.lineTo(center - 4 * mScale, center);
    pathSouth.lineTo(center, center + (mCompassRadius - 3) * mScale);
    pathSouth.close();
    canvas.drawPath(pathSouth, southPaint);

    // Draw a little white dot in the middle
    canvas.drawCircle(center, center, 2, centerPaint);

    mCompassRose.endRecording();
  }
  private void drawChecked(Canvas canvas) {
    float size = mBoxSize - mStrokeSize * 2;
    float x = mBoxRect.left + mStrokeSize;
    float y = mBoxRect.top + mStrokeSize;

    if (isRunning()) {
      if (mAnimProgress < FILL_TIME) {
        float progress = mAnimProgress / FILL_TIME;
        float fillWidth = (mBoxSize - mStrokeSize) / 2f * progress;
        float padding = mStrokeSize / 2f + fillWidth / 2f - 0.5f;

        mPaint.setColor(ColorUtil.getMiddleColor(mPrevColor, mCurColor, progress));
        mPaint.setStrokeWidth(fillWidth);
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawRect(
            mBoxRect.left + padding,
            mBoxRect.top + padding,
            mBoxRect.right - padding,
            mBoxRect.bottom - padding,
            mPaint);

        mPaint.setStrokeWidth(mStrokeSize);
        canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);
      } else {
        float progress = (mAnimProgress - FILL_TIME) / (1f - FILL_TIME);

        mPaint.setColor(mCurColor);
        mPaint.setStrokeWidth(mStrokeSize);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);

        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.MITER);
        mPaint.setStrokeCap(Paint.Cap.BUTT);
        mPaint.setColor(mTickColor);

        canvas.drawPath(getTickPath(mTickPath, x, y, size, progress, true), mPaint);
      }
    } else {
      mPaint.setColor(mCurColor);
      mPaint.setStrokeWidth(mStrokeSize);
      mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
      canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);

      mPaint.setStyle(Paint.Style.STROKE);
      mPaint.setStrokeJoin(Paint.Join.MITER);
      mPaint.setStrokeCap(Paint.Cap.BUTT);
      mPaint.setColor(mTickColor);

      canvas.drawPath(getTickPath(mTickPath, x, y, size, 1f, true), mPaint);
    }
  }
 @Override
 protected void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawColor(0xFFFFFFFF);
   if (paths != null) {
     for (DrawingPath drawingPath : paths) {
       canvas.drawPath(drawingPath.path, drawingPath.paint);
     }
     if (currentDrawingPath != null) {
       canvas.drawPath(currentDrawingPath.path, currentDrawingPath.paint);
     }
   }
 }
  private void drawBrightnessIndicator(Canvas canvas) {
    // get a representation of the height of the indicator within the bar
    float brightnessHeight = mNewColor[2] * mWheel.getHeight();
    // Log.d(TAG, String.format("Brightness height: %f", brightnessHeight));
    // convert the height to an absolute y position based on the bar's position
    float absoluteY = mWheelPosition.y + mWheel.getHeight() - brightnessHeight;
    // get the y value "above" the x axis for the x coordinate calculation
    // note: because of symmetry, the sign doesn't matter so we'll use the positive
    float heightAboveXAxis = Math.abs(brightnessHeight - (float) mRadius);
    // Log.d(TAG, String.format("Height above X: %f", heightAboveXAxis));
    float leftEdgeRadius = (float) (mRadius + SPACE_BETWEEN_WHEEL_AND_BAR);
    float rightEdgeRadius = leftEdgeRadius + ARC_WIDTH;
    // get the x coordinate relative to the center of the wheel
    float leftXInCircle =
        (float) Math.sqrt(leftEdgeRadius * leftEdgeRadius - heightAboveXAxis * heightAboveXAxis);
    float rightXInCircle =
        (float) Math.sqrt(rightEdgeRadius * rightEdgeRadius - heightAboveXAxis * heightAboveXAxis);
    // get the absolute x and y coordinates of the left edge of the bar at the bar height
    float leftX = mWheelCenter.x + leftXInCircle;
    float rightX = mWheelCenter.x + rightXInCircle;

    float indicatorHeight = BRIGHTNESS_INDICATOR_SIZE / 2.0f;
    float indicatorWidth = BRIGHTNESS_INDICATOR_SIZE;

    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setStrokeWidth(1.0f);

    Path leftTrianglePath = new Path();
    leftTrianglePath.moveTo(leftX, absoluteY - indicatorHeight);
    leftTrianglePath.lineTo(leftX + indicatorWidth, absoluteY);
    leftTrianglePath.lineTo(leftX, absoluteY + indicatorHeight);
    leftTrianglePath.close();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawPath(leftTrianglePath, paint);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(leftTrianglePath, paint);

    Path rightTrianglePath = new Path();
    rightTrianglePath.moveTo(rightX, absoluteY - indicatorHeight);
    rightTrianglePath.lineTo(rightX - indicatorWidth, absoluteY);
    rightTrianglePath.lineTo(rightX, absoluteY + indicatorHeight);
    rightTrianglePath.close();
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.FILL);
    canvas.drawPath(rightTrianglePath, paint);
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    canvas.drawPath(rightTrianglePath, paint);
  }
Example #27
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (null == mBitmap) {
      return;
    }
    canvas.drawColor(Color.TRANSPARENT);
    canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

    if (mbEraser) {
      mCanvas.drawPath(mPath, mpaintEraser);
    } else {
      canvas.drawPath(mPath, mPaint);
    }
  }
 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);
 }
  @Override
  public void draw(Canvas canvas) {
    String file = getEnvObject().getCurrentRepresentation().getIcon();
    Path objectPath =
        DrawingUtils.freedomPolygonToPath(
            (FreedomPolygon) getEnvObject().getCurrentRepresentation().getShape());
    RectF box = new RectF();
    objectPath.computeBounds(box, true);
    System.out.print("GPT box: box widht:" + box.width() + " box heigh" + box.height());
    drawingMatrix = new Matrix();
    float rotation = (float) getEnvObject().getCurrentRepresentation().getRotation();
    drawingMatrix.postRotate(rotation);
    drawingMatrix.postTranslate(
        getEnvObject().getCurrentRepresentation().getOffset().getX(),
        getEnvObject().getCurrentRepresentation().getOffset().getY());
    Bitmap bmp = null;
    if (file != null) { // TODO: Asign the bmp in the setEnvObject
      bmp = BitmapUtils.getImage(file, (int) box.width(), (int) box.height());
    }
    if (bmp != null) {
      ghostBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(), Config.ARGB_8888);
      canvas.drawBitmap(bmp, drawingMatrix, null);

    } else {
      // TODO: Cache path
      Paint paint = new Paint();
      paint.setStyle(Style.FILL);

      ghostPath = new Path();
      objectPath.transform(drawingMatrix, ghostPath);
      int fillColor = -1;
      try {
        fillColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getFillColor());
        paint.setColor(fillColor);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in fill");
      }
      int borderColor = -1;
      try {
        borderColor = Color.parseColor(getEnvObject().getCurrentRepresentation().getBorderColor());
        paint.setColor(borderColor);
        paint.setStyle(Style.STROKE);
        canvas.drawPath(ghostPath, paint);
      } catch (IllegalArgumentException ex) {
        System.out.println("ParseColor exception in border");
      }
    }
  }
Example #30
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);
 }