public void setAutoFocus(boolean state) { if (mCamera != null && mPreviewing) { if (state == mAutoFocus) { return; } mAutoFocus = state; if (mAutoFocus) { if (mSurfaceCreated) { // check if surface created before using autofocus Log.v(TAG, "Starting autofocus"); safeAutoFocus(); } else { scheduleAutoFocus(); // wait 1 sec and then do check again } } else { Log.v(TAG, "Cancelling autofocus"); mCamera.cancelAutoFocus(); } } }
public void showCameraPreview() { if (mCamera != null) { try { mPreviewing = true; setupCameraParameters(); mCamera.setPreviewDisplay(getHolder()); mCamera.setDisplayOrientation(getDisplayOrientation()); mCamera.setOneShotPreviewCallback(mPreviewCallback); mCamera.startPreview(); if (mAutoFocus) { if (mSurfaceCreated) { // check if surface created before using autofocus safeAutoFocus(); } else { scheduleAutoFocus(); // wait 1 sec and then do check again } } } catch (Exception e) { Log.e(TAG, e.toString(), e); } } }
public void run() { if (mCamera != null && mPreviewing && mAutoFocus && mSurfaceCreated) { safeAutoFocus(); } }