diff --git a/.gitignore b/.gitignore index 883e1740..61503b55 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,13 @@ bin/ gen/ +# Android Studio project files # +################################ +*.iml +.idea +.gradle +build/ + # Proguard folder generated by Eclipse proguard/ diff --git a/PointCloudJava/app/build.gradle b/PointCloudJava/app/build.gradle index c72f3c2d..62b05b4c 100644 --- a/PointCloudJava/app/build.gradle +++ b/PointCloudJava/app/build.gradle @@ -39,6 +39,7 @@ if (project.hasProperty("Tango.catkin_devel_prefix")) { dependencies { compile fileTree(dir: external_lib_prefix + '/jar', include: ['**/*.jar']) compile(name: 'TangoUtils', ext: 'aar') + compile (name: 'tango-ux-support-library', ext: 'aar') } repositories{ diff --git a/PointCloudJava/app/src/main/java/com/projecttango/experiments/javapointcloud/PointCloudActivity.java b/PointCloudJava/app/src/main/java/com/projecttango/experiments/javapointcloud/PointCloudActivity.java index 10758053..86f34ccb 100644 --- a/PointCloudJava/app/src/main/java/com/projecttango/experiments/javapointcloud/PointCloudActivity.java +++ b/PointCloudJava/app/src/main/java/com/projecttango/experiments/javapointcloud/PointCloudActivity.java @@ -16,6 +16,8 @@ package com.projecttango.experiments.javapointcloud; +import com.google.atap.tango.ux.UxExceptionEvent; +import com.google.atap.tango.ux.UxExceptionEventListener; import com.google.atap.tangoservice.Tango; import com.google.atap.tangoservice.Tango.OnTangoUpdateListener; import com.google.atap.tangoservice.TangoConfig; @@ -27,6 +29,10 @@ import com.google.atap.tangoservice.TangoPoseData; import com.google.atap.tangoservice.TangoXyzIjData; +import com.google.atap.tango.ux.TangoUx; +import com.google.atap.tango.ux.TangoUxLayout; + + import android.app.Activity; import android.content.Intent; import android.content.pm.PackageInfo; @@ -88,10 +94,62 @@ public class PointCloudActivity extends Activity implements OnClickListener { private String mServiceVersion; private boolean mIsTangoServiceConnected; private TangoPoseData mPose; + + private TangoUx mTangoUx; + private TangoUxLayout mTangoUxLayout; + private static final int UPDATE_INTERVAL_MS = 100; public static Object poseLock = new Object(); public static Object depthLock = new Object(); + + /* + * This is an advanced way of using UX exceptions. In most cases developers can just use the in + * built exception notifications using the Ux Exception layout. In case a developer doesn't want + * to use the default Ux Exception notifications, he can set the UxException listener as shown + * below. + * In this example we are just logging all the ux exceptions to logcat, but in a real app, + * developers should use these exceptions to contextually notify the user and help direct the + * user in using the device in a way Tango service expects it. + */ + private UxExceptionEventListener mUxExceptionListener = new UxExceptionEventListener() { + + @Override + public void onUxExceptionEvent(UxExceptionEvent uxExceptionEvent) { + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_LYING_ON_SURFACE){ + Log.i(TAG, "Device lying on surface "); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_FEW_DEPTH_POINTS){ + Log.i(TAG, "Very few depth points in point cloud " ); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_FEW_FEATURES){ + Log.i(TAG, "Invalid poses in MotionTracking "); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_INCOMPATIBLE_VM){ + Log.i(TAG, "Device not running on ART"); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_MOTION_TRACK_INVALID){ + Log.i(TAG, "Invalid poses in MotionTracking "); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_MOVING_TOO_FAST){ + Log.i(TAG, "Invalid poses in MotionTracking "); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_OVER_EXPOSED){ + Log.i(TAG, "Camera Over Exposed"); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_TANGO_SERVICE_NOT_RESPONDING){ + Log.i(TAG, "TangoService is not responding "); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_TANGO_UPDATE_NEEDED){ + Log.i(TAG, "Device not running on ART"); + } + if(uxExceptionEvent.getType() == UxExceptionEvent.TYPE_UNDER_EXPOSED){ + Log.i(TAG, "Camera Under Exposed " ); + } + + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -121,6 +179,12 @@ protected void onCreate(Bundle savedInstanceState) { mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); + mTangoUx = new TangoUx.Builder(this).build(); + mTangoUxLayout = (TangoUxLayout) findViewById(R.id.layout_tango); + mTangoUx = new TangoUx.Builder(this).setTangoUxLayout(mTangoUxLayout).build(); + mTangoUx.setUxExceptionEventListener(mUxExceptionListener); + + int maxDepthPoints = mConfig.getInt("max_point_cloud_elements"); mRenderer = new PCRenderer(maxDepthPoints); mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view); @@ -145,6 +209,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onPause() { super.onPause(); + mTangoUx.stop(); try { mTango.disconnect(); mIsTangoServiceConnected = false; @@ -156,6 +221,7 @@ protected void onPause() { @Override protected void onResume() { super.onResume(); + mTangoUx.start(); if (!mIsTangoServiceConnected) { startActivityForResult( Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING), @@ -186,9 +252,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { try { mTango.connect(mConfig); mIsTangoServiceConnected = true; - } catch (TangoOutOfDateException e) { - Toast.makeText(getApplicationContext(), R.string.TangoOutOfDateException, - Toast.LENGTH_SHORT).show(); + } catch (TangoOutOfDateException outDateEx) { + if (mTangoUx != null) { + mTangoUx.onTangoOutOfDate(); + } } catch (TangoErrorException e) { Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT) .show(); @@ -264,6 +331,10 @@ private void setTangoListeners() { @Override public void onPoseAvailable(final TangoPoseData pose) { + // Passing in the pose data to UX library produce exceptions. + if (mTangoUx != null) { + mTangoUx.updatePoseStatus(pose.statusCode); + } // Make sure to have atomic access to Tango Pose Data so that // render loop doesn't interfere while Pose call back is updating // the data. @@ -289,6 +360,9 @@ public void onPoseAvailable(final TangoPoseData pose) { @Override public void onXyzIjAvailable(final TangoXyzIjData xyzIj) { + if(mTangoUx!=null){ + mTangoUx.updateXyzCount(xyzIj.xyzCount); + } // Make sure to have atomic access to TangoXyzIjData so that // render loop doesn't interfere while onXYZijAvailable callback is updating // the point cloud data. @@ -322,6 +396,9 @@ public void onXyzIjAvailable(final TangoXyzIjData xyzIj) { @Override public void onTangoEvent(final TangoEvent event) { + if(mTangoUx!=null){ + mTangoUx.onTangoEvent(event); + } runOnUiThread(new Runnable() { @Override public void run() { diff --git a/PointCloudJava/app/src/main/res/layout/activity_jpoint_cloud.xml b/PointCloudJava/app/src/main/res/layout/activity_jpoint_cloud.xml index cec2fef3..c62d15b0 100644 --- a/PointCloudJava/app/src/main/res/layout/activity_jpoint_cloud.xml +++ b/PointCloudJava/app/src/main/res/layout/activity_jpoint_cloud.xml @@ -241,4 +241,8 @@ android:layout_marginRight="5dp" android:paddingRight="5dp" android:text="@string/third_person" /> + \ No newline at end of file diff --git a/PointCloudJava/settings.gradle b/PointCloudJava/settings.gradle index e989940b..9d495b34 100644 --- a/PointCloudJava/settings.gradle +++ b/PointCloudJava/settings.gradle @@ -1,3 +1 @@ -include ':app' -include ':TangoUtils' -project(':TangoUtils').projectDir = new File('../TangoUtils/TangoUtils') \ No newline at end of file +include ':app' \ No newline at end of file diff --git a/TangoReleaseLibs/aar/TangoUtils.aar b/TangoReleaseLibs/aar/TangoUtils.aar index 40b00a12..e84ff9d2 100644 Binary files a/TangoReleaseLibs/aar/TangoUtils.aar and b/TangoReleaseLibs/aar/TangoUtils.aar differ diff --git a/TangoReleaseLibs/aar/tango-ux-support-library.aar b/TangoReleaseLibs/aar/tango-ux-support-library.aar new file mode 100644 index 00000000..ececa3ba Binary files /dev/null and b/TangoReleaseLibs/aar/tango-ux-support-library.aar differ diff --git a/TangoReleaseLibs/jar/tango_java_lib.jar b/TangoReleaseLibs/jar/tango_java_lib.jar new file mode 100644 index 00000000..987a260b Binary files /dev/null and b/TangoReleaseLibs/jar/tango_java_lib.jar differ diff --git a/TangoReleaseLibs/jar/tango_java_lib/tango_java_lib.jar b/TangoReleaseLibs/jar/tango_java_lib/tango_java_lib.jar deleted file mode 100644 index bc1031bd..00000000 Binary files a/TangoReleaseLibs/jar/tango_java_lib/tango_java_lib.jar and /dev/null differ