diff --git a/Android/com/phantomsxr/armodplugin/ARMODCallbackAPI.java b/Android/com/phantomsxr/armodplugin/ARMODCallbackAPI.java new file mode 100644 index 0000000..a77d539 Binary files /dev/null and b/Android/com/phantomsxr/armodplugin/ARMODCallbackAPI.java differ diff --git a/Android/com/phantomsxr/armodplugin/ARMODEventListener.java b/Android/com/phantomsxr/armodplugin/ARMODEventListener.java new file mode 100644 index 0000000..5265916 --- /dev/null +++ b/Android/com/phantomsxr/armodplugin/ARMODEventListener.java @@ -0,0 +1,18 @@ +package com.phantomsxr.armodplugin; + +public interface ARMODEventListener { + void onDeviceNotSupport(); + void onAddLoadingOverlay(); + void onUpdateLoadingProgress(float progress); + void onRemoveLoadingOverlay(); + void onThrowException(String errorMsg,int errorCode); + void onNeedInstallARCoreService(); + void onSdkInitialized(); + void onOpenBuiltInBrowser(String url); + void onRecognitionStart(); + void onRecognitionComplete(); + void onTryAcquireInformation(String opTag,AndroidCallback androidCallback); + void onPackageSizeMoreThanPresetSize(String currentSize,String presetSize); + void onARMODExit(); + void onARMODLaunch(); +} diff --git a/Android/com/phantomsxr/armodplugin/AndroidCallback.java b/Android/com/phantomsxr/armodplugin/AndroidCallback.java new file mode 100644 index 0000000..e7b07fc --- /dev/null +++ b/Android/com/phantomsxr/armodplugin/AndroidCallback.java @@ -0,0 +1,6 @@ +package com.phantomsxr.armodplugin; + + +public interface AndroidCallback{ + public void TryAcquireInformationCallback(String _info); +} \ No newline at end of file diff --git a/Android/com/phantoms/armodapi/android/AbstractARMODActivity.java b/Android/com/phantomsxr/armodplugin/BaseARMODActivity.java similarity index 55% rename from Android/com/phantoms/armodapi/android/AbstractARMODActivity.java rename to Android/com/phantomsxr/armodplugin/BaseARMODActivity.java index 0b3dbec..e86fcd5 100644 --- a/Android/com/phantoms/armodapi/android/AbstractARMODActivity.java +++ b/Android/com/phantomsxr/armodplugin/BaseARMODActivity.java @@ -1,4 +1,4 @@ -package com.phantoms.armodapi.android; +package com.phantomsxr.armodplugin; import android.content.Context; @@ -16,25 +16,29 @@ /** * AR SDK Activity,To access AR-SDK, you need to inherit this Activity. */ -public abstract class AbstractARMODActivity extends UnityPlayerActivity { +public abstract class BaseARMODActivity extends UnityPlayerActivity { private final String InitSDK = "InitSDK"; private final String FetchByUid = "LaunchARQuery"; private final String LaunchARScanner = "LaunchARScanner"; private final String Dispose = "Dispose"; - private final String EntryPoint = "EntryPoint"; private final String DoQuit = "doQuit"; private final String CleanCache = "CleanCache"; private final String SetUIInterfaceOrientation = "SetUIInterfaceOrientation"; + private ARMODCallbackAPI armodCallbackAPI; - public static AbstractARMODActivity instance = null; + public static UnityPlayer armodPlayer; private Class originalActivity; + protected Context context; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - instance = this; + armodPlayer = mUnityPlayer; + armodCallbackAPI = new ARMODCallbackAPI(); + context = this; onCreateUI(); } @@ -42,78 +46,14 @@ protected void onCreate(Bundle savedInstanceState) { protected void onDestroy() { super.onDestroy(); originalActivity = null; - instance = null; + armodCallbackAPI = null; } - - //-------------------------------------------------------------------------------------------------------------- - /** * Build the UI on the AR window */ public abstract void onCreateUI(); - /** - * When the device does not support AR-SDK, execute this method - * - */ - abstract public void deviceNotSupport(); - - /** - * This method is executed when the resource is loaded. - */ - abstract public void removeLoadingOverlay(); - - /** - * Download resource progress - */ - abstract public void updateLoadingProgress(float _progressValue); - - /** - * Start loading resources will execute the method - */ - abstract public void addLoadingOverlay(); - - - /** - * The method will be executed if an exception occurs - * - * @param _error SDK error string - * @param _errorCode Error code - */ - abstract public void throwException(String _error,int _errorCode); - - /** - * The device supports AR SDK, but AR Service needs to be installed - */ - abstract public void needInstallARCoreService(); - - /** - * Use the APP built-in browser to open the specified link - * @param _url url string - */ - abstract public void openBuiltInBrowser(String _url); - - /** - * The algorithm of AR is initialized - */ - abstract public void sdkInitialized(); - - /** - * Recognized successfully - */ - abstract public void recognitionComplete(); - - /** - * Start to recognize - */ - abstract public void recognitionStart(); - - /** - * Get device information - * @param _opTag The type of operation request sent by the sdk - */ - abstract public String tryAcquireInformation(String _opTag); /** * Initialize SDK @@ -123,39 +63,9 @@ protected void onDestroy() { */ public void initARMOD(String _appConfigure, Class _activity) { originalActivity = _activity; - callSDKMethod(InitSDK, _appConfigure); + Utils.getInstance().callSDKMethod(InitSDK, _appConfigure); } - /** - * Query project details by project Id - * - * @param _id Project unique Id - */ - public void fetchProject(String _id) { - new Handler(Looper.getMainLooper()) - .postDelayed(() -> callSDKMethod(FetchByUid, _id), 1000); - - } - - /** - * Start image recognition, the recognition is successful at the beginning of the recognition, please refer to'onRecognized' and'startRecognized' - */ - public void fetchProjectByImage(){ - new Handler(Looper.getMainLooper()) - .postDelayed(() -> callSDKMethod(LaunchARScanner, ""), 1000); - } - - /** - *Uninstall close the current SDK window - */ - public void unloadAndHideARMOD() { - if (isInitialized()) { - Intent intent = new Intent(getApplicationContext(), this.getClass()); - intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - intent.putExtra(DoQuit, true); - startActivity(intent); - } - } /** * Get the Frame layout on the AR window @@ -163,7 +73,7 @@ public void unloadAndHideARMOD() { * @return Frame Layout */ public FrameLayout getARMODFrameLayout() { - if (isInitialized()) + if (Utils.getInstance().isInitialized()) return mUnityPlayer; else return null; @@ -178,6 +88,17 @@ public LayoutInflater getLayoutInflater() { return (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } + /** + * Query project details by project Id + * + * @param _id Project unique Id + */ + public void fetchProject(String _id) { + new Handler(Looper.getMainLooper()) + .postDelayed(() -> Utils.getInstance().callSDKMethod(FetchByUid, _id), 1000); + + } + /** * Set the orientation of the current window @@ -185,17 +106,36 @@ public LayoutInflater getLayoutInflater() { * @param _orientationId Portrait=1; PortraitUpsideDown=2;LandscapeLeft=3;LandscapeRight=4; */ public void setUIInterfaceOrientation(String _orientationId) { - callSDKMethod(SetUIInterfaceOrientation, _orientationId); + Utils.getInstance().callSDKMethod(SetUIInterfaceOrientation, _orientationId); } /** * Clear AR cache */ public void cleanCache(){ - callSDKMethod(CleanCache,""); + Utils.getInstance().callSDKMethod(CleanCache,""); + } + + + /** + * Start image recognition, the recognition is successful at the beginning of the recognition, please refer to'onRecognized' and'startRecognized' + */ + public void fetchProjectByImage(){ + new Handler(Looper.getMainLooper()) + .postDelayed(() -> Utils.getInstance().callSDKMethod(LaunchARScanner, ""), 1000); } - //-------------------------------------------------------------------------------------------------------------- + /** + * Uninstall close the current SDK window + */ + public void unloadAndHideARMOD() { + if (Utils.getInstance().isInitialized()) { + Intent intent = new Intent(getApplicationContext(), this.getClass()); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra(DoQuit, true); + startActivity(intent); + } + } /** * Listen for Intent events @@ -208,27 +148,13 @@ private void handleIntent(Intent intent) { if (intent.getExtras().containsKey(DoQuit)) if (mUnityPlayer != null) { - callSDKMethod(Dispose, ""); + Utils.getInstance().callSDKMethod(Dispose, ""); finish(); } } /** - * Call SDK internal method - * - * @param _methodName Call method name - * @param _data transfer data - */ - private void callSDKMethod(String _methodName, String _data) { - if (isInitialized()) { - UnityPlayer.UnitySendMessage(EntryPoint, _methodName, _data); - } else { - System.out.println("You can not send anything message to AR,Because SDK is not initialize"); - } - } - - /** - *Uninstall AR window + * Uninstall AR window */ private void unloadARMODView() { Intent intent = new Intent(getApplicationContext(), originalActivity); @@ -237,15 +163,6 @@ private void unloadARMODView() { } - /** - * Determine whether the SDK is initialized - * - * @return False False means that it has not been initialized, and True means that the initialization is successful - */ - protected boolean isInitialized() { - return mUnityPlayer != null; - } - /** * Get a new Intent * @@ -265,8 +182,4 @@ protected void onNewIntent(Intent intent) { public void onUnityPlayerUnloaded() { unloadARMODView(); } - - - - //-------------------------------------------------------------------------------------------------------------- } diff --git a/Android/com/phantomsxr/armodplugin/Utils.java b/Android/com/phantomsxr/armodplugin/Utils.java new file mode 100644 index 0000000..9c2a58f --- /dev/null +++ b/Android/com/phantomsxr/armodplugin/Utils.java @@ -0,0 +1,58 @@ +package com.phantomsxr.armodplugin; + +import com.unity3d.player.UnityPlayer; +import java.util.concurrent.CopyOnWriteArraySet; + +public class Utils { + private final String EntryPoint = "EntryPoint"; + public final CopyOnWriteArraySet mARMODEventListeners = new CopyOnWriteArraySet(); + + private static Utils instance = null; + private Utils(){} + static{ + instance = new Utils(); + } + + public static Utils getInstance(){ + return instance; + } + + /** + * Call SDK internal method + * + * @param _methodName Call method name + * @param _data transfer data + */ + public void callSDKMethod(String _methodName, String _data) { + if (isInitialized()) { + UnityPlayer.UnitySendMessage(EntryPoint, _methodName, _data); + } else { + System.out.println("You can not send anything message to AR,Because SDK is not initialize"); + } + } + + /** + * Determine whether the SDK is initialized + * + * @return False False means that it has not been initialized, and True means that the initialization is successful + */ + public boolean isInitialized() { + return BaseARMODActivity.armodPlayer != null; + } + + /** + * Add AR-MOD SDK callback listener to listener array + * @param listener callback listener + */ + public void addARMODEventListener(ARMODEventListener listener){ + mARMODEventListeners.add(listener); + } + + /** + * Remove AR-MOD SDK callback listener from listener array + * @param listener callback listener + */ + public void removeARMODEventListener(ARMODEventListener listener){ + mARMODEventListeners.remove(listener); + } +} diff --git a/Android/libs/ARPresto.aar b/Android/libs/com.phantomsxr-ARPresto-0.0.4.aar similarity index 100% rename from Android/libs/ARPresto.aar rename to Android/libs/com.phantomsxr-ARPresto-0.0.4.aar diff --git a/Android/libs/IngameDebugConsole.aar b/Android/libs/com.phantomsxr-IngameDebugConsole-0.0.4.aar similarity index 100% rename from Android/libs/IngameDebugConsole.aar rename to Android/libs/com.phantomsxr-IngameDebugConsole-0.0.4.aar diff --git a/Android/libs/UnityARCore.aar b/Android/libs/com.phantomsxr-UnityARCore-0.0.4.aar similarity index 100% rename from Android/libs/UnityARCore.aar rename to Android/libs/com.phantomsxr-UnityARCore-0.0.4.aar diff --git a/Android/libs/arcore_client.aar b/Android/libs/com.phantomsxr-arcoreclient-0.0.4.aar similarity index 100% rename from Android/libs/arcore_client.aar rename to Android/libs/com.phantomsxr-arcoreclient-0.0.4.aar diff --git a/Android/libs/nativebindings.aar b/Android/libs/com.phantomsxr-nativebindings-0.0.4.aar similarity index 100% rename from Android/libs/nativebindings.aar rename to Android/libs/com.phantomsxr-nativebindings-0.0.4.aar diff --git a/Android/libs/poseplugin.aar b/Android/libs/com.phantomsxr-poseplugin-0.0.4.aar similarity index 100% rename from Android/libs/poseplugin.aar rename to Android/libs/com.phantomsxr-poseplugin-0.0.4.aar diff --git a/Android/libs/unityLibrary-release.aar b/Android/libs/com.phantomsxr-unityLibrary_release-0.0.4.aar similarity index 78% rename from Android/libs/unityLibrary-release.aar rename to Android/libs/com.phantomsxr-unityLibrary_release-0.0.4.aar index 19300f3..eba0e2c 100644 Binary files a/Android/libs/unityLibrary-release.aar and b/Android/libs/com.phantomsxr-unityLibrary_release-0.0.4.aar differ diff --git a/Android/libs/unityandroidpermissions.aar b/Android/libs/com.phantomsxr-unityandroidpermissions-0.0.4.aar similarity index 100% rename from Android/libs/unityandroidpermissions.aar rename to Android/libs/com.phantomsxr-unityandroidpermissions-0.0.4.aar diff --git a/iOS/ARMODCommunicationLayer.h b/iOS/ARMODCommunicationLayer.h index e4eccb5..9a81855 100644 --- a/iOS/ARMODCommunicationLayer.h +++ b/iOS/ARMODCommunicationLayer.h @@ -57,8 +57,9 @@ /*! @Discussion Use this method to initialize the SDK @param appconfigure SDK configuration + @param completed After initialization execute. */ -- (void) initARMOD:(NSString*) appconfigure; +- (void) initARMOD:(NSString*) appconfigure completed:(void (^)(void)) completed; /*! diff --git a/iOS/ARMODCommunicationLayer.mm b/iOS/ARMODCommunicationLayer.mm index ebf2bc3..69ac9f3 100644 --- a/iOS/ARMODCommunicationLayer.mm +++ b/iOS/ARMODCommunicationLayer.mm @@ -81,7 +81,7 @@ - (void)initARMODModule{ [[self ufw] setDataBundleId: dataBundleId]; - + [[self ufw] registerFrameworkListener: self]; if (ncp!=nil) { @@ -89,13 +89,14 @@ - (void)initARMODModule{ } [[self ufw] runEmbeddedWithArgc: self.selfgArgc argv: self.selfgArgv appLaunchOpts: appLaunchOpts]; - + // set quit handler to change default behavior of exit app [[self ufw] appController].quitHandler = ^(){ NSLog(@"AppController.quitHandler called"); }; - + if (@available(iOS 13.0, *)) { if(originWindow.windowScene != nil){ [[[[self ufw] appController] window] setWindowScene:originWindow.windowScene]; + [[[[self ufw] appController] window] addSubview:self.ufw.appController.rootView]; [[[[self ufw] appController] window] makeKeyAndVisible]; } } @@ -141,11 +142,11 @@ - (void)unloadARMODWindow{ */ - (void)showARMODWindow{ if([self armodIsInitialized]){ - [[self ufw] showUnityWindow]; }else{ NSLog(@"ARMOD is not initialized ,Initialize ARMOD first"); } + } /*! @@ -176,9 +177,10 @@ - (void) connectLaunchOpts:(NSDictionary*) applaunchOpts{ appLaunchOpts = applaunchOpts; } -- (void)initARMOD:(NSString*) appconfigure{ +- (void)initARMOD:(NSString*) appconfigure completed:(void (^)())completed{ [self initARMODModule]; [self callSDKMethod:initApp addData:[appconfigure UTF8String]]; + completed(); } /*! diff --git a/iOS/UnityFramework.framework.zip b/iOS/UnityFramework.framework.zip index 8699904..5d055a7 100644 Binary files a/iOS/UnityFramework.framework.zip and b/iOS/UnityFramework.framework.zip differ