Exemplo n.º 1
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    final float radius =
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP,
            CORNER_RADIUS,
            mContext.getResources().getDisplayMetrics());

    RectF rectF =
        new RectF(
            Edge.LEFT.getCoordinate(),
            Edge.TOP.getCoordinate(),
            Edge.RIGHT.getCoordinate(),
            Edge.BOTTOM.getCoordinate());
    float cx = (Edge.LEFT.getCoordinate() + Edge.RIGHT.getCoordinate()) / 2;
    float cy = (Edge.TOP.getCoordinate() + Edge.BOTTOM.getCoordinate()) / 2;
    float radius2 = (Edge.RIGHT.getCoordinate() - Edge.LEFT.getCoordinate()) / 2;

    Path clipPath = new Path();
    clipPath.addCircle(cx, cy, radius2, Path.Direction.CW);
    canvas.clipPath(clipPath, Region.Op.DIFFERENCE);
    canvas.drawARGB(204, 41, 48, 63);
    canvas.restore();
    canvas.drawCircle(cx, cy, radius2, mBorderPaint);
    // drawRuleOfThirdsGuidelines(canvas);
  }
Exemplo n.º 2
0
 public Rect getImageBounds() {
   return new Rect(
       (int) Edge.LEFT.getCoordinate(),
       (int) Edge.TOP.getCoordinate(),
       (int) Edge.RIGHT.getCoordinate(),
       (int) Edge.BOTTOM.getCoordinate());
 }
Exemplo n.º 3
0
 // Private Methods /////////////////////////////////////////////////////////
 private void init(Context context) {
   int w = context.getResources().getDisplayMetrics().widthPixels;
   cropWidth = w - 2 * mMarginSide;
   cropHeight = cropWidth;
   int edgeT = mMarginTop;
   int edgeB = mMarginTop + cropHeight;
   int edgeL = mMarginSide;
   int edgeR = mMarginSide + cropWidth;
   mBackgroundPaint = PaintUtil.newBackgroundPaint(context);
   mBorderPaint = PaintUtil.newBorderPaint(context);
   mGuidelinePaint = PaintUtil.newGuidelinePaint();
   Edge.TOP.setCoordinate(edgeT);
   Edge.BOTTOM.setCoordinate(edgeB);
   Edge.LEFT.setCoordinate(edgeL);
   Edge.RIGHT.setCoordinate(edgeR);
   new Rect(edgeL, edgeT, edgeR, edgeB);
   mBitmapRect = new Rect(0, 0, w, w);
 }
Exemplo n.º 4
0
  private void drawRuleOfThirdsGuidelines(Canvas canvas) {

    final float left = Edge.LEFT.getCoordinate();
    final float top = Edge.TOP.getCoordinate();
    final float right = Edge.RIGHT.getCoordinate();
    final float bottom = Edge.BOTTOM.getCoordinate();

    // Draw vertical guidelines.
    final float oneThirdCropWidth = Edge.getWidth() / 3;

    final float x1 = left + oneThirdCropWidth;
    canvas.drawLine(x1, top, x1, bottom, mGuidelinePaint);
    final float x2 = right - oneThirdCropWidth;
    canvas.drawLine(x2, top, x2, bottom, mGuidelinePaint);

    // Draw horizontal guidelines.
    final float oneThirdCropHeight = Edge.getHeight() / 3;

    final float y1 = top + oneThirdCropHeight;
    canvas.drawLine(left, y1, right, y1, mGuidelinePaint);
    final float y2 = bottom - oneThirdCropHeight;
    canvas.drawLine(left, y2, right, y2, mGuidelinePaint);
  }