summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util/RevealOutlineProvider.java
blob: 0db3984f815c6d7466e1d7363624ce1e439c2406 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.android.launcher3.util;

import android.annotation.TargetApi;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewOutlineProvider;

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class RevealOutlineProvider extends ViewOutlineProvider {

    private int mCenterX;
    private int mCenterY;
    private float mRadius0;
    private float mRadius1;
    private int mCurrentRadius;

    private final Rect mOval;

    /**
     * @param x reveal center x
     * @param y reveal center y
     * @param r0 initial radius
     * @param r1 final radius
     */
    public RevealOutlineProvider(int x, int y, float r0, float r1) {
        mCenterX = x;
        mCenterY = y;
        mRadius0 = r0;
        mRadius1 = r1;

        mOval = new Rect();
    }

    public void setProgress(float progress) {
        mCurrentRadius = (int) ((1 - progress) * mRadius0 + progress * mRadius1);

        mOval.left = mCenterX - mCurrentRadius;
        mOval.top = mCenterY - mCurrentRadius;
        mOval.right = mCenterX + mCurrentRadius;
        mOval.bottom = mCenterY + mCurrentRadius;
    }

    @Override
    public void getOutline(View v, Outline outline) {
        outline.setRoundRect(mOval, mCurrentRadius);
    }
}