From 1b4539a0dfaf8dc5ecc86fcbaef7e31ee7f71745 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Thu, 17 Mar 2016 22:37:59 -0400 Subject: [PATCH] Tango: added asking Motion Tracking permission --- .../com/introlab/rtabmap/RTABMapActivity.java | 52 +++++++++++++++---- 1 file changed, 42 insertions(+), 10 deletions(-) diff --git a/app/android/src/com/introlab/rtabmap/RTABMapActivity.java b/app/android/src/com/introlab/rtabmap/RTABMapActivity.java index 11fb354640..d02135f67c 100644 --- a/app/android/src/com/introlab/rtabmap/RTABMapActivity.java +++ b/app/android/src/com/introlab/rtabmap/RTABMapActivity.java @@ -35,6 +35,8 @@ import android.widget.TextView; import android.widget.Toast; +import com.google.atap.tangoservice.Tango; + // The main activity of the application. This activity shows debug information // and a glSurfaceView that renders graphic content. public class RTABMapActivity extends Activity implements OnClickListener { @@ -116,7 +118,7 @@ protected void onCreate(Bundle savedInstanceState) { Toast.makeText(this, "Tango Core out dated, please update in Play Store", Toast.LENGTH_LONG).show(); finish(); return; - } + } mOpenedDatabasePath = ""; mTempDatabasePath = ""; @@ -149,21 +151,51 @@ protected void onCreate(Bundle savedInstanceState) { RTABMapLib.initialize(this); RTABMapLib.openDatabase(mTempDatabasePath); } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // Check which request we're responding to + if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) { + // Make sure the request was successful + if (resultCode == RESULT_CANCELED) { + Toast.makeText(this, "Motion Tracking Permissions Required!", + Toast.LENGTH_SHORT).show(); + finish(); + } + } + } @Override protected void onResume() { super.onResume(); - mGLView.onResume(); - mTotalLoopClosures = 0; - if(mItemOpen != null) - { - mItemOpen.setEnabled(false); - mItemPause.setChecked(false); - mItemSave.setEnabled(false); - mItemExport.setEnabled(false); + Log.i(TAG, String.format("onResume()")); + + if (Tango.hasPermission(this, Tango.PERMISSIONTYPE_MOTION_TRACKING)) { + + mGLView.onResume(); + + mTotalLoopClosures = 0; + if(mItemOpen != null) + { + mItemOpen.setEnabled(false); + mItemPause.setChecked(false); + mItemSave.setEnabled(false); + mItemExport.setEnabled(false); + } + + if(RTABMapLib.onResume()!=0) + { + Toast.makeText(getApplicationContext(), + String.format("Failed to connect with Tango!"), Toast.LENGTH_SHORT).show(); + } + + } else { + Log.i(TAG, String.format("Asking for motion tracking permission")); + startActivityForResult( + Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING), + Tango.TANGO_INTENT_ACTIVITYCODE); } - RTABMapLib.onResume(); } @Override