Created
April 30, 2015 12:54
-
-
Save defHLT/7ade78c292534c1d5c1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mlatu.tv.ui.views; | |
import android.content.Context; | |
import android.graphics.Canvas; | |
import android.graphics.Path; | |
import android.util.AttributeSet; | |
import android.widget.FrameLayout; | |
public class ClipRevealFrame extends FrameLayout { | |
private final String TAG = this.getClass().getSimpleName(); | |
private Path mRevealPath; | |
boolean mClipOutlines; | |
float mCenterX; | |
float mCenterY; | |
float mRadius; | |
public ClipRevealFrame(Context context) { | |
super(context); | |
init(); | |
} | |
public ClipRevealFrame(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
init(); | |
} | |
public ClipRevealFrame(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
init(); | |
} | |
private void init(){ | |
mRevealPath = new Path(); | |
mClipOutlines = false; | |
setWillNotDraw(false); | |
} | |
public void setClipOutLines(boolean shouldClip){ | |
mClipOutlines = shouldClip; | |
} | |
public void setClipCenter(final int x, final int y){ | |
mCenterX = x; | |
mCenterY = y; | |
} | |
public void setClipRadius(final float radius){ | |
mRadius = radius; | |
invalidate(); | |
} | |
@Override | |
public void draw(Canvas canvas) { | |
if(!mClipOutlines){ | |
super.draw(canvas); | |
return; | |
} | |
final int state = canvas.save(); | |
mRevealPath.reset(); | |
mRevealPath.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW); | |
canvas.clipPath(mRevealPath); | |
super.draw(canvas); | |
canvas.restoreToCount(state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment