-
Notifications
You must be signed in to change notification settings - Fork 522
Expand file tree
/
Copy pathViewTarget.java
More file actions
55 lines (46 loc) · 1.53 KB
/
Copy pathViewTarget.java
File metadata and controls
55 lines (46 loc) · 1.53 KB
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
package uk.co.deanwild.materialshowcaseview.target;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.View;
public class ViewTarget implements Target {
private final View mView;
public ViewTarget(View view) {
mView = view;
}
public ViewTarget(int viewId, Activity activity) {
mView = activity.findViewById(viewId);
}
@Override
public Point getPoint() {
int[] location = new int[2];
mView.getLocationInWindow(location);
View decor = getActivity(mView).getWindow().getDecorView();
int x = location[0] - decor.getPaddingLeft() + mView.getWidth() / 2;
int y = location[1] - decor.getPaddingTop() + mView.getHeight() / 2;
return new Point(x, y);
}
private Activity getActivity(View view) {
Context context = view.getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity)context;
}
context = ((ContextWrapper)context).getBaseContext();
}
return null;
}
@Override
public Rect getBounds() {
int[] location = new int[2];
mView.getLocationInWindow(location);
return new Rect(
location[0],
location[1],
location[0] + mView.getMeasuredWidth(),
location[1] + mView.getMeasuredHeight()
);
}
}