android.graphics.Region Java Examples

The following examples show how to use android.graphics.Region. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimulationPageAnim.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) {
    mPath0.reset();
    mPath0.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
            mBezierEnd1.y);
    mPath0.lineTo(mTouchX, mTouchY);
    mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
            mBezierStart2.y);
    mPath0.lineTo(mCornerX, mCornerY);
    mPath0.close();

    canvas.save();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        canvas.clipOutPath(path);
    } else {
        canvas.clipPath(path, Region.Op.XOR);
    }
    canvas.drawBitmap(bitmap, 0, 0, null);
    try {
        canvas.restore();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: AndroidGraphics.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void setClip(int x, int y, int width, int height) {
    //System.out.println("Setting clip  "+x+","+y+","+width+", "+height);
    if (clipSet) {
        canvas.restore();
    }
    canvas.save();
    clipSet = true;
    clipFresh = false;
    if (getTransform().isIdentity() || transformSemaphore > 0) {
        canvas.clipRect(x, y, x + width, y + height, Region.Op.INTERSECT);
    } else {
        this.tmppath.rewind();
        this.tmppath.addRect((float) x, (float) y, (float) width + x, (float) height + y, Path.Direction.CW);
        this.tmppath.transform(getTransformMatrix());
        canvas.clipPath(this.tmppath, Region.Op.INTERSECT);
    }
}
 
Example #3
Source File: ColorFocusBorder.java    From AndroidTvDemo with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制外发光阴影
 * 
 * @param canvas
 */
private void onDrawShadow(Canvas canvas)
{
    if (mShadowWidth > 0)
    {
        canvas.save();
        // 裁剪处理(使阴影矩形框内变为透明)
        if (mRoundRadius > 0)
        {
            canvas.clipRect(0, 0, getWidth(), getHeight());
            mTempRectF.set(mFrameRectF);
            mTempRectF.inset(mRoundRadius / 2f, mRoundRadius / 2f);
            canvas.clipRect(mTempRectF, Region.Op.DIFFERENCE);
        }
        // 绘制外发光阴影效果
        canvas.drawRoundRect(mFrameRectF, mRoundRadius, mRoundRadius, mShadowPaint);
        canvas.restore();
    }
}
 
Example #4
Source File: ViewHighlightOverlays.java    From stetho with MIT License 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
  // We don't have access to the OverlayViewGroup instance directly, but we can manipulate
  // its Canvas via the Drawables' draw(). This allows us to draw outside the View bounds,
  // so we can position the margin overlays correctly.
  Rect newRect = canvas.getClipBounds();
  // Make the Canvas Rect bigger according to the View margins.
  newRect.inset(-(mMargins.right + mMargins.left), -(mMargins.top + mMargins.bottom));

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
    canvas.clipRect(newRect, Region.Op.REPLACE);
  } else {
    canvas.clipOutRect(newRect);
  }
  super.draw(canvas);
}
 
Example #5
Source File: DragLayer.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void dispatchDraw(Canvas canvas) {
    // Draw the background below children.
    if (mBackgroundAlpha > 0.0f) {
        // Update the scroll position first to ensure scrim cutout is in the right place.
        mLauncher.getWorkspace().computeScrollWithoutInvalidation();

        int alpha = (int) (mBackgroundAlpha * 255);
        CellLayout currCellLayout = mLauncher.getWorkspace().getCurrentDragOverlappingLayout();
        canvas.save();
        if (currCellLayout != null && currCellLayout != mLauncher.getHotseat().getLayout()) {
            // Cut a hole in the darkening scrim on the page that should be highlighted, if any.
            getDescendantRectRelativeToSelf(currCellLayout, mHighlightRect);
            canvas.clipRect(mHighlightRect, Region.Op.DIFFERENCE);
        }
        canvas.drawColor((alpha << 24) | SCRIM_COLOR);
        canvas.restore();
    }

    mFocusIndicatorHelper.draw(canvas);
    super.dispatchDraw(canvas);
}
 
Example #6
Source File: WaveSideBarView.java    From GetApk with MIT License 6 votes vote down vote up
private void drawBallPath(Canvas canvas) {
    //x轴的移动路径
    mBallCentreX = (mWidth + mBallRadius) - (2.0f * mRadius + 2.0f * mBallRadius) * mRatio;

    mBallPath.reset();
    mBallPath.addCircle(mBallCentreX, mCenterY, mBallRadius, Path.Direction.CW);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mBallPath.op(mWavePath, Path.Op.DIFFERENCE);
    } else {
        canvas.clipPath(mWavePath, Region.Op.DIFFERENCE);
    }

    mBallPath.close();
    canvas.drawPath(mBallPath, mWavePaint);

}
 
Example #7
Source File: CropImageView.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Draw background with transparent circular hole
    final float radius = Math.min((float) canvas.getWidth(), canvas.getHeight()) / 2 - cropCirclePadding;
    mRectF.set((float) canvas.getWidth() / 2 - radius, (float) canvas.getHeight() / 2 - radius, (float) canvas.getWidth() / 2 + radius, (float) canvas.getHeight() / 2 + radius);
    circleSelectionPath.reset();
    circleSelectionPath.addOval(mRectF, Path.Direction.CW);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        canvas.clipOutPath(circleSelectionPath);
    } else {
        canvas.clipPath(circleSelectionPath, Region.Op.XOR);
    }

    canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), backgroundPaint);
    // Canvas did not save and called restore due to which app crashes, so we have to save first then call restore
    canvas.save();
    canvas.restore();

    // Draw circle border
    canvas.drawCircle((float) canvas.getWidth() / 2, (float) canvas.getHeight() / 2, radius, borderPaint);
}
 
Example #8
Source File: PageView.java    From android-open-source-project-analysis with Apache License 2.0 6 votes vote down vote up
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) {
    mPath0.reset();
    mPath0.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
            mBezierEnd1.y);
    mPath0.lineTo(mTouch.x, mTouch.y);
    mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
            mBezierStart2.y);
    mPath0.lineTo(mCornerX, mCornerY);
    mPath0.close();

    canvas.save();
    canvas.clipPath(path, Region.Op.XOR);
    canvas.drawBitmap(bitmap, 0, 0, null);
    try {
        canvas.restore();
    } catch (Exception e) {

    }

}
 
Example #9
Source File: CropOverlayView.java    From IDCardCamera with Apache License 2.0 6 votes vote down vote up
private void drawBackground(Canvas canvas) {
    Paint paint = new Paint();
    paint.setColor(Color.parseColor("#66000000"));
    paint.setStyle(Paint.Style.FILL);

    Path path = new Path();
    path.moveTo(topLeft.x, topLeft.y);
    path.lineTo(topRight.x, topRight.y);
    path.lineTo(bottomRight.x, bottomRight.y);
    path.lineTo(bottomLeft.x, bottomLeft.y);
    path.close();

    canvas.save();
    canvas.clipPath(path, Region.Op.DIFFERENCE);
    canvas.drawColor(Color.parseColor("#66000000"));
    canvas.restore();
}
 
Example #10
Source File: OverlayView.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * This method draws dimmed area around the crop bounds.
 *
 * @param canvas - valid canvas object
 */
protected void drawDimmedLayer(@NonNull Canvas canvas) {
    canvas.save();
    if (mCircleDimmedLayer) {
        canvas.clipPath(mCircularPath, Region.Op.DIFFERENCE);
    } else {
        canvas.clipRect(mCropViewRect, Region.Op.DIFFERENCE);
    }
    canvas.drawColor(mDimmedColor);
    canvas.restore();

    if (mCircleDimmedLayer) { // Draw 1px stroke to fix antialias
        canvas.drawCircle(mCropViewRect.centerX(), mCropViewRect.centerY(),
                Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, mDimmedStrokePaint);
    }
}
 
Example #11
Source File: BookPageView.java    From BookPage with MIT License 6 votes vote down vote up
/**
     * 绘制C区域内容
     * @param canvas
     * @param pathA
     */
    private void drawPathCContent(Canvas canvas, Path pathA){
        canvas.save();
        canvas.clipPath(pathA);
        canvas.clipPath(getPathC(), Region.Op.REVERSE_DIFFERENCE);//裁剪出C区域不同于A区域的部分
//        canvas.drawPath(getPathC(),pathCPaint);

        float eh = (float) Math.hypot(f.x - e.x,h.y - f.y);
        float sin0 = (f.x - e.x) / eh;
        float cos0 = (h.y - f.y) / eh;
        //设置翻转和旋转矩阵
        mMatrixArray[0] = -(1-2 * sin0 * sin0);
        mMatrixArray[1] = 2 * sin0 * cos0;
        mMatrixArray[3] = 2 * sin0 * cos0;
        mMatrixArray[4] = 1 - 2 * sin0 * sin0;

        mMatrix.reset();
        mMatrix.setValues(mMatrixArray);//翻转和旋转
        mMatrix.preTranslate(-e.x, -e.y);//沿当前XY轴负方向位移得到 矩形A₃B₃C₃D₃
        mMatrix.postTranslate(e.x, e.y);//沿原XY轴方向位移得到 矩形A4 B4 C4 D4
        canvas.drawBitmap(pathCContentBitmap, mMatrix, null);

        drawPathCShadow(canvas);
        canvas.restore();
    }
 
Example #12
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void findAccessibilityNodeInfoByAccessibilityIdClientThread(
        long accessibilityNodeId, Region interactiveRegion, int interactionId,
        IAccessibilityInteractionConnectionCallback callback, int flags, int interrogatingPid,
        long interrogatingTid, MagnificationSpec spec, Bundle arguments) {
    final Message message = mHandler.obtainMessage();
    message.what = PrivateHandler.MSG_FIND_ACCESSIBILITY_NODE_INFO_BY_ACCESSIBILITY_ID;
    message.arg1 = flags;

    final SomeArgs args = SomeArgs.obtain();
    args.argi1 = AccessibilityNodeInfo.getAccessibilityViewId(accessibilityNodeId);
    args.argi2 = AccessibilityNodeInfo.getVirtualDescendantId(accessibilityNodeId);
    args.argi3 = interactionId;
    args.arg1 = callback;
    args.arg2 = spec;
    args.arg3 = interactiveRegion;
    args.arg4 = arguments;
    message.obj = args;

    scheduleMessage(message, interrogatingPid, interrogatingTid, CONSIDER_REQUEST_PREPARERS);
}
 
Example #13
Source File: PagedViewIcon.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    // If text is transparent, don't draw any shadow
    if (getCurrentTextColor() == getResources().getColor(android.R.color.transparent)) {
        getPaint().clearShadowLayer();
        super.draw(canvas);
        return;
    }

    // We enhance the shadow by drawing the shadow twice
    getPaint().setShadowLayer(BubbleTextView.SHADOW_LARGE_RADIUS, 0.0f,
            BubbleTextView.SHADOW_Y_OFFSET, BubbleTextView.SHADOW_LARGE_COLOUR);
    super.draw(canvas);
    canvas.save(Canvas.CLIP_SAVE_FLAG);
    canvas.clipRect(getScrollX(), getScrollY() + getExtendedPaddingTop(),
            getScrollX() + getWidth(),
            getScrollY() + getHeight(), Region.Op.INTERSECT);
    getPaint().setShadowLayer(BubbleTextView.SHADOW_SMALL_RADIUS, 0.0f, 0.0f,
            BubbleTextView.SHADOW_SMALL_COLOUR);
    super.draw(canvas);
    canvas.restore();
}
 
Example #14
Source File: MaterialShapeDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void prepareCanvasForShadow(@NonNull Canvas canvas) {
  // Calculate the translation to offset the canvas for the given offset and rotation.
  int shadowOffsetX = getShadowOffsetX();
  int shadowOffsetY = getShadowOffsetY();

  // We only handle clipping as a convenience for older apis where we are trying to seamlessly
  // provide fake shadows. On newer versions of android, we require that the parent is set so that
  // clipChildren is false.
  if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP && shadowBitmapDrawingEnable) {
    // Add space and offset the canvas for the shadows. Otherwise any shadows drawn outside would
    // be clipped and not visible.
    Rect canvasClipBounds = canvas.getClipBounds();
    canvasClipBounds.inset(-drawableState.shadowCompatRadius, -drawableState.shadowCompatRadius);
    canvasClipBounds.offset(shadowOffsetX, shadowOffsetY);
    canvas.clipRect(canvasClipBounds, Region.Op.REPLACE);
  }

  // Translate the canvas by an amount specified by the shadowCompatOffset. This will make the
  // shadow appear at and angle from the shape.
  canvas.translate(shadowOffsetX, shadowOffsetY);
}
 
Example #15
Source File: DownloadProgressButton.java    From Bailan with Apache License 2.0 6 votes vote down vote up
private void drawProgressRectWithClip(Canvas canvas) {
    mPaint.setColor(mProgressBarColor);
    mPaint.setStyle(Paint.Style.FILL);
    //根据进度比率计算出当前的进度值对应的宽度
    int progress = (int) (mValidWidth * (getProgress() * 1.0f / getMax()));
    canvas.save();
    canvas.translate(getPaddingLeft(), getPaddingTop());
    //裁剪圆角矩形路径
    drawRoundRectPath();
    canvas.clipPath(mRoundRectPath);//裁剪之后此时画布就变成了裁剪之后的圆角矩形
    //裁剪进度路径
    drawProgressPath(progress);
    canvas.clipPath(mProgressPath, Region.Op.INTERSECT);
    canvas.drawColor(mProgressBarColor);
    canvas.restore();
}
 
Example #16
Source File: PageWidget.java    From Jreader with GNU General Public License v2.0 6 votes vote down vote up
private void drawCurrentPageArea(Canvas canvas, Bitmap bitmap, Path path) {
    mPath0.reset();
    mPath0.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath0.quadTo(mBezierControl1.x, mBezierControl1.y, mBezierEnd1.x,
            mBezierEnd1.y);
    mPath0.lineTo(mTouch.x, mTouch.y);
    mPath0.lineTo(mBezierEnd2.x, mBezierEnd2.y);
    mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x,
            mBezierStart2.y);
    mPath0.lineTo(mCornerX, mCornerY);
    mPath0.close();

    canvas.save();
    canvas.clipPath(path, Region.Op.XOR);
    canvas.drawBitmap(bitmap, 0, 0, null);
    try {
        canvas.restore();
    } catch (Exception e) {

    }

}
 
Example #17
Source File: PinnedHeaderDecoration.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (mPinnedHeaderView != null) {
        c.save();

        mClipBounds.top = 0;
        c.clipRect(mClipBounds, Region.Op.UNION);
        c.translate(0, mPinnedHeaderTop);
        mPinnedHeaderView.draw(c);

        c.restore();
    }
}
 
Example #18
Source File: PinnedHeaderItemDecoration.java    From PinnedSectionItemDecoration with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {

    if (!mDisableDrawHeader && mPinnedHeaderView != null && mFirstVisiblePosition >= mPinnedHeaderPosition) {
        c.save();

        if (mItemTouchListener != null) {
            mItemTouchListener.invalidTopAndBottom(mPinnedHeaderOffset);
        }

        mClipBounds.top = mRecyclerViewPaddingTop + mHeaderTopMargin;
        // 锁定画布绘制范围,记为B
        // REVERSE_DIFFERENCE,实际上就是求得的B和A的差集范围,即B-A,只有在此范围内的绘制内容才会被显示
        // 因此,只绘制(0,0,parent.getWidth(),belowView.getTop())这个范围,然后画布移动了mPinnedHeaderTop,所以刚好是绘制顶部标签移动的范围
        // 低版本不行,换回Region.Op.UNION并集

        // 解决编译版本28修改后的抛出异常:java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed
        c.clipRect(mClipBounds, Region.Op.INTERSECT);

        c.translate(mRecyclerViewPaddingLeft + mHeaderLeftMargin, mPinnedHeaderOffset + mRecyclerViewPaddingTop + mHeaderTopMargin);
        mPinnedHeaderView.draw(c);

        c.restore();

    } else if (mItemTouchListener != null) {
        // 不绘制的时候,把头部的偏移值偏移用户点击不到的程度
        mItemTouchListener.invalidTopAndBottom(-1000);
    }
}
 
Example #19
Source File: VectorDrawableCommon.java    From VectorChildFinder with Apache License 2.0 5 votes vote down vote up
@Override
public Region getTransparentRegion() {
    if (mDelegateDrawable != null) {
        return mDelegateDrawable.getTransparentRegion();
    }
    return super.getTransparentRegion();
}
 
Example #20
Source File: BookPageView.java    From CrawlerForReader with Apache License 2.0 5 votes vote down vote up
/**
 * 绘制A区域内容
 *
 * @param canvas
 * @param pathA
 */
private void drawPathAContent(Canvas canvas, Path pathA) {
    canvas.save();
    canvas.clipPath(pathA, Region.Op.INTERSECT);//对绘制内容进行裁剪,取和A区域的交集
    canvas.drawBitmap(pathAContentBitmap, 0, 0, null);

    if (style.equals(STYLE_LEFT) || style.equals(STYLE_RIGHT)) {
        drawPathAHorizontalShadow(canvas, pathA);
    } else {
        drawPathALeftShadow(canvas, pathA);
        drawPathARightShadow(canvas, pathA);
    }
    canvas.restore();
}
 
Example #21
Source File: SimulationPageAnim.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
private void drawNextPageAreaAndShadow(Canvas canvas, Bitmap bitmap) {
    mPath1.reset();
    mPath1.moveTo(mBezierStart1.x, mBezierStart1.y);
    mPath1.lineTo(mBeziervertex1.x, mBeziervertex1.y);
    mPath1.lineTo(mBeziervertex2.x, mBeziervertex2.y);
    mPath1.lineTo(mBezierStart2.x, mBezierStart2.y);
    mPath1.lineTo(mCornerX, mCornerY);
    mPath1.close();

    mDegrees = (float) Math.toDegrees(Math.atan2(mBezierControl1.x
            - mCornerX, mBezierControl2.y - mCornerY));
    int leftx;
    int rightx;
    GradientDrawable mBackShadowDrawable;
    if (mIsRTandLB) {  //左下及右上
        leftx = (int) (mBezierStart1.x);
        rightx = (int) (mBezierStart1.x + mTouchToCornerDis / 4);
        mBackShadowDrawable = mBackShadowDrawableLR;
    } else {
        leftx = (int) (mBezierStart1.x - mTouchToCornerDis / 4);
        rightx = (int) mBezierStart1.x;
        mBackShadowDrawable = mBackShadowDrawableRL;
    }
    canvas.save();
    try {
        canvas.clipPath(mPath0);
        canvas.clipPath(mPath1, Region.Op.INTERSECT);
    } catch (Exception e) {
    }


    canvas.drawBitmap(bitmap, 0, 0, null);
    canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y);
    mBackShadowDrawable.setBounds(leftx, (int) mBezierStart1.y, rightx,
            (int) (mMaxLength + mBezierStart1.y));//左上及右下角的xy坐标值,构成一个矩形
    mBackShadowDrawable.draw(canvas);
    canvas.restore();
}
 
Example #22
Source File: AndroidGraphics.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public void clipRect(int x, int y, int width, int height) {
    //System.out.println("Clipping rect "+x+","+y+","+width+", "+height);
    clipFresh = false;
    if (getTransform().isIdentity() || transformSemaphore > 0) {
        canvas.clipRect(x, y, x + width, y + height, Region.Op.INTERSECT);
    } else {
        this.tmppath.rewind();
        this.tmppath.addRect(x, y, x + width, y + height, Path.Direction.CW);
        this.tmppath.transform(getTransformMatrix());

        canvas.clipPath(this.tmppath, Region.Op.INTERSECT);
    }
}
 
Example #23
Source File: CropOverlayView.java    From ImageSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	Logs.e(TAG, "onDraw");
	if (rectF == null)
		return;
	Logs.e(TAG, "onDrawOverlay");
	switch (mShape) {
		case OVERLAY_SHAPE_CIRCLE:
			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;
			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);
			break;
		case OVERLAY_SHAPE_SQUARE:
			final float radius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, CORNER_RADIUS, mContext.getResources().getDisplayMetrics());
			clipPath.addRoundRect(rectF, radius, radius, Path.Direction.CW);
			canvas.clipPath(clipPath, Region.Op.DIFFERENCE);
			canvas.drawARGB(204, 41, 48, 63);
			canvas.restore();
			canvas.drawRoundRect(rectF, radius, radius, mBorderPaint);
			break;
	}
	if (mGuidelines) {
		drawRuleOfThirdsGuidelines(canvas);
	}
}
 
Example #24
Source File: Utils.java    From ClipPathLayout with Apache License 2.0 5 votes vote down vote up
public static void clipOutPath(Canvas canvas, Path path) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        canvas.clipOutPath(path);
    } else {
        canvas.clipPath(path, Region.Op.DIFFERENCE);
    }
}
 
Example #25
Source File: VectorView.java    From SVG-Android with Apache License 2.0 5 votes vote down vote up
public int findPathIndexByPoint(int x, int y) {
    Region region = new Region();
    for (int i = 0; i < mPaths.length; i++) {
        mPaths[i].computeBounds(RECTF, true);
        region.setPath(mPaths[i], new Region((int)RECTF.left,(int)RECTF.top,(int)RECTF.right,(int)RECTF.bottom));
        if (region.contains(x, y)) {
            return i;
        }
    }
    return INVALID_PATH_INDEX;
}
 
Example #26
Source File: HighlightView.java    From GalleryFinal with Apache License 2.0 5 votes vote down vote up
protected void draw(Canvas canvas) {
    canvas.save();
    Path path = new Path();
    outlinePaint.setStrokeWidth(outlineWidth);
    if (!hasFocus()) {
        outlinePaint.setColor(Color.BLACK);
        canvas.drawRect(drawRect, outlinePaint);
    } else {
        Rect viewDrawingRect = new Rect();
        viewContext.getDrawingRect(viewDrawingRect);

        path.addRect(new RectF(drawRect), Path.Direction.CW);
        outlinePaint.setColor(highlightColor);

        if (isClipPathSupported(canvas)) {
            canvas.clipPath(path, Region.Op.DIFFERENCE);
            canvas.drawRect(viewDrawingRect, outsidePaint);
        } else {
            drawOutsideFallback(canvas);
        }

        canvas.restore();
        canvas.drawPath(path, outlinePaint);

        if (showThirds) {
            drawThirds(canvas);
        }

        if (showCircle) {
            drawCircle(canvas);
        }

        if (handleMode == HandleMode.Always ||
                (handleMode == HandleMode.Changing && modifyMode == ModifyMode.Grow)) {
            drawHandles(canvas);
        }
    }
}
 
Example #27
Source File: AccessibilityInteractionController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void focusSearchUiThread(Message message) {
    final int flags = message.arg1;
    final int accessibilityViewId = message.arg2;

    SomeArgs args = (SomeArgs) message.obj;
    final int direction = args.argi2;
    final int interactionId = args.argi3;
    final IAccessibilityInteractionConnectionCallback callback =
        (IAccessibilityInteractionConnectionCallback) args.arg1;
    final MagnificationSpec spec = (MagnificationSpec) args.arg2;
    final Region interactiveRegion = (Region) args.arg3;

    args.recycle();

    AccessibilityNodeInfo next = null;
    try {
        if (mViewRootImpl.mView == null || mViewRootImpl.mAttachInfo == null) {
            return;
        }
        mViewRootImpl.mAttachInfo.mAccessibilityFetchFlags = flags;
        View root = null;
        if (accessibilityViewId != AccessibilityNodeInfo.ROOT_ITEM_ID) {
            root = findViewByAccessibilityId(accessibilityViewId);
        } else {
            root = mViewRootImpl.mView;
        }
        if (root != null && isShown(root)) {
            View nextView = root.focusSearch(direction);
            if (nextView != null) {
                next = nextView.createAccessibilityNodeInfo();
            }
        }
    } finally {
        updateInfoForViewportAndReturnFindNodeResult(
                next, callback, interactionId, spec, interactiveRegion);
    }
}
 
Example #28
Source File: MaskEvaluator.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
/** Clip the given Canvas to the mask held by this evaluator. */
void clip(Canvas canvas) {
  if (VERSION.SDK_INT >= VERSION_CODES.M) {
    canvas.clipPath(path);
  } else {
    canvas.clipPath(startPath);
    canvas.clipPath(endPath, Region.Op.UNION);
  }
}
 
Example #29
Source File: WheelView.java    From Prodigal with Apache License 2.0 5 votes vote down vote up
private void drawRect(Canvas canvas) {
    float radiusIn = this.radiusIn * theme.getInner();
    float radiusOut = this.radiusOut * theme.getOuter();
    canvas.drawRect(center.x - radiusOut, center.y - radiusOut, center.x + radiusOut, center.y + radiusOut, paintOut);
    canvas.save();
    if (viewBound != null) {
        canvas.clipPath(viewBound, Region.Op.REPLACE);
    }
    canvas.drawRect(center.x - radiusIn, center.y - radiusIn, center.x + radiusIn, center.y + radiusIn, paintIn);
    if (Build.VERSION.SDK_INT != 23) {
        canvas.restore();
    }
}
 
Example #30
Source File: DisplayCutout.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Region boundingRectsToRegion(List<Rect> rects) {
    Region result = Region.obtain();
    if (rects != null) {
        for (Rect r : rects) {
            result.op(r, Region.Op.UNION);
        }
    }
    return result;
}