admin
2021-07-06 abce02c7a61820f5d580f87364d542e817be429c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.app.hubert.guide.model;
 
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;
 
import com.app.hubert.guide.util.LogUtil;
import com.app.hubert.guide.util.ViewUtils;
 
/**
 * Created by hubert
 * <p>
 * Created on 2017/7/27.
 */
public class HighlightView implements HighLight {
 
    private View mHole;
    private Shape shape;
    private int round;
    /**
     * 高亮相对view的padding
     */
    private int padding;
    private HighlightOptions options;
    private RectF rectF;
 
    public HighlightView(View mHole, Shape shape, int round, int padding) {
        this.mHole = mHole;
        this.shape = shape;
        this.round = round;
        this.padding = padding;
    }
 
    public void setOptions(HighlightOptions options) {
        this.options = options;
    }
 
    @Override
    public Shape getShape() {
        return shape;
    }
 
    @Override
    public int getRound() {
        return round;
    }
 
    @Override
    public HighlightOptions getOptions() {
        return options;
    }
 
    @Override
    public float getRadius() {
        if (mHole == null) {
            throw new IllegalArgumentException("the highlight view is null!");
        }
        return Math.max(mHole.getWidth() / 2, mHole.getHeight() / 2) + padding;
    }
 
    @Override
    public RectF getRectF(View target) {
        if (mHole == null) {
            throw new IllegalArgumentException("the highlight view is null!");
        }
        if (rectF == null) {
            rectF = fetchLocation(target);
        } else if (options != null && options.fetchLocationEveryTime) {
            rectF = fetchLocation(target);
        }
        LogUtil.i(mHole.getClass().getSimpleName() + "'s location:" + rectF);
        return rectF;
    }
 
    private RectF fetchLocation(View target) {
        RectF location = new RectF();
        Rect locationInView = ViewUtils.getLocationInView(target, mHole);
        location.left = locationInView.left - padding;
        location.top = locationInView.top - padding;
        location.right = locationInView.right + padding;
        location.bottom = locationInView.bottom + padding;
        return location;
    }
 
}