-
Notifications
You must be signed in to change notification settings - Fork 7
/
ViewSwazzledHooks.java
74 lines (63 loc) · 2.4 KB
/
ViewSwazzledHooks.java
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
package io.embrace.android.embracesdk;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.embrace.android.embracesdk.annotation.InternalApi;
import io.embrace.android.embracesdk.payload.TapBreadcrumb.TapBreadcrumbType;
import kotlin.Pair;
/**
* @hide
*/
@InternalApi
public final class ViewSwazzledHooks {
private static final String UNKNOWN_ELEMENT_NAME = "Unknown element";
private ViewSwazzledHooks() {
}
static void logOnClickEvent(android.view.View view, TapBreadcrumbType breadcrumbType) {
try {
String viewName = "";
try {
viewName = view.getResources().getResourceName(view.getId());
} catch (Exception e) {
viewName = UNKNOWN_ELEMENT_NAME;
}
Pair<Float, Float> point = null;
try {
point = new Pair<>(view.getX(), view.getY());
} catch (Exception e) {
point = new Pair<>(0.0F, 0.0F);
}
Embrace.getImpl().logTap(point, viewName, breadcrumbType);
} catch (NoSuchMethodError error) {
// The customer may be overwriting View with their own implementation, and some of the
// methods we use are missing.
logError("Could not log onClickEvent. Some methods are missing. ", error);
} catch (Exception exception) {
logError("Could not log onClickEvent.", exception);
}
}
private static void logError(@NonNull String message, @Nullable Throwable throwable) {
if (throwable != null) {
Embrace.getInstance().getInternalInterface().logInternalError(throwable);
}
}
@InternalApi
public static final class OnClickListener {
private OnClickListener() {
}
@SuppressWarnings("MethodNameCheck")
public static void _preOnClick(android.view.View.OnClickListener thiz, android.view.View view) {
logOnClickEvent(view, TapBreadcrumbType.TAP);
}
}
@InternalApi
public static final class OnLongClickListener {
private OnLongClickListener() {
}
@SuppressWarnings("MethodNameCheck")
public static void _preOnLongClick(android.view.View.OnLongClickListener thiz, android.view.View view) {
if (thiz != null) {
logOnClickEvent(view, TapBreadcrumbType.LONG_PRESS);
}
}
}
}