I have an activity B and activity A opens from B. In the activity B there is one imageView which holds the snapshot(bitmap) of activity A. I am trying to paint a part of this snapshot to make it transparent so that I can look at the other views of activity A that are beneath this snapshot. But when I extend the imageview and paint it with Color.Transparent in onDraw, the expected area turns black. What am I doing wrong here? I have gone through similar questions on SO but nothing worked.
P.S. 'B' is first activity and 'A' opens from 'B'
Edit: snapshot imageview has elevation and there are views beneath it.
'Activity B', 'Activity A with Snapshot on top of other views' , Activity A with Paint
public class SnapShotImageView extends ImageView {
private Bitmap bitmap;
private Canvas temp;
private Paint mPaint;
private Path mPath;
public SnapShotImageView(Context context) {
super(context);
init();
}
public SnapShotImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SnapShotImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public SnapShotImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
private void init() {
setWillNotDraw(false);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
mPaint.setColor(Color.TRANSPARENT);
mPaint.setStyle(Paint.Style.FILL);
mPath = new Path();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int width = getMeasuredWidth();
int halfWidth = width / 2;
int height = getMeasuredHeight();
mPath.moveTo(width, height -width);
mPath.addArc(0, height - 3 * halfWidth, width, height - halfWidth, 0, 90);
mPath.addArc(-halfWidth, height - width, halfWidth, height, 0, 90);
mPath.lineTo(width, height);
mPath.lineTo(width, height - width);
mPath.close();
canvas.clipPath(mPath);
canvas.drawPath(mPath,mPaint);
}
}