Skip to content

Commit 75b2d86

Browse files
committedSep 6, 2021
update to v0.0.4
1 parent 67d4e91 commit 75b2d86

16 files changed

+138
-140
lines changed
 
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.phantomsxr.armodplugin;
2+
3+
public interface ARMODEventListener {
4+
void onDeviceNotSupport();
5+
void onAddLoadingOverlay();
6+
void onUpdateLoadingProgress(float progress);
7+
void onRemoveLoadingOverlay();
8+
void onThrowException(String errorMsg,int errorCode);
9+
void onNeedInstallARCoreService();
10+
void onSdkInitialized();
11+
void onOpenBuiltInBrowser(String url);
12+
void onRecognitionStart();
13+
void onRecognitionComplete();
14+
void onTryAcquireInformation(String opTag,AndroidCallback androidCallback);
15+
void onPackageSizeMoreThanPresetSize(String currentSize,String presetSize);
16+
void onARMODExit();
17+
void onARMODLaunch();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.phantomsxr.armodplugin;
2+
3+
4+
public interface AndroidCallback{
5+
public void TryAcquireInformationCallback(String _info);
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.phantoms.armodapi.android;
1+
package com.phantomsxr.armodplugin;
22

33

44
import android.content.Context;
@@ -16,104 +16,44 @@
1616
/**
1717
* AR SDK Activity,To access AR-SDK, you need to inherit this Activity.
1818
*/
19-
public abstract class AbstractARMODActivity extends UnityPlayerActivity {
19+
public abstract class BaseARMODActivity extends UnityPlayerActivity {
2020

2121
private final String InitSDK = "InitSDK";
2222
private final String FetchByUid = "LaunchARQuery";
2323
private final String LaunchARScanner = "LaunchARScanner";
2424
private final String Dispose = "Dispose";
25-
private final String EntryPoint = "EntryPoint";
2625
private final String DoQuit = "doQuit";
2726
private final String CleanCache = "CleanCache";
2827
private final String SetUIInterfaceOrientation = "SetUIInterfaceOrientation";
28+
private ARMODCallbackAPI armodCallbackAPI;
2929

30-
public static AbstractARMODActivity instance = null;
30+
public static UnityPlayer armodPlayer;
3131

3232
private Class<?> originalActivity;
3333

34+
protected Context context;
35+
3436
@Override
3537
protected void onCreate(Bundle savedInstanceState) {
3638
super.onCreate(savedInstanceState);
37-
instance = this;
39+
armodPlayer = mUnityPlayer;
40+
armodCallbackAPI = new ARMODCallbackAPI();
41+
context = this;
3842
onCreateUI();
3943
}
4044

4145
@Override
4246
protected void onDestroy() {
4347
super.onDestroy();
4448
originalActivity = null;
45-
instance = null;
49+
armodCallbackAPI = null;
4650
}
4751

48-
49-
//--------------------------------------------------------------------------------------------------------------
50-
5152
/**
5253
* Build the UI on the AR window
5354
*/
5455
public abstract void onCreateUI();
5556

56-
/**
57-
* When the device does not support AR-SDK, execute this method
58-
*
59-
*/
60-
abstract public void deviceNotSupport();
61-
62-
/**
63-
* This method is executed when the resource is loaded.
64-
*/
65-
abstract public void removeLoadingOverlay();
66-
67-
/**
68-
* Download resource progress
69-
*/
70-
abstract public void updateLoadingProgress(float _progressValue);
71-
72-
/**
73-
* Start loading resources will execute the method
74-
*/
75-
abstract public void addLoadingOverlay();
76-
77-
78-
/**
79-
* The method will be executed if an exception occurs
80-
*
81-
* @param _error SDK error string
82-
* @param _errorCode Error code
83-
*/
84-
abstract public void throwException(String _error,int _errorCode);
85-
86-
/**
87-
* The device supports AR SDK, but AR Service needs to be installed
88-
*/
89-
abstract public void needInstallARCoreService();
90-
91-
/**
92-
* Use the APP built-in browser to open the specified link
93-
* @param _url url string
94-
*/
95-
abstract public void openBuiltInBrowser(String _url);
96-
97-
/**
98-
* The algorithm of AR is initialized
99-
*/
100-
abstract public void sdkInitialized();
101-
102-
/**
103-
* Recognized successfully
104-
*/
105-
abstract public void recognitionComplete();
106-
107-
/**
108-
* Start to recognize
109-
*/
110-
abstract public void recognitionStart();
111-
112-
/**
113-
* Get device information
114-
* @param _opTag The type of operation request sent by the sdk
115-
*/
116-
abstract public String tryAcquireInformation(String _opTag);
11757

11858
/**
11959
* Initialize SDK
@@ -123,47 +63,17 @@ protected void onDestroy() {
12363
*/
12464
public void initARMOD(String _appConfigure, Class<?> _activity) {
12565
originalActivity = _activity;
126-
callSDKMethod(InitSDK, _appConfigure);
66+
Utils.getInstance().callSDKMethod(InitSDK, _appConfigure);
12767
}
12868

129-
/**
130-
* Query project details by project Id
131-
*
132-
* @param _id Project unique Id
133-
*/
134-
public void fetchProject(String _id) {
135-
new Handler(Looper.getMainLooper())
136-
.postDelayed(() -> callSDKMethod(FetchByUid, _id), 1000);
137-
138-
}
139-
140-
/**
141-
* Start image recognition, the recognition is successful at the beginning of the recognition, please refer to'onRecognized' and'startRecognized'
142-
*/
143-
public void fetchProjectByImage(){
144-
new Handler(Looper.getMainLooper())
145-
.postDelayed(() -> callSDKMethod(LaunchARScanner, ""), 1000);
146-
}
147-
148-
/**
149-
*Uninstall close the current SDK window
150-
*/
151-
public void unloadAndHideARMOD() {
152-
if (isInitialized()) {
153-
Intent intent = new Intent(getApplicationContext(), this.getClass());
154-
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
155-
intent.putExtra(DoQuit, true);
156-
startActivity(intent);
157-
}
158-
}
15969

16070
/**
16171
* Get the Frame layout on the AR window
16272
*
16373
* @return Frame Layout
16474
*/
16575
public FrameLayout getARMODFrameLayout() {
166-
if (isInitialized())
76+
if (Utils.getInstance().isInitialized())
16777
return mUnityPlayer;
16878
else
16979
return null;
@@ -178,24 +88,54 @@ public LayoutInflater getLayoutInflater() {
17888
return (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
17989
}
18090

91+
/**
92+
* Query project details by project Id
93+
*
94+
* @param _id Project unique Id
95+
*/
96+
public void fetchProject(String _id) {
97+
new Handler(Looper.getMainLooper())
98+
.postDelayed(() -> Utils.getInstance().callSDKMethod(FetchByUid, _id), 1000);
99+
100+
}
101+
181102

182103
/**
183104
* Set the orientation of the current window
184105
*
185106
* @param _orientationId Portrait=1; PortraitUpsideDown=2;LandscapeLeft=3;LandscapeRight=4;
186107
*/
187108
public void setUIInterfaceOrientation(String _orientationId) {
188-
callSDKMethod(SetUIInterfaceOrientation, _orientationId);
109+
Utils.getInstance().callSDKMethod(SetUIInterfaceOrientation, _orientationId);
189110
}
190111

191112
/**
192113
* Clear AR cache
193114
*/
194115
public void cleanCache(){
195-
callSDKMethod(CleanCache,"");
116+
Utils.getInstance().callSDKMethod(CleanCache,"");
117+
}
118+
119+
120+
/**
121+
* Start image recognition, the recognition is successful at the beginning of the recognition, please refer to'onRecognized' and'startRecognized'
122+
*/
123+
public void fetchProjectByImage(){
124+
new Handler(Looper.getMainLooper())
125+
.postDelayed(() -> Utils.getInstance().callSDKMethod(LaunchARScanner, ""), 1000);
196126
}
197127

198-
//--------------------------------------------------------------------------------------------------------------
128+
/**
129+
* Uninstall close the current SDK window
130+
*/
131+
public void unloadAndHideARMOD() {
132+
if (Utils.getInstance().isInitialized()) {
133+
Intent intent = new Intent(getApplicationContext(), this.getClass());
134+
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
135+
intent.putExtra(DoQuit, true);
136+
startActivity(intent);
137+
}
138+
}
199139

200140
/**
201141
* Listen for Intent events
@@ -208,27 +148,13 @@ private void handleIntent(Intent intent) {
208148

209149
if (intent.getExtras().containsKey(DoQuit))
210150
if (mUnityPlayer != null) {
211-
callSDKMethod(Dispose, "");
151+
Utils.getInstance().callSDKMethod(Dispose, "");
212152
finish();
213153
}
214154
}
215155

216156
/**
217-
* Call SDK internal method
218-
*
219-
* @param _methodName Call method name
220-
* @param _data transfer data
221-
*/
222-
private void callSDKMethod(String _methodName, String _data) {
223-
if (isInitialized()) {
224-
UnityPlayer.UnitySendMessage(EntryPoint, _methodName, _data);
225-
} else {
226-
System.out.println("You can not send anything message to AR,Because SDK is not initialize");
227-
}
228-
}
229-
230-
/**
231-
*Uninstall AR window
157+
* Uninstall AR window
232158
*/
233159
private void unloadARMODView() {
234160
Intent intent = new Intent(getApplicationContext(), originalActivity);
@@ -237,15 +163,6 @@ private void unloadARMODView() {
237163
}
238164

239165

240-
/**
241-
* Determine whether the SDK is initialized
242-
*
243-
* @return False False means that it has not been initialized, and True means that the initialization is successful
244-
*/
245-
protected boolean isInitialized() {
246-
return mUnityPlayer != null;
247-
}
248-
249166
/**
250167
* Get a new Intent
251168
*
@@ -265,8 +182,4 @@ protected void onNewIntent(Intent intent) {
265182
public void onUnityPlayerUnloaded() {
266183
unloadARMODView();
267184
}
268-
269-
270-
271-
//--------------------------------------------------------------------------------------------------------------
272185
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.phantomsxr.armodplugin;
2+
3+
import com.unity3d.player.UnityPlayer;
4+
import java.util.concurrent.CopyOnWriteArraySet;
5+
6+
public class Utils {
7+
private final String EntryPoint = "EntryPoint";
8+
public final CopyOnWriteArraySet<ARMODEventListener> mARMODEventListeners = new CopyOnWriteArraySet<ARMODEventListener>();
9+
10+
private static Utils instance = null;
11+
private Utils(){}
12+
static{
13+
instance = new Utils();
14+
}
15+
16+
public static Utils getInstance(){
17+
return instance;
18+
}
19+
20+
/**
21+
* Call SDK internal method
22+
*
23+
* @param _methodName Call method name
24+
* @param _data transfer data
25+
*/
26+
public void callSDKMethod(String _methodName, String _data) {
27+
if (isInitialized()) {
28+
UnityPlayer.UnitySendMessage(EntryPoint, _methodName, _data);
29+
} else {
30+
System.out.println("You can not send anything message to AR,Because SDK is not initialize");
31+
}
32+
}
33+
34+
/**
35+
* Determine whether the SDK is initialized
36+
*
37+
* @return False False means that it has not been initialized, and True means that the initialization is successful
38+
*/
39+
public boolean isInitialized() {
40+
return BaseARMODActivity.armodPlayer != null;
41+
}
42+
43+
/**
44+
* Add AR-MOD SDK callback listener to listener array
45+
* @param listener callback listener
46+
*/
47+
public void addARMODEventListener(ARMODEventListener listener){
48+
mARMODEventListeners.add(listener);
49+
}
50+
51+
/**
52+
* Remove AR-MOD SDK callback listener from listener array
53+
* @param listener callback listener
54+
*/
55+
public void removeARMODEventListener(ARMODEventListener listener){
56+
mARMODEventListeners.remove(listener);
57+
}
58+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎iOS/ARMODCommunicationLayer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
/*!
5858
@Discussion Use this method to initialize the SDK
5959
@param appconfigure SDK configuration
60+
@param completed After initialization execute.
6061
*/
61-
- (void) initARMOD:(NSString*) appconfigure;
62+
- (void) initARMOD:(NSString*) appconfigure completed:(void (^)(void)) completed;
6263

6364

6465
/*!

0 commit comments

Comments
 (0)