diff options
author | Wu-cheng Li <wuchengli@google.com> | 2011-05-13 14:16:15 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2011-05-23 18:04:20 +0800 |
commit | 04dfecf4f289e7ab888d3ff7f66588783bce2d6b (patch) | |
tree | 6f8eaff7771faeaf8d9e652bd97f0869fc6581de | |
parent | 8cf2f66e4623cf9dd48bdbf9a0fc2d544a64fd32 (diff) | |
download | LegacyCamera-04dfecf4f289e7ab888d3ff7f66588783bce2d6b.zip LegacyCamera-04dfecf4f289e7ab888d3ff7f66588783bce2d6b.tar.gz LegacyCamera-04dfecf4f289e7ab888d3ff7f66588783bce2d6b.tar.bz2 |
Improve touch focus UI.
1. Now users can trigger touch focus if autofocus is already
in progress.
2. Autofocus is triggered in ACTION_UP. So users can drag
the focus rectangle and see exposure change.
bug:3475893
Change-Id: Ifbf586ae5ec2a11c64155e16bd25ae753220f4ce
-rw-r--r-- | src/com/android/camera/Camera.java | 49 | ||||
-rw-r--r-- | src/com/android/camera/ui/FocusRectangle.java | 1 |
2 files changed, 35 insertions, 15 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 790e3ca..da8f20d 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1598,6 +1598,10 @@ public class Camera extends ActivityBase implements View.OnClickListener, mFocusRectangle.showSuccess(); } else if (mCameraState == FOCUS_FAIL) { mFocusRectangle.showFail(); + } else if (mCameraState == IDLE && mFocusArea != null) { + // Users touch on the preview and the rectangle indicates the metering area. + // Either focus area is not supported or autoFocus call is not required. + mFocusRectangle.showStart(); } else { mFocusRectangle.clear(); } @@ -1606,22 +1610,34 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Preview area is touched. Handle touch focus. @Override public boolean onTouch(View v, MotionEvent e) { - if (e.getAction() != MotionEvent.ACTION_DOWN) return false; + if (mPausing || !mFirstTimeInitialized || mCameraState == SNAPSHOT_IN_PROGRESS + || mCameraState == FOCUSING_SNAP_ON_FINISH) { + return false; + } - // Do not trigger touch focus when popup window is dismissed. + // Do not trigger touch focus if popup window is opened. if (collapseCameraControls()) return false; - if (mPausing || !mFirstTimeInitialized || !canTakePicture()) { - return false; + // Check if metering area or focus area is supported. + boolean focusAreaSupported = (mParameters.getMaxNumFocusAreas() > 0 + && (mFocusMode.equals(Parameters.FOCUS_MODE_AUTO) || + mFocusMode.equals(Parameters.FOCUS_MODE_MACRO) || + mFocusMode.equals(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))); + boolean meteringAreaSupported = (mParameters.getMaxNumMeteringAreas() > 0); + if (!focusAreaSupported && !meteringAreaSupported) return false; + + boolean callAutoFocusRequired = false; + if (focusAreaSupported && + (mFocusMode.equals(Parameters.FOCUS_MODE_AUTO) || + mFocusMode.equals(Parameters.FOCUS_MODE_MACRO))) { + callAutoFocusRequired = true; } - // Take a picture if metering area or focus area is supported. - if (mParameters.getMaxNumMeteringAreas() == 0 - && (mParameters.getMaxNumFocusAreas() == 0 - || (!mFocusMode.equals(Parameters.FOCUS_MODE_AUTO) && - !mFocusMode.equals(Parameters.FOCUS_MODE_MACRO) && - !mFocusMode.equals(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)))) { - return false; + // Let users be able to cancel previous touch focus. + if (callAutoFocusRequired && mFocusArea != null && e.getAction() == MotionEvent.ACTION_DOWN + && (mCameraState == FOCUSING || mCameraState == FOCUS_SUCCESS || + mCameraState == FOCUS_FAIL)) { + cancelAutoFocus(); } // Calculate the position of the focus rectangle. @@ -1652,16 +1668,19 @@ public class Camera extends ActivityBase implements View.OnClickListener, // Use margin to set the focus rectangle to the touched area. RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) mFocusRectangle.getLayoutParams(); - p.setMargins(left + mPreviewBorder.getPaddingLeft(), - top + mPreviewBorder.getPaddingTop(), 0, 0); + p.setMargins(left, top, 0, 0); // Disable "center" rule because we no longer want to put it in the center. int[] rules = p.getRules(); rules[RelativeLayout.CENTER_IN_PARENT] = 0; mFocusRectangle.requestLayout(); - // Set the focus area and do autofocus. + // Set the focus area and metering area. setCameraParameters(UPDATE_PARAM_PREFERENCE); - autoFocus(); + if (callAutoFocusRequired && e.getAction() == MotionEvent.ACTION_UP) { + autoFocus(); + } else { // Just show the rectangle in all other cases. + updateFocusUI(); + } return true; } diff --git a/src/com/android/camera/ui/FocusRectangle.java b/src/com/android/camera/ui/FocusRectangle.java index c3f9a51..fe6e7a0 100644 --- a/src/com/android/camera/ui/FocusRectangle.java +++ b/src/com/android/camera/ui/FocusRectangle.java @@ -22,6 +22,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.View; +// A square that indicates the focus area or the metering area. public class FocusRectangle extends View { public FocusRectangle(Context context, AttributeSet attrs) { super(context, attrs); |