1 package com.android.launcher3.util; 2 3 import android.annotation.TargetApi; 4 import android.graphics.Outline; 5 import android.graphics.Rect; 6 import android.os.Build; 7 import android.view.View; 8 import android.view.ViewOutlineProvider; 9 10 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 11 public class RevealOutlineProvider extends ViewOutlineProvider { 12 13 private int mCenterX; 14 private int mCenterY; 15 private float mRadius0; 16 private float mRadius1; 17 private int mCurrentRadius; 18 19 private final Rect mOval; 20 21 /** 22 * @param x reveal center x 23 * @param y reveal center y 24 * @param r0 initial radius 25 * @param r1 final radius 26 */ RevealOutlineProvider(int x, int y, float r0, float r1)27 public RevealOutlineProvider(int x, int y, float r0, float r1) { 28 mCenterX = x; 29 mCenterY = y; 30 mRadius0 = r0; 31 mRadius1 = r1; 32 33 mOval = new Rect(); 34 } 35 setProgress(float progress)36 public void setProgress(float progress) { 37 mCurrentRadius = (int) ((1 - progress) * mRadius0 + progress * mRadius1); 38 39 mOval.left = mCenterX - mCurrentRadius; 40 mOval.top = mCenterY - mCurrentRadius; 41 mOval.right = mCenterX + mCurrentRadius; 42 mOval.bottom = mCenterY + mCurrentRadius; 43 } 44 45 @Override getOutline(View v, Outline outline)46 public void getOutline(View v, Outline outline) { 47 outline.setRoundRect(mOval, mCurrentRadius); 48 } 49 } 50