1
- package com .phantoms . armodapi . android ;
1
+ package com .phantomsxr . armodplugin ;
2
2
3
3
4
4
import android .content .Context ;
16
16
/**
17
17
* AR SDK Activity,To access AR-SDK, you need to inherit this Activity.
18
18
*/
19
- public abstract class AbstractARMODActivity extends UnityPlayerActivity {
19
+ public abstract class BaseARMODActivity extends UnityPlayerActivity {
20
20
21
21
private final String InitSDK = "InitSDK" ;
22
22
private final String FetchByUid = "LaunchARQuery" ;
23
23
private final String LaunchARScanner = "LaunchARScanner" ;
24
24
private final String Dispose = "Dispose" ;
25
- private final String EntryPoint = "EntryPoint" ;
26
25
private final String DoQuit = "doQuit" ;
27
26
private final String CleanCache = "CleanCache" ;
28
27
private final String SetUIInterfaceOrientation = "SetUIInterfaceOrientation" ;
28
+ private ARMODCallbackAPI armodCallbackAPI ;
29
29
30
- public static AbstractARMODActivity instance = null ;
30
+ public static UnityPlayer armodPlayer ;
31
31
32
32
private Class <?> originalActivity ;
33
33
34
+ protected Context context ;
35
+
34
36
@ Override
35
37
protected void onCreate (Bundle savedInstanceState ) {
36
38
super .onCreate (savedInstanceState );
37
- instance = this ;
39
+ armodPlayer = mUnityPlayer ;
40
+ armodCallbackAPI = new ARMODCallbackAPI ();
41
+ context = this ;
38
42
onCreateUI ();
39
43
}
40
44
41
45
@ Override
42
46
protected void onDestroy () {
43
47
super .onDestroy ();
44
48
originalActivity = null ;
45
- instance = null ;
49
+ armodCallbackAPI = null ;
46
50
}
47
51
48
-
49
- //--------------------------------------------------------------------------------------------------------------
50
-
51
52
/**
52
53
* Build the UI on the AR window
53
54
*/
54
55
public abstract void onCreateUI ();
55
56
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 );
117
57
118
58
/**
119
59
* Initialize SDK
@@ -123,47 +63,17 @@ protected void onDestroy() {
123
63
*/
124
64
public void initARMOD (String _appConfigure , Class <?> _activity ) {
125
65
originalActivity = _activity ;
126
- callSDKMethod (InitSDK , _appConfigure );
66
+ Utils . getInstance (). callSDKMethod (InitSDK , _appConfigure );
127
67
}
128
68
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
- }
159
69
160
70
/**
161
71
* Get the Frame layout on the AR window
162
72
*
163
73
* @return Frame Layout
164
74
*/
165
75
public FrameLayout getARMODFrameLayout () {
166
- if (isInitialized ())
76
+ if (Utils . getInstance (). isInitialized ())
167
77
return mUnityPlayer ;
168
78
else
169
79
return null ;
@@ -178,24 +88,54 @@ public LayoutInflater getLayoutInflater() {
178
88
return (LayoutInflater ) this .getSystemService (Context .LAYOUT_INFLATER_SERVICE );
179
89
}
180
90
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
+
181
102
182
103
/**
183
104
* Set the orientation of the current window
184
105
*
185
106
* @param _orientationId Portrait=1; PortraitUpsideDown=2;LandscapeLeft=3;LandscapeRight=4;
186
107
*/
187
108
public void setUIInterfaceOrientation (String _orientationId ) {
188
- callSDKMethod (SetUIInterfaceOrientation , _orientationId );
109
+ Utils . getInstance (). callSDKMethod (SetUIInterfaceOrientation , _orientationId );
189
110
}
190
111
191
112
/**
192
113
* Clear AR cache
193
114
*/
194
115
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 );
196
126
}
197
127
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
+ }
199
139
200
140
/**
201
141
* Listen for Intent events
@@ -208,27 +148,13 @@ private void handleIntent(Intent intent) {
208
148
209
149
if (intent .getExtras ().containsKey (DoQuit ))
210
150
if (mUnityPlayer != null ) {
211
- callSDKMethod (Dispose , "" );
151
+ Utils . getInstance (). callSDKMethod (Dispose , "" );
212
152
finish ();
213
153
}
214
154
}
215
155
216
156
/**
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
232
158
*/
233
159
private void unloadARMODView () {
234
160
Intent intent = new Intent (getApplicationContext (), originalActivity );
@@ -237,15 +163,6 @@ private void unloadARMODView() {
237
163
}
238
164
239
165
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
-
249
166
/**
250
167
* Get a new Intent
251
168
*
@@ -265,8 +182,4 @@ protected void onNewIntent(Intent intent) {
265
182
public void onUnityPlayerUnloaded () {
266
183
unloadARMODView ();
267
184
}
268
-
269
-
270
-
271
- //--------------------------------------------------------------------------------------------------------------
272
185
}
0 commit comments