react-native-quicktracking-analytics-module 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/QuicktrackingAnalyticsModule.podspec +29 -0
- package/README.md +211 -151
- package/android/build.gradle +40 -101
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QTSDKManager.kt +112 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QuicktrackingAnalyticsModuleModule.kt +259 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/QuicktrackingAnalyticsModulePackage.kt +17 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/property/QTViewProperties.kt +84 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/QTLog.kt +119 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNPropertyManager.kt +35 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNTouchTargetHelper.kt +162 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNUtils.kt +170 -0
- package/android/src/main/java/com/quicktrackinganalyticsmodule/utils/RNViewUtils.kt +233 -0
- package/ios/QuicktrackingAnalyticsModule.h +1 -4
- package/ios/{QuicktrackingAnalyticsModule.m → QuicktrackingAnalyticsModule.mm} +144 -110
- package/lib/commonjs/hook.js +564 -0
- package/lib/commonjs/hook.js.map +1 -0
- package/lib/commonjs/index.js +276 -166
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/hook.js +564 -0
- package/lib/module/hook.js.map +1 -0
- package/lib/module/index.js +253 -164
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/index.d.ts +120 -79
- package/lib/typescript/index.d.ts.map +1 -0
- package/package.json +83 -67
- package/src/hook.js +3 -3
- package/src/index.tsx +266 -169
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -234
- package/android/gradlew.bat +0 -89
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QTSDKManager.java +0 -93
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QuicktrackingAnalyticsModule.java +0 -242
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/QuicktrackingAnalyticsModulePackage.java +0 -28
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/property/QTViewProperties.java +0 -48
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/QTLog.java +0 -122
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNPropertyManager.java +0 -29
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNTouchTargetHelper.java +0 -139
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNUtils.java +0 -188
- package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNViewUtils.java +0 -148
- package/ios/QuicktrackingAnalyticsModule.xcodeproj/project.pbxproj +0 -282
- package/ios/QuicktrackingAnalyticsModule.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/react-native-quicktracking-analytics-module.podspec +0 -37
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
package com.reactnativequicktrackinganalyticsmodule.property;
|
|
3
|
-
import com.reactnativequicktrackinganalyticsmodule.utils.RNUtils;
|
|
4
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
5
|
-
import org.json.JSONObject;
|
|
6
|
-
|
|
7
|
-
import android.content.Context;
|
|
8
|
-
import android.view.View;
|
|
9
|
-
import android.widget.ScrollView;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
public class QTViewProperties {
|
|
13
|
-
public static final String TAG = "QuickTracking == ";
|
|
14
|
-
private boolean clickable;
|
|
15
|
-
public JSONObject properties;
|
|
16
|
-
private int viewTagKey = 0;
|
|
17
|
-
|
|
18
|
-
public QTViewProperties(boolean clickable, ReadableMap params) {
|
|
19
|
-
this.clickable = clickable;
|
|
20
|
-
this.properties = RNUtils.convertToJSONObject(params);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public void setViewClickable(View view) {
|
|
24
|
-
try {
|
|
25
|
-
if (view != null && !(view instanceof ScrollView)) {
|
|
26
|
-
view.setClickable(clickable);
|
|
27
|
-
}
|
|
28
|
-
} catch (Exception e) {
|
|
29
|
-
android.util.Log.e(TAG, e.getMessage());
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public void setViewTag(View view) {
|
|
34
|
-
try {
|
|
35
|
-
if (view != null) {
|
|
36
|
-
if (viewTagKey == 0) {
|
|
37
|
-
Context context = view.getContext();
|
|
38
|
-
viewTagKey = context.getResources().getIdentifier("qt_rn_tag_view_rn_key", "id", context.getPackageName());
|
|
39
|
-
}
|
|
40
|
-
if (viewTagKey != 0) {
|
|
41
|
-
view.setTag(viewTagKey, true);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
} catch (Exception e) {
|
|
45
|
-
android.util.Log.e(TAG, "设置viewTag 失败!" + e.getMessage());
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
-
|
|
3
|
-
import android.util.Log;
|
|
4
|
-
|
|
5
|
-
public class QTLog {
|
|
6
|
-
private static boolean debug;
|
|
7
|
-
private static boolean enableLog;
|
|
8
|
-
private static boolean disableSDK;
|
|
9
|
-
private static final int CHUNK_SIZE = 4000;
|
|
10
|
-
|
|
11
|
-
public static void d(String tag, String msg) {
|
|
12
|
-
if (debug && !disableSDK) {
|
|
13
|
-
info(tag, msg, null);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static void t(String msg, Object... object) {
|
|
18
|
-
if (enableLog && !disableSDK) {
|
|
19
|
-
i("===TEST===", msg, object);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public static void d(String tag, String msg, Throwable tr) {
|
|
24
|
-
if (debug && !disableSDK) {
|
|
25
|
-
info(tag, msg, tr);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static void i(String tag, String msg) {
|
|
30
|
-
if (enableLog && !disableSDK) {
|
|
31
|
-
info(tag, msg, null);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static void i(String tag, Throwable tr) {
|
|
36
|
-
if (enableLog && !disableSDK) {
|
|
37
|
-
info(tag, "", tr);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public static void i(String tag, String msg, Throwable tr) {
|
|
42
|
-
if (enableLog && !disableSDK) {
|
|
43
|
-
info(tag, msg, tr);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public static void i(String tag, String msg, Object... object) {
|
|
48
|
-
if (enableLog && !disableSDK) {
|
|
49
|
-
info(tag, String.format(msg, object), null);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public static void info(String tag, String msg, Throwable tr) {
|
|
54
|
-
try {
|
|
55
|
-
if (msg != null) {
|
|
56
|
-
byte[] bytes = msg.getBytes();
|
|
57
|
-
int length = bytes.length;
|
|
58
|
-
if (length <= CHUNK_SIZE) {
|
|
59
|
-
Log.i(tag, msg, tr);
|
|
60
|
-
} else {
|
|
61
|
-
int index = 0, lastIndexOfLF = 0;
|
|
62
|
-
//当最后一次剩余值小于 CHUNK_SIZE 时,不需要再截断
|
|
63
|
-
while (index < length - CHUNK_SIZE) {
|
|
64
|
-
lastIndexOfLF = lastIndexOfLF(bytes, index);
|
|
65
|
-
int chunkLength = lastIndexOfLF - index;
|
|
66
|
-
Log.i(tag, new String(bytes, index, chunkLength), null);
|
|
67
|
-
if (chunkLength < CHUNK_SIZE) {
|
|
68
|
-
//跳过换行符
|
|
69
|
-
index = lastIndexOfLF + 1;
|
|
70
|
-
} else {
|
|
71
|
-
index = lastIndexOfLF;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (length > index) {
|
|
75
|
-
Log.i(tag, new String(bytes, index, length - index), tr);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
Log.i(tag, null, tr);
|
|
80
|
-
}
|
|
81
|
-
} catch (Exception e) {
|
|
82
|
-
printStackTrace(e);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private static int lastIndexOfLF(byte[] bytes, int fromIndex) {
|
|
87
|
-
int index = Math.min(fromIndex + CHUNK_SIZE, bytes.length - 1);
|
|
88
|
-
for (int i = index; i > index - CHUNK_SIZE; i--) {
|
|
89
|
-
//返回换行符的位置
|
|
90
|
-
if (bytes[i] == (byte) 10) {
|
|
91
|
-
return i;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return index;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public static void printStackTrace(Exception e) {
|
|
98
|
-
if (enableLog && !disableSDK && e != null) {
|
|
99
|
-
Log.e("QuickTracking Exception", "", e);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
static void setDebug(boolean isDebug) {
|
|
104
|
-
debug = isDebug;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public static void setEnableLog(boolean isEnableLog) {
|
|
108
|
-
enableLog = isEnableLog;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public static void setDisableSDK(boolean configDisableSDK) {
|
|
112
|
-
disableSDK = configDisableSDK;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public static boolean isLogEnabled() {
|
|
116
|
-
return enableLog;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public static boolean isDebug() {
|
|
120
|
-
return debug;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
-
|
|
3
|
-
import org.json.JSONObject;
|
|
4
|
-
|
|
5
|
-
import java.util.ArrayList;
|
|
6
|
-
import java.util.List;
|
|
7
|
-
|
|
8
|
-
public class RNPropertyManager {
|
|
9
|
-
public static List<Interceptor> interceptors = new ArrayList<>();
|
|
10
|
-
|
|
11
|
-
public static void addInterceptor(Interceptor interceptor){
|
|
12
|
-
interceptors.add(interceptor);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public static JSONObject mergeProperty(JSONObject properties){
|
|
16
|
-
return mergeProperty(properties, false);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public static JSONObject mergeProperty(JSONObject properties, boolean isAuto){
|
|
20
|
-
for(Interceptor interceptor:interceptors){
|
|
21
|
-
properties = interceptor.proceed(properties, isAuto);
|
|
22
|
-
}
|
|
23
|
-
return properties;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface Interceptor{
|
|
27
|
-
JSONObject proceed(JSONObject properties, boolean isAuto);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.graphics.Matrix;
|
|
5
|
-
import android.graphics.PointF;
|
|
6
|
-
import android.graphics.Rect;
|
|
7
|
-
import android.view.View;
|
|
8
|
-
import android.view.ViewGroup;
|
|
9
|
-
|
|
10
|
-
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
|
|
11
|
-
import com.facebook.react.bridge.UiThreadUtil;
|
|
12
|
-
import com.facebook.react.touch.ReactHitSlopView;
|
|
13
|
-
import com.facebook.react.uimanager.PointerEvents;
|
|
14
|
-
import com.facebook.react.uimanager.ReactCompoundView;
|
|
15
|
-
import com.facebook.react.uimanager.ReactCompoundViewGroup;
|
|
16
|
-
import com.facebook.react.uimanager.ReactPointerEventsView;
|
|
17
|
-
|
|
18
|
-
public class RNTouchTargetHelper {
|
|
19
|
-
private static final float[] mEventCoords = new float[2];
|
|
20
|
-
private static final Matrix mInverseMatrix = new Matrix();
|
|
21
|
-
private static final float[] mMatrixTransformCoords = new float[2];
|
|
22
|
-
private static final PointF mTempPoint = new PointF();
|
|
23
|
-
|
|
24
|
-
public static int findTargetTagForTouch(float eventX, float eventY, ViewGroup viewGroup) {
|
|
25
|
-
return findTargetTagAndCoordinatesForTouch(eventX, eventY, viewGroup, mEventCoords);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public static int findTargetTagAndCoordinatesForTouch(float eventX, float eventY, ViewGroup viewGroup, float[] viewCoords) {
|
|
29
|
-
UiThreadUtil.assertOnUiThread();
|
|
30
|
-
int targetTag = viewGroup.getId();
|
|
31
|
-
viewCoords[0] = eventX;
|
|
32
|
-
viewCoords[1] = eventY;
|
|
33
|
-
View nativeTargetView = findTouchTargetView(viewCoords, viewGroup);
|
|
34
|
-
if (nativeTargetView == null) {
|
|
35
|
-
return targetTag;
|
|
36
|
-
}
|
|
37
|
-
View reactTargetView = findClosestReactAncestor(nativeTargetView);
|
|
38
|
-
if (reactTargetView != null) {
|
|
39
|
-
return getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
|
|
40
|
-
}
|
|
41
|
-
return targetTag;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@SuppressLint("ResourceType")
|
|
45
|
-
public static View findClosestReactAncestor(View view) {
|
|
46
|
-
while (view != null && view.getId() <= 0) {
|
|
47
|
-
view = (View) view.getParent();
|
|
48
|
-
}
|
|
49
|
-
return view;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public static View findTouchTargetView(float[] eventCoords, ViewGroup viewGroup) {
|
|
53
|
-
for (int i = viewGroup.getChildCount() - 1; i >= 0; i--) {
|
|
54
|
-
View child = viewGroup.getChildAt(i);
|
|
55
|
-
PointF childPoint = mTempPoint;
|
|
56
|
-
if (isTransformedTouchPointInView(eventCoords[0], eventCoords[1], viewGroup, child, childPoint)) {
|
|
57
|
-
float restoreX = eventCoords[0];
|
|
58
|
-
float restoreY = eventCoords[1];
|
|
59
|
-
eventCoords[0] = childPoint.x;
|
|
60
|
-
eventCoords[1] = childPoint.y;
|
|
61
|
-
View targetView = findTouchTargetViewWithPointerEvents(eventCoords, child);
|
|
62
|
-
if (targetView != null) {
|
|
63
|
-
return targetView;
|
|
64
|
-
}
|
|
65
|
-
eventCoords[0] = restoreX;
|
|
66
|
-
eventCoords[1] = restoreY;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return viewGroup;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private static boolean isTransformedTouchPointInView(float x, float y, ViewGroup parent, View child, PointF outLocalPoint) {
|
|
73
|
-
float localX = (((float) parent.getScrollX()) + x) - ((float) child.getLeft());
|
|
74
|
-
float localY = (((float) parent.getScrollY()) + y) - ((float) child.getTop());
|
|
75
|
-
Matrix matrix = child.getMatrix();
|
|
76
|
-
if (!matrix.isIdentity()) {
|
|
77
|
-
float[] localXY = mMatrixTransformCoords;
|
|
78
|
-
localXY[0] = localX;
|
|
79
|
-
localXY[1] = localY;
|
|
80
|
-
Matrix inverseMatrix = mInverseMatrix;
|
|
81
|
-
matrix.invert(inverseMatrix);
|
|
82
|
-
inverseMatrix.mapPoints(localXY);
|
|
83
|
-
localX = localXY[0];
|
|
84
|
-
localY = localXY[1];
|
|
85
|
-
}
|
|
86
|
-
if ((child instanceof ReactHitSlopView) && ((ReactHitSlopView) child).getHitSlopRect() != null) {
|
|
87
|
-
Rect hitSlopRect = ((ReactHitSlopView) child).getHitSlopRect();
|
|
88
|
-
if (localX < ((float) (-hitSlopRect.left)) || localX >= ((float) ((child.getRight() - child.getLeft()) + hitSlopRect.right)) || localY < ((float) (-hitSlopRect.top)) || localY >= ((float) ((child.getBottom() - child.getTop()) + hitSlopRect.bottom))) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
outLocalPoint.set(localX, localY);
|
|
92
|
-
return true;
|
|
93
|
-
} else if (localX < 0.0f || localX >= ((float) (child.getRight() - child.getLeft())) || localY < 0.0f || localY >= ((float) (child.getBottom() - child.getTop()))) {
|
|
94
|
-
return false;
|
|
95
|
-
} else {
|
|
96
|
-
outLocalPoint.set(localX, localY);
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private static View findTouchTargetViewWithPointerEvents(float[] eventCoords, View view) {
|
|
102
|
-
PointerEvents pointerEvents = view instanceof ReactPointerEventsView ? ((ReactPointerEventsView) view).getPointerEvents() : PointerEvents.AUTO;
|
|
103
|
-
if (pointerEvents == PointerEvents.NONE) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
if (pointerEvents == PointerEvents.BOX_ONLY) {
|
|
107
|
-
return view;
|
|
108
|
-
}
|
|
109
|
-
if (pointerEvents == PointerEvents.BOX_NONE) {
|
|
110
|
-
if (view instanceof ViewGroup) {
|
|
111
|
-
View targetView = findTouchTargetView(eventCoords, (ViewGroup) view);
|
|
112
|
-
if (targetView != view) {
|
|
113
|
-
return targetView;
|
|
114
|
-
}
|
|
115
|
-
if (!(view instanceof ReactCompoundView) || ((ReactCompoundView) view).reactTagForTouch(eventCoords[0], eventCoords[1]) == view.getId()) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return view;
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
} else if (pointerEvents != PointerEvents.AUTO) {
|
|
122
|
-
StringBuilder stringBuilder = new StringBuilder();
|
|
123
|
-
stringBuilder.append("Unknown pointer event type: ");
|
|
124
|
-
stringBuilder.append(pointerEvents.toString());
|
|
125
|
-
throw new JSApplicationIllegalArgumentException(stringBuilder.toString());
|
|
126
|
-
} else if ((!(view instanceof ReactCompoundViewGroup) || !((ReactCompoundViewGroup) view).interceptsTouchEvent(eventCoords[0], eventCoords[1])) && (view instanceof ViewGroup)) {
|
|
127
|
-
return findTouchTargetView(eventCoords, (ViewGroup) view);
|
|
128
|
-
} else {
|
|
129
|
-
return view;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
public static int getTouchTargetForView(View targetView, float eventX, float eventY) {
|
|
134
|
-
if (targetView instanceof ReactCompoundView) {
|
|
135
|
-
return ((ReactCompoundView) targetView).reactTagForTouch(eventX, eventY);
|
|
136
|
-
}
|
|
137
|
-
return targetView.getId();
|
|
138
|
-
}
|
|
139
|
-
}
|
package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNUtils.java
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
-
|
|
3
|
-
import android.graphics.drawable.AnimationDrawable;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.Arguments;
|
|
6
|
-
import com.facebook.react.bridge.ReadableMap;
|
|
7
|
-
import com.facebook.react.bridge.ReadableNativeMap;
|
|
8
|
-
import com.facebook.react.bridge.WritableMap;
|
|
9
|
-
|
|
10
|
-
import java.security.MessageDigest;
|
|
11
|
-
import java.util.ArrayList;
|
|
12
|
-
import java.util.HashMap;
|
|
13
|
-
import java.util.Iterator;
|
|
14
|
-
import java.util.List;
|
|
15
|
-
import java.util.Map;
|
|
16
|
-
|
|
17
|
-
import org.json.JSONArray;
|
|
18
|
-
import org.json.JSONObject;
|
|
19
|
-
|
|
20
|
-
public class RNUtils {
|
|
21
|
-
public static final String TAG = "QuickTracking == ";
|
|
22
|
-
/**
|
|
23
|
-
* ReadableMap 转换成 JSONObject
|
|
24
|
-
* */
|
|
25
|
-
public static JSONObject convertToJSONObject(ReadableMap params) {
|
|
26
|
-
if (params == null) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
JSONObject json = null;
|
|
30
|
-
ReadableNativeMap nativeMap = null;
|
|
31
|
-
try {
|
|
32
|
-
nativeMap = (ReadableNativeMap) params;
|
|
33
|
-
json = new JSONObject(params.toString()).getJSONObject("NativeMap");
|
|
34
|
-
} catch (Exception e) {
|
|
35
|
-
android.util.Log.e(TAG, "JSON 解析失败!", e);
|
|
36
|
-
String superName = nativeMap.getClass().getSuperclass().getSimpleName();
|
|
37
|
-
try {
|
|
38
|
-
json = new JSONObject(params.toString()).getJSONObject(superName);
|
|
39
|
-
} catch (Exception e1) {
|
|
40
|
-
android.util.Log.e(TAG, "JSON 解析失败!", e1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return json;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* JSONObject 转换成 WritableMap
|
|
48
|
-
* */
|
|
49
|
-
public static WritableMap convertToWritableMap(JSONObject json) {
|
|
50
|
-
if (json == null || json.length() == 0) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
WritableMap writableMap = Arguments.createMap();
|
|
54
|
-
Iterator<String> it = json.keys();
|
|
55
|
-
while(it.hasNext()) {
|
|
56
|
-
try {
|
|
57
|
-
String key = it.next();
|
|
58
|
-
writableMap.putString(key, json.optString(key));
|
|
59
|
-
} catch (Exception e) {
|
|
60
|
-
QTLog.i(TAG, "JSON to WritableMap 解析失败!", e);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return writableMap;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* ReadableMap 转换成 HashMap
|
|
68
|
-
* */
|
|
69
|
-
public static HashMap<String, Object> convertToHashMap(ReadableMap params) {
|
|
70
|
-
if (params == null) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
HashMap<String, Object> map = null;
|
|
74
|
-
try {
|
|
75
|
-
map = ((ReadableNativeMap)params).toHashMap();
|
|
76
|
-
}catch (Exception e){
|
|
77
|
-
android.util.Log.e(TAG, "ReadableMap to HashMap 解析失败!", e);
|
|
78
|
-
}
|
|
79
|
-
return map;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* merge JSONObject
|
|
84
|
-
* */
|
|
85
|
-
public static void mergeJSONObject(final JSONObject source, JSONObject dest) {
|
|
86
|
-
try {
|
|
87
|
-
Iterator<String> sourceIterator = source.keys();
|
|
88
|
-
while (sourceIterator.hasNext()) {
|
|
89
|
-
String key = sourceIterator.next();
|
|
90
|
-
Object value = source.get(key);
|
|
91
|
-
dest.put(key, value);
|
|
92
|
-
}
|
|
93
|
-
} catch (Exception e) {
|
|
94
|
-
android.util.Log.e(TAG, "JSONObject Merge失败!", e);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public static Map<String, Object> convertToMap(JSONObject jsonObject) {
|
|
99
|
-
try {
|
|
100
|
-
Map<String, Object> map = new HashMap<String, Object>();
|
|
101
|
-
Iterator<String> keys = jsonObject.keys();
|
|
102
|
-
while(keys.hasNext()) {
|
|
103
|
-
String key = keys.next();
|
|
104
|
-
Object value = jsonObject.get(key);
|
|
105
|
-
if (value instanceof JSONArray) {
|
|
106
|
-
value = toList((JSONArray) value);
|
|
107
|
-
} else if (value instanceof JSONObject) {
|
|
108
|
-
value = toMap((JSONObject) value);
|
|
109
|
-
}
|
|
110
|
-
map.put(key, value);
|
|
111
|
-
}
|
|
112
|
-
return map;
|
|
113
|
-
} catch (Exception e) {
|
|
114
|
-
QTLog.printStackTrace(e);
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
public static List<Object> toList(JSONArray jsonArray) {
|
|
120
|
-
try {
|
|
121
|
-
List<Object> list = new ArrayList<Object>();
|
|
122
|
-
for (int i = 0; i < jsonArray.length(); i++) {
|
|
123
|
-
Object obj = jsonArray.get(i);
|
|
124
|
-
if (obj instanceof JSONArray) {
|
|
125
|
-
obj = toList((JSONArray) obj);
|
|
126
|
-
} else if (obj instanceof JSONObject) {
|
|
127
|
-
obj = toMap((JSONObject) obj);
|
|
128
|
-
}
|
|
129
|
-
list.add(obj);
|
|
130
|
-
}
|
|
131
|
-
} catch (Exception e) {
|
|
132
|
-
QTLog.printStackTrace(e);
|
|
133
|
-
}
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
public static Map<String, Object> toMap(JSONObject jsonObject) {
|
|
138
|
-
try {
|
|
139
|
-
Map<String, Object> map = new HashMap<String, Object>();
|
|
140
|
-
Iterator<String> keysItr = jsonObject.keys();
|
|
141
|
-
while(keysItr.hasNext()) {
|
|
142
|
-
String key = keysItr.next();
|
|
143
|
-
Object value = jsonObject.get(key);
|
|
144
|
-
|
|
145
|
-
if(value instanceof JSONArray) {
|
|
146
|
-
value = toList((JSONArray) value);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
else if(value instanceof JSONObject) {
|
|
150
|
-
value = toMap((JSONObject) value);
|
|
151
|
-
}
|
|
152
|
-
map.put(key, value);
|
|
153
|
-
}
|
|
154
|
-
return map;
|
|
155
|
-
} catch (Exception e) {
|
|
156
|
-
QTLog.printStackTrace(e);
|
|
157
|
-
}
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
public static String MD5(String str) {
|
|
162
|
-
try {
|
|
163
|
-
if (str != null) {
|
|
164
|
-
try {
|
|
165
|
-
byte[] defaultBytes = str.getBytes();
|
|
166
|
-
MessageDigest algorithm = MessageDigest.getInstance("MD5");
|
|
167
|
-
algorithm.reset();
|
|
168
|
-
algorithm.update(defaultBytes);
|
|
169
|
-
byte messageDigest[] = algorithm.digest();
|
|
170
|
-
StringBuffer hexString = new StringBuffer();
|
|
171
|
-
for (int i = 0; i < messageDigest.length; i++) {
|
|
172
|
-
hexString.append(String.format("%02X", messageDigest[i]));
|
|
173
|
-
}
|
|
174
|
-
return hexString.toString();
|
|
175
|
-
} catch (Exception e) {
|
|
176
|
-
return str.replaceAll("[^[a-z][A-Z][0-9][.][_]]", "");
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return null;
|
|
180
|
-
} catch (Exception e) {
|
|
181
|
-
android.util.Log.e(TAG, "MD5 e is " + e);
|
|
182
|
-
return null;
|
|
183
|
-
} catch (Throwable e) {
|
|
184
|
-
android.util.Log.e(TAG, "MD5 e is " + e);
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
package/android/src/main/java/com/reactnativequicktrackinganalyticsmodule/utils/RNViewUtils.java
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
package com.reactnativequicktrackinganalyticsmodule.utils;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.view.View;
|
|
5
|
-
import android.view.ViewGroup;
|
|
6
|
-
import android.view.ViewParent;
|
|
7
|
-
|
|
8
|
-
import org.json.JSONObject;
|
|
9
|
-
|
|
10
|
-
import java.lang.ref.WeakReference;
|
|
11
|
-
import java.util.WeakHashMap;
|
|
12
|
-
|
|
13
|
-
public class RNViewUtils {
|
|
14
|
-
private static WeakReference mWeakCurrentActivityReference;
|
|
15
|
-
private static String currentTitle;
|
|
16
|
-
private static String currentScreenName;
|
|
17
|
-
public static boolean isScreenVisiable = false;
|
|
18
|
-
private static JSONObject screenProperties;
|
|
19
|
-
private static WeakReference onTouchViewReference;
|
|
20
|
-
private static WeakHashMap<Activity, JSONObject> mScreenMap = new WeakHashMap<>();
|
|
21
|
-
|
|
22
|
-
public static void setOnTouchView(View nativeTargetView) {
|
|
23
|
-
onTouchViewReference = new WeakReference(nativeTargetView);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public static Activity getCurrentActivity() {
|
|
27
|
-
if (mWeakCurrentActivityReference == null) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return (Activity) mWeakCurrentActivityReference.get();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private static View getClickView(int viewId, View onTouchView) {
|
|
34
|
-
View currentView = onTouchView;
|
|
35
|
-
while (currentView.getId() != viewId) {
|
|
36
|
-
ViewParent parent = currentView.getParent();
|
|
37
|
-
if (!(parent instanceof View)) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
currentView = (View) parent;
|
|
41
|
-
}
|
|
42
|
-
return currentView;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private static View getClickViewInChild(int viewId, ViewGroup currentView) {
|
|
46
|
-
int currentViewCount = currentView.getChildCount();
|
|
47
|
-
for (int i = 0; i < currentViewCount; i++) {
|
|
48
|
-
View childView = currentView.getChildAt(i);
|
|
49
|
-
if (childView != null) {
|
|
50
|
-
if (childView.getId() == viewId) {
|
|
51
|
-
return childView;
|
|
52
|
-
}
|
|
53
|
-
if (childView instanceof ViewGroup) {
|
|
54
|
-
View clickView = getClickViewInChild(viewId, (ViewGroup) childView);
|
|
55
|
-
if (clickView != null) {
|
|
56
|
-
return clickView;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public static View getTouchViewByTag(int viewTag) {
|
|
65
|
-
if(onTouchViewReference != null) {
|
|
66
|
-
View onTouchView = (View) onTouchViewReference.get();
|
|
67
|
-
if (onTouchView != null) {
|
|
68
|
-
View clickView = getClickView(viewTag, onTouchView);
|
|
69
|
-
if (clickView == null && (onTouchView instanceof ViewGroup)) {
|
|
70
|
-
clickView = getClickViewInChild(viewTag, (ViewGroup) onTouchView);
|
|
71
|
-
}
|
|
72
|
-
return clickView;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
public static View getViewByTag(int viewTag) {
|
|
79
|
-
View clickView = null;
|
|
80
|
-
try {
|
|
81
|
-
Activity currentActivity = getCurrentActivity();
|
|
82
|
-
if (currentActivity != null) {
|
|
83
|
-
clickView = currentActivity.findViewById(viewTag);
|
|
84
|
-
}
|
|
85
|
-
if (clickView == null) {
|
|
86
|
-
clickView = getTouchViewByTag(viewTag);
|
|
87
|
-
}
|
|
88
|
-
} catch (Exception ignored) {
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
return clickView;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public static String getTitle() { return currentTitle; }
|
|
95
|
-
|
|
96
|
-
public static String getScreenName() { return currentScreenName; }
|
|
97
|
-
|
|
98
|
-
private static void setCurrentActivity(Activity currentActivity) {
|
|
99
|
-
clearCurrentActivityReference();
|
|
100
|
-
mWeakCurrentActivityReference = new WeakReference(currentActivity);
|
|
101
|
-
JSONObject properties = mScreenMap.get(currentActivity);
|
|
102
|
-
if (properties != null && properties.has("$screen_name")) {
|
|
103
|
-
saveScreenAndTitle(properties.optString("$screen_name"), properties.optString("$title"));
|
|
104
|
-
} else {
|
|
105
|
-
currentScreenName = null;
|
|
106
|
-
currentTitle = null;
|
|
107
|
-
screenProperties = null;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
public static void saveScreenAndTitle(String screenName, String title) {
|
|
112
|
-
currentScreenName = screenName;
|
|
113
|
-
currentTitle = title;
|
|
114
|
-
try {
|
|
115
|
-
screenProperties = new JSONObject();
|
|
116
|
-
screenProperties.put("$title", title);
|
|
117
|
-
screenProperties.put("$screen_name", screenName);
|
|
118
|
-
screenProperties.put("isSetRNViewTag", true);//标识当前页面已区分 RNView 和原生 View
|
|
119
|
-
} catch (Exception ignored) {
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
Activity currentActivity;
|
|
123
|
-
if ((currentActivity = getCurrentActivity()) != null) {
|
|
124
|
-
mScreenMap.put(currentActivity, screenProperties);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public static void clearCurrentActivityReference() {
|
|
129
|
-
if (mWeakCurrentActivityReference != null) {
|
|
130
|
-
mWeakCurrentActivityReference.clear();
|
|
131
|
-
mWeakCurrentActivityReference = null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
public static void setScreenVisiable(boolean isVisiable) {
|
|
136
|
-
isScreenVisiable = isVisiable;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public static void onActivityResumed(Activity currentActivity) {
|
|
140
|
-
setScreenVisiable(true);
|
|
141
|
-
setCurrentActivity(currentActivity);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
public static void onActivityPaused() {
|
|
145
|
-
setScreenVisiable(false);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
}
|