2828import com .google .atap .tangoservice .TangoCameraPreview ;
2929import com .google .atap .tangoservice .TangoConfig ;
3030import com .google .atap .tangoservice .TangoCoordinateFramePair ;
31+ import com .google .atap .tangoservice .TangoErrorException ;
3132import com .google .atap .tangoservice .TangoEvent ;
33+ import com .google .atap .tangoservice .TangoOutOfDateException ;
3234import com .google .atap .tangoservice .TangoPoseData ;
3335import com .google .atap .tangoservice .TangoXyzIjData ;
3436
@@ -48,7 +50,6 @@ public class MainActivity extends Activity {
4850 private TangoCameraPreview tangoCameraPreview ;
4951 private Tango mTango ;
5052 private boolean mIsConnected ;
51- private boolean mIsPermissionGranted ;
5253
5354 @ Override
5455 protected void onCreate (Bundle savedInstanceState ) {
@@ -61,33 +62,17 @@ protected void onCreate(Bundle savedInstanceState) {
6162 setContentView (tangoCameraPreview );
6263 }
6364
64- @ Override
65- protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
66- // Check which request we're responding to
67- if (requestCode == Tango .TANGO_INTENT_ACTIVITYCODE ) {
68- // Make sure the request was successful
69- if (resultCode == RESULT_CANCELED ) {
70- Toast .makeText (this , "Motion Tracking Permissions Required!" ,
71- Toast .LENGTH_SHORT ).show ();
72- finish ();
73- } else {
74- startCameraPreview ();
75- mIsPermissionGranted = true ;
76- }
77- }
78- }
79-
8065 // Camera Preview
8166 private void startCameraPreview () {
82- // Connect to color camera
67+ // Connect to color camera
8368 tangoCameraPreview .connectToTangoCamera (mTango ,
8469 TangoCameraIntrinsics .TANGO_CAMERA_COLOR );
8570 // Use default configuration for Tango Service.
8671 TangoConfig config = mTango .getConfig (TangoConfig .CONFIG_TYPE_DEFAULT );
8772 mTango .connect (config );
8873 mIsConnected = true ;
89-
90- // No need to add any coordinate frame pairs since we are not using
74+
75+ // No need to add any coordinate frame pairs since we are not using
9176 // pose data. So just initialize.
9277 ArrayList <TangoCoordinateFramePair > framePairs = new ArrayList <TangoCoordinateFramePair >();
9378 mTango .connectListener (framePairs , new OnTangoUpdateListener () {
@@ -98,9 +83,9 @@ public void onPoseAvailable(TangoPoseData pose) {
9883
9984 @ Override
10085 public void onFrameAvailable (int cameraId ) {
101-
102- // Check if the frame available is for the camera we want and
103- // update its frame on the camera preview.
86+
87+ // Check if the frame available is for the camera we want and
88+ // update its frame on the camera preview.
10489 if (cameraId == TangoCameraIntrinsics .TANGO_CAMERA_COLOR ) {
10590 tangoCameraPreview .onFrameAvailable ();
10691 }
@@ -131,8 +116,15 @@ protected void onPause() {
131116 @ Override
132117 protected void onResume () {
133118 super .onResume ();
134- if (!mIsConnected && mIsPermissionGranted ) {
135- startCameraPreview ();
119+ try {
120+ if (!mIsConnected ) {
121+ startCameraPreview ();
122+ }
123+ } catch (TangoOutOfDateException e ) {
124+ Toast .makeText (getApplicationContext (), R .string .TangoOutOfDateException ,
125+ Toast .LENGTH_SHORT ).show ();
126+ } catch (TangoErrorException e ) {
127+ Toast .makeText (getApplicationContext (), R .string .TangoError , Toast .LENGTH_SHORT ).show ();
136128 }
137129 }
138130}
0 commit comments