private void startCameraSnappingThread() { mCameraThread = new Thread() { @Override public void run() { super.run(); while (isSnapping) { Log.d(LOG_TAG, "Attempting to take picture now."); try { // // http://stackoverflow.com/questions/15623944/how-to-autofocus-android-camera-automatically mCamera.autoFocus( new Camera.AutoFocusCallback() { public void onAutoFocus(boolean success, Camera camera) { if (success) { mCamera.takePicture(null, null, mPicture); } } }); runOnUiThread( new Runnable() { @Override public void run() { mNumberOfSnapsTaken++; mNumSnapET.setText(String.valueOf(mNumberOfSnapsTaken)); } }); } catch (Exception e) { e.printStackTrace(); Log.d(LOG_TAG, e.getMessage()); } try { sleep(mTimeLapseDelay); } catch (Exception e) { e.printStackTrace(); Log.d(LOG_TAG, "Not sleeping very well" + e.getMessage()); } Log.d(LOG_TAG, "NUMBER OF SNAPS: " + mNumberOfSnapsTaken); } } }; mCameraThread.start(); // Once the picture thread is running and if the network exists, start sending the pictures! // and listening for direction responses. if (testConnectivity()) { mSnapDisbatcher.start(); mDirectionListener.start(); } else { Toast.makeText(getApplicationContext(), "No network connection.", Toast.LENGTH_LONG).show(); stopSnapping(); } }
private void stopSnapping() { Log.d(LOG_TAG, "stopSnapping"); isSnapping = false; mFlightDuraChrono.stop(); mDurationOfFlight = SystemClock.elapsedRealtime() - mFlightDuraChrono.getBase(); if (mCamera != null) { mCamera.release(); mCamera = null; } mSnapDisbatcher.stopDisbatching(); mDirectionListener.stopListening(); Intent resultIntent = new Intent(); resultIntent.putExtra(mRes.getString(R.string.intent_extra_flight_duration), mDurationOfFlight); resultIntent.putExtra(mRes.getString(R.string.intent_extra_snap_count), mNumberOfSnapsTaken); setResult(RESULT_OK, resultIntent); finish(); }