Created
December 19, 2014 06:34
-
-
Save nschwermann/e566f248723bb1754972 to your computer and use it in GitHub Desktop.
CircularReveal backport
This file contains 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
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 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; | |
} | |
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); | |
} | |
} |
This file contains 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
private Animator createCheckoutRevealAnimator(final ClipRevealFrame view, int x, int y, float startRadius, float endRadius) { | |
final Animator reveal; | |
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ | |
reveal = ViewAnimationUtils.createCircularReveal(view, x, y, startRadius, endRadius); | |
} else { | |
view.setClipOutLines(true); | |
view.setClipCenter(x, y); | |
reveal = ObjectAnimator.ofFloat(view, "ClipRadius", startRadius, endRadius); | |
reveal.addListener(new Animator.AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
view.setClipOutLines(false); | |
} | |
@Override | |
public void onAnimationCancel(Animator animation) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animation) { | |
} | |
}); | |
} | |
reveal.setDuration(500); | |
return reveal; | |
} | |
} |
No but I'll try to put one together.
It doesn't work for me for 4.1-4.3. View just reveals itself at once
It was fun to debug. onDraw
was never called. Modifying init
to this fixes it:
private void init(){
mRevealPath = new Path();
mClipOutlines = false;
setWillNotDraw(false);
}
P.S. Great gist
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a sample project?