@sodyo/react-native-sodyo-sdk 3.1.2
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/.gitattributes +1 -0
- package/README.md +131 -0
- package/RNSodyoSdk.podspec +22 -0
- package/android/build.gradle +62 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/sodyo/RNSodyoSdk/ConversionUtil.java +169 -0
- package/android/src/main/java/com/sodyo/RNSodyoSdk/RNSodyoSdkModule.java +293 -0
- package/android/src/main/java/com/sodyo/RNSodyoSdk/RNSodyoSdkPackage.java +29 -0
- package/android/src/main/java/com/sodyo/RNSodyoSdk/RNSodyoSdkView.java +101 -0
- package/ios/RNSodyoSdk.h +26 -0
- package/ios/RNSodyoSdk.m +180 -0
- package/ios/RNSodyoSdk.xcodeproj/project.pbxproj +269 -0
- package/ios/RNSodyoSdk.xcodeproj/xcshareddata/xcschemes/RNSodyoSdk.xcscheme +80 -0
- package/ios/RNSodyoSdk.xcworkspace/contents.xcworkspacedata +9 -0
- package/ios/RNSodyoSdkManager.m +59 -0
- package/ios/RNSodyoSdkView.h +4 -0
- package/ios/RNSodyoSdkView.m +28 -0
- package/package.json +27 -0
- package/sodyosdk.d.ts +36 -0
- package/sodyosdk.js +199 -0
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.pbxproj -text
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
|
|
2
|
+
# React Native Sodyo SDK Plugin that wraps Sodyo sdk for Android and iOS
|
|
3
|
+
|
|
4
|
+
[SodyoSDK for iOS](https://github.com/sodyo-ltd/SodyoSDKPod) v3.54.24
|
|
5
|
+
|
|
6
|
+
[SodyoSDK for Android](https://search.maven.org/search?q=a:sodyo-android-sdk) v3.54.30
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
npm i @sodyo/react-native-sodyo-sdk -E
|
|
11
|
+
|
|
12
|
+
If you using version of react-native < 60 then you have to make a link
|
|
13
|
+
|
|
14
|
+
react-native link
|
|
15
|
+
|
|
16
|
+
[Requires multidex support for android](https://medium.com/@aungmt/multidex-on-androidx-for-rn-0-60-x-cbb37c50d85)
|
|
17
|
+
|
|
18
|
+
## Quick start
|
|
19
|
+
Init the plugin with your Sodyo App Key project token with
|
|
20
|
+
```
|
|
21
|
+
import SodyoSdk from '@sodyo/react-native-sodyo-sdk'
|
|
22
|
+
|
|
23
|
+
SodyoSDK.init(your-app-key,
|
|
24
|
+
function(){ /* successful init callback */ },
|
|
25
|
+
function(){ /* fail init callback */})
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use scanner as fragment (only after initialize SodyoSDK)
|
|
29
|
+
```
|
|
30
|
+
import { Scanner } from '@sodyo/react-native-sodyo-sdk'
|
|
31
|
+
...
|
|
32
|
+
<Scanner isEnabled={true}>
|
|
33
|
+
<Text>Children on top of the scanner</Text>
|
|
34
|
+
</Scanner>
|
|
35
|
+
```
|
|
36
|
+
`isEnabled toggles the Scanners active / pause status.`
|
|
37
|
+
|
|
38
|
+
Set the Sodyo error listener
|
|
39
|
+
```
|
|
40
|
+
SodyoSDK.onError(
|
|
41
|
+
function(err){ /* fail callback */ }
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
`For unsubscribing just call the returned function`
|
|
45
|
+
|
|
46
|
+
Open the Sodyo scanner
|
|
47
|
+
```
|
|
48
|
+
SodyoSDK.start(
|
|
49
|
+
function(markerData){ /* data content callback */ },
|
|
50
|
+
function(err){ /* fail */}
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Close Sodyo scanner (if scanner run by SodyoSDK.start())
|
|
55
|
+
```
|
|
56
|
+
SodyoSDK.close()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Marker content listener
|
|
60
|
+
```
|
|
61
|
+
SodyoSDK.onMarkerContent(
|
|
62
|
+
function(markerId, markerData){ /* successfully scanned marker */ },
|
|
63
|
+
)
|
|
64
|
+
```
|
|
65
|
+
`For unsubscribing just call the returned function`
|
|
66
|
+
|
|
67
|
+
Load marker by Id
|
|
68
|
+
```
|
|
69
|
+
SodyoSDK.performMarker(markerId)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Personal User Information (some object)
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
SodyoSDK.setUserInfo(userInfo)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
User Identification (ID)
|
|
80
|
+
```
|
|
81
|
+
SodyoSDK.setAppUserId(userId)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Setting Scanner Preferences (some flat object)
|
|
85
|
+
```
|
|
86
|
+
SodyoSDK.setScannerParams(scannerPreferences)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Personalized Content
|
|
90
|
+
```
|
|
91
|
+
SodyoSDK.setCustomAdLabel(label)
|
|
92
|
+
```
|
|
93
|
+
`The label may include one or more tags in comma-separated values (CSV) format as follows: “label1,label2,label3”`
|
|
94
|
+
|
|
95
|
+
Remove all listeners
|
|
96
|
+
```
|
|
97
|
+
SodyoSDK.removeAllListeners()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
If you get an error similar to this when building Android:
|
|
101
|
+
```
|
|
102
|
+
More than one file was found with OS independent path 'META-INF/DEPENDENCIES'
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
then add in your `android/app/build.gradle` file add the following:
|
|
106
|
+
```
|
|
107
|
+
android {
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
packagingOptions {
|
|
111
|
+
...
|
|
112
|
+
|
|
113
|
+
exclude "META-INF/DEPENDENCIES.txt"
|
|
114
|
+
exclude "META-INF/LICENSE.txt"
|
|
115
|
+
exclude "META-INF/NOTICE.txt"
|
|
116
|
+
exclude "META-INF/NOTICE"
|
|
117
|
+
exclude "META-INF/LICENSE"
|
|
118
|
+
exclude "META-INF/DEPENDENCIES"
|
|
119
|
+
exclude "META-INF/notice.txt"
|
|
120
|
+
exclude "META-INF/license.txt"
|
|
121
|
+
exclude "META-INF/dependencies.txt"
|
|
122
|
+
exclude "META-INF/LGPL2.1"
|
|
123
|
+
exclude "META-INF/ASL2.0"
|
|
124
|
+
exclude "META-INF/maven/com.google.guava/guava/pom.properties"
|
|
125
|
+
exclude "META-INF/maven/com.google.guava/guava/pom.xml"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
For more examples see [the sample app](https://github.com/sodyo-ltd/react-native-sample-app)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "RNSodyoSdk"
|
|
8
|
+
s.version = package['version']
|
|
9
|
+
s.summary = package['description']
|
|
10
|
+
s.description = package['description']
|
|
11
|
+
s.license = package['license']
|
|
12
|
+
s.author = package['author']
|
|
13
|
+
s.homepage = package['homepage']
|
|
14
|
+
s.platform = :ios, "11.0"
|
|
15
|
+
s.source = { :git => "https://github.com/sodyo-ltd/SodyoSDKPod", :tag => "3.54.24" }
|
|
16
|
+
s.source_files = "ios/**/*.{h,m}"
|
|
17
|
+
s.requires_arc = true
|
|
18
|
+
|
|
19
|
+
s.dependency "React"
|
|
20
|
+
s.dependency "SodyoSDK", "3.54.24"
|
|
21
|
+
end
|
|
22
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
def DEFAULT_COMPILE_SDK_VERSION = 24
|
|
4
|
+
def DEFAULT_BUILD_TOOLS_VERSION = "25.0.2"
|
|
5
|
+
def DEFAULT_TARGET_SDK_VERSION = 22
|
|
6
|
+
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
jcenter()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath 'com.android.tools.build:gradle:1.3.1'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? project.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
|
|
22
|
+
buildToolsVersion project.hasProperty('buildToolsVersion') ? project.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
|
|
23
|
+
|
|
24
|
+
defaultConfig {
|
|
25
|
+
minSdkVersion 16
|
|
26
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? project.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
|
|
27
|
+
versionCode 2
|
|
28
|
+
versionName "1.1"
|
|
29
|
+
multiDexEnabled true
|
|
30
|
+
}
|
|
31
|
+
lintOptions {
|
|
32
|
+
abortOnError false
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
packagingOptions {
|
|
36
|
+
exclude "META-INF/DEPENDENCIES.txt"
|
|
37
|
+
exclude "META-INF/LICENSE.txt"
|
|
38
|
+
exclude "META-INF/NOTICE.txt"
|
|
39
|
+
exclude "META-INF/NOTICE"
|
|
40
|
+
exclude "META-INF/LICENSE"
|
|
41
|
+
exclude "META-INF/DEPENDENCIES"
|
|
42
|
+
exclude "META-INF/notice.txt"
|
|
43
|
+
exclude "META-INF/license.txt"
|
|
44
|
+
exclude "META-INF/dependencies.txt"
|
|
45
|
+
exclude "META-INF/LGPL2.1"
|
|
46
|
+
exclude "META-INF/ASL2.0"
|
|
47
|
+
exclude "META-INF/maven/com.google.guava/guava/pom.properties"
|
|
48
|
+
exclude "META-INF/maven/com.google.guava/guava/pom.xml"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
repositories {
|
|
53
|
+
mavenCentral()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
dependencies {
|
|
57
|
+
implementation ('com.facebook.react:react-native:+')
|
|
58
|
+
implementation ('com.sodyo:sodyo-android-sdk:3.54.30') {
|
|
59
|
+
transitive = true
|
|
60
|
+
exclude group: 'com.parse.bolts', module: 'bolts-android'
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConversionUtil.java
|
|
3
|
+
* react-native-eval
|
|
4
|
+
* <p>
|
|
5
|
+
* Created by Andy Prock on 9/24/15.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
package com.sodyo.RNSodyoSDK;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.ReadableType;
|
|
13
|
+
|
|
14
|
+
import java.util.ArrayList;
|
|
15
|
+
import java.util.HashMap;
|
|
16
|
+
import java.util.List;
|
|
17
|
+
import java.util.Map;
|
|
18
|
+
|
|
19
|
+
import javax.annotation.Nullable;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Helper utilities to convert from react-native types to POJOs
|
|
23
|
+
*/
|
|
24
|
+
public final class ConversionUtil {
|
|
25
|
+
/**
|
|
26
|
+
* toObject extracts a value from a {@link ReadableMap} by its key,
|
|
27
|
+
* and returns a POJO representing that object.
|
|
28
|
+
*
|
|
29
|
+
* @param readableMap The Map to containing the value to be converted
|
|
30
|
+
* @param key The key for the value to be converted
|
|
31
|
+
* @return The converted POJO
|
|
32
|
+
*/
|
|
33
|
+
public static Object toObject(@Nullable ReadableMap readableMap, String key) {
|
|
34
|
+
if (readableMap == null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
Object result;
|
|
39
|
+
|
|
40
|
+
ReadableType readableType = readableMap.getType(key);
|
|
41
|
+
switch (readableType) {
|
|
42
|
+
case Null:
|
|
43
|
+
result = key;
|
|
44
|
+
break;
|
|
45
|
+
case Boolean:
|
|
46
|
+
result = readableMap.getBoolean(key);
|
|
47
|
+
break;
|
|
48
|
+
case Number:
|
|
49
|
+
// Can be int or double.
|
|
50
|
+
double tmp = readableMap.getDouble(key);
|
|
51
|
+
if (tmp == (int) tmp) {
|
|
52
|
+
result = (int) tmp;
|
|
53
|
+
} else {
|
|
54
|
+
result = tmp;
|
|
55
|
+
}
|
|
56
|
+
break;
|
|
57
|
+
case String:
|
|
58
|
+
result = readableMap.getString(key);
|
|
59
|
+
break;
|
|
60
|
+
case Map:
|
|
61
|
+
result = toMap(readableMap.getMap(key));
|
|
62
|
+
break;
|
|
63
|
+
case Array:
|
|
64
|
+
result = toList(readableMap.getArray(key));
|
|
65
|
+
break;
|
|
66
|
+
default:
|
|
67
|
+
throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* toMap converts a {@link ReadableMap} into a HashMap.
|
|
75
|
+
*
|
|
76
|
+
* @param readableMap The ReadableMap to be conveted.
|
|
77
|
+
* @return A HashMap containing the data that was in the ReadableMap.
|
|
78
|
+
*/
|
|
79
|
+
public static Map<String, Object> toMap(@Nullable ReadableMap readableMap) {
|
|
80
|
+
if (readableMap == null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
com.facebook.react.bridge.ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
|
85
|
+
if (!iterator.hasNextKey()) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
Map<String, Object> result = new HashMap<>();
|
|
90
|
+
while (iterator.hasNextKey()) {
|
|
91
|
+
String key = iterator.nextKey();
|
|
92
|
+
result.put(key, toObject(readableMap, key));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* toFlatMap converts a {@link ReadableMap} into a HashMap<string, string>.
|
|
100
|
+
*
|
|
101
|
+
* @param readableMap The ReadableMap to be conveted.
|
|
102
|
+
* @return A HashMap containing the data that was in the ReadableMap.
|
|
103
|
+
*/
|
|
104
|
+
public static Map<String, String> toFlatMap(@Nullable ReadableMap readableMap) {
|
|
105
|
+
if (readableMap == null) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
com.facebook.react.bridge.ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
|
|
110
|
+
if (!iterator.hasNextKey()) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
Map<String, String> result = new HashMap<>();
|
|
115
|
+
while (iterator.hasNextKey()) {
|
|
116
|
+
String key = iterator.nextKey();
|
|
117
|
+
result.put(key, readableMap.getString(key));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* toList converts a {@link ReadableArray} into an ArrayList.
|
|
125
|
+
*
|
|
126
|
+
* @param readableArray The ReadableArray to be conveted.
|
|
127
|
+
* @return An ArrayList containing the data that was in the ReadableArray.
|
|
128
|
+
*/
|
|
129
|
+
public static List<Object> toList(@Nullable ReadableArray readableArray) {
|
|
130
|
+
if (readableArray == null) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
List<Object> result = new ArrayList<>(readableArray.size());
|
|
135
|
+
for (int index = 0; index < readableArray.size(); index++) {
|
|
136
|
+
ReadableType readableType = readableArray.getType(index);
|
|
137
|
+
switch (readableType) {
|
|
138
|
+
case Null:
|
|
139
|
+
result.add(String.valueOf(index));
|
|
140
|
+
break;
|
|
141
|
+
case Boolean:
|
|
142
|
+
result.add(readableArray.getBoolean(index));
|
|
143
|
+
break;
|
|
144
|
+
case Number:
|
|
145
|
+
// Can be int or double.
|
|
146
|
+
double tmp = readableArray.getDouble(index);
|
|
147
|
+
if (tmp == (int) tmp) {
|
|
148
|
+
result.add((int) tmp);
|
|
149
|
+
} else {
|
|
150
|
+
result.add(tmp);
|
|
151
|
+
}
|
|
152
|
+
break;
|
|
153
|
+
case String:
|
|
154
|
+
result.add(readableArray.getString(index));
|
|
155
|
+
break;
|
|
156
|
+
case Map:
|
|
157
|
+
result.add(toMap(readableArray.getMap(index)));
|
|
158
|
+
break;
|
|
159
|
+
case Array:
|
|
160
|
+
result = toList(readableArray.getArray(index));
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
throw new IllegalArgumentException("Could not convert object with index: " + index + ".");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
package com.sodyo.RNSodyoSDK;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactContext;
|
|
6
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
7
|
+
import com.facebook.react.bridge.Callback;
|
|
8
|
+
import com.facebook.react.bridge.WritableMap;
|
|
9
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
10
|
+
import com.facebook.react.bridge.Arguments;
|
|
11
|
+
import com.facebook.react.bridge.ActivityEventListener;
|
|
12
|
+
import com.facebook.react.bridge.BaseActivityEventListener;
|
|
13
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
14
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
15
|
+
|
|
16
|
+
import java.util.HashMap;
|
|
17
|
+
import java.util.Map;
|
|
18
|
+
|
|
19
|
+
import javax.annotation.Nullable;
|
|
20
|
+
|
|
21
|
+
import android.util.Log;
|
|
22
|
+
import android.content.Intent;
|
|
23
|
+
import android.app.Application;
|
|
24
|
+
import android.app.Activity;
|
|
25
|
+
import android.graphics.Color;
|
|
26
|
+
|
|
27
|
+
import org.json.JSONObject;
|
|
28
|
+
|
|
29
|
+
import com.sodyo.sdk.Sodyo;
|
|
30
|
+
import com.sodyo.sdk.SodyoInitCallback;
|
|
31
|
+
import com.sodyo.sdk.SodyoScannerActivity;
|
|
32
|
+
import com.sodyo.sdk.SodyoScannerCallback;
|
|
33
|
+
import com.sodyo.sdk.SodyoMarkerContentCallback;
|
|
34
|
+
|
|
35
|
+
public class RNSodyoSdkModule extends ReactContextBaseJavaModule {
|
|
36
|
+
public static enum SodyoEnv {
|
|
37
|
+
DEV(3),
|
|
38
|
+
QA(0),
|
|
39
|
+
PROD(1);
|
|
40
|
+
|
|
41
|
+
private int value;
|
|
42
|
+
|
|
43
|
+
private SodyoEnv(int value) {
|
|
44
|
+
this.value = value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public int getValue() {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private static final int SODYO_SCANNER_REQUEST_CODE = 2222;
|
|
53
|
+
|
|
54
|
+
private static final String TAG = "SodyoSDK";
|
|
55
|
+
|
|
56
|
+
private final ReactApplicationContext reactContext;
|
|
57
|
+
|
|
58
|
+
private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
|
|
59
|
+
|
|
60
|
+
@Override
|
|
61
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent intent) {
|
|
62
|
+
Log.i(TAG, "onActivityResult()");
|
|
63
|
+
|
|
64
|
+
if (requestCode == SODYO_SCANNER_REQUEST_CODE) {
|
|
65
|
+
sendEvent("EventCloseSodyoScanner", null);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
public RNSodyoSdkModule(ReactApplicationContext reactContext) {
|
|
71
|
+
super(reactContext);
|
|
72
|
+
this.reactContext = reactContext;
|
|
73
|
+
this.reactContext.addActivityEventListener(mActivityEventListener);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
public String getName() {
|
|
78
|
+
return "RNSodyoSdk";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private class SodyoCallback implements SodyoScannerCallback, SodyoInitCallback, SodyoMarkerContentCallback {
|
|
82
|
+
|
|
83
|
+
private Callback successCallback;
|
|
84
|
+
private Callback errorCallback;
|
|
85
|
+
private boolean isCallbackUsed;
|
|
86
|
+
|
|
87
|
+
public SodyoCallback(Callback successCallback, Callback errorCallback) {
|
|
88
|
+
this.successCallback = successCallback;
|
|
89
|
+
this.errorCallback = errorCallback;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* SodyoInitCallback implementation
|
|
94
|
+
*/
|
|
95
|
+
public void onSodyoAppLoadSuccess() {
|
|
96
|
+
String message = "onSodyoAppLoadSuccess";
|
|
97
|
+
Log.i(TAG, message);
|
|
98
|
+
|
|
99
|
+
if (this.successCallback == null || this.isCallbackUsed) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this.successCallback.invoke();
|
|
104
|
+
this.isCallbackUsed = true;
|
|
105
|
+
|
|
106
|
+
SodyoCallback callbackClosure = new SodyoCallback(null, null);
|
|
107
|
+
Sodyo.getInstance().setSodyoScannerCallback(callbackClosure);
|
|
108
|
+
Sodyo.getInstance().setSodyoMarkerContentCallback(callbackClosure);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* SodyoInitCallback implementation
|
|
113
|
+
*/
|
|
114
|
+
public void onSodyoAppLoadFailed(String error) {
|
|
115
|
+
String message = "onSodyoAppLoadFailed. Error=\"" + error + "\"";
|
|
116
|
+
Log.e(TAG, message);
|
|
117
|
+
|
|
118
|
+
if (this.errorCallback == null || this.isCallbackUsed) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.errorCallback.invoke(error);
|
|
123
|
+
this.isCallbackUsed = true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* SodyoInitCallback implementation
|
|
128
|
+
*/
|
|
129
|
+
@Override
|
|
130
|
+
public void sodyoError(Error err) {
|
|
131
|
+
String message = "sodyoError. Error=\"" + err + "\"";
|
|
132
|
+
Log.e(TAG, message);
|
|
133
|
+
|
|
134
|
+
WritableMap params = Arguments.createMap();
|
|
135
|
+
params.putString("error", err.getMessage());
|
|
136
|
+
sendEvent("EventSodyoError", params);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* SodyoScannerCallback implementation
|
|
141
|
+
*/
|
|
142
|
+
@Override
|
|
143
|
+
public void onMarkerDetect(String markerType, String data, String error) {
|
|
144
|
+
Log.i(TAG, "onMarkerDetect()");
|
|
145
|
+
|
|
146
|
+
if (data == null) {
|
|
147
|
+
data = "null";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
String message;
|
|
151
|
+
|
|
152
|
+
if (error == null) {
|
|
153
|
+
message = "SodyoScannerCallback.onMarkerDetect data=\"" + data + "\"";
|
|
154
|
+
Log.i(TAG, message);
|
|
155
|
+
WritableMap params = Arguments.createMap();
|
|
156
|
+
params.putString("data", data);
|
|
157
|
+
sendEvent("EventMarkerDetectSuccess", params);
|
|
158
|
+
} else {
|
|
159
|
+
message = "SodyoScannerCallback.onMarkerDetect data=\"" + data + "\" error=\"" + error + "\"";
|
|
160
|
+
Log.e(TAG, message);
|
|
161
|
+
WritableMap params = Arguments.createMap();
|
|
162
|
+
params.putString("error", error);
|
|
163
|
+
sendEvent("EventMarkerDetectError", params);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* SodyoMarkerContentCallback implementation
|
|
169
|
+
*/
|
|
170
|
+
@Override
|
|
171
|
+
public void onMarkerContent(String markerId, JSONObject data) {
|
|
172
|
+
Log.i(TAG, "onMarkerContent()");
|
|
173
|
+
|
|
174
|
+
WritableMap params = Arguments.createMap();
|
|
175
|
+
params.putString("markerId", markerId);
|
|
176
|
+
|
|
177
|
+
if (data == null) {
|
|
178
|
+
params.putString("data", "{}");
|
|
179
|
+
} else {
|
|
180
|
+
params.putString("data", data.toString());
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
sendEvent("EventMarkerContent", params);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@ReactMethod
|
|
188
|
+
public void init(final String apiKey, Callback successCallback, Callback errorCallback) {
|
|
189
|
+
Log.i(TAG, "init()");
|
|
190
|
+
|
|
191
|
+
if (Sodyo.isInitialized()) {
|
|
192
|
+
Log.i(TAG, "init(): already initialized, ignore");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
final SodyoCallback callbackClosure = new SodyoCallback(successCallback, errorCallback);
|
|
197
|
+
|
|
198
|
+
UiThreadUtil.runOnUiThread(new Runnable() {
|
|
199
|
+
@Override
|
|
200
|
+
public void run() {
|
|
201
|
+
Sodyo.init(
|
|
202
|
+
(Application) reactContext.getApplicationContext(),
|
|
203
|
+
apiKey,
|
|
204
|
+
callbackClosure
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@ReactMethod
|
|
211
|
+
public void start() {
|
|
212
|
+
Log.i(TAG, "start()");
|
|
213
|
+
Intent intent = new Intent(this.reactContext, SodyoScannerActivity.class);
|
|
214
|
+
Activity activity = getCurrentActivity();
|
|
215
|
+
activity.startActivityForResult(intent, SODYO_SCANNER_REQUEST_CODE);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
@ReactMethod
|
|
219
|
+
public void close() {
|
|
220
|
+
Log.i(TAG, "close()");
|
|
221
|
+
Activity activity = getCurrentActivity();
|
|
222
|
+
activity.finishActivity(SODYO_SCANNER_REQUEST_CODE);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@ReactMethod
|
|
226
|
+
public void setUserInfo(ReadableMap userInfo) {
|
|
227
|
+
Log.i(TAG, "setUserInfo()");
|
|
228
|
+
|
|
229
|
+
if(userInfo != null) {
|
|
230
|
+
Sodyo.getInstance().setUserInfo(ConversionUtil.toMap(userInfo));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@ReactMethod
|
|
235
|
+
public void setCustomAdLabel(String label) {
|
|
236
|
+
Log.i(TAG, "setCustomAdLabel()");
|
|
237
|
+
Sodyo.setCustomAdLabel(label);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
@ReactMethod
|
|
241
|
+
public void setAppUserId(String userId) {
|
|
242
|
+
Log.i(TAG, "setAppUserId()");
|
|
243
|
+
Sodyo.setAppUserId(userId);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@ReactMethod
|
|
247
|
+
public void setScannerParams(ReadableMap scannerPreferences) {
|
|
248
|
+
Log.i(TAG, "setScannerParams()");
|
|
249
|
+
Sodyo.setScannerParams(ConversionUtil.toFlatMap(scannerPreferences));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@ReactMethod
|
|
253
|
+
public void addScannerParam(String key, String value) {
|
|
254
|
+
Log.i(TAG, "addScannerParam()");
|
|
255
|
+
Sodyo.addScannerParams(key, value);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
@ReactMethod
|
|
259
|
+
public void setDynamicProfileValue(String key, String value) {
|
|
260
|
+
Log.i(TAG, "setDynamicProfileValue()");
|
|
261
|
+
Sodyo.setDynamicProfileValue(key, value);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@ReactMethod
|
|
265
|
+
public void performMarker(String markerId) {
|
|
266
|
+
Log.i(TAG, "performMarker()");
|
|
267
|
+
Activity activity = getCurrentActivity();
|
|
268
|
+
Sodyo.performMarker(markerId, activity);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@ReactMethod
|
|
272
|
+
public void setSodyoLogoVisible(Boolean isVisible) {
|
|
273
|
+
Log.i(TAG, "setSodyoLogoVisible()");
|
|
274
|
+
Sodyo.setSodyoLogoVisible(isVisible);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@ReactMethod
|
|
278
|
+
private void setEnv(String env) {
|
|
279
|
+
Log.i(TAG, "setEnv:" + env);
|
|
280
|
+
|
|
281
|
+
Map<String, String> params = new HashMap<>();
|
|
282
|
+
String value = String.valueOf(SodyoEnv.valueOf(env.trim().toUpperCase()).getValue());
|
|
283
|
+
params.put("webad_env", value);
|
|
284
|
+
params.put("scanner_QR_code_enabled", "false");
|
|
285
|
+
Sodyo.setScannerParams(params);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private void sendEvent(String eventName, @Nullable WritableMap params) {
|
|
289
|
+
this.reactContext
|
|
290
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
291
|
+
.emit(eventName, params);
|
|
292
|
+
}
|
|
293
|
+
}
|