@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Check which request we're responding to if (requestCode == Tango.TANGO_INTENT_ACTIVITYCODE) { Log.i(TAG, "Triggered"); // Make sure the request was successful if (resultCode == RESULT_CANCELED) { Toast.makeText(this, R.string.motiontrackingpermission, Toast.LENGTH_LONG).show(); finish(); return; } try { setTangoListeners(); } catch (TangoErrorException e) { Toast.makeText(this, R.string.TangoError, Toast.LENGTH_SHORT).show(); } catch (SecurityException e) { Toast.makeText( getApplicationContext(), R.string.motiontrackingpermission, Toast.LENGTH_SHORT) .show(); } try { mTango.connect(mConfig); mIsTangoServiceConnected = true; } catch (TangoOutOfDateException outDateEx) { if (mTangoUx != null) { mTangoUx.showTangoOutOfDate(); } } catch (TangoErrorException e) { Toast.makeText(getApplicationContext(), R.string.TangoError, Toast.LENGTH_SHORT).show(); } setUpExtrinsics(); } }
@Override protected void onDestroy() { super.onDestroy(); vibrator.cancel(); mTangoUx.stop(); mTango.disconnect(); mIsTangoServiceConnected = false; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_point_cloud); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mPoseTextView = (TextView) findViewById(R.id.pose); mQuatTextView = (TextView) findViewById(R.id.quat); mPoseCountTextView = (TextView) findViewById(R.id.posecount); mDeltaTextView = (TextView) findViewById(R.id.deltatime); mTangoEventTextView = (TextView) findViewById(R.id.tangoevent); mPoseStatusTextView = (TextView) findViewById(R.id.status); mPointCountTextView = (TextView) findViewById(R.id.pointCount); mAverageZTextView = (TextView) findViewById(R.id.averageZ); mFrequencyTextView = (TextView) findViewById(R.id.frameDelta); mFirstPersonButton = (Button) findViewById(R.id.first_person_button); mFirstPersonButton.setOnClickListener(this); mThirdPersonButton = (Button) findViewById(R.id.third_person_button); mThirdPersonButton.setOnClickListener(this); mTopDownButton = (Button) findViewById(R.id.top_down_button); mTopDownButton.setOnClickListener(this); mTango = new Tango(this); mConfig = new TangoConfig(); mConfig = mTango.getConfig(TangoConfig.CONFIG_TYPE_CURRENT); mConfig.putBoolean(TangoConfig.KEY_BOOLEAN_DEPTH, true); mTangoUxLayout = (TangoUxLayout) findViewById(R.id.layout_tango); mTangoUx = new TangoUx(this); mTangoUx.setLayout(mTangoUxLayout); mTangoUx.setUxExceptionEventListener(mUxExceptionListener); int maxDepthPoints = mConfig.getInt("max_point_cloud_elements"); mRenderer = new PCRenderer(maxDepthPoints); mGLView = (GLSurfaceView) findViewById(R.id.gl_surface_view); mGLView.setEGLContextClientVersion(2); mGLView.setRenderer(mRenderer); mIsTangoServiceConnected = false; startUIThread(); }
@Override protected void onResume() { super.onResume(); TangoUx.StartParams params = new TangoUx.StartParams(); mTangoUx.start(params); if (!mIsTangoServiceConnected) { startActivityForResult( Tango.getRequestPermissionIntent(Tango.PERMISSIONTYPE_MOTION_TRACKING), Tango.TANGO_INTENT_ACTIVITYCODE); } Log.i(TAG, "onResumed"); }