Skip to content

Commit

Permalink
update to v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantomxm2021 committed Sep 6, 2021
1 parent 67d4e91 commit 75b2d86
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 140 deletions.
Binary file not shown.
18 changes: 18 additions & 0 deletions Android/com/phantomsxr/armodplugin/ARMODEventListener.java
Original file line number Diff line number Diff line change
@@ -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();
}
6 changes: 6 additions & 0 deletions Android/com/phantomsxr/armodplugin/AndroidCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.phantomsxr.armodplugin;


public interface AndroidCallback{
public void TryAcquireInformationCallback(String _info);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.phantoms.armodapi.android;
package com.phantomsxr.armodplugin;


import android.content.Context;
Expand All @@ -16,104 +16,44 @@
/**
* 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();
}

@Override
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
Expand All @@ -123,47 +63,17 @@ 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
*
* @return Frame Layout
*/
public FrameLayout getARMODFrameLayout() {
if (isInitialized())
if (Utils.getInstance().isInitialized())
return mUnityPlayer;
else
return null;
Expand All @@ -178,24 +88,54 @@ 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
*
* @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
Expand All @@ -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);
Expand All @@ -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
*
Expand All @@ -265,8 +182,4 @@ protected void onNewIntent(Intent intent) {
public void onUnityPlayerUnloaded() {
unloadARMODView();
}



//--------------------------------------------------------------------------------------------------------------
}
58 changes: 58 additions & 0 deletions Android/com/phantomsxr/armodplugin/Utils.java
Original file line number Diff line number Diff line change
@@ -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<ARMODEventListener> mARMODEventListeners = new CopyOnWriteArraySet<ARMODEventListener>();

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);
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion iOS/ARMODCommunicationLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/*!
Expand Down
Loading

0 comments on commit 75b2d86

Please sign in to comment.