Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.camera; |
| 18 | |
| 19 | import android.annotation.TargetApi; |
| 20 | import android.app.Activity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 21 | import android.content.ContentResolver; |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 23 | import android.content.Intent; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 25 | import android.graphics.BitmapFactory; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 26 | import android.graphics.SurfaceTexture; |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 27 | import android.hardware.Sensor; |
| 28 | import android.hardware.SensorEvent; |
| 29 | import android.hardware.SensorEventListener; |
| 30 | import android.hardware.SensorManager; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 31 | import android.location.Location; |
| 32 | import android.media.CameraProfile; |
| 33 | import android.net.Uri; |
Sascha Haeberling | bca64bf | 2014-04-17 10:51:53 -0700 | [diff] [blame] | 34 | import android.os.AsyncTask; |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 35 | import android.os.Build; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 36 | import android.os.Bundle; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.Looper; |
| 39 | import android.os.Message; |
| 40 | import android.os.MessageQueue; |
| 41 | import android.os.SystemClock; |
| 42 | import android.provider.MediaStore; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 43 | import android.view.KeyEvent; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 44 | import android.view.OrientationEventListener; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 45 | import android.view.View; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 46 | |
Sameer Padala | 2c8cc45 | 2013-11-05 18:49:12 -0800 | [diff] [blame] | 47 | import com.android.camera.PhotoModule.NamedImages.NamedEntity; |
| 48 | import com.android.camera.app.AppController; |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 49 | import com.android.camera.app.CameraAppUI; |
Angus Kong | 0b9eb5b | 2014-04-30 15:03:33 -0700 | [diff] [blame] | 50 | import com.android.camera.app.CameraProvider; |
Sascha Haeberling | f9cba4e | 2014-04-22 09:11:28 -0700 | [diff] [blame] | 51 | import com.android.camera.app.MediaSaver; |
| 52 | import com.android.camera.app.MemoryManager; |
| 53 | import com.android.camera.app.MemoryManager.MemoryListener; |
Kevin Gabayan | fb33336 | 2014-06-02 14:48:20 -0700 | [diff] [blame] | 54 | import com.android.camera.app.MotionManager; |
Angus Kong | 2bca210 | 2014-03-11 16:27:30 -0700 | [diff] [blame] | 55 | import com.android.camera.debug.Log; |
ztenghui | a16e7b5 | 2013-08-23 11:47:56 -0700 | [diff] [blame] | 56 | import com.android.camera.exif.ExifInterface; |
| 57 | import com.android.camera.exif.ExifTag; |
| 58 | import com.android.camera.exif.Rational; |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 59 | import com.android.camera.hardware.HardwareSpec; |
| 60 | import com.android.camera.hardware.HardwareSpecImpl; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 61 | import com.android.camera.module.ModuleController; |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 62 | import com.android.camera.remote.RemoteCameraModule; |
Andy Huibers | 90c7ad5 | 2014-05-20 22:13:54 -0700 | [diff] [blame] | 63 | import com.android.camera.settings.CameraPictureSizesCacher; |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 64 | import com.android.camera.settings.Keys; |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 65 | import com.android.camera.settings.ResolutionUtil; |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 66 | import com.android.camera.settings.SettingsManager; |
Sascha Haeberling | 3b0ab89 | 2014-01-29 20:54:39 +0100 | [diff] [blame] | 67 | import com.android.camera.settings.SettingsUtil; |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 68 | import com.android.camera.ui.CountDownView; |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 69 | import com.android.camera.ui.TouchCoordinate; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 70 | import com.android.camera.util.ApiHelper; |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 71 | import com.android.camera.util.CameraUtil; |
Ruben Brunk | 4601f5d | 2013-09-24 18:35:22 -0700 | [diff] [blame] | 72 | import com.android.camera.util.GcamHelper; |
Sol Boucher | 44ce4b2 | 2014-08-04 23:41:38 -0700 | [diff] [blame] | 73 | import com.android.camera.util.GservicesHelper; |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 74 | import com.android.camera.util.SessionStatsCollector; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 75 | import com.android.camera.util.UsageStatistics; |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 76 | import com.android.camera.widget.AspectRatioSelector; |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 77 | import com.android.camera2.R; |
Spike Sprague | 3c3b31d | 2014-09-08 10:43:04 -0700 | [diff] [blame] | 78 | import com.android.ex.camera2.portability.CameraAgent; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 79 | import com.android.ex.camera2.portability.CameraAgent.CameraAFCallback; |
| 80 | import com.android.ex.camera2.portability.CameraAgent.CameraAFMoveCallback; |
| 81 | import com.android.ex.camera2.portability.CameraAgent.CameraPictureCallback; |
| 82 | import com.android.ex.camera2.portability.CameraAgent.CameraProxy; |
| 83 | import com.android.ex.camera2.portability.CameraAgent.CameraShutterCallback; |
Sascha Haeberling | ee36c5f | 2014-07-29 17:05:43 -0700 | [diff] [blame] | 84 | import com.android.ex.camera2.portability.CameraCapabilities; |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 85 | import com.android.ex.camera2.portability.CameraDeviceInfo.Characteristics; |
Sol Boucher | 5a34496 | 2014-06-17 14:05:08 -0700 | [diff] [blame] | 86 | import com.android.ex.camera2.portability.CameraSettings; |
| 87 | import com.android.ex.camera2.portability.Size; |
Seth Raphael | 5e09d01 | 2013-12-18 13:45:03 -0800 | [diff] [blame] | 88 | import com.google.common.logging.eventprotos; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 89 | |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 90 | import java.io.ByteArrayOutputStream; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 91 | import java.io.File; |
| 92 | import java.io.FileNotFoundException; |
| 93 | import java.io.FileOutputStream; |
| 94 | import java.io.IOException; |
| 95 | import java.io.OutputStream; |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 96 | import java.lang.ref.WeakReference; |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 97 | import java.util.ArrayList; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 98 | import java.util.List; |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 99 | import java.util.Vector; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 100 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 101 | public class PhotoModule |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 102 | extends CameraModule |
| 103 | implements PhotoController, |
| 104 | ModuleController, |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 105 | MemoryListener, |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 106 | FocusOverlayManager.Listener, |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 107 | SensorEventListener, |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 108 | SettingsManager.OnSettingChangedListener, |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 109 | RemoteCameraModule, |
| 110 | CountDownView.OnCountDownStatusListener { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 111 | |
Alan Newberger | 00a390e | 2014-08-18 18:40:47 -0700 | [diff] [blame] | 112 | public static final String PHOTO_MODULE_STRING_ID = "PhotoModule"; |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 113 | |
| 114 | private static final Log.Tag TAG = new Log.Tag(PHOTO_MODULE_STRING_ID); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 115 | |
| 116 | // We number the request code from 1000 to avoid collision with Gallery. |
| 117 | private static final int REQUEST_CROP = 1000; |
| 118 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 119 | // Messages defined for the UI thread handler. |
Angus Kong | 1587b04 | 2014-01-02 18:09:27 -0800 | [diff] [blame] | 120 | private static final int MSG_FIRST_TIME_INIT = 1; |
| 121 | private static final int MSG_SET_CAMERA_PARAMETERS_WHEN_IDLE = 2; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 122 | |
| 123 | // The subset of parameters we need to update in setCameraParameters(). |
| 124 | private static final int UPDATE_PARAM_INITIALIZE = 1; |
| 125 | private static final int UPDATE_PARAM_ZOOM = 2; |
| 126 | private static final int UPDATE_PARAM_PREFERENCE = 4; |
| 127 | private static final int UPDATE_PARAM_ALL = -1; |
| 128 | |
Ruben Brunk | d748827 | 2013-10-10 18:45:53 -0700 | [diff] [blame] | 129 | private static final String DEBUG_IMAGE_PREFIX = "DEBUG_"; |
| 130 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 131 | private CameraActivity mActivity; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 132 | private CameraProxy mCameraDevice; |
| 133 | private int mCameraId; |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 134 | private CameraCapabilities mCameraCapabilities; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 135 | private CameraSettings mCameraSettings; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 136 | private boolean mPaused; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 137 | |
| 138 | private PhotoUI mUI; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 139 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 140 | // The activity is going to switch to the specified camera id. This is |
| 141 | // needed because texture copy is done in GL thread. -1 means camera is not |
| 142 | // switching. |
| 143 | protected int mPendingSwitchCameraId = -1; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 144 | |
| 145 | // When setCameraParametersWhenIdle() is called, we accumulate the subsets |
| 146 | // needed to be updated in mUpdateSet. |
| 147 | private int mUpdateSet; |
| 148 | |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 149 | private float mZoomValue; // The current zoom ratio. |
Andy Huibers | 547d7c8 | 2014-05-20 23:03:18 -0700 | [diff] [blame] | 150 | private int mTimerDuration; |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 151 | /** Set when a volume button is clicked to take photo */ |
| 152 | private boolean mVolumeButtonClickedFlag = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 153 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 154 | private boolean mFocusAreaSupported; |
| 155 | private boolean mMeteringAreaSupported; |
| 156 | private boolean mAeLockSupported; |
| 157 | private boolean mAwbLockSupported; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 158 | private boolean mContinuousFocusSupported; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 159 | |
| 160 | // The degrees of the device rotated clockwise from its natural orientation. |
| 161 | private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 162 | |
| 163 | private static final String sTempCropFilename = "crop-temp"; |
| 164 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 165 | private boolean mFaceDetectionStarted = false; |
| 166 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 167 | // mCropValue and mSaveUri are used only if isImageCaptureIntent() is true. |
| 168 | private String mCropValue; |
| 169 | private Uri mSaveUri; |
| 170 | |
Ruben Brunk | d217ed0 | 2013-10-08 23:31:13 -0700 | [diff] [blame] | 171 | private Uri mDebugUri; |
| 172 | |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 173 | // We use a queue to generated names of the images to be used later |
| 174 | // when the image is ready to be saved. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 175 | private NamedImages mNamedImages; |
| 176 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 177 | private final Runnable mDoSnapRunnable = new Runnable() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 178 | @Override |
| 179 | public void run() { |
| 180 | onShutterButtonClick(); |
| 181 | } |
| 182 | }; |
| 183 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 184 | /** |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 185 | * An unpublished intent flag requesting to return as soon as capturing is |
| 186 | * completed. TODO: consider publishing by moving into MediaStore. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 187 | */ |
| 188 | private static final String EXTRA_QUICK_CAPTURE = |
| 189 | "android.intent.extra.quickCapture"; |
| 190 | |
| 191 | // The display rotation in degrees. This is only valid when mCameraState is |
| 192 | // not PREVIEW_STOPPED. |
| 193 | private int mDisplayRotation; |
| 194 | // The value for android.hardware.Camera.setDisplayOrientation. |
| 195 | private int mCameraDisplayOrientation; |
| 196 | // The value for UI components like indicators. |
| 197 | private int mDisplayOrientation; |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 198 | // The value for cameradevice.CameraSettings.setPhotoRotationDegrees. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 199 | private int mJpegRotation; |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 200 | // Indicates whether we are using front camera |
| 201 | private boolean mMirror; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 202 | private boolean mFirstTimeInitialized; |
| 203 | private boolean mIsImageCaptureIntent; |
| 204 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 205 | private int mCameraState = PREVIEW_STOPPED; |
| 206 | private boolean mSnapshotOnIdle = false; |
| 207 | |
| 208 | private ContentResolver mContentResolver; |
| 209 | |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 210 | private AppController mAppController; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 211 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 212 | private final PostViewPictureCallback mPostViewPictureCallback = |
| 213 | new PostViewPictureCallback(); |
| 214 | private final RawPictureCallback mRawPictureCallback = |
| 215 | new RawPictureCallback(); |
| 216 | private final AutoFocusCallback mAutoFocusCallback = |
| 217 | new AutoFocusCallback(); |
| 218 | private final Object mAutoFocusMoveCallback = |
| 219 | ApiHelper.HAS_AUTO_FOCUS_MOVE_CALLBACK |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 220 | ? new AutoFocusMoveCallback() |
| 221 | : null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 222 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 223 | private long mFocusStartTime; |
| 224 | private long mShutterCallbackTime; |
| 225 | private long mPostViewPictureCallbackTime; |
| 226 | private long mRawPictureCallbackTime; |
| 227 | private long mJpegPictureCallbackTime; |
| 228 | private long mOnResumeTime; |
| 229 | private byte[] mJpegImageData; |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 230 | /** Touch coordinate for shutter button press. */ |
| 231 | private TouchCoordinate mShutterTouchCoordinate; |
| 232 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 233 | |
| 234 | // These latency time are for the CameraLatency test. |
| 235 | public long mAutoFocusTime; |
| 236 | public long mShutterLag; |
| 237 | public long mShutterToPictureDisplayedTime; |
| 238 | public long mPictureDisplayedToJpegCallbackTime; |
| 239 | public long mJpegCallbackFinishTime; |
| 240 | public long mCaptureStartTime; |
| 241 | |
| 242 | // This handles everything about focus. |
| 243 | private FocusOverlayManager mFocusManager; |
| 244 | |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 245 | private final int mGcamModeIndex; |
Andy Huibers | a31162c | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 246 | private SoundPlayer mCountdownSoundPlayer; |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 247 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 248 | private CameraCapabilities.SceneMode mSceneMode; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 249 | |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 250 | private final Handler mHandler = new MainHandler(this); |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 251 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 252 | private boolean mQuickCapture; |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 253 | private SensorManager mSensorManager; |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 254 | private final float[] mGData = new float[3]; |
| 255 | private final float[] mMData = new float[3]; |
| 256 | private final float[] mR = new float[16]; |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 257 | private int mHeading = -1; |
| 258 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 259 | /** True if all the parameters needed to start preview is ready. */ |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 260 | private boolean mCameraPreviewParamsReady = false; |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 261 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 262 | private final MediaSaver.OnMediaSavedListener mOnMediaSavedListener = |
Angus Kong | fd4fc0e | 2013-11-07 15:38:09 -0800 | [diff] [blame] | 263 | new MediaSaver.OnMediaSavedListener() { |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 264 | @Override |
| 265 | public void onMediaSaved(Uri uri) { |
| 266 | if (uri != null) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 267 | mActivity.notifyNewMedia(uri); |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | }; |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 271 | private boolean mShouldResizeTo16x9 = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 272 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 273 | /** |
Angus Kong | 3699c41 | 2014-05-23 15:31:09 -0700 | [diff] [blame] | 274 | * We keep the flash setting before entering scene modes (HDR) |
| 275 | * and restore it after HDR is off. |
| 276 | */ |
| 277 | private String mFlashModeBeforeSceneMode; |
| 278 | |
| 279 | /** |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 280 | * This callback gets called when user select whether or not to |
| 281 | * turn on geo-tagging. |
| 282 | */ |
| 283 | public interface LocationDialogCallback { |
| 284 | /** |
| 285 | * Gets called after user selected/unselected geo-tagging feature. |
| 286 | * |
| 287 | * @param selected whether or not geo-tagging feature is selected |
| 288 | */ |
| 289 | public void onLocationTaggingSelected(boolean selected); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * This callback defines the text that is shown in the aspect ratio selection |
| 294 | * dialog, provides the current aspect ratio, and gets notified when user changes |
| 295 | * aspect ratio selection in the dialog. |
| 296 | */ |
| 297 | public interface AspectRatioDialogCallback { |
| 298 | /** |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 299 | * Returns current aspect ratio that is being used to set as default. |
| 300 | */ |
| 301 | public AspectRatioSelector.AspectRatio getCurrentAspectRatio(); |
| 302 | |
| 303 | /** |
| 304 | * Gets notified when user has made the aspect ratio selection. |
| 305 | * |
| 306 | * @param newAspectRatio aspect ratio that user has selected |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 307 | * @param dialogHandlingFinishedRunnable runnable to run when the operations |
| 308 | * needed to handle changes from dialog |
| 309 | * are finished. |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 310 | */ |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 311 | public void onAspectRatioSelected(AspectRatioSelector.AspectRatio newAspectRatio, |
| 312 | Runnable dialogHandlingFinishedRunnable); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 315 | private void checkDisplayRotation() { |
Senpo Hu | 9746ebe | 2014-10-14 11:51:56 -0700 | [diff] [blame^] | 316 | // Need to just be a no-op for the quick resume-pause scenario. |
| 317 | if (mPaused) { |
| 318 | return; |
| 319 | } |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 320 | // Set the display orientation if display rotation has changed. |
| 321 | // Sometimes this happens when the device is held upside |
| 322 | // down and camera app is opened. Rotation animation will |
| 323 | // take some time and the rotation value we have got may be |
| 324 | // wrong. Framework does not have a callback for this now. |
| 325 | if (CameraUtil.getDisplayRotation(mActivity) != mDisplayRotation) { |
| 326 | setDisplayOrientation(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 327 | } |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 328 | if (SystemClock.uptimeMillis() - mOnResumeTime < 5000) { |
| 329 | mHandler.postDelayed(new Runnable() { |
| 330 | @Override |
| 331 | public void run() { |
| 332 | checkDisplayRotation(); |
| 333 | } |
| 334 | }, 100); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * This Handler is used to post message back onto the main thread of the |
| 340 | * application |
| 341 | */ |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 342 | private static class MainHandler extends Handler { |
| 343 | private final WeakReference<PhotoModule> mModule; |
| 344 | |
| 345 | public MainHandler(PhotoModule module) { |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 346 | super(Looper.getMainLooper()); |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 347 | mModule = new WeakReference<PhotoModule>(module); |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 348 | } |
| 349 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 350 | @Override |
| 351 | public void handleMessage(Message msg) { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 352 | PhotoModule module = mModule.get(); |
| 353 | if (module == null) { |
| 354 | return; |
| 355 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 356 | switch (msg.what) { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 357 | case MSG_FIRST_TIME_INIT: { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 358 | module.initializeFirstTime(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 359 | break; |
| 360 | } |
| 361 | |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 362 | case MSG_SET_CAMERA_PARAMETERS_WHEN_IDLE: { |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 363 | module.setCameraParametersWhenIdle(0); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 364 | break; |
| 365 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 370 | private void switchToGcamCapture() { |
| 371 | if (mActivity != null && mGcamModeIndex != 0) { |
| 372 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 373 | settingsManager.set(SettingsManager.SCOPE_GLOBAL, |
| 374 | Keys.KEY_CAMERA_HDR_PLUS, true); |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 375 | |
| 376 | // Disable the HDR+ button to prevent callbacks from being |
| 377 | // queued before the correct callback is attached to the button |
| 378 | // in the new module. The new module will set the enabled/disabled |
| 379 | // of this button when the module's preferred camera becomes available. |
| 380 | ButtonManager buttonManager = mActivity.getButtonManager(); |
Spike Sprague | 66d3d0d | 2014-08-18 14:11:33 -0700 | [diff] [blame] | 381 | |
| 382 | buttonManager.disableButtonClick(ButtonManager.BUTTON_HDR_PLUS); |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 383 | |
Seth Raphael | 274f6e9 | 2014-05-21 17:11:53 -0700 | [diff] [blame] | 384 | mAppController.getCameraAppUI().freezeScreenUntilPreviewReady(); |
| 385 | |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 386 | // Do not post this to avoid this module switch getting interleaved with |
| 387 | // other button callbacks. |
| 388 | mActivity.onModeSelected(mGcamModeIndex); |
Spike Sprague | 66d3d0d | 2014-08-18 14:11:33 -0700 | [diff] [blame] | 389 | |
| 390 | buttonManager.enableButtonClick(ButtonManager.BUTTON_HDR_PLUS); |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 394 | /** |
| 395 | * Constructs a new photo module. |
| 396 | */ |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 397 | public PhotoModule(AppController app) { |
| 398 | super(app); |
Doris Liu | bd1b8f9 | 2014-01-03 17:59:51 -0800 | [diff] [blame] | 399 | mGcamModeIndex = app.getAndroidContext().getResources() |
| 400 | .getInteger(R.integer.camera_mode_gcam); |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 401 | } |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 402 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 403 | @Override |
Spike Sprague | 159e6e9 | 2014-05-27 18:26:30 -0700 | [diff] [blame] | 404 | public String getPeekAccessibilityString() { |
| 405 | return mAppController.getAndroidContext() |
| 406 | .getResources().getString(R.string.photo_accessibility_peek); |
| 407 | } |
| 408 | |
| 409 | @Override |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 410 | public String getModuleStringIdentifier() { |
| 411 | return PHOTO_MODULE_STRING_ID; |
| 412 | } |
| 413 | |
| 414 | @Override |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 415 | public void init(CameraActivity activity, boolean isSecureCamera, boolean isCaptureIntent) { |
| 416 | mActivity = activity; |
| 417 | // TODO: Need to look at the controller interface to see if we can get |
| 418 | // rid of passing in the activity directly. |
| 419 | mAppController = mActivity; |
| 420 | |
| 421 | mUI = new PhotoUI(mActivity, this, mActivity.getModuleLayoutRoot()); |
| 422 | mActivity.setPreviewStatusListener(mUI); |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 423 | |
| 424 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 425 | mCameraId = settingsManager.getInteger(mAppController.getModuleScope(), |
| 426 | Keys.KEY_CAMERA_ID); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 427 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 428 | // TODO: Move this to SettingsManager as a part of upgrade procedure. |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 429 | if (!settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, |
| 430 | Keys.KEY_USER_SELECTED_ASPECT_RATIO)) { |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 431 | // Switch to back camera to set aspect ratio. |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 432 | mCameraId = settingsManager.getIntegerDefault(Keys.KEY_CAMERA_ID); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 435 | mContentResolver = mActivity.getContentResolver(); |
| 436 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 437 | // Surface texture is from camera screen nail and startPreview needs it. |
| 438 | // This must be done before startPreview. |
| 439 | mIsImageCaptureIntent = isImageCaptureIntent(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 440 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 441 | mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 442 | mSensorManager = (SensorManager) (mActivity.getSystemService(Context.SENSOR_SERVICE)); |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 443 | mUI.setCountdownFinishedListener(this); |
Andy Huibers | a31162c | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 444 | mCountdownSoundPlayer = new SoundPlayer(mAppController.getAndroidContext()); |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 445 | |
| 446 | // TODO: Make this a part of app controller API. |
| 447 | View cancelButton = mActivity.findViewById(R.id.shutter_cancel_button); |
| 448 | cancelButton.setOnClickListener(new View.OnClickListener() { |
| 449 | @Override |
| 450 | public void onClick(View view) { |
| 451 | cancelCountDown(); |
| 452 | } |
| 453 | }); |
| 454 | } |
| 455 | |
| 456 | private void cancelCountDown() { |
| 457 | if (mUI.isCountingDown()) { |
| 458 | // Cancel on-going countdown. |
| 459 | mUI.cancelCountDown(); |
| 460 | } |
| 461 | mAppController.getCameraAppUI().transitionToCapture(); |
| 462 | mAppController.getCameraAppUI().showModeOptions(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Erin Dahlgren | 4efa8b5 | 2013-12-17 18:31:35 -0800 | [diff] [blame] | 465 | @Override |
| 466 | public boolean isUsingBottomBar() { |
| 467 | return true; |
| 468 | } |
| 469 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 470 | private void initializeControlByIntent() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 471 | if (mIsImageCaptureIntent) { |
Spike Sprague | 15690d0 | 2014-02-10 12:11:20 -0800 | [diff] [blame] | 472 | mActivity.getCameraAppUI().transitionToIntentCaptureLayout(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 473 | setupCaptureParams(); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | private void onPreviewStarted() { |
Doris Liu | 2b906b8 | 2013-12-10 16:34:08 -0800 | [diff] [blame] | 478 | mAppController.onPreviewStarted(); |
Alan Newberger | ffc395d | 2014-09-10 13:07:18 -0700 | [diff] [blame] | 479 | mAppController.setShutterEnabled(true); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 480 | setCameraState(IDLE); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 481 | startFaceDetection(); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 482 | settingsFirstRun(); |
Seth Raphael | 3083642 | 2014-02-06 14:49:47 -0800 | [diff] [blame] | 483 | } |
| 484 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 485 | /** |
| 486 | * Prompt the user to pick to record location and choose aspect ratio for the |
| 487 | * very first run of camera only. |
| 488 | */ |
| 489 | private void settingsFirstRun() { |
| 490 | final SettingsManager settingsManager = mActivity.getSettingsManager(); |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 491 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 492 | if (mActivity.isSecureCamera() || isImageCaptureIntent()) { |
Erin Dahlgren | 4569b70 | 2014-02-24 14:21:11 -0800 | [diff] [blame] | 493 | return; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 494 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 495 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 496 | boolean locationPrompt = !settingsManager.isSet(SettingsManager.SCOPE_GLOBAL, |
| 497 | Keys.KEY_RECORD_LOCATION); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 498 | boolean aspectRatioPrompt = !settingsManager.getBoolean( |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 499 | SettingsManager.SCOPE_GLOBAL, Keys.KEY_USER_SELECTED_ASPECT_RATIO); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 500 | if (!locationPrompt && !aspectRatioPrompt) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 501 | return; |
| 502 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 503 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 504 | // Check if the back camera exists |
Angus Kong | d74e6a1 | 2014-01-07 11:29:44 -0800 | [diff] [blame] | 505 | int backCameraId = mAppController.getCameraProvider().getFirstBackCameraId(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 506 | if (backCameraId == -1) { |
| 507 | // If there is no back camera, do not show the prompt. |
| 508 | return; |
| 509 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 510 | |
| 511 | if (locationPrompt) { |
| 512 | // Show both location and aspect ratio selection dialog. |
| 513 | mUI.showLocationAndAspectRatioDialog(new LocationDialogCallback(){ |
Sascha Haeberling | b32af4f | 2014-05-16 08:22:00 -0700 | [diff] [blame] | 514 | @Override |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 515 | public void onLocationTaggingSelected(boolean selected) { |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 516 | Keys.setLocation(mActivity.getSettingsManager(), selected, |
| 517 | mActivity.getLocationManager()); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 518 | } |
| 519 | }, createAspectRatioDialogCallback()); |
| 520 | } else { |
| 521 | // App upgrade. Only show aspect ratio selection. |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 522 | boolean wasShown = mUI.showAspectRatioDialog(createAspectRatioDialogCallback()); |
| 523 | if (!wasShown) { |
| 524 | // If the dialog was not shown, set this flag to true so that we |
| 525 | // never have to check for it again. It means that we don't need |
| 526 | // to show the dialog on this device. |
| 527 | mActivity.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL, |
| 528 | Keys.KEY_USER_SELECTED_ASPECT_RATIO, true); |
| 529 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | private AspectRatioDialogCallback createAspectRatioDialogCallback() { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 534 | Size currentSize = mCameraSettings.getCurrentPhotoSize(); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 535 | float aspectRatio = (float) currentSize.width() / (float) currentSize.height(); |
| 536 | if (aspectRatio < 1f) { |
| 537 | aspectRatio = 1 / aspectRatio; |
| 538 | } |
| 539 | final AspectRatioSelector.AspectRatio currentAspectRatio; |
| 540 | if (Math.abs(aspectRatio - 4f / 3f) <= 0.1f) { |
| 541 | currentAspectRatio = AspectRatioSelector.AspectRatio.ASPECT_RATIO_4x3; |
| 542 | } else if (Math.abs(aspectRatio - 16f / 9f) <= 0.1f) { |
| 543 | currentAspectRatio = AspectRatioSelector.AspectRatio.ASPECT_RATIO_16x9; |
| 544 | } else { |
| 545 | // TODO: Log error and not show dialog. |
| 546 | return null; |
| 547 | } |
| 548 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 549 | List<Size> sizes = mCameraCapabilities.getSupportedPhotoSizes(); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 550 | List<Size> pictureSizes = ResolutionUtil |
| 551 | .getDisplayableSizesFromSupported(sizes, true); |
| 552 | |
| 553 | // This logic below finds the largest resolution for each aspect ratio. |
| 554 | // TODO: Move this somewhere that can be shared with SettingsActivity |
| 555 | int aspectRatio4x3Resolution = 0; |
| 556 | int aspectRatio16x9Resolution = 0; |
| 557 | Size largestSize4x3 = new Size(0, 0); |
| 558 | Size largestSize16x9 = new Size(0, 0); |
| 559 | for (Size size : pictureSizes) { |
| 560 | float pictureAspectRatio = (float) size.width() / (float) size.height(); |
| 561 | pictureAspectRatio = pictureAspectRatio < 1 ? |
| 562 | 1f / pictureAspectRatio : pictureAspectRatio; |
| 563 | int resolution = size.width() * size.height(); |
| 564 | if (Math.abs(pictureAspectRatio - 4f / 3f) < 0.1f) { |
| 565 | if (resolution > aspectRatio4x3Resolution) { |
| 566 | aspectRatio4x3Resolution = resolution; |
| 567 | largestSize4x3 = size; |
| 568 | } |
| 569 | } else if (Math.abs(pictureAspectRatio - 16f / 9f) < 0.1f) { |
| 570 | if (resolution > aspectRatio16x9Resolution) { |
| 571 | aspectRatio16x9Resolution = resolution; |
| 572 | largestSize16x9 = size; |
| 573 | } |
| 574 | } |
| 575 | } |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 576 | |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 577 | // Use the largest 4x3 and 16x9 sizes as candidates for picture size selection. |
| 578 | final Size size4x3ToSelect = largestSize4x3; |
| 579 | final Size size16x9ToSelect = largestSize16x9; |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 580 | |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 581 | AspectRatioDialogCallback callback = new AspectRatioDialogCallback() { |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 582 | |
| 583 | @Override |
| 584 | public AspectRatioSelector.AspectRatio getCurrentAspectRatio() { |
| 585 | return currentAspectRatio; |
| 586 | } |
| 587 | |
| 588 | @Override |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 589 | public void onAspectRatioSelected(AspectRatioSelector.AspectRatio newAspectRatio, |
| 590 | Runnable dialogHandlingFinishedRunnable) { |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 591 | if (newAspectRatio == AspectRatioSelector.AspectRatio.ASPECT_RATIO_4x3) { |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 592 | String largestSize4x3Text = SettingsUtil.sizeToSetting(size4x3ToSelect); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 593 | mActivity.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL, |
| 594 | Keys.KEY_PICTURE_SIZE_BACK, |
| 595 | largestSize4x3Text); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 596 | } else if (newAspectRatio == AspectRatioSelector.AspectRatio.ASPECT_RATIO_16x9) { |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 597 | String largestSize16x9Text = SettingsUtil.sizeToSetting(size16x9ToSelect); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 598 | mActivity.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL, |
| 599 | Keys.KEY_PICTURE_SIZE_BACK, |
| 600 | largestSize16x9Text); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 601 | } |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 602 | mActivity.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL, |
| 603 | Keys.KEY_USER_SELECTED_ASPECT_RATIO, true); |
| 604 | String aspectRatio = mActivity.getSettingsManager().getString( |
| 605 | SettingsManager.SCOPE_GLOBAL, |
| 606 | Keys.KEY_USER_SELECTED_ASPECT_RATIO); |
| 607 | Log.e(TAG, "aspect ratio after setting it to true=" + aspectRatio); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 608 | if (newAspectRatio != currentAspectRatio) { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 609 | Log.i(TAG, "changing aspect ratio from dialog"); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 610 | stopPreview(); |
| 611 | startPreview(); |
Doris Liu | 08b0cdd | 2014-05-13 19:19:55 -0700 | [diff] [blame] | 612 | mUI.setRunnableForNextFrame(dialogHandlingFinishedRunnable); |
| 613 | } else { |
| 614 | mHandler.post(dialogHandlingFinishedRunnable); |
Doris Liu | db8f975 | 2014-05-12 15:25:13 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | }; |
| 618 | return callback; |
Doris Liu | 6a83d52 | 2013-07-02 12:03:32 -0700 | [diff] [blame] | 619 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 620 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 621 | @Override |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 622 | public void onPreviewUIReady() { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 623 | Log.i(TAG, "onPreviewUIReady"); |
Erin Dahlgren | dc282e1 | 2013-11-12 09:39:08 -0800 | [diff] [blame] | 624 | startPreview(); |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | @Override |
| 628 | public void onPreviewUIDestroyed() { |
| 629 | if (mCameraDevice == null) { |
| 630 | return; |
| 631 | } |
| 632 | mCameraDevice.setPreviewTexture(null); |
| 633 | stopPreview(); |
| 634 | } |
| 635 | |
Doris Liu | 1dfe782 | 2013-12-12 00:02:08 -0800 | [diff] [blame] | 636 | @Override |
| 637 | public void startPreCaptureAnimation() { |
| 638 | mAppController.startPreCaptureAnimation(); |
| 639 | } |
| 640 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 641 | private void onCameraOpened() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 642 | openCameraCommon(); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 643 | initializeControlByIntent(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 646 | private void switchCamera() { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 647 | if (mPaused) { |
| 648 | return; |
| 649 | } |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 650 | cancelCountDown(); |
Doris Liu | 6809eb8 | 2014-05-21 13:16:59 -0700 | [diff] [blame] | 651 | |
| 652 | mAppController.freezeScreenUntilPreviewReady(); |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 653 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 654 | |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 655 | Log.i(TAG, "Start to switch camera. id=" + mPendingSwitchCameraId); |
Angus Kong | d4109bc | 2014-01-08 18:38:03 -0800 | [diff] [blame] | 656 | closeCamera(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 657 | mCameraId = mPendingSwitchCameraId; |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 658 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 659 | settingsManager.set(mAppController.getModuleScope(), Keys.KEY_CAMERA_ID, mCameraId); |
Sol Boucher | 44ce4b2 | 2014-08-04 23:41:38 -0700 | [diff] [blame] | 660 | requestCameraOpen(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 661 | mUI.clearFaces(); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 662 | if (mFocusManager != null) { |
| 663 | mFocusManager.removeMessages(); |
| 664 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 665 | |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 666 | mMirror = isCameraFrontFacing(); |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 667 | mFocusManager.setMirror(mMirror); |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 668 | // Start switch camera animation. Post a message because |
| 669 | // onFrameAvailable from the old camera may already exist. |
Doris Liu | 48239f4 | 2013-03-04 22:19:10 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Sol Boucher | 44ce4b2 | 2014-08-04 23:41:38 -0700 | [diff] [blame] | 672 | /** |
| 673 | * Uses the {@link CameraProvider} to open the currently-selected camera |
| 674 | * device, using {@link GservicesHelper} to choose between API-1 and API-2. |
| 675 | */ |
| 676 | private void requestCameraOpen() { |
Alan Newberger | 29a009c | 2014-09-05 12:47:42 -0700 | [diff] [blame] | 677 | Log.v(TAG, "requestCameraOpen"); |
Sol Boucher | 44ce4b2 | 2014-08-04 23:41:38 -0700 | [diff] [blame] | 678 | mActivity.getCameraProvider().requestCamera(mCameraId, |
| 679 | GservicesHelper.useCamera2ApiThroughPortabilityLayer(mActivity)); |
| 680 | } |
| 681 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 682 | private final ButtonManager.ButtonCallback mCameraCallback = |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 683 | new ButtonManager.ButtonCallback() { |
| 684 | @Override |
| 685 | public void onStateChanged(int state) { |
Erin Dahlgren | 1ba90e3 | 2014-03-03 12:05:57 -0800 | [diff] [blame] | 686 | // At the time this callback is fired, the camera id |
| 687 | // has be set to the desired camera. |
| 688 | |
Angus Kong | 97e282a | 2014-03-04 18:44:49 -0800 | [diff] [blame] | 689 | if (mPaused || mAppController.getCameraProvider().waitingForCamera()) { |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 690 | return; |
| 691 | } |
Erin Dahlgren | 1ba90e3 | 2014-03-03 12:05:57 -0800 | [diff] [blame] | 692 | // If switching to back camera, and HDR+ is still on, |
| 693 | // switch back to gcam, otherwise handle callback normally. |
| 694 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 695 | if (Keys.isCameraBackFacing(settingsManager, |
| 696 | mAppController.getModuleScope())) { |
| 697 | if (Keys.requestsReturnToHdrPlus(settingsManager, |
| 698 | mAppController.getModuleScope())) { |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 699 | switchToGcamCapture(); |
Erin Dahlgren | 1ba90e3 | 2014-03-03 12:05:57 -0800 | [diff] [blame] | 700 | return; |
| 701 | } |
| 702 | } |
| 703 | |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 704 | mPendingSwitchCameraId = state; |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 705 | |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 706 | Log.d(TAG, "Start to switch camera. cameraId=" + state); |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 707 | // We need to keep a preview frame for the animation before |
| 708 | // releasing the camera. This will trigger |
| 709 | // onPreviewTextureCopied. |
| 710 | // TODO: Need to animate the camera switch |
| 711 | switchCamera(); |
| 712 | } |
| 713 | }; |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 714 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 715 | private final ButtonManager.ButtonCallback mHdrPlusCallback = |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 716 | new ButtonManager.ButtonCallback() { |
| 717 | @Override |
| 718 | public void onStateChanged(int state) { |
Doris Liu | 8ad8ad4 | 2014-03-27 14:43:31 -0700 | [diff] [blame] | 719 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 720 | if (GcamHelper.hasGcamAsSeparateModule()) { |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 721 | // Set the camera setting to default backfacing. |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 722 | settingsManager.setToDefault(mAppController.getModuleScope(), |
| 723 | Keys.KEY_CAMERA_ID); |
Erin Dahlgren | 4cdaf51 | 2014-03-19 12:48:30 -0700 | [diff] [blame] | 724 | switchToGcamCapture(); |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 725 | } else { |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 726 | if (Keys.isHdrOn(settingsManager)) { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 727 | settingsManager.set(mAppController.getCameraScope(), Keys.KEY_SCENE_MODE, |
| 728 | mCameraCapabilities.getStringifier().stringify( |
| 729 | CameraCapabilities.SceneMode.HDR)); |
Doris Liu | 8ad8ad4 | 2014-03-27 14:43:31 -0700 | [diff] [blame] | 730 | } else { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 731 | settingsManager.set(mAppController.getCameraScope(), Keys.KEY_SCENE_MODE, |
| 732 | mCameraCapabilities.getStringifier().stringify( |
| 733 | CameraCapabilities.SceneMode.AUTO)); |
Doris Liu | 8ad8ad4 | 2014-03-27 14:43:31 -0700 | [diff] [blame] | 734 | } |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 735 | updateParametersSceneMode(); |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 736 | if (mCameraDevice != null) { |
| 737 | mCameraDevice.applySettings(mCameraSettings); |
| 738 | } |
Doris Liu | 8ad8ad4 | 2014-03-27 14:43:31 -0700 | [diff] [blame] | 739 | updateSceneMode(); |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 740 | } |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 741 | } |
Sascha Haeberling | de30323 | 2014-02-07 02:30:53 +0100 | [diff] [blame] | 742 | }; |
Erin Dahlgren | 18e2ef6 | 2013-12-05 14:53:38 -0800 | [diff] [blame] | 743 | |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 744 | private final View.OnClickListener mCancelCallback = new View.OnClickListener() { |
| 745 | @Override |
| 746 | public void onClick(View v) { |
| 747 | onCaptureCancelled(); |
| 748 | } |
| 749 | }; |
| 750 | |
| 751 | private final View.OnClickListener mDoneCallback = new View.OnClickListener() { |
| 752 | @Override |
| 753 | public void onClick(View v) { |
| 754 | onCaptureDone(); |
| 755 | } |
| 756 | }; |
| 757 | |
| 758 | private final View.OnClickListener mRetakeCallback = new View.OnClickListener() { |
| 759 | @Override |
| 760 | public void onClick(View v) { |
Spike Sprague | 15690d0 | 2014-02-10 12:11:20 -0800 | [diff] [blame] | 761 | mActivity.getCameraAppUI().transitionToIntentCaptureLayout(); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 762 | onCaptureRetake(); |
| 763 | } |
| 764 | }; |
| 765 | |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 766 | @Override |
Erin Dahlgren | 1ca516f | 2014-03-28 12:44:04 -0700 | [diff] [blame] | 767 | public void hardResetSettings(SettingsManager settingsManager) { |
Erin Dahlgren | e154793 | 2014-06-23 15:17:07 -0700 | [diff] [blame] | 768 | // PhotoModule should hard reset HDR+ to off, |
| 769 | // and HDR to off if HDR+ is supported. |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 770 | settingsManager.set(SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR_PLUS, false); |
Sascha Haeberling | 4c1bffe | 2014-08-21 10:01:00 -0700 | [diff] [blame] | 771 | if (GcamHelper.hasGcamAsSeparateModule()) { |
Erin Dahlgren | 21a6236 | 2014-06-24 10:13:01 -0700 | [diff] [blame] | 772 | settingsManager.set(SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR, false); |
Erin Dahlgren | e154793 | 2014-06-23 15:17:07 -0700 | [diff] [blame] | 773 | } |
Erin Dahlgren | 1ca516f | 2014-03-28 12:44:04 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | @Override |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 777 | public HardwareSpec getHardwareSpec() { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 778 | return (mCameraSettings != null ? |
| 779 | new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities) : null); |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | @Override |
| 783 | public CameraAppUI.BottomBarUISpec getBottomBarSpec() { |
| 784 | CameraAppUI.BottomBarUISpec bottomBarSpec = new CameraAppUI.BottomBarUISpec(); |
| 785 | |
| 786 | bottomBarSpec.enableCamera = true; |
| 787 | bottomBarSpec.cameraCallback = mCameraCallback; |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 788 | bottomBarSpec.enableFlash = !mAppController.getSettingsManager() |
| 789 | .getBoolean(SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_HDR); |
Erin Dahlgren | a6587a1 | 2014-02-03 13:24:55 -0800 | [diff] [blame] | 790 | bottomBarSpec.enableHdr = true; |
| 791 | bottomBarSpec.hdrCallback = mHdrPlusCallback; |
Erin Dahlgren | d5e5146 | 2014-02-07 12:38:57 -0800 | [diff] [blame] | 792 | bottomBarSpec.enableGridLines = true; |
Spike Sprague | 8f7425c | 2014-05-12 11:08:34 -0700 | [diff] [blame] | 793 | if (mCameraCapabilities != null) { |
| 794 | bottomBarSpec.enableExposureCompensation = true; |
| 795 | bottomBarSpec.exposureCompensationSetCallback = |
| 796 | new CameraAppUI.BottomBarUISpec.ExposureCompensationSetCallback() { |
| 797 | @Override |
| 798 | public void setExposure(int value) { |
| 799 | setExposureCompensation(value); |
| 800 | } |
| 801 | }; |
| 802 | bottomBarSpec.minExposureCompensation = |
| 803 | mCameraCapabilities.getMinExposureCompensation(); |
| 804 | bottomBarSpec.maxExposureCompensation = |
| 805 | mCameraCapabilities.getMaxExposureCompensation(); |
| 806 | bottomBarSpec.exposureCompensationStep = |
| 807 | mCameraCapabilities.getExposureCompensationStep(); |
| 808 | } |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 809 | |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 810 | bottomBarSpec.enableSelfTimer = true; |
Sascha Haeberling | 4333fac | 2014-05-20 16:28:11 -0700 | [diff] [blame] | 811 | bottomBarSpec.showSelfTimer = true; |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 812 | |
Erin Dahlgren | b1641f5 | 2014-01-14 15:58:52 -0800 | [diff] [blame] | 813 | if (isImageCaptureIntent()) { |
| 814 | bottomBarSpec.showCancel = true; |
| 815 | bottomBarSpec.cancelCallback = mCancelCallback; |
| 816 | bottomBarSpec.showDone = true; |
| 817 | bottomBarSpec.doneCallback = mDoneCallback; |
| 818 | bottomBarSpec.showRetake = true; |
| 819 | bottomBarSpec.retakeCallback = mRetakeCallback; |
| 820 | } |
| 821 | |
| 822 | return bottomBarSpec; |
Erin Dahlgren | 0a6a8d8 | 2014-01-09 22:17:38 -0800 | [diff] [blame] | 823 | } |
| 824 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 825 | // either open a new camera or switch cameras |
| 826 | private void openCameraCommon() { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 827 | mUI.onCameraOpened(mCameraCapabilities, mCameraSettings); |
Angus Kong | 0fb819b | 2013-10-08 13:44:19 -0700 | [diff] [blame] | 828 | if (mIsImageCaptureIntent) { |
Erin Dahlgren | e419b19 | 2013-12-03 13:10:27 -0800 | [diff] [blame] | 829 | // Set hdr plus to default: off. |
| 830 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 831 | settingsManager.setToDefault(SettingsManager.SCOPE_GLOBAL, |
| 832 | Keys.KEY_CAMERA_HDR_PLUS); |
Angus Kong | 0fb819b | 2013-10-08 13:44:19 -0700 | [diff] [blame] | 833 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 834 | updateSceneMode(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 835 | } |
| 836 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 837 | @Override |
Doris Liu | 70da918 | 2013-12-17 18:41:15 -0800 | [diff] [blame] | 838 | public void updatePreviewAspectRatio(float aspectRatio) { |
| 839 | mAppController.updatePreviewAspectRatio(aspectRatio); |
| 840 | } |
| 841 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 842 | private void resetExposureCompensation() { |
Erin Dahlgren | 357b767 | 2013-11-20 17:38:14 -0800 | [diff] [blame] | 843 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 844 | if (settingsManager == null) { |
| 845 | Log.e(TAG, "Settings manager is null!"); |
| 846 | return; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 847 | } |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 848 | settingsManager.setToDefault(mAppController.getCameraScope(), |
| 849 | Keys.KEY_EXPOSURE); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 850 | } |
| 851 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 852 | // Snapshots can only be taken after this is called. It should be called |
| 853 | // once only. We could have done these things in onCreate() but we want to |
| 854 | // make preview screen appear as soon as possible. |
| 855 | private void initializeFirstTime() { |
Sascha Haeberling | 330dafb | 2013-10-10 19:00:41 -0700 | [diff] [blame] | 856 | if (mFirstTimeInitialized || mPaused) { |
| 857 | return; |
| 858 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 859 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 860 | mUI.initializeFirstTime(); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 861 | |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 862 | // We set the listener only when both service and shutterbutton |
| 863 | // are initialized. |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 864 | getServices().getMemoryManager().addListener(this); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 865 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 866 | mNamedImages = new NamedImages(); |
| 867 | |
| 868 | mFirstTimeInitialized = true; |
| 869 | addIdleHandler(); |
| 870 | |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 871 | mActivity.updateStorageSpaceAndHint(null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 872 | } |
| 873 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 874 | // If the activity is paused and resumed, this method will be called in |
| 875 | // onResume. |
| 876 | private void initializeSecondTime() { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 877 | getServices().getMemoryManager().addListener(this); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 878 | mNamedImages = new NamedImages(); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 879 | mUI.initializeSecondTime(mCameraCapabilities, mCameraSettings); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 880 | } |
| 881 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 882 | private void addIdleHandler() { |
| 883 | MessageQueue queue = Looper.myQueue(); |
| 884 | queue.addIdleHandler(new MessageQueue.IdleHandler() { |
| 885 | @Override |
| 886 | public boolean queueIdle() { |
| 887 | Storage.ensureOSXCompatible(); |
| 888 | return false; |
| 889 | } |
| 890 | }); |
| 891 | } |
| 892 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 893 | @Override |
| 894 | public void startFaceDetection() { |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 895 | if (mFaceDetectionStarted || mCameraDevice == null) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 896 | return; |
| 897 | } |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 898 | if (mCameraCapabilities.getMaxNumOfFacesSupported() > 0) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 899 | mFaceDetectionStarted = true; |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 900 | mUI.onStartFaceDetection(mDisplayOrientation, isCameraFrontFacing()); |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 901 | mCameraDevice.setFaceDetectionCallback(mHandler, mUI); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 902 | mCameraDevice.startFaceDetection(); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 903 | SessionStatsCollector.instance().faceScanActive(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 907 | @Override |
| 908 | public void stopFaceDetection() { |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 909 | if (!mFaceDetectionStarted || mCameraDevice == null) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 910 | return; |
| 911 | } |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 912 | if (mCameraCapabilities.getMaxNumOfFacesSupported() > 0) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 913 | mFaceDetectionStarted = false; |
Angus Kong | 9e76552 | 2013-07-31 14:05:20 -0700 | [diff] [blame] | 914 | mCameraDevice.setFaceDetectionCallback(null, null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 915 | mCameraDevice.stopFaceDetection(); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 916 | mUI.clearFaces(); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 917 | SessionStatsCollector.instance().faceScanActive(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 921 | private final class ShutterCallback |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 922 | implements CameraShutterCallback { |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 923 | |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 924 | private final boolean mNeedsAnimation; |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 925 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 926 | public ShutterCallback(boolean needsAnimation) { |
| 927 | mNeedsAnimation = needsAnimation; |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 930 | @Override |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 931 | public void onShutter(CameraProxy camera) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 932 | mShutterCallbackTime = System.currentTimeMillis(); |
| 933 | mShutterLag = mShutterCallbackTime - mCaptureStartTime; |
| 934 | Log.v(TAG, "mShutterLag = " + mShutterLag + "ms"); |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 935 | if (mNeedsAnimation) { |
| 936 | mActivity.runOnUiThread(new Runnable() { |
| 937 | @Override |
| 938 | public void run() { |
| 939 | animateAfterShutter(); |
| 940 | } |
| 941 | }); |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 942 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 946 | private final class PostViewPictureCallback |
| 947 | implements CameraPictureCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 948 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 949 | public void onPictureTaken(byte[] data, CameraProxy camera) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 950 | mPostViewPictureCallbackTime = System.currentTimeMillis(); |
| 951 | Log.v(TAG, "mShutterToPostViewCallbackTime = " |
| 952 | + (mPostViewPictureCallbackTime - mShutterCallbackTime) |
| 953 | + "ms"); |
| 954 | } |
| 955 | } |
| 956 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 957 | private final class RawPictureCallback |
| 958 | implements CameraPictureCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 959 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 960 | public void onPictureTaken(byte[] rawData, CameraProxy camera) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 961 | mRawPictureCallbackTime = System.currentTimeMillis(); |
| 962 | Log.v(TAG, "mShutterToRawCallbackTime = " |
| 963 | + (mRawPictureCallbackTime - mShutterCallbackTime) + "ms"); |
| 964 | } |
| 965 | } |
| 966 | |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 967 | private static class ResizeBundle { |
| 968 | byte[] jpegData; |
| 969 | float targetAspectRatio; |
| 970 | ExifInterface exif; |
| 971 | } |
| 972 | |
| 973 | /** |
| 974 | * @return Cropped image if the target aspect ratio is larger than the jpeg |
| 975 | * aspect ratio on the long axis. The original jpeg otherwise. |
| 976 | */ |
| 977 | private ResizeBundle cropJpegDataToAspectRatio(ResizeBundle dataBundle) { |
| 978 | |
| 979 | final byte[] jpegData = dataBundle.jpegData; |
| 980 | final ExifInterface exif = dataBundle.exif; |
| 981 | float targetAspectRatio = dataBundle.targetAspectRatio; |
| 982 | |
| 983 | Bitmap original = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); |
| 984 | int originalWidth = original.getWidth(); |
| 985 | int originalHeight = original.getHeight(); |
| 986 | int newWidth; |
| 987 | int newHeight; |
| 988 | |
| 989 | if (originalWidth > originalHeight) { |
| 990 | newHeight = (int) (originalWidth / targetAspectRatio); |
| 991 | newWidth = originalWidth; |
| 992 | } else { |
| 993 | newWidth = (int) (originalHeight / targetAspectRatio); |
| 994 | newHeight = originalHeight; |
| 995 | } |
| 996 | int xOffset = (originalWidth - newWidth)/2; |
| 997 | int yOffset = (originalHeight - newHeight)/2; |
| 998 | |
| 999 | if (xOffset < 0 || yOffset < 0) { |
| 1000 | return dataBundle; |
| 1001 | } |
| 1002 | |
| 1003 | Bitmap resized = Bitmap.createBitmap(original,xOffset,yOffset,newWidth, newHeight); |
| 1004 | exif.setTagValue(ExifInterface.TAG_PIXEL_X_DIMENSION, new Integer(newWidth)); |
| 1005 | exif.setTagValue(ExifInterface.TAG_PIXEL_Y_DIMENSION, new Integer(newHeight)); |
| 1006 | |
| 1007 | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| 1008 | |
| 1009 | resized.compress(Bitmap.CompressFormat.JPEG, 90, stream); |
| 1010 | dataBundle.jpegData = stream.toByteArray(); |
| 1011 | return dataBundle; |
| 1012 | } |
| 1013 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1014 | private final class JpegPictureCallback |
| 1015 | implements CameraPictureCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1016 | Location mLocation; |
| 1017 | |
| 1018 | public JpegPictureCallback(Location loc) { |
| 1019 | mLocation = loc; |
| 1020 | } |
| 1021 | |
| 1022 | @Override |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1023 | public void onPictureTaken(final byte[] originalJpegData, final CameraProxy camera) { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1024 | Log.i(TAG, "onPictureTaken"); |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1025 | mAppController.setShutterEnabled(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1026 | if (mPaused) { |
| 1027 | return; |
| 1028 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1029 | if (mIsImageCaptureIntent) { |
| 1030 | stopPreview(); |
| 1031 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1032 | if (mSceneMode == CameraCapabilities.SceneMode.HDR) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1033 | mUI.setSwipingEnabled(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | mJpegPictureCallbackTime = System.currentTimeMillis(); |
| 1037 | // If postview callback has arrived, the captured image is displayed |
| 1038 | // in postview callback. If not, the captured image is displayed in |
| 1039 | // raw picture callback. |
| 1040 | if (mPostViewPictureCallbackTime != 0) { |
| 1041 | mShutterToPictureDisplayedTime = |
| 1042 | mPostViewPictureCallbackTime - mShutterCallbackTime; |
| 1043 | mPictureDisplayedToJpegCallbackTime = |
| 1044 | mJpegPictureCallbackTime - mPostViewPictureCallbackTime; |
| 1045 | } else { |
| 1046 | mShutterToPictureDisplayedTime = |
| 1047 | mRawPictureCallbackTime - mShutterCallbackTime; |
| 1048 | mPictureDisplayedToJpegCallbackTime = |
| 1049 | mJpegPictureCallbackTime - mRawPictureCallbackTime; |
| 1050 | } |
| 1051 | Log.v(TAG, "mPictureDisplayedToJpegCallbackTime = " |
| 1052 | + mPictureDisplayedToJpegCallbackTime + "ms"); |
| 1053 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1054 | mFocusManager.updateFocusUI(); // Ensure focus indicator is hidden. |
| 1055 | if (!mIsImageCaptureIntent) { |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 1056 | setupPreview(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1057 | } |
| 1058 | |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1059 | long now = System.currentTimeMillis(); |
| 1060 | mJpegCallbackFinishTime = now - mJpegPictureCallbackTime; |
| 1061 | Log.v(TAG, "mJpegCallbackFinishTime = " + mJpegCallbackFinishTime + "ms"); |
| 1062 | mJpegPictureCallbackTime = 0; |
| 1063 | |
| 1064 | final ExifInterface exif = Exif.getExif(originalJpegData); |
Sascha Haeberling | ce90f7b | 2014-10-10 15:20:35 -0700 | [diff] [blame] | 1065 | final NamedEntity name = mNamedImages.getNextNameEntity(); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1066 | if (mShouldResizeTo16x9) { |
| 1067 | final ResizeBundle dataBundle = new ResizeBundle(); |
| 1068 | dataBundle.jpegData = originalJpegData; |
| 1069 | dataBundle.targetAspectRatio = ResolutionUtil.NEXUS_5_LARGE_16_BY_9_ASPECT_RATIO; |
| 1070 | dataBundle.exif = exif; |
| 1071 | new AsyncTask<ResizeBundle, Void, ResizeBundle>() { |
| 1072 | |
| 1073 | @Override |
| 1074 | protected ResizeBundle doInBackground(ResizeBundle... resizeBundles) { |
| 1075 | return cropJpegDataToAspectRatio(resizeBundles[0]); |
| 1076 | } |
| 1077 | |
| 1078 | @Override |
| 1079 | protected void onPostExecute(ResizeBundle result) { |
Sascha Haeberling | ce90f7b | 2014-10-10 15:20:35 -0700 | [diff] [blame] | 1080 | saveFinalPhoto(result.jpegData, name, result.exif, camera); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1081 | } |
| 1082 | }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, dataBundle); |
| 1083 | |
| 1084 | } else { |
Sascha Haeberling | ce90f7b | 2014-10-10 15:20:35 -0700 | [diff] [blame] | 1085 | saveFinalPhoto(originalJpegData, name, exif, camera); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1086 | } |
| 1087 | } |
| 1088 | |
Sascha Haeberling | ce90f7b | 2014-10-10 15:20:35 -0700 | [diff] [blame] | 1089 | void saveFinalPhoto(final byte[] jpegData, NamedEntity name, final ExifInterface exif, |
| 1090 | CameraProxy camera) { |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 1091 | int orientation = Exif.getOrientation(exif); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1092 | |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1093 | float zoomValue = 1.0f; |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 1094 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.ZOOM)) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1095 | zoomValue = mCameraSettings.getCurrentZoomRatio(); |
Andy Huibers | e08bc04 | 2014-04-11 19:26:47 -0700 | [diff] [blame] | 1096 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1097 | boolean hdrOn = CameraCapabilities.SceneMode.HDR == mSceneMode; |
Andy Huibers | 203abe5 | 2014-05-19 13:59:01 -0700 | [diff] [blame] | 1098 | String flashSetting = |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1099 | mActivity.getSettingsManager().getString(mAppController.getCameraScope(), |
| 1100 | Keys.KEY_FLASH_MODE); |
| 1101 | boolean gridLinesOn = Keys.areGridLinesOn(mActivity.getSettingsManager()); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1102 | UsageStatistics.instance().photoCaptureDoneEvent( |
| 1103 | eventprotos.NavigationChange.Mode.PHOTO_CAPTURE, |
Sascha Haeberling | ce90f7b | 2014-10-10 15:20:35 -0700 | [diff] [blame] | 1104 | name.title + ".jpg", exif, |
Andy Huibers | 547d7c8 | 2014-05-20 23:03:18 -0700 | [diff] [blame] | 1105 | isCameraFrontFacing(), hdrOn, zoomValue, flashSetting, gridLinesOn, |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1106 | (float) mTimerDuration, mShutterTouchCoordinate, mVolumeButtonClickedFlag); |
| 1107 | mShutterTouchCoordinate = null; |
| 1108 | mVolumeButtonClickedFlag = false; |
Ruben Brunk | d217ed0 | 2013-10-08 23:31:13 -0700 | [diff] [blame] | 1109 | |
Ruben Brunk | d748827 | 2013-10-10 18:45:53 -0700 | [diff] [blame] | 1110 | if (!mIsImageCaptureIntent) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1111 | // Calculate the width and the height of the jpeg. |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1112 | Integer exifWidth = exif.getTagIntValue(ExifInterface.TAG_PIXEL_X_DIMENSION); |
| 1113 | Integer exifHeight = exif.getTagIntValue(ExifInterface.TAG_PIXEL_Y_DIMENSION); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1114 | int width, height; |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1115 | if (mShouldResizeTo16x9 && exifWidth != null && exifHeight != null) { |
| 1116 | width = exifWidth; |
| 1117 | height = exifHeight; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1118 | } else { |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1119 | Size s; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1120 | s = mCameraSettings.getCurrentPhotoSize(); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 1121 | if ((mJpegRotation + orientation) % 180 == 0) { |
| 1122 | width = s.width(); |
| 1123 | height = s.height(); |
| 1124 | } else { |
| 1125 | width = s.height(); |
| 1126 | height = s.width(); |
| 1127 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1128 | } |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1129 | String title = (name == null) ? null : name.title; |
| 1130 | long date = (name == null) ? -1 : name.date; |
Ruben Brunk | d748827 | 2013-10-10 18:45:53 -0700 | [diff] [blame] | 1131 | |
| 1132 | // Handle debug mode outputs |
| 1133 | if (mDebugUri != null) { |
| 1134 | // If using a debug uri, save jpeg there. |
| 1135 | saveToDebugUri(jpegData); |
| 1136 | |
| 1137 | // Adjust the title of the debug image shown in mediastore. |
| 1138 | if (title != null) { |
| 1139 | title = DEBUG_IMAGE_PREFIX + title; |
| 1140 | } |
| 1141 | } |
| 1142 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1143 | if (title == null) { |
| 1144 | Log.e(TAG, "Unbalanced name/data pair"); |
| 1145 | } else { |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 1146 | if (date == -1) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1147 | date = mCaptureStartTime; |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 1148 | } |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1149 | if (mHeading >= 0) { |
| 1150 | // heading direction has been updated by the sensor. |
| 1151 | ExifTag directionRefTag = exif.buildTag( |
| 1152 | ExifInterface.TAG_GPS_IMG_DIRECTION_REF, |
| 1153 | ExifInterface.GpsTrackRef.MAGNETIC_DIRECTION); |
| 1154 | ExifTag directionTag = exif.buildTag( |
| 1155 | ExifInterface.TAG_GPS_IMG_DIRECTION, |
| 1156 | new Rational(mHeading, 1)); |
| 1157 | exif.setTag(directionRefTag); |
| 1158 | exif.setTag(directionTag); |
| 1159 | } |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 1160 | getServices().getMediaSaver().addImage( |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 1161 | jpegData, title, date, mLocation, width, height, |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1162 | orientation, exif, mOnMediaSavedListener, mContentResolver); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1163 | } |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1164 | // Animate capture with real jpeg data instead of a preview |
| 1165 | // frame. |
Doris Liu | 29da2db | 2013-08-28 14:28:45 -0700 | [diff] [blame] | 1166 | mUI.animateCapture(jpegData, orientation, mMirror); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1167 | } else { |
| 1168 | mJpegImageData = jpegData; |
| 1169 | if (!mQuickCapture) { |
Doris Liu | 36e56fb | 2013-09-11 17:38:08 -0700 | [diff] [blame] | 1170 | mUI.showCapturedImageForReview(jpegData, orientation, mMirror); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1171 | } else { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1172 | onCaptureDone(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | |
Sascha Haeberling | bca64bf | 2014-04-17 10:51:53 -0700 | [diff] [blame] | 1176 | // Send the taken photo to remote shutter listeners, if any are |
| 1177 | // registered. |
Sascha Haeberling | 3c6de14 | 2014-07-14 12:23:36 -0700 | [diff] [blame] | 1178 | getServices().getRemoteShutterListener().onPictureTaken(jpegData); |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 1179 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1180 | // Check this in advance of each shot so we don't add to shutter |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1181 | // latency. It's true that someone else could write to the SD card |
| 1182 | // in the mean time and fill it, but that could have happened |
| 1183 | // between the shutter press and saving the JPEG too. |
Spike Sprague | e6374b7 | 2014-04-25 17:24:32 -0700 | [diff] [blame] | 1184 | mActivity.updateStorageSpaceAndHint(null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1188 | private final class AutoFocusCallback implements CameraAFCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1189 | @Override |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1190 | public void onAutoFocus(boolean focused, CameraProxy camera) { |
| 1191 | SessionStatsCollector.instance().autofocusResult(focused); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1192 | if (mPaused) { |
| 1193 | return; |
| 1194 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1195 | |
| 1196 | mAutoFocusTime = System.currentTimeMillis() - mFocusStartTime; |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1197 | Log.v(TAG, "mAutoFocusTime = " + mAutoFocusTime + "ms focused = "+focused); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1198 | setCameraState(IDLE); |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1199 | mFocusManager.onAutoFocus(focused, false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 1203 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1204 | private final class AutoFocusMoveCallback |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1205 | implements CameraAFMoveCallback { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1206 | @Override |
| 1207 | public void onAutoFocusMoving( |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1208 | boolean moving, CameraProxy camera) { |
| 1209 | mFocusManager.onAutoFocusMoving(moving); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1210 | SessionStatsCollector.instance().autofocusMoving(moving); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1214 | /** |
| 1215 | * This class is just a thread-safe queue for name,date holder objects. |
| 1216 | */ |
| 1217 | public static class NamedImages { |
Sascha Haeberling | 280fd3e | 2013-11-21 13:52:15 -0800 | [diff] [blame] | 1218 | private final Vector<NamedEntity> mQueue; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1219 | |
| 1220 | public NamedImages() { |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1221 | mQueue = new Vector<NamedEntity>(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1224 | public void nameNewImage(long date) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1225 | NamedEntity r = new NamedEntity(); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1226 | r.title = CameraUtil.createJpegName(date); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1227 | r.date = date; |
| 1228 | mQueue.add(r); |
| 1229 | } |
| 1230 | |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1231 | public NamedEntity getNextNameEntity() { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1232 | synchronized (mQueue) { |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1233 | if (!mQueue.isEmpty()) { |
| 1234 | return mQueue.remove(0); |
| 1235 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1236 | } |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1237 | return null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1240 | public static class NamedEntity { |
| 1241 | public String title; |
| 1242 | public long date; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | private void setCameraState(int state) { |
| 1247 | mCameraState = state; |
| 1248 | switch (state) { |
Angus Kong | 62753ae | 2014-02-10 10:53:54 -0800 | [diff] [blame] | 1249 | case PREVIEW_STOPPED: |
| 1250 | case SNAPSHOT_IN_PROGRESS: |
| 1251 | case SWITCHING_CAMERA: |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1252 | // TODO: Tell app UI to disable swipe |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1253 | break; |
| 1254 | case PhotoController.IDLE: |
Doris Liu | f55f3c4 | 2013-11-20 00:24:46 -0800 | [diff] [blame] | 1255 | // TODO: Tell app UI to enable swipe |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1256 | break; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1257 | } |
| 1258 | } |
| 1259 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1260 | private void animateAfterShutter() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1261 | // Only animate when in full screen capture mode |
| 1262 | // i.e. If monkey/a user swipes to the gallery during picture taking, |
| 1263 | // don't show animation |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 1264 | if (!mIsImageCaptureIntent) { |
| 1265 | mUI.animateFlash(); |
Doris Liu | c2e9abd | 2013-06-19 14:20:51 -0700 | [diff] [blame] | 1266 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | @Override |
| 1270 | public boolean capture() { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1271 | // If we are already in the middle of taking a snapshot or the image |
| 1272 | // save request is full then ignore. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1273 | if (mCameraDevice == null || mCameraState == SNAPSHOT_IN_PROGRESS |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1274 | || mCameraState == SWITCHING_CAMERA || !mAppController.isShutterEnabled()) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1275 | return false; |
| 1276 | } |
| 1277 | mCaptureStartTime = System.currentTimeMillis(); |
Sascha Haeberling | bca64bf | 2014-04-17 10:51:53 -0700 | [diff] [blame] | 1278 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1279 | mPostViewPictureCallbackTime = 0; |
| 1280 | mJpegImageData = null; |
| 1281 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1282 | final boolean animateBefore = (mSceneMode == CameraCapabilities.SceneMode.HDR); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1283 | |
| 1284 | if (animateBefore) { |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1285 | animateAfterShutter(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
Erin Dahlgren | c120b0f | 2013-11-19 10:53:49 -0800 | [diff] [blame] | 1288 | Location loc = mActivity.getLocationManager().getCurrentLocation(); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1289 | CameraUtil.setGpsParameters(mCameraSettings, loc); |
| 1290 | mCameraDevice.applySettings(mCameraSettings); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1291 | |
Senpo Hu | bb1c72f | 2014-09-08 01:07:27 -0700 | [diff] [blame] | 1292 | // Set JPEG orientation. Even if screen UI is locked in portrait, camera orientation should |
| 1293 | // still match device orientation (e.g., users should always get landscape photos while |
| 1294 | // capturing by putting device in landscape.) |
| 1295 | int orientation = mActivity.isAutoRotateScreen() ? mDisplayRotation : mOrientation; |
| 1296 | Characteristics info = mActivity.getCameraProvider().getCharacteristics(mCameraId); |
| 1297 | mJpegRotation = info.getJpegOrientation(orientation); |
| 1298 | mCameraDevice.setJpegOrientation(mJpegRotation); |
| 1299 | |
Sascha Haeberling | 8890194 | 2013-08-28 17:49:00 -0700 | [diff] [blame] | 1300 | // We don't want user to press the button again while taking a |
| 1301 | // multi-second HDR photo. |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 1302 | mAppController.setShutterEnabled(false); |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1303 | mCameraDevice.takePicture(mHandler, |
| 1304 | new ShutterCallback(!animateBefore), |
Angus Kong | dcb0ef1 | 2013-03-25 23:11:43 -0700 | [diff] [blame] | 1305 | mRawPictureCallback, mPostViewPictureCallback, |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1306 | new JpegPictureCallback(loc)); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1307 | |
Ruben Brunk | a9d66bd | 2013-09-06 11:56:32 -0700 | [diff] [blame] | 1308 | mNamedImages.nameNewImage(mCaptureStartTime); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1309 | |
| 1310 | mFaceDetectionStarted = false; |
| 1311 | setCameraState(SNAPSHOT_IN_PROGRESS); |
| 1312 | return true; |
| 1313 | } |
| 1314 | |
| 1315 | @Override |
| 1316 | public void setFocusParameters() { |
| 1317 | setCameraParameters(UPDATE_PARAM_PREFERENCE); |
| 1318 | } |
| 1319 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1320 | private void updateSceneMode() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1321 | // If scene mode is set, we cannot set flash mode, white balance, and |
| 1322 | // focus mode, instead, we read it from driver |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1323 | if (CameraCapabilities.SceneMode.AUTO != mSceneMode) { |
| 1324 | overrideCameraSettings(mCameraSettings.getCurrentFlashMode(), |
| 1325 | mCameraSettings.getCurrentFocusMode()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1326 | } |
| 1327 | } |
| 1328 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1329 | private void overrideCameraSettings(CameraCapabilities.FlashMode flashMode, |
| 1330 | CameraCapabilities.FocusMode focusMode) { |
| 1331 | CameraCapabilities.Stringifier stringifier = mCameraCapabilities.getStringifier(); |
Erin Dahlgren | e419b19 | 2013-12-03 13:10:27 -0800 | [diff] [blame] | 1332 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Alan Newberger | 347dccb | 2014-09-24 17:19:25 -0700 | [diff] [blame] | 1333 | if (!CameraCapabilities.FlashMode.NO_FLASH.equals(flashMode)) { |
| 1334 | settingsManager.set(mAppController.getCameraScope(), Keys.KEY_FLASH_MODE, |
| 1335 | stringifier.stringify(flashMode)); |
| 1336 | } |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1337 | settingsManager.set(mAppController.getCameraScope(), Keys.KEY_FOCUS_MODE, |
Alan Newberger | 347dccb | 2014-09-24 17:19:25 -0700 | [diff] [blame] | 1338 | stringifier.stringify(focusMode)); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1342 | public void onOrientationChanged(int orientation) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1343 | if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) { |
| 1344 | return; |
| 1345 | } |
Senpo Hu | bb1c72f | 2014-09-08 01:07:27 -0700 | [diff] [blame] | 1346 | |
| 1347 | // TODO: Document orientation compute logic and unify them in OrientationManagerImpl. |
| 1348 | // b/17443789 |
| 1349 | // Flip to counter-clockwise orientation. |
| 1350 | mOrientation = (360 - orientation) % 360; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | @Override |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1354 | public void onCameraAvailable(CameraProxy cameraProxy) { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1355 | Log.i(TAG, "onCameraAvailable"); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1356 | if (mPaused) { |
| 1357 | return; |
| 1358 | } |
| 1359 | mCameraDevice = cameraProxy; |
| 1360 | |
| 1361 | initializeCapabilities(); |
| 1362 | |
| 1363 | // Reset zoom value index. |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1364 | mZoomValue = 1.0f; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1365 | if (mFocusManager == null) { |
| 1366 | initializeFocusManager(); |
| 1367 | } |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1368 | mFocusManager.updateCapabilities(mCameraCapabilities); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1369 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 1370 | // Do camera parameter dependent initialization. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1371 | mCameraSettings = mCameraDevice.getSettings(); |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1372 | |
| 1373 | setCameraParameters(UPDATE_PARAM_ALL); |
| 1374 | // Set a listener which updates camera parameters based |
| 1375 | // on changed settings. |
| 1376 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 1377 | settingsManager.addListener(this); |
| 1378 | mCameraPreviewParamsReady = true; |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 1379 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1380 | startPreview(); |
| 1381 | |
| 1382 | onCameraOpened(); |
| 1383 | } |
| 1384 | |
| 1385 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1386 | public void onCaptureCancelled() { |
| 1387 | mActivity.setResultEx(Activity.RESULT_CANCELED, new Intent()); |
| 1388 | mActivity.finish(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1389 | } |
| 1390 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1391 | @Override |
| 1392 | public void onCaptureRetake() { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1393 | Log.i(TAG, "onCaptureRetake"); |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 1394 | if (mPaused) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1395 | return; |
Sascha Haeberling | 3b0ab89 | 2014-01-29 20:54:39 +0100 | [diff] [blame] | 1396 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1397 | mUI.hidePostCaptureAlert(); |
Spike Sprague | b4a2222 | 2014-05-22 14:40:53 -0700 | [diff] [blame] | 1398 | mUI.hideIntentReviewImageView(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1399 | setupPreview(); |
| 1400 | } |
| 1401 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1402 | @Override |
| 1403 | public void onCaptureDone() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1404 | if (mPaused) { |
| 1405 | return; |
| 1406 | } |
| 1407 | |
| 1408 | byte[] data = mJpegImageData; |
| 1409 | |
| 1410 | if (mCropValue == null) { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1411 | // First handle the no crop case -- just return the value. If the |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1412 | // caller specifies a "save uri" then write the data to its |
| 1413 | // stream. Otherwise, pass back a scaled down version of the bitmap |
| 1414 | // directly in the extras. |
| 1415 | if (mSaveUri != null) { |
| 1416 | OutputStream outputStream = null; |
| 1417 | try { |
| 1418 | outputStream = mContentResolver.openOutputStream(mSaveUri); |
| 1419 | outputStream.write(data); |
| 1420 | outputStream.close(); |
| 1421 | |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1422 | Log.v(TAG, "saved result to URI: " + mSaveUri); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1423 | mActivity.setResultEx(Activity.RESULT_OK); |
| 1424 | mActivity.finish(); |
| 1425 | } catch (IOException ex) { |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1426 | Log.w(TAG, "exception saving result to URI: " + mSaveUri, ex); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1427 | // ignore exception |
| 1428 | } finally { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1429 | CameraUtil.closeSilently(outputStream); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1430 | } |
| 1431 | } else { |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1432 | ExifInterface exif = Exif.getExif(data); |
| 1433 | int orientation = Exif.getOrientation(exif); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1434 | Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024); |
| 1435 | bitmap = CameraUtil.rotate(bitmap, orientation); |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1436 | Log.v(TAG, "inlined bitmap into capture intent result"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1437 | mActivity.setResultEx(Activity.RESULT_OK, |
| 1438 | new Intent("inline-data").putExtra("data", bitmap)); |
| 1439 | mActivity.finish(); |
| 1440 | } |
| 1441 | } else { |
| 1442 | // Save the image to a temp file and invoke the cropper |
| 1443 | Uri tempUri = null; |
| 1444 | FileOutputStream tempStream = null; |
| 1445 | try { |
| 1446 | File path = mActivity.getFileStreamPath(sTempCropFilename); |
| 1447 | path.delete(); |
| 1448 | tempStream = mActivity.openFileOutput(sTempCropFilename, 0); |
| 1449 | tempStream.write(data); |
| 1450 | tempStream.close(); |
| 1451 | tempUri = Uri.fromFile(path); |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1452 | Log.v(TAG, "wrote temp file for cropping to: " + sTempCropFilename); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1453 | } catch (FileNotFoundException ex) { |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1454 | Log.w(TAG, "error writing temp cropping file to: " + sTempCropFilename, ex); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1455 | mActivity.setResultEx(Activity.RESULT_CANCELED); |
| 1456 | mActivity.finish(); |
| 1457 | return; |
| 1458 | } catch (IOException ex) { |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1459 | Log.w(TAG, "error writing temp cropping file to: " + sTempCropFilename, ex); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1460 | mActivity.setResultEx(Activity.RESULT_CANCELED); |
| 1461 | mActivity.finish(); |
| 1462 | return; |
| 1463 | } finally { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1464 | CameraUtil.closeSilently(tempStream); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | Bundle newExtras = new Bundle(); |
| 1468 | if (mCropValue.equals("circle")) { |
| 1469 | newExtras.putString("circleCrop", "true"); |
| 1470 | } |
| 1471 | if (mSaveUri != null) { |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1472 | Log.v(TAG, "setting output of cropped file to: " + mSaveUri); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1473 | newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, mSaveUri); |
| 1474 | } else { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1475 | newExtras.putBoolean(CameraUtil.KEY_RETURN_DATA, true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1476 | } |
| 1477 | if (mActivity.isSecureCamera()) { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1478 | newExtras.putBoolean(CameraUtil.KEY_SHOW_WHEN_LOCKED, true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
Sascha Haeberling | 37f3611 | 2013-08-06 14:31:52 -0700 | [diff] [blame] | 1481 | // TODO: Share this constant. |
Sascha Haeberling | 8e963a5 | 2013-08-06 11:43:02 -0700 | [diff] [blame] | 1482 | final String CROP_ACTION = "com.android.camera.action.CROP"; |
| 1483 | Intent cropIntent = new Intent(CROP_ACTION); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1484 | |
| 1485 | cropIntent.setData(tempUri); |
| 1486 | cropIntent.putExtras(newExtras); |
Alan Newberger | f974ba7 | 2014-09-08 14:44:30 -0700 | [diff] [blame] | 1487 | Log.v(TAG, "starting CROP intent for capture"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1488 | mActivity.startActivityForResult(cropIntent, REQUEST_CROP); |
| 1489 | } |
| 1490 | } |
| 1491 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1492 | @Override |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1493 | public void onShutterCoordinate(TouchCoordinate coord) { |
| 1494 | mShutterTouchCoordinate = coord; |
| 1495 | } |
| 1496 | |
| 1497 | @Override |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1498 | public void onShutterButtonFocus(boolean pressed) { |
Angus Kong | eaaf56d | 2014-02-20 11:59:10 -0800 | [diff] [blame] | 1499 | // Do nothing. We don't support half-press to focus anymore. |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | @Override |
| 1503 | public void onShutterButtonClick() { |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 1504 | if (mPaused || (mCameraState == SWITCHING_CAMERA) |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1505 | || (mCameraState == PREVIEW_STOPPED)) { |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1506 | mVolumeButtonClickedFlag = false; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1507 | return; |
| 1508 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1509 | |
| 1510 | // Do not take the picture if there is not enough storage. |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1511 | if (mActivity.getStorageSpaceBytes() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1512 | Log.i(TAG, "Not enough space or storage not ready. remaining=" |
Angus Kong | 2dcc0a9 | 2013-09-25 13:00:08 -0700 | [diff] [blame] | 1513 | + mActivity.getStorageSpaceBytes()); |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1514 | mVolumeButtonClickedFlag = false; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1515 | return; |
| 1516 | } |
Andy Huibers | b7c7d9a | 2014-06-18 22:26:14 -0700 | [diff] [blame] | 1517 | Log.d(TAG, "onShutterButtonClick: mCameraState=" + mCameraState + |
| 1518 | " mVolumeButtonClickedFlag=" + mVolumeButtonClickedFlag); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1519 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1520 | int countDownDuration = mActivity.getSettingsManager() |
| 1521 | .getInteger(SettingsManager.SCOPE_GLOBAL, Keys.KEY_COUNTDOWN_DURATION); |
Andy Huibers | 547d7c8 | 2014-05-20 23:03:18 -0700 | [diff] [blame] | 1522 | mTimerDuration = countDownDuration; |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1523 | if (countDownDuration > 0) { |
| 1524 | // Start count down. |
| 1525 | mAppController.getCameraAppUI().transitionToCancel(); |
| 1526 | mAppController.getCameraAppUI().hideModeOptions(); |
| 1527 | mUI.startCountdown(countDownDuration); |
| 1528 | return; |
| 1529 | } else { |
| 1530 | focusAndCapture(); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | private void focusAndCapture() { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 1535 | if (mSceneMode == CameraCapabilities.SceneMode.HDR) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1536 | mUI.setSwipingEnabled(false); |
Doris Liu | 9cdfe00 | 2013-04-16 09:50:56 -0700 | [diff] [blame] | 1537 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1538 | // If the user wants to do a snapshot while the previous one is still |
| 1539 | // in progress, remember the fact and do it after we finish the previous |
| 1540 | // one and re-start the preview. Snapshot in progress also includes the |
| 1541 | // state that autofocus is focusing and a picture will be taken when |
| 1542 | // focus callback arrives. |
Angus Kong | eaaf56d | 2014-02-20 11:59:10 -0800 | [diff] [blame] | 1543 | if ((mFocusManager.isFocusingSnapOnFinish() || mCameraState == SNAPSHOT_IN_PROGRESS)) { |
| 1544 | if (!mIsImageCaptureIntent) { |
| 1545 | mSnapshotOnIdle = true; |
| 1546 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1547 | return; |
| 1548 | } |
| 1549 | |
Doris Liu | f9e4f8f | 2013-12-04 18:04:22 -0800 | [diff] [blame] | 1550 | mSnapshotOnIdle = false; |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1551 | mFocusManager.focusAndCapture(mCameraSettings.getCurrentFocusMode()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1554 | @Override |
| 1555 | public void onRemainingSecondsChanged(int remainingSeconds) { |
Andy Huibers | a31162c | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 1556 | if (remainingSeconds == 1) { |
Spike Sprague | eeeed4f | 2014-08-27 12:01:36 -0700 | [diff] [blame] | 1557 | mCountdownSoundPlayer.play(R.raw.timer_final_second, 0.6f); |
Andy Huibers | a31162c | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 1558 | } else if (remainingSeconds == 2 || remainingSeconds == 3) { |
Spike Sprague | eeeed4f | 2014-08-27 12:01:36 -0700 | [diff] [blame] | 1559 | mCountdownSoundPlayer.play(R.raw.timer_increment, 0.6f); |
Andy Huibers | a31162c | 2014-09-02 11:27:11 -0700 | [diff] [blame] | 1560 | } |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | @Override |
| 1564 | public void onCountDownFinished() { |
Spike Sprague | 9f3d01d | 2014-06-30 14:52:57 -0700 | [diff] [blame] | 1565 | if (mIsImageCaptureIntent) { |
| 1566 | mAppController.getCameraAppUI().transitionToIntentReviewLayout(); |
| 1567 | } else { |
| 1568 | mAppController.getCameraAppUI().transitionToCapture(); |
| 1569 | } |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1570 | mAppController.getCameraAppUI().showModeOptions(); |
| 1571 | if (mPaused) { |
| 1572 | return; |
| 1573 | } |
| 1574 | focusAndCapture(); |
| 1575 | } |
| 1576 | |
Puneet Lall | 4de9b72 | 2014-09-25 15:05:47 -0700 | [diff] [blame] | 1577 | @Override |
| 1578 | public void resume() { |
| 1579 | mPaused = false; |
Sascha Haeberling | dcea763 | 2014-07-17 14:06:02 -0700 | [diff] [blame] | 1580 | |
Spike Sprague | eeeed4f | 2014-08-27 12:01:36 -0700 | [diff] [blame] | 1581 | mCountdownSoundPlayer.loadSound(R.raw.timer_final_second); |
| 1582 | mCountdownSoundPlayer.loadSound(R.raw.timer_increment); |
Sascha Haeberling | dcea763 | 2014-07-17 14:06:02 -0700 | [diff] [blame] | 1583 | if (mFocusManager != null) { |
| 1584 | // If camera is not open when resume is called, focus manager will |
| 1585 | // not be initialized yet, in which case it will start listening to |
| 1586 | // preview area size change later in the initialization. |
| 1587 | mAppController.addPreviewAreaSizeChangedListener(mFocusManager); |
| 1588 | } |
| 1589 | mAppController.addPreviewAreaSizeChangedListener(mUI); |
| 1590 | |
Angus Kong | 0b9eb5b | 2014-04-30 15:03:33 -0700 | [diff] [blame] | 1591 | CameraProvider camProvider = mActivity.getCameraProvider(); |
| 1592 | if (camProvider == null) { |
| 1593 | // No camera provider, the Activity is destroyed already. |
| 1594 | return; |
| 1595 | } |
Sol Boucher | 44ce4b2 | 2014-08-04 23:41:38 -0700 | [diff] [blame] | 1596 | requestCameraOpen(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1597 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1598 | mJpegPictureCallbackTime = 0; |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 1599 | mZoomValue = 1.0f; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1600 | |
| 1601 | mOnResumeTime = SystemClock.uptimeMillis(); |
| 1602 | checkDisplayRotation(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1603 | |
| 1604 | // If first time initialization is not finished, put it in the |
| 1605 | // message queue. |
| 1606 | if (!mFirstTimeInitialized) { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1607 | mHandler.sendEmptyMessage(MSG_FIRST_TIME_INIT); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1608 | } else { |
| 1609 | initializeSecondTime(); |
| 1610 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1611 | |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1612 | Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); |
| 1613 | if (gsensor != null) { |
| 1614 | mSensorManager.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_NORMAL); |
| 1615 | } |
| 1616 | |
| 1617 | Sensor msensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); |
| 1618 | if (msensor != null) { |
| 1619 | mSensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_NORMAL); |
| 1620 | } |
Sascha Haeberling | dcea763 | 2014-07-17 14:06:02 -0700 | [diff] [blame] | 1621 | |
| 1622 | getServices().getRemoteShutterListener().onModuleReady(this); |
| 1623 | SessionStatsCollector.instance().sessionActive(true); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1626 | /** |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 1627 | * @return Whether the currently active camera is front-facing. |
| 1628 | */ |
| 1629 | private boolean isCameraFrontFacing() { |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 1630 | return mAppController.getCameraProvider().getCharacteristics(mCameraId) |
| 1631 | .isFacingFront(); |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | /** |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 1635 | * The focus manager is the first UI related element to get initialized, and |
| 1636 | * it requires the RenderOverlay, so initialize it here |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1637 | */ |
| 1638 | private void initializeFocusManager() { |
| 1639 | // Create FocusManager object. startPreview needs it. |
| 1640 | // if mFocusManager not null, reuse it |
| 1641 | // otherwise create a new instance |
| 1642 | if (mFocusManager != null) { |
| 1643 | mFocusManager.removeMessages(); |
| 1644 | } else { |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 1645 | mMirror = isCameraFrontFacing(); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1646 | String[] defaultFocusModesStrings = mActivity.getResources().getStringArray( |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1647 | R.array.pref_camera_focusmode_default_array); |
Sascha Haeberling | ee36c5f | 2014-07-29 17:05:43 -0700 | [diff] [blame] | 1648 | ArrayList<CameraCapabilities.FocusMode> defaultFocusModes = |
| 1649 | new ArrayList<CameraCapabilities.FocusMode>(); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 1650 | CameraCapabilities.Stringifier stringifier = mCameraCapabilities.getStringifier(); |
| 1651 | for (String modeString : defaultFocusModesStrings) { |
| 1652 | CameraCapabilities.FocusMode mode = stringifier.focusModeFromString(modeString); |
| 1653 | if (mode != null) { |
| 1654 | defaultFocusModes.add(mode); |
| 1655 | } |
| 1656 | } |
| 1657 | mFocusManager = |
| 1658 | new FocusOverlayManager(mAppController, defaultFocusModes, |
| 1659 | mCameraCapabilities, this, mMirror, mActivity.getMainLooper(), |
| 1660 | mUI.getFocusUI()); |
Kevin Gabayan | fb33336 | 2014-06-02 14:48:20 -0700 | [diff] [blame] | 1661 | MotionManager motionManager = getServices().getMotionManager(); |
| 1662 | if (motionManager != null) { |
| 1663 | motionManager.addListener(mFocusManager); |
| 1664 | } |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1665 | } |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 1666 | mAppController.addPreviewAreaSizeChangedListener(mFocusManager); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1667 | } |
| 1668 | |
Sascha Haeberling | dcea763 | 2014-07-17 14:06:02 -0700 | [diff] [blame] | 1669 | /** |
| 1670 | * @return Whether we are resuming from within the lockscreen. |
| 1671 | */ |
| 1672 | private boolean isResumeFromLockscreen() { |
| 1673 | String action = mActivity.getIntent().getAction(); |
| 1674 | return (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action) |
| 1675 | || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)); |
| 1676 | } |
| 1677 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1678 | @Override |
Angus Kong | c4e6656 | 2013-11-22 23:03:21 -0800 | [diff] [blame] | 1679 | public void pause() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1680 | mPaused = true; |
Sascha Haeberling | 1bf0889 | 2014-06-18 09:38:06 -0700 | [diff] [blame] | 1681 | getServices().getRemoteShutterListener().onModuleExit(); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1682 | SessionStatsCollector.instance().sessionActive(false); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 1683 | |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 1684 | Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); |
| 1685 | if (gsensor != null) { |
| 1686 | mSensorManager.unregisterListener(this, gsensor); |
| 1687 | } |
| 1688 | |
| 1689 | Sensor msensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); |
| 1690 | if (msensor != null) { |
| 1691 | mSensorManager.unregisterListener(this, msensor); |
| 1692 | } |
Andy Huibers | def975d | 2013-11-22 09:13:39 -0800 | [diff] [blame] | 1693 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1694 | // Reset the focus first. Camera CTS does not guarantee that |
| 1695 | // cancelAutoFocus is allowed after preview stops. |
| 1696 | if (mCameraDevice != null && mCameraState != PREVIEW_STOPPED) { |
| 1697 | mCameraDevice.cancelAutoFocus(); |
| 1698 | } |
Andy Huibers | def975d | 2013-11-22 09:13:39 -0800 | [diff] [blame] | 1699 | |
Erin Dahlgren | b09b53e | 2013-11-06 11:57:51 -0800 | [diff] [blame] | 1700 | // If the camera has not been opened asynchronously yet, |
| 1701 | // and startPreview hasn't been called, then this is a no-op. |
| 1702 | // (e.g. onResume -> onPause -> onResume). |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1703 | stopPreview(); |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1704 | cancelCountDown(); |
Andy Huibers | 877c2b6 | 2014-10-03 15:22:47 -0700 | [diff] [blame] | 1705 | mCountdownSoundPlayer.unloadSound(R.raw.timer_final_second); |
| 1706 | mCountdownSoundPlayer.unloadSound(R.raw.timer_increment); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1707 | |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 1708 | mNamedImages = null; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1709 | // If we are in an image capture intent and has taken |
| 1710 | // a picture, we just clear it in onPause. |
| 1711 | mJpegImageData = null; |
| 1712 | |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 1713 | // Remove the messages and runnables in the queue. |
| 1714 | mHandler.removeCallbacksAndMessages(null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1715 | |
Erin Dahlgren | dc282e1 | 2013-11-12 09:39:08 -0800 | [diff] [blame] | 1716 | closeCamera(); |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 1717 | mActivity.enableKeepScreenOn(false); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1718 | mUI.onPause(); |
| 1719 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1720 | mPendingSwitchCameraId = -1; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1721 | if (mFocusManager != null) { |
| 1722 | mFocusManager.removeMessages(); |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 1723 | } |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1724 | getServices().getMemoryManager().removeListener(this); |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 1725 | mAppController.removePreviewAreaSizeChangedListener(mFocusManager); |
Doris Liu | 6c75164 | 2014-05-05 18:43:26 -0700 | [diff] [blame] | 1726 | mAppController.removePreviewAreaSizeChangedListener(mUI); |
Erin Dahlgren | 1648c36 | 2014-01-06 15:06:04 -0800 | [diff] [blame] | 1727 | |
| 1728 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 1729 | settingsManager.removeListener(this); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1732 | @Override |
| 1733 | public void destroy() { |
Andy Huibers | 877c2b6 | 2014-10-03 15:22:47 -0700 | [diff] [blame] | 1734 | mCountdownSoundPlayer.release(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | @Override |
Angus Kong | 2f0e4a3 | 2013-12-03 10:02:35 -0800 | [diff] [blame] | 1738 | public void onLayoutOrientationChanged(boolean isLandscape) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1739 | setDisplayOrientation(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | @Override |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1743 | public void updateCameraOrientation() { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1744 | if (mDisplayRotation != CameraUtil.getDisplayRotation(mActivity)) { |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1745 | setDisplayOrientation(); |
| 1746 | } |
| 1747 | } |
| 1748 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1749 | private boolean canTakePicture() { |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1750 | return isCameraIdle() |
| 1751 | && (mActivity.getStorageSpaceBytes() > Storage.LOW_STORAGE_THRESHOLD_BYTES); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | @Override |
| 1755 | public void autoFocus() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1756 | if (mCameraDevice == null) { |
| 1757 | return; |
| 1758 | } |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1759 | Log.v(TAG,"Starting auto focus"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1760 | mFocusStartTime = System.currentTimeMillis(); |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 1761 | mCameraDevice.autoFocus(mHandler, mAutoFocusCallback); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1762 | SessionStatsCollector.instance().autofocusManualTrigger(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1763 | setCameraState(FOCUSING); |
| 1764 | } |
| 1765 | |
| 1766 | @Override |
| 1767 | public void cancelAutoFocus() { |
Senpo Hu | 4ba2829 | 2014-09-26 11:05:08 -0700 | [diff] [blame] | 1768 | if (mCameraDevice == null) { |
| 1769 | return; |
| 1770 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1771 | mCameraDevice.cancelAutoFocus(); |
| 1772 | setCameraState(IDLE); |
| 1773 | setCameraParameters(UPDATE_PARAM_PREFERENCE); |
| 1774 | } |
| 1775 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1776 | @Override |
| 1777 | public void onSingleTapUp(View view, int x, int y) { |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 1778 | if (mPaused || mCameraDevice == null || !mFirstTimeInitialized |
| 1779 | || mCameraState == SNAPSHOT_IN_PROGRESS |
| 1780 | || mCameraState == SWITCHING_CAMERA |
| 1781 | || mCameraState == PREVIEW_STOPPED) { |
| 1782 | return; |
| 1783 | } |
| 1784 | |
| 1785 | // Check if metering area or focus area is supported. |
Doris Liu | 15b9961 | 2013-12-21 11:32:28 -0800 | [diff] [blame] | 1786 | if (!mFocusAreaSupported && !mMeteringAreaSupported) { |
| 1787 | return; |
| 1788 | } |
Doris Liu | 482de02 | 2013-12-18 19:18:16 -0800 | [diff] [blame] | 1789 | mFocusManager.onSingleTapUp(x, y); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | @Override |
| 1793 | public boolean onBackPressed() { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1794 | return mUI.onBackPressed(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | @Override |
| 1798 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 1799 | switch (keyCode) { |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1800 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 1801 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 1802 | case KeyEvent.KEYCODE_FOCUS: |
Spike Sprague | 9f3d01d | 2014-06-30 14:52:57 -0700 | [diff] [blame] | 1803 | if (/* TODO: mActivity.isInCameraApp() && */mFirstTimeInitialized && |
| 1804 | !mActivity.getCameraAppUI().isInIntentReview()) { |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1805 | if (event.getRepeatCount() == 0) { |
| 1806 | onShutterButtonFocus(true); |
| 1807 | } |
| 1808 | return true; |
| 1809 | } |
| 1810 | return false; |
| 1811 | case KeyEvent.KEYCODE_CAMERA: |
| 1812 | if (mFirstTimeInitialized && event.getRepeatCount() == 0) { |
| 1813 | onShutterButtonClick(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1814 | } |
| 1815 | return true; |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1816 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 1817 | // If we get a dpad center event without any focused view, move |
| 1818 | // the focus to the shutter button and press it. |
| 1819 | if (mFirstTimeInitialized && event.getRepeatCount() == 0) { |
| 1820 | // Start auto-focus immediately to reduce shutter lag. After |
| 1821 | // the shutter button gets the focus, onShutterButtonFocus() |
| 1822 | // will be called again but it is fine. |
| 1823 | onShutterButtonFocus(true); |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1824 | } |
| 1825 | return true; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1826 | } |
| 1827 | return false; |
| 1828 | } |
| 1829 | |
| 1830 | @Override |
| 1831 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 1832 | switch (keyCode) { |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1833 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 1834 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Spike Sprague | 9f3d01d | 2014-06-30 14:52:57 -0700 | [diff] [blame] | 1835 | if (/* mActivity.isInCameraApp() && */mFirstTimeInitialized && |
| 1836 | !mActivity.getCameraAppUI().isInIntentReview()) { |
| 1837 | if (mUI.isCountingDown()) { |
| 1838 | cancelCountDown(); |
| 1839 | } else { |
| 1840 | mVolumeButtonClickedFlag = true; |
| 1841 | onShutterButtonClick(); |
| 1842 | } |
Dan Aminzade | 92ae10e | 2013-08-13 14:44:25 -0700 | [diff] [blame] | 1843 | return true; |
| 1844 | } |
| 1845 | return false; |
| 1846 | case KeyEvent.KEYCODE_FOCUS: |
| 1847 | if (mFirstTimeInitialized) { |
| 1848 | onShutterButtonFocus(false); |
| 1849 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1850 | return true; |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1851 | } |
| 1852 | return false; |
| 1853 | } |
| 1854 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1855 | private void closeCamera() { |
| 1856 | if (mCameraDevice != null) { |
Angus Kong | 97e282a | 2014-03-04 18:44:49 -0800 | [diff] [blame] | 1857 | stopFaceDetection(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1858 | mCameraDevice.setZoomChangeListener(null); |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 1859 | mCameraDevice.setFaceDetectionCallback(null, null); |
Ruben Brunk | 5914783 | 2013-11-05 15:53:28 -0800 | [diff] [blame] | 1860 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1861 | mFaceDetectionStarted = false; |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1862 | mActivity.getCameraProvider().releaseCamera(mCameraDevice.getCameraId()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1863 | mCameraDevice = null; |
| 1864 | setCameraState(PREVIEW_STOPPED); |
| 1865 | mFocusManager.onCameraReleased(); |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | private void setDisplayOrientation() { |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 1870 | mDisplayRotation = CameraUtil.getDisplayRotation(mActivity); |
Sol Boucher | 43e1813 | 2014-06-19 15:03:18 -0700 | [diff] [blame] | 1871 | Characteristics info = |
| 1872 | mActivity.getCameraProvider().getCharacteristics(mCameraId); |
Sol Boucher | 73ec985 | 2014-07-24 23:59:21 -0700 | [diff] [blame] | 1873 | mDisplayOrientation = info.getPreviewOrientation(mDisplayRotation); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1874 | mCameraDisplayOrientation = mDisplayOrientation; |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1875 | mUI.setDisplayOrientation(mDisplayOrientation); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1876 | if (mFocusManager != null) { |
| 1877 | mFocusManager.setDisplayOrientation(mDisplayOrientation); |
| 1878 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1879 | // Change the camera display orientation |
| 1880 | if (mCameraDevice != null) { |
Sol Boucher | 73ec985 | 2014-07-24 23:59:21 -0700 | [diff] [blame] | 1881 | mCameraDevice.setDisplayOrientation(mDisplayRotation); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 1882 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
Sascha Haeberling | ddef779 | 2013-08-13 14:41:10 -0700 | [diff] [blame] | 1885 | /** Only called by UI thread. */ |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1886 | private void setupPreview() { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1887 | Log.i(TAG, "setupPreview"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1888 | mFocusManager.resetTouchFocus(); |
| 1889 | startPreview(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1892 | /** |
| 1893 | * Returns whether we can/should start the preview or not. |
| 1894 | */ |
| 1895 | private boolean checkPreviewPreconditions() { |
| 1896 | if (mPaused) { |
| 1897 | return false; |
Angus Kong | dcccc51 | 2013-08-08 17:06:03 -0700 | [diff] [blame] | 1898 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1899 | |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1900 | if (mCameraDevice == null) { |
| 1901 | Log.w(TAG, "startPreview: camera device not ready yet."); |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
Erin Dahlgren | d8de077 | 2014-02-03 10:12:27 -0800 | [diff] [blame] | 1905 | SurfaceTexture st = mActivity.getCameraAppUI().getSurfaceTexture(); |
Erin Dahlgren | dc282e1 | 2013-11-12 09:39:08 -0800 | [diff] [blame] | 1906 | if (st == null) { |
| 1907 | Log.w(TAG, "startPreview: surfaceTexture is not ready."); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1908 | return false; |
Erin Dahlgren | dc282e1 | 2013-11-12 09:39:08 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | if (!mCameraPreviewParamsReady) { |
| 1912 | Log.w(TAG, "startPreview: parameters for preview is not ready."); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1913 | return false; |
| 1914 | } |
| 1915 | return true; |
| 1916 | } |
| 1917 | |
| 1918 | /** |
| 1919 | * The start/stop preview should only run on the UI thread. |
| 1920 | */ |
| 1921 | private void startPreview() { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1922 | if (mCameraDevice == null) { |
| 1923 | Log.i(TAG, "attempted to start preview before camera device"); |
Puneet Lall | 70a9652 | 2014-09-11 17:33:21 -0700 | [diff] [blame] | 1924 | // do nothing |
Erin Dahlgren | dc282e1 | 2013-11-12 09:39:08 -0800 | [diff] [blame] | 1925 | return; |
| 1926 | } |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1927 | |
| 1928 | if (!checkPreviewPreconditions()) { |
| 1929 | return; |
| 1930 | } |
| 1931 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1932 | setDisplayOrientation(); |
| 1933 | |
| 1934 | if (!mSnapshotOnIdle) { |
| 1935 | // If the focus mode is continuous autofocus, call cancelAutoFocus |
| 1936 | // to resume it because it may have been paused by autoFocus call. |
| 1937 | if (mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode()) == |
| 1938 | CameraCapabilities.FocusMode.CONTINUOUS_PICTURE) { |
| 1939 | mCameraDevice.cancelAutoFocus(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1940 | } |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1941 | mFocusManager.setAeAwbLock(false); // Unlock AE and AWB. |
| 1942 | } |
| 1943 | setCameraParameters(UPDATE_PARAM_ALL); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1944 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1945 | updateParametersPictureSize(); |
Angus Kong | 20fad24 | 2013-11-11 18:23:46 -0800 | [diff] [blame] | 1946 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1947 | mCameraDevice.setPreviewTexture(mActivity.getCameraAppUI().getSurfaceTexture()); |
Puneet Lall | 70a9652 | 2014-09-11 17:33:21 -0700 | [diff] [blame] | 1948 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1949 | Log.i(TAG, "startPreview"); |
| 1950 | // If we're using API2 in portability layers, don't use startPreviewWithCallback() |
| 1951 | // b/17576554 |
| 1952 | CameraAgent.CameraStartPreviewCallback startPreviewCallback = |
| 1953 | new CameraAgent.CameraStartPreviewCallback() { |
| 1954 | @Override |
| 1955 | public void onPreviewStarted() { |
| 1956 | mFocusManager.onPreviewStarted(); |
| 1957 | PhotoModule.this.onPreviewStarted(); |
| 1958 | SessionStatsCollector.instance().previewActive(true); |
| 1959 | if (mSnapshotOnIdle) { |
| 1960 | mHandler.post(mDoSnapRunnable); |
Spike Sprague | 3c3b31d | 2014-09-08 10:43:04 -0700 | [diff] [blame] | 1961 | } |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 1962 | } |
| 1963 | }; |
| 1964 | if (GservicesHelper.useCamera2ApiThroughPortabilityLayer(mActivity)) { |
| 1965 | mCameraDevice.startPreview(); |
| 1966 | startPreviewCallback.onPreviewStarted(); |
| 1967 | } else { |
| 1968 | mCameraDevice.startPreviewWithCallback(new Handler(Looper.getMainLooper()), |
| 1969 | startPreviewCallback); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 1973 | @Override |
| 1974 | public void stopPreview() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1975 | if (mCameraDevice != null && mCameraState != PREVIEW_STOPPED) { |
Alan Newberger | d41766f | 2014-04-09 18:25:34 -0700 | [diff] [blame] | 1976 | Log.i(TAG, "stopPreview"); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1977 | mCameraDevice.stopPreview(); |
| 1978 | mFaceDetectionStarted = false; |
| 1979 | } |
| 1980 | setCameraState(PREVIEW_STOPPED); |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 1981 | if (mFocusManager != null) { |
| 1982 | mFocusManager.onPreviewStopped(); |
| 1983 | } |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 1984 | SessionStatsCollector.instance().previewActive(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 1985 | } |
| 1986 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 1987 | @Override |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 1988 | public void onSettingChanged(SettingsManager settingsManager, String key) { |
| 1989 | if (key.equals(Keys.KEY_FLASH_MODE)) { |
| 1990 | updateParametersFlashMode(); |
| 1991 | } |
| 1992 | if (key.equals(Keys.KEY_CAMERA_HDR)) { |
| 1993 | if (settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, |
| 1994 | Keys.KEY_CAMERA_HDR)) { |
| 1995 | // HDR is on. |
| 1996 | mAppController.getButtonManager().disableButton(ButtonManager.BUTTON_FLASH); |
| 1997 | mFlashModeBeforeSceneMode = settingsManager.getString( |
| 1998 | mAppController.getCameraScope(), Keys.KEY_FLASH_MODE); |
| 1999 | } else { |
| 2000 | if (mFlashModeBeforeSceneMode != null) { |
| 2001 | settingsManager.set(mAppController.getCameraScope(), |
| 2002 | Keys.KEY_FLASH_MODE, |
| 2003 | mFlashModeBeforeSceneMode); |
| 2004 | updateParametersFlashMode(); |
| 2005 | mFlashModeBeforeSceneMode = null; |
Angus Kong | 8c07fe9 | 2014-05-22 14:42:45 -0700 | [diff] [blame] | 2006 | } |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2007 | mAppController.getButtonManager().enableButton(ButtonManager.BUTTON_FLASH); |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2008 | } |
| 2009 | } |
Erin Dahlgren | 1648c36 | 2014-01-06 15:06:04 -0800 | [diff] [blame] | 2010 | |
| 2011 | if (mCameraDevice != null) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2012 | mCameraDevice.applySettings(mCameraSettings); |
Erin Dahlgren | 1648c36 | 2014-01-06 15:06:04 -0800 | [diff] [blame] | 2013 | } |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2016 | private void updateCameraParametersInitialize() { |
| 2017 | // Reset preview frame rate to the maximum because it may be lowered by |
| 2018 | // video camera application. |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 2019 | int[] fpsRange = CameraUtil.getPhotoPreviewFpsRange(mCameraCapabilities); |
ztenghui | 16a3520 | 2013-09-23 11:35:36 -0700 | [diff] [blame] | 2020 | if (fpsRange != null && fpsRange.length > 0) { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2021 | mCameraSettings.setPreviewFpsRange(fpsRange[0], fpsRange[1]); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2024 | mCameraSettings.setRecordingHintEnabled(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2025 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2026 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.VIDEO_STABILIZATION)) { |
| 2027 | mCameraSettings.setVideoStabilization(false); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | private void updateCameraParametersZoom() { |
| 2032 | // Set zoom. |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 2033 | if (mCameraCapabilities.supports(CameraCapabilities.Feature.ZOOM)) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2034 | mCameraSettings.setZoomRatio(mZoomValue); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2035 | } |
| 2036 | } |
| 2037 | |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 2038 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2039 | private void setAutoExposureLockIfSupported() { |
| 2040 | if (mAeLockSupported) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2041 | mCameraSettings.setAutoExposureLock(mFocusManager.getAeAwbLock()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2042 | } |
| 2043 | } |
| 2044 | |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 2045 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2046 | private void setAutoWhiteBalanceLockIfSupported() { |
| 2047 | if (mAwbLockSupported) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2048 | mCameraSettings.setAutoWhiteBalanceLock(mFocusManager.getAeAwbLock()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2052 | private void setFocusAreasIfSupported() { |
| 2053 | if (mFocusAreaSupported) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2054 | mCameraSettings.setFocusAreas(mFocusManager.getFocusAreas()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2055 | } |
| 2056 | } |
| 2057 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2058 | private void setMeteringAreasIfSupported() { |
| 2059 | if (mMeteringAreaSupported) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2060 | mCameraSettings.setMeteringAreas(mFocusManager.getMeteringAreas()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2061 | } |
| 2062 | } |
| 2063 | |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2064 | private void updateCameraParametersPreference() { |
Spike Sprague | ae56c12 | 2014-09-19 11:18:46 -0700 | [diff] [blame] | 2065 | // some monkey tests can get here when shutting the app down |
| 2066 | // make sure mCameraDevice is still valid, b/17580046 |
| 2067 | if (mCameraDevice == null) { |
| 2068 | return; |
| 2069 | } |
| 2070 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2071 | setAutoExposureLockIfSupported(); |
| 2072 | setAutoWhiteBalanceLockIfSupported(); |
| 2073 | setFocusAreasIfSupported(); |
| 2074 | setMeteringAreasIfSupported(); |
| 2075 | |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2076 | // Initialize focus mode. |
Michael Kolb | d3253f2 | 2013-07-12 11:36:47 -0700 | [diff] [blame] | 2077 | mFocusManager.overrideFocusMode(null); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2078 | mCameraSettings |
| 2079 | .setFocusMode(mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode())); |
Andy Huibers | 10c5816 | 2014-03-29 14:06:54 -0700 | [diff] [blame] | 2080 | SessionStatsCollector.instance().autofocusActive( |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2081 | mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode()) == |
| 2082 | CameraCapabilities.FocusMode.CONTINUOUS_PICTURE |
| 2083 | ); |
Michael Kolb | d3253f2 | 2013-07-12 11:36:47 -0700 | [diff] [blame] | 2084 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2085 | // Set JPEG quality. |
| 2086 | updateParametersPictureQuality(); |
| 2087 | |
| 2088 | // For the following settings, we need to check if the settings are |
| 2089 | // still supported by latest driver, if not, ignore the settings. |
| 2090 | |
| 2091 | // Set exposure compensation |
| 2092 | updateParametersExposureCompensation(); |
| 2093 | |
| 2094 | // Set the scene mode: also sets flash and white balance. |
| 2095 | updateParametersSceneMode(); |
| 2096 | |
| 2097 | if (mContinuousFocusSupported && ApiHelper.HAS_AUTO_FOCUS_MOVE_CALLBACK) { |
| 2098 | updateAutoFocusMoveCallback(); |
| 2099 | } |
| 2100 | } |
| 2101 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 2102 | /** |
| 2103 | * This method sets picture size parameters. Size parameters should only be |
| 2104 | * set when the preview is stopped, and so this method is only invoked in |
| 2105 | * {@link #startPreview()} just before starting the preview. |
| 2106 | */ |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2107 | private void updateParametersPictureSize() { |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 2108 | if (mCameraDevice == null) { |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 2109 | Log.w(TAG, "attempting to set picture size without caemra device"); |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 2110 | return; |
| 2111 | } |
| 2112 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2113 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2114 | String pictureSizeKey = isCameraFrontFacing() ? Keys.KEY_PICTURE_SIZE_FRONT |
| 2115 | : Keys.KEY_PICTURE_SIZE_BACK; |
| 2116 | String pictureSize = settingsManager.getString(SettingsManager.SCOPE_GLOBAL, |
| 2117 | pictureSizeKey); |
Sascha Haeberling | 3b0ab89 | 2014-01-29 20:54:39 +0100 | [diff] [blame] | 2118 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2119 | List<Size> supported = mCameraCapabilities.getSupportedPhotoSizes(); |
Andy Huibers | 90c7ad5 | 2014-05-20 22:13:54 -0700 | [diff] [blame] | 2120 | CameraPictureSizesCacher.updateSizesForCamera(mAppController.getAndroidContext(), |
| 2121 | mCameraDevice.getCameraId(), supported); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2122 | SettingsUtil.setCameraPictureSize(pictureSize, supported, mCameraSettings, |
Sascha Haeberling | 6ccec20 | 2014-03-11 09:44:34 -0700 | [diff] [blame] | 2123 | mCameraDevice.getCameraId()); |
Angus Kong | 454d63f | 2014-05-06 14:45:59 -0700 | [diff] [blame] | 2124 | |
| 2125 | Size size = SettingsUtil.getPhotoSize(pictureSize, supported, |
| 2126 | mCameraDevice.getCameraId()); |
| 2127 | if (ApiHelper.IS_NEXUS_5) { |
| 2128 | if (ResolutionUtil.NEXUS_5_LARGE_16_BY_9.equals(pictureSize)) { |
| 2129 | mShouldResizeTo16x9 = true; |
| 2130 | } else { |
| 2131 | mShouldResizeTo16x9 = false; |
| 2132 | } |
| 2133 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2134 | |
| 2135 | // Set a preview size that is closest to the viewfinder height and has |
| 2136 | // the right aspect ratio. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2137 | List<Size> sizes = mCameraCapabilities.getSupportedPreviewSizes(); |
Angus Kong | b50b5cb | 2013-08-09 14:55:20 -0700 | [diff] [blame] | 2138 | Size optimalSize = CameraUtil.getOptimalPreviewSize(mActivity, sizes, |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 2139 | (double) size.width() / size.height()); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2140 | Size original = mCameraSettings.getCurrentPreviewSize(); |
| 2141 | if (!optimalSize.equals(original)) { |
Alan Newberger | 2631a15 | 2014-09-24 14:23:30 -0700 | [diff] [blame] | 2142 | Log.v(TAG, "setting preview size. optimal: " + optimalSize + "original: " + original); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2143 | mCameraSettings.setPreviewSize(optimalSize); |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 2144 | |
Alan Newberger | 1959737 | 2014-10-03 18:27:50 -0700 | [diff] [blame] | 2145 | mCameraDevice.applySettings(mCameraSettings); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2146 | mCameraSettings = mCameraDevice.getSettings(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2147 | } |
Doris Liu | 9540574 | 2013-11-05 15:25:26 -0800 | [diff] [blame] | 2148 | |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 2149 | if (optimalSize.width() != 0 && optimalSize.height() != 0) { |
Alan Newberger | 7351415 | 2014-09-10 15:03:27 -0700 | [diff] [blame] | 2150 | Log.v(TAG, "updating aspect ratio"); |
Angus Kong | 00b7b10 | 2014-04-24 15:46:52 -0700 | [diff] [blame] | 2151 | mUI.updatePreviewAspectRatio((float) optimalSize.width() |
| 2152 | / (float) optimalSize.height()); |
Doris Liu | 9540574 | 2013-11-05 15:25:26 -0800 | [diff] [blame] | 2153 | } |
Alan Newberger | 7351415 | 2014-09-10 15:03:27 -0700 | [diff] [blame] | 2154 | Log.d(TAG, "Preview size is " + optimalSize); |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2155 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2156 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2157 | private void updateParametersPictureQuality() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2158 | int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(mCameraId, |
| 2159 | CameraProfile.QUALITY_HIGH); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2160 | mCameraSettings.setPhotoJpegCompressionQuality(jpegQuality); |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2161 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2162 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2163 | private void updateParametersExposureCompensation() { |
| 2164 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2165 | if (settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, |
| 2166 | Keys.KEY_EXPOSURE_COMPENSATION_ENABLED)) { |
| 2167 | int value = settingsManager.getInteger(mAppController.getCameraScope(), |
| 2168 | Keys.KEY_EXPOSURE); |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 2169 | int max = mCameraCapabilities.getMaxExposureCompensation(); |
| 2170 | int min = mCameraCapabilities.getMinExposureCompensation(); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2171 | if (value >= min && value <= max) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2172 | mCameraSettings.setExposureCompensationIndex(value); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2173 | } else { |
| 2174 | Log.w(TAG, "invalid exposure range: " + value); |
| 2175 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2176 | } else { |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2177 | // If exposure compensation is not enabled, reset the exposure compensation value. |
| 2178 | setExposureCompensation(0); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2179 | } |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2180 | |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2181 | } |
| 2182 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2183 | private void updateParametersSceneMode() { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2184 | CameraCapabilities.Stringifier stringifier = mCameraCapabilities.getStringifier(); |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2185 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 2186 | |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2187 | mSceneMode = stringifier. |
| 2188 | sceneModeFromString(settingsManager.getString(mAppController.getCameraScope(), |
| 2189 | Keys.KEY_SCENE_MODE)); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2190 | if (mCameraCapabilities.supports(mSceneMode)) { |
| 2191 | if (mCameraSettings.getCurrentSceneMode() != mSceneMode) { |
| 2192 | mCameraSettings.setSceneMode(mSceneMode); |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2193 | |
| 2194 | // Setting scene mode will change the settings of flash mode, |
| 2195 | // white balance, and focus mode. Here we read back the |
| 2196 | // parameters, so we can know those settings. |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2197 | mCameraDevice.applySettings(mCameraSettings); |
| 2198 | mCameraSettings = mCameraDevice.getSettings(); |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2199 | } |
| 2200 | } else { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2201 | mSceneMode = mCameraSettings.getCurrentSceneMode(); |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2202 | if (mSceneMode == null) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2203 | mSceneMode = CameraCapabilities.SceneMode.AUTO; |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2204 | } |
| 2205 | } |
| 2206 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2207 | if (CameraCapabilities.SceneMode.AUTO == mSceneMode) { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2208 | // Set flash mode. |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2209 | updateParametersFlashMode(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2210 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2211 | // Set focus mode. |
| 2212 | mFocusManager.overrideFocusMode(null); |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2213 | mCameraSettings.setFocusMode( |
| 2214 | mFocusManager.getFocusMode(mCameraSettings.getCurrentFocusMode())); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2215 | } else { |
Angus Kong | 831347d | 2014-06-16 16:07:28 -0700 | [diff] [blame] | 2216 | mFocusManager.overrideFocusMode(mCameraSettings.getCurrentFocusMode()); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2217 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2218 | } |
| 2219 | |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2220 | private void updateParametersFlashMode() { |
| 2221 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
| 2222 | |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2223 | CameraCapabilities.FlashMode flashMode = mCameraCapabilities.getStringifier() |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2224 | .flashModeFromString(settingsManager.getString(mAppController.getCameraScope(), |
| 2225 | Keys.KEY_FLASH_MODE)); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2226 | if (mCameraCapabilities.supports(flashMode)) { |
| 2227 | mCameraSettings.setFlashMode(flashMode); |
Erin Dahlgren | 7f0151d | 2014-01-02 16:08:12 -0800 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | |
Sascha Haeberling | 638e6f0 | 2013-09-18 14:28:51 -0700 | [diff] [blame] | 2231 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2232 | private void updateAutoFocusMoveCallback() { |
Senpo Hu | ee3123b | 2014-09-25 10:53:12 -0700 | [diff] [blame] | 2233 | if (mCameraDevice == null) { |
| 2234 | return; |
| 2235 | } |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2236 | if (mCameraSettings.getCurrentFocusMode() == |
| 2237 | CameraCapabilities.FocusMode.CONTINUOUS_PICTURE) { |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 2238 | mCameraDevice.setAutoFocusMoveCallback(mHandler, |
Angus Kong | 4f795b8 | 2013-09-16 14:25:35 -0700 | [diff] [blame] | 2239 | (CameraAFMoveCallback) mAutoFocusMoveCallback); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2240 | } else { |
Angus Kong | 9ef9925 | 2013-07-18 18:04:19 -0700 | [diff] [blame] | 2241 | mCameraDevice.setAutoFocusMoveCallback(null, null); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2242 | } |
| 2243 | } |
| 2244 | |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2245 | /** |
| 2246 | * Sets the exposure compensation to the given value and also updates settings. |
| 2247 | * |
| 2248 | * @param value exposure compensation value to be set |
| 2249 | */ |
| 2250 | public void setExposureCompensation(int value) { |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 2251 | int max = mCameraCapabilities.getMaxExposureCompensation(); |
| 2252 | int min = mCameraCapabilities.getMinExposureCompensation(); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2253 | if (value >= min && value <= max) { |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2254 | mCameraSettings.setExposureCompensationIndex(value); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2255 | SettingsManager settingsManager = mActivity.getSettingsManager(); |
Erin Dahlgren | 6190c36 | 2014-06-13 14:12:08 -0700 | [diff] [blame] | 2256 | settingsManager.set(mAppController.getCameraScope(), |
| 2257 | Keys.KEY_EXPOSURE, value); |
Spike Sprague | abf54e2 | 2014-03-27 15:41:28 -0700 | [diff] [blame] | 2258 | } else { |
| 2259 | Log.w(TAG, "invalid exposure range: " + value); |
| 2260 | } |
| 2261 | } |
| 2262 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2263 | // We separate the parameters into several subsets, so we can update only |
| 2264 | // the subsets actually need updating. The PREFERENCE set needs extra |
| 2265 | // locking because the preference can be changed from GLThread as well. |
| 2266 | private void setCameraParameters(int updateSet) { |
| 2267 | if ((updateSet & UPDATE_PARAM_INITIALIZE) != 0) { |
| 2268 | updateCameraParametersInitialize(); |
| 2269 | } |
| 2270 | |
| 2271 | if ((updateSet & UPDATE_PARAM_ZOOM) != 0) { |
| 2272 | updateCameraParametersZoom(); |
| 2273 | } |
| 2274 | |
| 2275 | if ((updateSet & UPDATE_PARAM_PREFERENCE) != 0) { |
Erin Dahlgren | ba6994d | 2013-12-12 16:04:38 -0800 | [diff] [blame] | 2276 | updateCameraParametersPreference(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2277 | } |
| 2278 | |
Spike Sprague | 5cc48d6 | 2014-09-22 10:52:32 -0700 | [diff] [blame] | 2279 | if (mCameraDevice != null) { |
| 2280 | mCameraDevice.applySettings(mCameraSettings); |
| 2281 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2282 | } |
| 2283 | |
| 2284 | // If the Camera is idle, update the parameters immediately, otherwise |
| 2285 | // accumulate them in mUpdateSet and update later. |
| 2286 | private void setCameraParametersWhenIdle(int additionalUpdateSet) { |
| 2287 | mUpdateSet |= additionalUpdateSet; |
| 2288 | if (mCameraDevice == null) { |
| 2289 | // We will update all the parameters when we open the device, so |
| 2290 | // we don't need to do anything now. |
| 2291 | mUpdateSet = 0; |
| 2292 | return; |
| 2293 | } else if (isCameraIdle()) { |
| 2294 | setCameraParameters(mUpdateSet); |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2295 | updateSceneMode(); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2296 | mUpdateSet = 0; |
| 2297 | } else { |
Angus Kong | 13e87c4 | 2013-11-25 10:02:47 -0800 | [diff] [blame] | 2298 | if (!mHandler.hasMessages(MSG_SET_CAMERA_PARAMETERS_WHEN_IDLE)) { |
| 2299 | mHandler.sendEmptyMessageDelayed(MSG_SET_CAMERA_PARAMETERS_WHEN_IDLE, 1000); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2300 | } |
| 2301 | } |
| 2302 | } |
| 2303 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 2304 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2305 | public boolean isCameraIdle() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2306 | return (mCameraState == IDLE) || |
| 2307 | (mCameraState == PREVIEW_STOPPED) || |
| 2308 | ((mFocusManager != null) && mFocusManager.isFocusCompleted() |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 2309 | && (mCameraState != SWITCHING_CAMERA)); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2310 | } |
| 2311 | |
ztenghui | 7b265a6 | 2013-09-09 14:58:44 -0700 | [diff] [blame] | 2312 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2313 | public boolean isImageCaptureIntent() { |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2314 | String action = mActivity.getIntent().getAction(); |
| 2315 | return (MediaStore.ACTION_IMAGE_CAPTURE.equals(action) |
Sascha Haeberling | 846d3ab | 2014-02-04 12:48:55 +0100 | [diff] [blame] | 2316 | || CameraActivity.ACTION_IMAGE_CAPTURE_SECURE.equals(action)); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | private void setupCaptureParams() { |
| 2320 | Bundle myExtras = mActivity.getIntent().getExtras(); |
| 2321 | if (myExtras != null) { |
| 2322 | mSaveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT); |
| 2323 | mCropValue = myExtras.getString("crop"); |
| 2324 | } |
| 2325 | } |
| 2326 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2327 | private void initializeCapabilities() { |
Angus Kong | 8828904 | 2014-04-22 16:39:42 -0700 | [diff] [blame] | 2328 | mCameraCapabilities = mCameraDevice.getCapabilities(); |
| 2329 | mFocusAreaSupported = mCameraCapabilities.supports(CameraCapabilities.Feature.FOCUS_AREA); |
| 2330 | mMeteringAreaSupported = mCameraCapabilities.supports(CameraCapabilities.Feature.METERING_AREA); |
| 2331 | mAeLockSupported = mCameraCapabilities.supports(CameraCapabilities.Feature.AUTO_EXPOSURE_LOCK); |
| 2332 | mAwbLockSupported = mCameraCapabilities.supports(CameraCapabilities.Feature.AUTO_WHITE_BALANCE_LOCK); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2333 | mContinuousFocusSupported = |
| 2334 | mCameraCapabilities.supports(CameraCapabilities.FocusMode.CONTINUOUS_PICTURE); |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2335 | } |
| 2336 | |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2337 | @Override |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2338 | public void onZoomChanged(float ratio) { |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2339 | // Not useful to change zoom value when the activity is paused. |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2340 | if (mPaused) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2341 | return; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2342 | } |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2343 | mZoomValue = ratio; |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2344 | if (mCameraSettings == null || mCameraDevice == null) { |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2345 | return; |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2346 | } |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2347 | // Set zoom parameters asynchronously |
Sol Boucher | 2192fba | 2014-08-19 17:24:07 -0700 | [diff] [blame] | 2348 | mCameraSettings.setZoomRatio(mZoomValue); |
Angus Kong | 6607dae | 2014-06-10 16:07:45 -0700 | [diff] [blame] | 2349 | mCameraDevice.applySettings(mCameraSettings); |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | @Override |
Michael Kolb | d6954f3 | 2013-03-08 20:43:01 -0800 | [diff] [blame] | 2353 | public int getCameraState() { |
| 2354 | return mCameraState; |
| 2355 | } |
| 2356 | |
| 2357 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2358 | public void onMemoryStateChanged(int state) { |
Erin Dahlgren | 667630d | 2014-04-01 14:03:25 -0700 | [diff] [blame] | 2359 | mAppController.setShutterEnabled(state == MemoryManager.STATE_OK); |
Angus Kong | ce5480e | 2013-01-29 17:43:48 -0800 | [diff] [blame] | 2360 | } |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 2361 | |
| 2362 | @Override |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2363 | public void onLowMemory() { |
| 2364 | // Not much we can do in the photo module. |
Angus Kong | 86d3631 | 2013-01-31 18:22:44 -0800 | [diff] [blame] | 2365 | } |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 2366 | |
| 2367 | @Override |
| 2368 | public void onAccuracyChanged(Sensor sensor, int accuracy) { |
| 2369 | } |
| 2370 | |
| 2371 | @Override |
| 2372 | public void onSensorChanged(SensorEvent event) { |
| 2373 | int type = event.sensor.getType(); |
| 2374 | float[] data; |
| 2375 | if (type == Sensor.TYPE_ACCELEROMETER) { |
| 2376 | data = mGData; |
| 2377 | } else if (type == Sensor.TYPE_MAGNETIC_FIELD) { |
| 2378 | data = mMData; |
| 2379 | } else { |
| 2380 | // we should not be here. |
| 2381 | return; |
| 2382 | } |
Sascha Haeberling | a63dbb6 | 2013-11-22 11:55:32 -0800 | [diff] [blame] | 2383 | for (int i = 0; i < 3; i++) { |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 2384 | data[i] = event.values[i]; |
| 2385 | } |
| 2386 | float[] orientation = new float[3]; |
| 2387 | SensorManager.getRotationMatrix(mR, null, mGData, mMData); |
| 2388 | SensorManager.getOrientation(mR, orientation); |
| 2389 | mHeading = (int) (orientation[0] * 180f / Math.PI) % 360; |
| 2390 | if (mHeading < 0) { |
| 2391 | mHeading += 360; |
| 2392 | } |
Angus Kong | 0d00a89 | 2013-03-26 11:40:40 -0700 | [diff] [blame] | 2393 | } |
Doris Liu | 6432cd6 | 2013-06-13 17:20:31 -0700 | [diff] [blame] | 2394 | |
Ruben Brunk | d217ed0 | 2013-10-08 23:31:13 -0700 | [diff] [blame] | 2395 | // For debugging only. |
| 2396 | public void setDebugUri(Uri uri) { |
| 2397 | mDebugUri = uri; |
| 2398 | } |
| 2399 | |
| 2400 | // For debugging only. |
| 2401 | private void saveToDebugUri(byte[] data) { |
| 2402 | if (mDebugUri != null) { |
| 2403 | OutputStream outputStream = null; |
| 2404 | try { |
| 2405 | outputStream = mContentResolver.openOutputStream(mDebugUri); |
| 2406 | outputStream.write(data); |
| 2407 | outputStream.close(); |
| 2408 | } catch (IOException e) { |
| 2409 | Log.e(TAG, "Exception while writing debug jpeg file", e); |
| 2410 | } finally { |
| 2411 | CameraUtil.closeSilently(outputStream); |
| 2412 | } |
| 2413 | } |
| 2414 | } |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 2415 | |
| 2416 | @Override |
| 2417 | public void onRemoteShutterPress() { |
Sascha Haeberling | 57d4f74 | 2014-06-25 11:05:49 -0700 | [diff] [blame] | 2418 | mHandler.post(new Runnable() { |
| 2419 | @Override |
| 2420 | public void run() { |
| 2421 | focusAndCapture(); |
| 2422 | } |
| 2423 | }); |
Sascha Haeberling | f2994f0 | 2014-01-23 19:55:01 -0800 | [diff] [blame] | 2424 | } |
Michael Kolb | 8872c23 | 2013-01-29 10:33:22 -0800 | [diff] [blame] | 2425 | } |