diff options
author | Steve Kondik <shade@chemlab.org> | 2013-08-28 14:21:49 +0800 |
---|---|---|
committer | Steve Kondik <shade@chemlab.org> | 2013-12-21 13:24:20 -0800 |
commit | 46339424a455e37f9bac9137bbd96cd57f61deed (patch) | |
tree | 21de84416244ab4cd76a0f4e5a3294eb43130c07 | |
parent | f729b85e12cfa2674048d8cce2f724014b8fc910 (diff) | |
download | android_packages_apps_Camera2-46339424a455e37f9bac9137bbd96cd57f61deed.tar.gz android_packages_apps_Camera2-46339424a455e37f9bac9137bbd96cd57f61deed.tar.bz2 android_packages_apps_Camera2-46339424a455e37f9bac9137bbd96cd57f61deed.zip |
camera: Touch focus support for camcorder
* Available when video snapshots are not supported.
* Original from CodeAurora Forum.
Change-Id: I232c178430db08e7366aa9f91b4926d07e7c225d
-rw-r--r-- | res/values/arrays.xml | 5 | ||||
-rw-r--r-- | src/com/android/camera/VideoController.java | 2 | ||||
-rw-r--r-- | src/com/android/camera/VideoMenu.java | 5 | ||||
-rw-r--r-- | src/com/android/camera/VideoModule.java | 152 | ||||
-rw-r--r-- | src/com/android/camera/VideoUI.java | 50 |
5 files changed, 202 insertions, 12 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml index dc4fec2a9..2d9ef1c9a 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -667,6 +667,11 @@ <item>auto</item> </string-array> + <string-array name="pref_video_focusmode_default_array" translatable="false"> + <item>continuous-video</item> + <item>auto</item> + </string-array> + <!-- Icons for exposure compensation --> <array name="pref_camera_exposure_icons" translatable="false"> <item>@drawable/ic_exposure_n3</item> diff --git a/src/com/android/camera/VideoController.java b/src/com/android/camera/VideoController.java index e84654821..724013940 100644 --- a/src/com/android/camera/VideoController.java +++ b/src/com/android/camera/VideoController.java @@ -39,4 +39,6 @@ public interface VideoController extends OnShutterButtonListener { // Callbacks for camera preview UI events. public void onPreviewUIReady(); public void onPreviewUIDestroyed(); + + public void onScreenSizeChanged(int width, int height, int previewWidth, int previewHeight); } diff --git a/src/com/android/camera/VideoMenu.java b/src/com/android/camera/VideoMenu.java index f0fec3617..94d554792 100644 --- a/src/com/android/camera/VideoMenu.java +++ b/src/com/android/camera/VideoMenu.java @@ -191,9 +191,10 @@ public class VideoMenu extends PieController } // extra settings popup mOtherKeys = new String[] { - CameraSettings.KEY_JPEG_QUALITY, CameraSettings.KEY_VIDEO_ENCODER, - CameraSettings.KEY_AUDIO_ENCODER + CameraSettings.KEY_AUDIO_ENCODER, + CameraSettings.KEY_FOCUS_TIME, + CameraSettings.KEY_JPEG_QUALITY }; item = makeItem(R.drawable.ic_settings_holo_light); item.setLabel(res.getString(R.string.camera_menu_more_label).toUpperCase(locale)); diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java index 84a830fff..6cb8070cc 100644 --- a/src/com/android/camera/VideoModule.java +++ b/src/com/android/camera/VideoModule.java @@ -55,6 +55,7 @@ import android.view.View; import android.view.WindowManager; import android.widget.Toast; +import com.android.camera.CameraManager.CameraAFCallback; import com.android.camera.CameraManager.CameraPictureCallback; import com.android.camera.CameraManager.CameraProxy; import com.android.camera.app.OrientationManager; @@ -76,6 +77,7 @@ import java.util.HashMap; public class VideoModule implements CameraModule, VideoController, + FocusOverlayManager.Listener, CameraPreference.OnPreferenceChangedListener, ShutterButton.OnShutterButtonListener, MediaRecorder.OnErrorListener, @@ -108,6 +110,8 @@ public class VideoModule implements CameraModule, private boolean mPaused; private int mCameraId; private Parameters mParameters; + private boolean mFocusAreaSupported; + private boolean mMeteringAreaSupported; private boolean mIsInReviewMode; private boolean mSnapshotInProgress = false; @@ -165,7 +169,14 @@ public class VideoModule implements CameraModule, private LocationManager mLocationManager; private OrientationManager mOrientationManager; + private final AutoFocusCallback mAutoFocusCallback = + new AutoFocusCallback(); + private int mPendingSwitchCameraId; + + // This handles everything about focus. + private FocusOverlayManager mFocusManager; + private final Handler mHandler = new MainHandler(); private VideoUI mUI; private CameraProxy mCameraDevice; @@ -209,6 +220,7 @@ public class VideoModule implements CameraModule, @Override public void run() { openCamera(); + if (mFocusManager == null) initializeFocusManager(); } } @@ -223,6 +235,9 @@ public class VideoModule implements CameraModule, return; } mParameters = mCameraDevice.getParameters(); + + initializeCapabilities(); + String sceneMode = mParameters.getSceneMode(); if ((null != sceneMode) && (!sceneMode.equals(Parameters.SCENE_MODE_AUTO))){ if (CameraUtil.isSupported(Parameters.SCENE_MODE_AUTO, @@ -299,6 +314,10 @@ public class VideoModule implements CameraModule, private boolean mUnsupportedHFRVideoSize = false; private boolean mUnsupportedHFRVideoCodec = false; + public void onScreenSizeChanged(int width, int height, int previewWidth, int previewHeight) { + if (mFocusManager != null) mFocusManager.setPreviewSize(width, height); + } + // This Handler is used to post message back onto the main thread of the // application private class MainHandler extends Handler { @@ -457,22 +476,72 @@ public class VideoModule implements CameraModule, mPendingSwitchCameraId = -1; } + @Override + public void autoFocus() { + Log.e(TAG, "start autoFocus."); + mCameraDevice.autoFocus(mHandler, mAutoFocusCallback); + } + + @Override + public void cancelAutoFocus() { + if (null != mCameraDevice) { + mCameraDevice.cancelAutoFocus(); + setFocusParameters(); + } + } + + @Override + public boolean capture() { + return true; + } + + @Override + public void startFaceDetection() { + } + + @Override + public void stopFaceDetection() { + } + + @Override + public void setFocusParameters() { + if (mFocusAreaSupported) + mParameters.setFocusAreas(mFocusManager.getFocusAreas()); + if (mMeteringAreaSupported) + mParameters.setMeteringAreas(mFocusManager.getMeteringAreas()); + if (mFocusAreaSupported || mMeteringAreaSupported) { + mParameters.setFocusMode(mFocusManager.getFocusMode()); + mCameraDevice.setParameters(mParameters); + } + } + // SingleTapListener // Preview area is touched. Take a picture. @Override public void onSingleTapUp(View view, int x, int y) { - takeASnapshot(); + boolean snapped = takeASnapshot(); + if (!snapped) { + // Do not trigger touch focus if popup window is opened. + if (mUI.removeTopLevelPopup()) { + return; + } + + // Check if metering area or focus area is supported. + if (mFocusAreaSupported || mMeteringAreaSupported) { + mFocusManager.onSingleTapUp(x, y); + } + } } - private void takeASnapshot() { + private boolean takeASnapshot() { // Only take snapshots if video snapshot is supported by device if (CameraUtil.isVideoSnapshotSupported(mParameters) && !mIsVideoCaptureIntent) { if (!mMediaRecorderRecording || mPaused || mSnapshotInProgress) { - return; + return false; } MediaSaveService s = mActivity.getMediaSaveService(); if (s == null || s.isQueueFull()) { - return; + return false; } // Set rotation and gps data. @@ -489,7 +558,10 @@ public class VideoModule implements CameraModule, mSnapshotInProgress = true; UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_CAPTURE_DONE, "VideoSnapshot"); + + return true; } + return false; } @Override @@ -705,6 +777,19 @@ public class VideoModule implements CameraModule, } } + private final class AutoFocusCallback + implements CameraAFCallback { + @Override + public void onAutoFocus( + boolean focused, CameraProxy camera) { + Log.v(TAG, "AutoFocusCallback, mPaused=" + mPaused); + if (mPaused) return; + + //setCameraState(IDLE); + mFocusManager.onAutoFocus(focused, false); + } + } + private void readVideoPreferences() { // The preference stores values from ListPreference and is thus string type for all values. // We need to convert it to int manually. @@ -877,6 +962,9 @@ public class VideoModule implements CameraModule, private void setDisplayOrientation() { mDisplayRotation = CameraUtil.getDisplayRotation(mActivity); mCameraDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, mCameraId); + if (mFocusManager != null) { + mFocusManager.setDisplayOrientation(mCameraDisplayOrientation); + } // Change the camera display orientation if (mCameraDevice != null) { mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation); @@ -935,6 +1023,8 @@ public class VideoModule implements CameraModule, throw new RuntimeException("startPreview failed", ex); } mStartPrevPending = false; + + mFocusManager.onPreviewStarted(); } private void onPreviewStarted() { @@ -945,6 +1035,8 @@ public class VideoModule implements CameraModule, public void stopPreview() { mStopPrevPending = true; + if (mFocusManager != null) mFocusManager.onPreviewStopped(); + if (!mPreviewing) { mStopPrevPending = false; return; @@ -966,6 +1058,7 @@ public class VideoModule implements CameraModule, mCameraDevice = null; mPreviewing = false; mSnapshotInProgress = false; + mFocusManager.onCameraReleased(); } private void releasePreviewResources() { @@ -1014,6 +1107,28 @@ public class VideoModule implements CameraModule, @Override public void onPauseAfterSuper() { + if (mFocusManager != null) mFocusManager.removeMessages(); + } + + /** + * The focus manager is the first UI related element to get initialized, + * and it requires the RenderOverlay, so initialize it here + */ + private void initializeFocusManager() { + // Create FocusManager object. startPreview needs it. + // if mFocusManager not null, reuse it + // otherwise create a new instance + if (mFocusManager != null) { + mFocusManager.removeMessages(); + } else { + CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; + boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); + String[] defaultFocusModes = mActivity.getResources().getStringArray( + R.array.pref_video_focusmode_default_array); + mFocusManager = new FocusOverlayManager(mPreferences, defaultFocusModes, + mParameters, this, mirror, + mActivity.getMainLooper(), mUI); + } } @Override @@ -1103,6 +1218,7 @@ public class VideoModule implements CameraModule, } private void setupMediaRecorderPreviewDisplay() { + mFocusManager.resetTouchFocus(); // Nothing to do here if using SurfaceTexture. if (!ApiHelper.HAS_SURFACE_TEXTURE_RECORDING) { // We stop the preview here before unlocking the device because we @@ -1871,11 +1987,13 @@ public class VideoModule implements CameraModule, mParameters.setZoom(mZoomValue); } - // Set continuous autofocus. - List<String> supportedFocus = mParameters.getSupportedFocusModes(); - if (isSupported(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, supportedFocus)) { - mParameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); - } + // Set focus mode + mParameters.setFocusMode(mFocusManager.getFocusMode()); + + // Set focus time. + mFocusManager.setFocusTime(Integer.valueOf( + mPreferences.getString(CameraSettings.KEY_FOCUS_TIME, + mActivity.getString(R.string.pref_camera_focustime_default)))); mParameters.set(CameraUtil.RECORDING_HINT, CameraUtil.TRUE); @@ -1922,6 +2040,8 @@ public class VideoModule implements CameraModule, // Update UI based on the new parameters. mUI.updateOnScreenIndicators(mParameters, mPreferences); + + mFocusManager.setPreviewSize(videoWidth, videoHeight); } @Override @@ -1995,6 +2115,7 @@ public class VideoModule implements CameraModule, closeCamera(); mUI.collapseCameraControls(); + if (mFocusManager != null) mFocusManager.removeMessages(); // Restart the camera and initialize the UI. From onCreate. mPreferences.setLocalId(mActivity, mCameraId); CameraSettings.upgradeLocalPreferences(mPreferences.getLocal()); @@ -2005,6 +2126,14 @@ public class VideoModule implements CameraModule, resizeForPreviewAspectRatio(); initializeVideoControl(); + CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId]; + boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT); + mParameters = mCameraDevice.getParameters(); + mFocusManager.setMirror(mirror); + mFocusManager.setParameters(mParameters); + + initializeCapabilities(); + // From onResume mZoomValue = 0; mUI.initializeZoom(mParameters); @@ -2016,6 +2145,11 @@ public class VideoModule implements CameraModule, mUI.updateOnScreenIndicators(mParameters, mPreferences); } + private void initializeCapabilities() { + mFocusAreaSupported = CameraUtil.isFocusAreaSupported(mParameters); + mMeteringAreaSupported = CameraUtil.isMeteringAreaSupported(mParameters); + } + // Preview texture has been copied. Now camera can be released and the // animation can be started. @Override diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 52302a49c..4645b982d 100644 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -40,11 +40,14 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.PopupWindow; import android.widget.TextView; +import android.view.View.OnLayoutChangeListener; import com.android.camera.CameraPreference.OnPreferenceChangedListener; +import com.android.camera.FocusOverlayManager.FocusUI; import com.android.camera.ui.AbstractSettingPopup; import com.android.camera.ui.CameraControls; import com.android.camera.ui.CameraRootView; +import com.android.camera.ui.FocusIndicator; import com.android.camera.ui.ModuleSwitcher; import com.android.camera.ui.PieRenderer; import com.android.camera.ui.RenderOverlay; @@ -57,7 +60,7 @@ import java.util.List; public class VideoUI implements PieRenderer.PieListener, PreviewGestures.SingleTapListener, - CameraRootView.MyDisplayListener, + CameraRootView.MyDisplayListener, FocusUI, SurfaceTextureListener, SurfaceHolder.Callback { private static final String TAG = "CAM_VideoUI"; private static final int UPDATE_TRANSFORM_MATRIX = 1; @@ -283,6 +286,7 @@ public class VideoUI implements PieRenderer.PieListener, public void onScreenSizeChanged(int width, int height, int previewWidth, int previewHeight) { setTransformMatrix(width, height); + mController.onScreenSizeChanged(width, height, previewWidth, previewHeight); } private void setTransformMatrix(int width, int height) { @@ -758,6 +762,50 @@ public class VideoUI implements PieRenderer.PieListener, } } + // implement focusUI interface + private FocusIndicator getFocusIndicator() { + return mPieRenderer; + } + + @Override + public boolean hasFaces() { + return false; + } + + @Override + public void clearFocus() { + FocusIndicator indicator = getFocusIndicator(); + if (indicator != null) indicator.clear(); + } + + @Override + public void setFocusPosition(int x, int y) { + mPieRenderer.setFocus(x, y); + } + + @Override + public void onFocusStarted(){ + getFocusIndicator().showStart(); + } + + @Override + public void onFocusSucceeded(boolean timeOut) { + getFocusIndicator().showSuccess(timeOut); + } + + @Override + public void onFocusFailed(boolean timeOut) { + getFocusIndicator().showFail(timeOut); + } + + @Override + public void pauseFaceDetection() { + } + + @Override + public void resumeFaceDetection() { + } + public SurfaceTexture getSurfaceTexture() { return mSurfaceTexture; } |