blob: 76c6a21b1a3bfc50083995a4b5984537bdd6ee4f [file] [log] [blame]
Michael Kolb8872c232013-01-29 10:33:22 -08001/*
Vijay kumar Tumati43e575a2014-01-10 12:24:16 +05302 * Copyright (C) 2012 The Android Open Source Project
Michael Kolb8872c232013-01-29 10:33:22 -08003 *
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
17package com.android.camera;
18
19import android.annotation.TargetApi;
20import android.app.Activity;
Michael Kolb8872c232013-01-29 10:33:22 -080021import android.content.ContentProviderClient;
22import android.content.ContentResolver;
Angus Kong0d00a892013-03-26 11:40:40 -070023import android.content.Context;
Michael Kolb8872c232013-01-29 10:33:22 -080024import android.content.Intent;
25import android.content.SharedPreferences.Editor;
26import android.content.res.Configuration;
27import android.graphics.Bitmap;
Doris Liu36ebcb12013-10-28 14:44:24 -070028import android.graphics.Rect;
Likai Ding40d36372014-11-20 08:00:28 +080029import android.graphics.SurfaceTexture;
Michael Kolb8872c232013-01-29 10:33:22 -080030import android.hardware.Camera.CameraInfo;
Michael Kolb8872c232013-01-29 10:33:22 -080031import android.hardware.Camera.Parameters;
Michael Kolb8872c232013-01-29 10:33:22 -080032import android.hardware.Camera.Size;
Vijay kumar Tumatiefabd532014-03-24 18:45:35 +053033import android.hardware.Camera;
Angus Kong0d00a892013-03-26 11:40:40 -070034import android.hardware.Sensor;
35import android.hardware.SensorEvent;
36import android.hardware.SensorEventListener;
37import android.hardware.SensorManager;
Michael Kolb8872c232013-01-29 10:33:22 -080038import android.location.Location;
39import android.media.CameraProfile;
40import android.net.Uri;
Sascha Haeberling638e6f02013-09-18 14:28:51 -070041import android.os.Build;
Michael Kolb8872c232013-01-29 10:33:22 -080042import android.os.Bundle;
Michael Kolb8872c232013-01-29 10:33:22 -080043import android.os.Handler;
44import android.os.Looper;
45import android.os.Message;
46import android.os.MessageQueue;
47import android.os.SystemClock;
48import android.provider.MediaStore;
49import android.util.Log;
Michael Kolb8872c232013-01-29 10:33:22 -080050import android.view.KeyEvent;
Michael Kolb8872c232013-01-29 10:33:22 -080051import android.view.OrientationEventListener;
Michael Kolb8872c232013-01-29 10:33:22 -080052import android.view.View;
Michael Kolb8872c232013-01-29 10:33:22 -080053import android.view.WindowManager;
Alok Kediya0dc64ff2013-09-27 20:22:45 +053054import android.widget.Toast;
55import android.widget.ProgressBar;
56import android.widget.SeekBar;
57import android.widget.SeekBar.OnSeekBarChangeListener;
58import android.widget.LinearLayout;
59import android.widget.TextView;
Michael Kolb8872c232013-01-29 10:33:22 -080060
Angus Kong9ef99252013-07-18 18:04:19 -070061import com.android.camera.CameraManager.CameraAFCallback;
62import com.android.camera.CameraManager.CameraAFMoveCallback;
63import com.android.camera.CameraManager.CameraPictureCallback;
Michael Kolb8872c232013-01-29 10:33:22 -080064import com.android.camera.CameraManager.CameraProxy;
Angus Kong9ef99252013-07-18 18:04:19 -070065import com.android.camera.CameraManager.CameraShutterCallback;
Ruben Brunka9d66bd2013-09-06 11:56:32 -070066import com.android.camera.PhotoModule.NamedImages.NamedEntity;
ztenghuia16e7b52013-08-23 11:47:56 -070067import com.android.camera.exif.ExifInterface;
68import com.android.camera.exif.ExifTag;
69import com.android.camera.exif.Rational;
Michael Kolbd6954f32013-03-08 20:43:01 -080070import com.android.camera.ui.CountDownView.OnCountDownFinishedListener;
Ruben Brunk4601f5d2013-09-24 18:35:22 -070071import com.android.camera.ui.ModuleSwitcher;
Michael Kolb8872c232013-01-29 10:33:22 -080072import com.android.camera.ui.RotateTextToast;
Angus Kongdcccc512013-08-08 17:06:03 -070073import com.android.camera.util.ApiHelper;
Angus Kongb50b5cb2013-08-09 14:55:20 -070074import com.android.camera.util.CameraUtil;
Ruben Brunk4601f5d2013-09-24 18:35:22 -070075import com.android.camera.util.GcamHelper;
Sascha Haeberling8e963a52013-08-06 11:43:02 -070076import com.android.camera.util.UsageStatistics;
Sachin Shah89d153b2014-08-15 18:36:44 -070077import org.codeaurora.snapcam.R;
Michael Kolb8872c232013-01-29 10:33:22 -080078
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +053079import android.widget.EditText;
80import android.app.AlertDialog;
81import android.content.DialogInterface;
82import android.text.InputType;
83
Fei Zhang3d391b52014-06-04 14:51:41 +080084import com.android.internal.util.MemInfoReader;
85import android.app.ActivityManager;
86
Angus Kongdcccc512013-08-08 17:06:03 -070087import java.io.File;
88import java.io.FileNotFoundException;
89import java.io.FileOutputStream;
90import java.io.IOException;
91import java.io.OutputStream;
Angus Kongdcccc512013-08-08 17:06:03 -070092import java.util.List;
Ruben Brunka9d66bd2013-09-06 11:56:32 -070093import java.util.Vector;
Alok Kediya0dc64ff2013-09-27 20:22:45 +053094import java.util.HashMap;
95import android.util.AttributeSet;
96import android.graphics.Canvas;
97import android.graphics.Color;
98import android.graphics.Paint;
99import android.os.SystemProperties;
100import java.util.Collections;
101import java.util.Formatter;
Angus Kongdcccc512013-08-08 17:06:03 -0700102
Michael Kolb8872c232013-01-29 10:33:22 -0800103public class PhotoModule
Dan Aminzade92ae10e2013-08-13 14:44:25 -0700104 implements CameraModule,
105 PhotoController,
106 FocusOverlayManager.Listener,
107 CameraPreference.OnPreferenceChangedListener,
108 ShutterButton.OnShutterButtonListener,
109 MediaSaveService.Listener,
110 OnCountDownFinishedListener,
111 SensorEventListener {
Michael Kolb8872c232013-01-29 10:33:22 -0800112
113 private static final String TAG = "CAM_PhotoModule";
114
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530115 //QCom data members
Suman Mukherjee752bc162014-04-28 10:36:56 +0530116 public static boolean mBrightnessVisible = false;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530117 private static final int MAX_SHARPNESS_LEVEL = 6;
118 private boolean mRestartPreview = false;
119 private int mSnapshotMode;
Alok Kediya28c31962013-09-28 16:43:35 +0530120 private int mBurstSnapNum = 1;
121 private int mReceivedSnapNum = 0;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530122 public boolean mFaceDetectionEnabled = false;
Abhishek Pantcb4748b2013-12-04 15:51:48 +0530123 private DrawAutoHDR mDrawAutoHDR;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530124 /*Histogram variables*/
125 private GraphView mGraphView;
126 private static final int STATS_DATA = 257;
127 public static int statsdata[] = new int[STATS_DATA];
128 public boolean mHiston = false;
Michael Kolb8872c232013-01-29 10:33:22 -0800129 // We number the request code from 1000 to avoid collision with Gallery.
130 private static final int REQUEST_CROP = 1000;
131
132 private static final int SETUP_PREVIEW = 1;
133 private static final int FIRST_TIME_INIT = 2;
134 private static final int CLEAR_SCREEN_DELAY = 3;
135 private static final int SET_CAMERA_PARAMETERS_WHEN_IDLE = 4;
Angus Kongdcccc512013-08-08 17:06:03 -0700136 private static final int SHOW_TAP_TO_FOCUS_TOAST = 5;
137 private static final int SWITCH_CAMERA = 6;
138 private static final int SWITCH_CAMERA_START_ANIMATION = 7;
139 private static final int CAMERA_OPEN_DONE = 8;
140 private static final int OPEN_CAMERA_FAIL = 9;
141 private static final int CAMERA_DISABLED = 10;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530142 private static final int SET_SKIN_TONE_FACTOR = 11;
Alok Kediya3c9da9a2013-10-03 15:12:43 +0530143 private static final int SET_PHOTO_UI_PARAMS = 12;
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +0530144 private static final int SWITCH_TO_GCAM_MODULE = 13;
145 private static final int CONFIGURE_SKIN_TONE_FACTOR = 14;
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530146 private static final int ON_PREVIEW_STARTED = 15;
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +0530147
Michael Kolb8872c232013-01-29 10:33:22 -0800148 // The subset of parameters we need to update in setCameraParameters().
149 private static final int UPDATE_PARAM_INITIALIZE = 1;
150 private static final int UPDATE_PARAM_ZOOM = 2;
151 private static final int UPDATE_PARAM_PREFERENCE = 4;
152 private static final int UPDATE_PARAM_ALL = -1;
153
Andy Huibersdf2b0812013-11-19 15:10:04 -0800154 // This is the delay before we execute onResume tasks when coming
155 // from the lock screen, to allow time for onPause to execute.
156 private static final int ON_RESUME_TASKS_DELAY_MSEC = 20;
Michael Kolb8872c232013-01-29 10:33:22 -0800157
Ruben Brunkd7488272013-10-10 18:45:53 -0700158 private static final String DEBUG_IMAGE_PREFIX = "DEBUG_";
159
Michael Kolb8872c232013-01-29 10:33:22 -0800160 // copied from Camera hierarchy
161 private CameraActivity mActivity;
Michael Kolb8872c232013-01-29 10:33:22 -0800162 private CameraProxy mCameraDevice;
163 private int mCameraId;
164 private Parameters mParameters;
165 private boolean mPaused;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530166 private View mRootView;
Michael Kolbd6954f32013-03-08 20:43:01 -0800167
168 private PhotoUI mUI;
Michael Kolb8872c232013-01-29 10:33:22 -0800169
Abhishek Pantcb4748b2013-12-04 15:51:48 +0530170 public boolean mAutoHdrEnable;
Michael Kolb8872c232013-01-29 10:33:22 -0800171 // The activity is going to switch to the specified camera id. This is
172 // needed because texture copy is done in GL thread. -1 means camera is not
173 // switching.
174 protected int mPendingSwitchCameraId = -1;
175 private boolean mOpenCameraFail;
176 private boolean mCameraDisabled;
177
178 // When setCameraParametersWhenIdle() is called, we accumulate the subsets
179 // needed to be updated in mUpdateSet.
180 private int mUpdateSet;
181
182 private static final int SCREEN_DELAY = 2 * 60 * 1000;
183
184 private int mZoomValue; // The current zoom value.
Michael Kolb8872c232013-01-29 10:33:22 -0800185
186 private Parameters mInitialParams;
187 private boolean mFocusAreaSupported;
188 private boolean mMeteringAreaSupported;
189 private boolean mAeLockSupported;
190 private boolean mAwbLockSupported;
Angus Kongdcccc512013-08-08 17:06:03 -0700191 private boolean mContinuousFocusSupported;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530192 private boolean mTouchAfAecFlag;
Alok Kediyaf5b11812013-11-07 13:53:09 +0530193 private boolean mLongshotSave = false;
Emilian Peevde5dd902014-03-17 16:34:20 -0700194 private boolean mRefocus = false;
Michael Kolb8872c232013-01-29 10:33:22 -0800195
196 // The degrees of the device rotated clockwise from its natural orientation.
197 private int mOrientation = OrientationEventListener.ORIENTATION_UNKNOWN;
198 private ComboPreferences mPreferences;
Dimitar Borisov19656472014-09-24 17:32:06 +0300199 private String mPrevSavedCDS;
200 private boolean isTNREnabled;
Michael Kolb8872c232013-01-29 10:33:22 -0800201
202 private static final String sTempCropFilename = "crop-temp";
203
204 private ContentProviderClient mMediaProviderClient;
Michael Kolb8872c232013-01-29 10:33:22 -0800205 private boolean mFaceDetectionStarted = false;
206
Alok Kediyaf5b11812013-11-07 13:53:09 +0530207 private static final String PERSIST_LONG_ENABLE = "persist.camera.longshot.enable";
208 private static final String PERSIST_LONG_SAVE = "persist.camera.longshot.save";
Emilian Peevbfd8f312013-12-17 17:16:36 +0200209 private static final String PERSIST_PREVIEW_RESTART = "persist.camera.feature.restart";
Alok Kediyaf5b11812013-11-07 13:53:09 +0530210
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530211 private static final int MINIMUM_BRIGHTNESS = 0;
212 private static final int MAXIMUM_BRIGHTNESS = 6;
Santhosh Kumar H E16557922014-10-16 12:28:39 +0530213 private static final int DEFAULT_BRIGHTNESS = 3;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530214 private int mbrightness = 3;
215 private int mbrightness_step = 1;
216 private ProgressBar brightnessProgressBar;
217 // Constant from android.hardware.Camera.Parameters
218 private static final String KEY_PICTURE_FORMAT = "picture-format";
219 private static final String KEY_QC_RAW_PICUTRE_SIZE = "raw-size";
Alok Kediyad8887ed2013-09-28 17:12:35 +0530220 public static final String PIXEL_FORMAT_JPEG = "jpeg";
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530221
222 private static final int MIN_SCE_FACTOR = -10;
223 private static final int MAX_SCE_FACTOR = +10;
224 private int SCE_FACTOR_STEP = 10;
225 private int mskinToneValue = 0;
226 private boolean mSkinToneSeekBar= false;
227 private boolean mSeekBarInitialized = false;
228 private SeekBar skinToneSeekBar;
229 private TextView LeftValue;
230 private TextView RightValue;
231 private TextView Title;
232
Emilian Peevbfd8f312013-12-17 17:16:36 +0200233 private boolean mPreviewRestartSupport = false;
234
Michael Kolb8872c232013-01-29 10:33:22 -0800235 // mCropValue and mSaveUri are used only if isImageCaptureIntent() is true.
236 private String mCropValue;
237 private Uri mSaveUri;
238
Ruben Brunkd217ed02013-10-08 23:31:13 -0700239 private Uri mDebugUri;
240
Fei Zhang3d391b52014-06-04 14:51:41 +0800241 // Used for check memory status for longshot mode
242 // Currently, this cancel threshold selection is based on test experiments,
243 // we can change it based on memory status or other requirements.
244 private static final int LONGSHOT_CANCEL_THRESHOLD = 40;
245 private MemInfoReader mMemInfoReader = new MemInfoReader();
246 private ActivityManager mAm;
247 private long SECONDARY_SERVER_MEM;
248 private long mMB = 1024 * 1024;
249 private boolean mLongshotActive = false;
250
Angus Kongce5480e2013-01-29 17:43:48 -0800251 // We use a queue to generated names of the images to be used later
252 // when the image is ready to be saved.
Michael Kolb8872c232013-01-29 10:33:22 -0800253 private NamedImages mNamedImages;
254
255 private Runnable mDoSnapRunnable = new Runnable() {
256 @Override
257 public void run() {
258 onShutterButtonClick();
259 }
260 };
261
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530262 private class OpenCameraThread extends Thread {
263 @Override
264 public void run() {
265 openCamera();
266 startPreview();
267 }
268 }
269
270 private OpenCameraThread mOpenCameraThread = null;
Michael Kolb8872c232013-01-29 10:33:22 -0800271 /**
272 * An unpublished intent flag requesting to return as soon as capturing
273 * is completed.
274 *
275 * TODO: consider publishing by moving into MediaStore.
276 */
277 private static final String EXTRA_QUICK_CAPTURE =
278 "android.intent.extra.quickCapture";
279
280 // The display rotation in degrees. This is only valid when mCameraState is
281 // not PREVIEW_STOPPED.
282 private int mDisplayRotation;
283 // The value for android.hardware.Camera.setDisplayOrientation.
284 private int mCameraDisplayOrientation;
285 // The value for UI components like indicators.
286 private int mDisplayOrientation;
287 // The value for android.hardware.Camera.Parameters.setRotation.
288 private int mJpegRotation;
Doris Liu29da2db2013-08-28 14:28:45 -0700289 // Indicates whether we are using front camera
290 private boolean mMirror;
Michael Kolb8872c232013-01-29 10:33:22 -0800291 private boolean mFirstTimeInitialized;
292 private boolean mIsImageCaptureIntent;
293
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530294 private int mCameraState = INIT;
Michael Kolb8872c232013-01-29 10:33:22 -0800295 private boolean mSnapshotOnIdle = false;
296
297 private ContentResolver mContentResolver;
298
299 private LocationManager mLocationManager;
300
Michael Kolb8872c232013-01-29 10:33:22 -0800301 private final PostViewPictureCallback mPostViewPictureCallback =
302 new PostViewPictureCallback();
303 private final RawPictureCallback mRawPictureCallback =
304 new RawPictureCallback();
305 private final AutoFocusCallback mAutoFocusCallback =
306 new AutoFocusCallback();
307 private final Object mAutoFocusMoveCallback =
308 ApiHelper.HAS_AUTO_FOCUS_MOVE_CALLBACK
Dan Aminzade92ae10e2013-08-13 14:44:25 -0700309 ? new AutoFocusMoveCallback()
310 : null;
Michael Kolb8872c232013-01-29 10:33:22 -0800311
312 private final CameraErrorCallback mErrorCallback = new CameraErrorCallback();
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530313 private final StatsCallback mStatsCallback = new StatsCallback();
Abhishek Pantcb4748b2013-12-04 15:51:48 +0530314 private final MetaDataCallback mMetaDataCallback = new MetaDataCallback();
Michael Kolb8872c232013-01-29 10:33:22 -0800315 private long mFocusStartTime;
316 private long mShutterCallbackTime;
317 private long mPostViewPictureCallbackTime;
318 private long mRawPictureCallbackTime;
319 private long mJpegPictureCallbackTime;
320 private long mOnResumeTime;
321 private byte[] mJpegImageData;
322
323 // These latency time are for the CameraLatency test.
324 public long mAutoFocusTime;
325 public long mShutterLag;
326 public long mShutterToPictureDisplayedTime;
327 public long mPictureDisplayedToJpegCallbackTime;
328 public long mJpegCallbackFinishTime;
329 public long mCaptureStartTime;
330
331 // This handles everything about focus.
332 private FocusOverlayManager mFocusManager;
333
Michael Kolb8872c232013-01-29 10:33:22 -0800334 private String mSceneMode;
Alok Kediya5fdf67e2013-10-02 18:00:14 +0530335 private String mCurrTouchAfAec = Parameters.TOUCH_AF_AEC_ON;
Michael Kolb8872c232013-01-29 10:33:22 -0800336
337 private final Handler mHandler = new MainHandler();
Gaoxiang Chend29d0d62014-04-16 15:15:05 +0800338 private MessageQueue.IdleHandler mIdleHandler = null;
Erin Dahlgrenb09b53e2013-11-06 11:57:51 -0800339
Michael Kolb8872c232013-01-29 10:33:22 -0800340 private PreferenceGroup mPreferenceGroup;
341
342 private boolean mQuickCapture;
Angus Kong0d00a892013-03-26 11:40:40 -0700343 private SensorManager mSensorManager;
344 private float[] mGData = new float[3];
345 private float[] mMData = new float[3];
346 private float[] mR = new float[16];
347 private int mHeading = -1;
348
Angus Kongdcccc512013-08-08 17:06:03 -0700349 // True if all the parameters needed to start preview is ready.
350 private boolean mCameraPreviewParamsReady = false;
Doris Liu6432cd62013-06-13 17:20:31 -0700351
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +0530352 private int mManual3AEnabled = 0;
353 private static final int MANUAL_FOCUS = 1;
354 private static final int MANUAL_WB = 2;
355 private static final int MANUAL_EXPOSURE = 4;
356
Angus Kongce5480e2013-01-29 17:43:48 -0800357 private MediaSaveService.OnMediaSavedListener mOnMediaSavedListener =
358 new MediaSaveService.OnMediaSavedListener() {
359 @Override
360 public void onMediaSaved(Uri uri) {
361 if (uri != null) {
Doris Liu6432cd62013-06-13 17:20:31 -0700362 mActivity.notifyNewMedia(uri);
Angus Kongce5480e2013-01-29 17:43:48 -0800363 }
364 }
365 };
Michael Kolb8872c232013-01-29 10:33:22 -0800366
Angus Kongdcccc512013-08-08 17:06:03 -0700367 private void checkDisplayRotation() {
368 // Set the display orientation if display rotation has changed.
369 // Sometimes this happens when the device is held upside
370 // down and camera app is opened. Rotation animation will
371 // take some time and the rotation value we have got may be
372 // wrong. Framework does not have a callback for this now.
373 if (CameraUtil.getDisplayRotation(mActivity) != mDisplayRotation) {
374 setDisplayOrientation();
Michael Kolb8872c232013-01-29 10:33:22 -0800375 }
Angus Kongdcccc512013-08-08 17:06:03 -0700376 if (SystemClock.uptimeMillis() - mOnResumeTime < 5000) {
377 mHandler.postDelayed(new Runnable() {
378 @Override
379 public void run() {
380 checkDisplayRotation();
381 }
382 }, 100);
Michael Kolb8872c232013-01-29 10:33:22 -0800383 }
384 }
385
386 /**
387 * This Handler is used to post message back onto the main thread of the
388 * application
389 */
390 private class MainHandler extends Handler {
Erin Dahlgrenb09b53e2013-11-06 11:57:51 -0800391 public MainHandler() {
392 super(Looper.getMainLooper());
393 }
394
Michael Kolb8872c232013-01-29 10:33:22 -0800395 @Override
396 public void handleMessage(Message msg) {
397 switch (msg.what) {
398 case SETUP_PREVIEW: {
399 setupPreview();
400 break;
401 }
402
403 case CLEAR_SCREEN_DELAY: {
404 mActivity.getWindow().clearFlags(
405 WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
406 break;
407 }
408
409 case FIRST_TIME_INIT: {
410 initializeFirstTime();
411 break;
412 }
413
414 case SET_CAMERA_PARAMETERS_WHEN_IDLE: {
415 setCameraParametersWhenIdle(0);
416 break;
417 }
418
Michael Kolb8872c232013-01-29 10:33:22 -0800419 case SHOW_TAP_TO_FOCUS_TOAST: {
420 showTapToFocusToast();
421 break;
422 }
423
424 case SWITCH_CAMERA: {
425 switchCamera();
426 break;
427 }
428
429 case SWITCH_CAMERA_START_ANIMATION: {
Dan Aminzade92ae10e2013-08-13 14:44:25 -0700430 // TODO: Need to revisit
431 // ((CameraScreenNail) mActivity.mCameraScreenNail).animateSwitchCamera();
Michael Kolb8872c232013-01-29 10:33:22 -0800432 break;
433 }
434
435 case CAMERA_OPEN_DONE: {
Michael Kolbd6954f32013-03-08 20:43:01 -0800436 onCameraOpened();
Michael Kolb8872c232013-01-29 10:33:22 -0800437 break;
438 }
439
Michael Kolb8872c232013-01-29 10:33:22 -0800440 case OPEN_CAMERA_FAIL: {
Michael Kolb8872c232013-01-29 10:33:22 -0800441 mOpenCameraFail = true;
Angus Kongb50b5cb2013-08-09 14:55:20 -0700442 CameraUtil.showErrorAndFinish(mActivity,
Michael Kolb8872c232013-01-29 10:33:22 -0800443 R.string.cannot_connect_camera);
444 break;
445 }
446
447 case CAMERA_DISABLED: {
Michael Kolb8872c232013-01-29 10:33:22 -0800448 mCameraDisabled = true;
Angus Kongb50b5cb2013-08-09 14:55:20 -0700449 CameraUtil.showErrorAndFinish(mActivity,
Michael Kolb8872c232013-01-29 10:33:22 -0800450 R.string.camera_disabled);
451 break;
452 }
Manish Kumara9942e82013-10-30 19:55:01 +0530453 case SET_SKIN_TONE_FACTOR: {
454 Log.v(TAG, "set tone bar: mSceneMode = " + mSceneMode);
455 setSkinToneFactor();
456 mSeekBarInitialized = true;
457 // skin tone ie enabled only for party and portrait BSM
458 // when color effects are not enabled
459 String colorEffect = mPreferences.getString(
460 CameraSettings.KEY_COLOR_EFFECT,
461 mActivity.getString(R.string.pref_camera_coloreffect_default));
462 if((Parameters.SCENE_MODE_PARTY.equals(mSceneMode) ||
463 Parameters.SCENE_MODE_PORTRAIT.equals(mSceneMode))&&
464 (Parameters.EFFECT_NONE.equals(colorEffect))) {
465 ;
466 }
467 else{
468 Log.v(TAG, "Skin tone bar: disable");
469 disableSkinToneSeekBar();
470 }
471 break;
472 }
473 case SET_PHOTO_UI_PARAMS: {
474 setCameraParametersWhenIdle(UPDATE_PARAM_PREFERENCE);
475 mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup,
476 mPreferences);
477 break;
478 }
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +0530479
480 case SWITCH_TO_GCAM_MODULE: {
481 mActivity.onModuleSelected(ModuleSwitcher.GCAM_MODULE_INDEX);
482 }
483
484 case CONFIGURE_SKIN_TONE_FACTOR: {
Santhosh Kumar Thimmanna Bhattarabb8aa22014-01-10 12:55:40 +0530485 if ((mCameraDevice != null) && isCameraIdle()) {
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +0530486 synchronized (mCameraDevice) {
487 mParameters = mCameraDevice.getParameters();
488 mParameters.set("skinToneEnhancement", String.valueOf(msg.arg1));
489 mCameraDevice.setParameters(mParameters);
490 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530491 }
492 break;
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +0530493 }
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530494 case ON_PREVIEW_STARTED: {
495 onPreviewStarted();
496 break;
497 }
Michael Kolb8872c232013-01-29 10:33:22 -0800498 }
499 }
500 }
Manish Kumara9942e82013-10-30 19:55:01 +0530501
502
Michael Kolb8872c232013-01-29 10:33:22 -0800503 @Override
Doris Liu6432cd62013-06-13 17:20:31 -0700504 public void init(CameraActivity activity, View parent) {
Michael Kolb8872c232013-01-29 10:33:22 -0800505 mActivity = activity;
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530506 mRootView = parent;
Michael Kolb8872c232013-01-29 10:33:22 -0800507 mPreferences = new ComboPreferences(mActivity);
508 CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal());
509 mCameraId = getPreferredCameraId(mPreferences);
510
511 mContentResolver = mActivity.getContentResolver();
Fei Zhang3d391b52014-06-04 14:51:41 +0800512 mAm = (ActivityManager)(mActivity.getSystemService(Context.ACTIVITY_SERVICE));
Michael Kolb8872c232013-01-29 10:33:22 -0800513
Michael Kolb8872c232013-01-29 10:33:22 -0800514 // Surface texture is from camera screen nail and startPreview needs it.
515 // This must be done before startPreview.
516 mIsImageCaptureIntent = isImageCaptureIntent();
Michael Kolb8872c232013-01-29 10:33:22 -0800517
518 mPreferences.setLocalId(mActivity, mCameraId);
519 CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
Michael Kolb8872c232013-01-29 10:33:22 -0800520
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530521 if (mOpenCameraThread == null && !mActivity.mIsModuleSwitchInProgress) {
522 mOpenCameraThread = new OpenCameraThread();
523 mOpenCameraThread.start();
524 }
525 mUI = new PhotoUI(activity, this, parent);
Michael Kolb8872c232013-01-29 10:33:22 -0800526 initializeControlByIntent();
527 mQuickCapture = mActivity.getIntent().getBooleanExtra(EXTRA_QUICK_CAPTURE, false);
Michael Kolbd6954f32013-03-08 20:43:01 -0800528 mLocationManager = new LocationManager(mActivity, mUI);
Angus Kong0d00a892013-03-26 11:40:40 -0700529 mSensorManager = (SensorManager)(mActivity.getSystemService(Context.SENSOR_SERVICE));
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530530
531 brightnessProgressBar = (ProgressBar)mRootView.findViewById(R.id.progress);
532 if (brightnessProgressBar instanceof SeekBar) {
533 SeekBar seeker = (SeekBar) brightnessProgressBar;
534 seeker.setOnSeekBarChangeListener(mSeekListener);
535 }
536 brightnessProgressBar.setMax(MAXIMUM_BRIGHTNESS);
Santhosh Kumar H E16557922014-10-16 12:28:39 +0530537 mbrightness = mPreferences.getInt(
538 CameraSettings.KEY_BRIGHTNESS,
539 DEFAULT_BRIGHTNESS);
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530540 brightnessProgressBar.setProgress(mbrightness);
541 skinToneSeekBar = (SeekBar) mRootView.findViewById(R.id.skintoneseek);
542 skinToneSeekBar.setOnSeekBarChangeListener(mskinToneSeekListener);
543 skinToneSeekBar.setVisibility(View.INVISIBLE);
544 Title = (TextView)mRootView.findViewById(R.id.skintonetitle);
545 RightValue = (TextView)mRootView.findViewById(R.id.skintoneright);
546 LeftValue = (TextView)mRootView.findViewById(R.id.skintoneleft);
Santhosh Kumar H Eb2da1c12014-01-21 19:21:42 +0530547 Storage.setSaveSDCard(
548 mPreferences.getString(CameraSettings.KEY_CAMERA_SAVEPATH, "0").equals("1"));
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530549
Fei Zhang3d391b52014-06-04 14:51:41 +0800550 ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
551 mAm.getMemoryInfo(memInfo);
552 SECONDARY_SERVER_MEM = memInfo.secondaryServerThreshold;
553
Michael Kolbd6954f32013-03-08 20:43:01 -0800554 }
555
556 private void initializeControlByIntent() {
557 mUI.initializeControlByIntent();
558 if (mIsImageCaptureIntent) {
559 setupCaptureParams();
560 }
561 }
562
563 private void onPreviewStarted() {
Emilian Peevd4694ec2014-12-04 17:00:38 +0200564 if (mCameraState == SNAPSHOT_IN_PROGRESS) {
565 return;
566 }
Michael Kolbd6954f32013-03-08 20:43:01 -0800567 setCameraState(IDLE);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530568 mFocusManager.onPreviewStarted();
Michael Kolbd6954f32013-03-08 20:43:01 -0800569 startFaceDetection();
570 locationFirstRun();
Likai Dingc811a1f2014-05-29 10:57:34 +0800571 mUI.enableShutter(true);
Michael Kolb8872c232013-01-29 10:33:22 -0800572 }
573
574 // Prompt the user to pick to record location for the very first run of
575 // camera only
576 private void locationFirstRun() {
Likai Ding40d36372014-11-20 08:00:28 +0800577 if (RecordLocationPreference.isSet(mPreferences)) {
Michael Kolb8872c232013-01-29 10:33:22 -0800578 return;
579 }
Likai Ding40d36372014-11-20 08:00:28 +0800580 if (mActivity.isSecureCamera()) return;
Michael Kolb8872c232013-01-29 10:33:22 -0800581 // Check if the back camera exists
582 int backCameraId = CameraHolder.instance().getBackCameraId();
583 if (backCameraId == -1) {
584 // If there is no back camera, do not show the prompt.
585 return;
586 }
Doris Liu6a83d522013-07-02 12:03:32 -0700587 mUI.showLocationDialog();
588 }
Michael Kolb8872c232013-01-29 10:33:22 -0800589
ztenghui7b265a62013-09-09 14:58:44 -0700590 @Override
Doris Liu6a83d522013-07-02 12:03:32 -0700591 public void enableRecordingLocation(boolean enable) {
592 setLocationPreference(enable ? RecordLocationPreference.VALUE_ON
593 : RecordLocationPreference.VALUE_OFF);
Michael Kolb8872c232013-01-29 10:33:22 -0800594 }
595
Angus Kongdcccc512013-08-08 17:06:03 -0700596 @Override
597 public void onPreviewUIReady() {
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530598 if (mPaused || mCameraDevice == null) {
599 return;
600 }
601 Log.v(TAG, "onPreviewUIReady");
Santhosh Kumar Thimmanna Bhattar94932b72014-12-08 18:05:46 +0530602 if (mCameraState == PREVIEW_STOPPED) {
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530603 startPreview();
604 } else {
Likai Ding40d36372014-11-20 08:00:28 +0800605 SurfaceTexture st = mUI.getSurfaceTexture();
606 if (st == null) {
607 Log.w(TAG, "startPreview: surfaceTexture is not ready.");
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530608 return;
609 }
Likai Ding40d36372014-11-20 08:00:28 +0800610 mCameraDevice.setPreviewTexture(st);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530611 }
Angus Kongdcccc512013-08-08 17:06:03 -0700612 }
613
614 @Override
615 public void onPreviewUIDestroyed() {
616 if (mCameraDevice == null) {
617 return;
618 }
Likai Ding40d36372014-11-20 08:00:28 +0800619 Log.v(TAG, "onPreviewUIDestroyed");
620 mCameraDevice.setPreviewTexture(null);
Angus Kongdcccc512013-08-08 17:06:03 -0700621 stopPreview();
622 }
623
Michael Kolb8872c232013-01-29 10:33:22 -0800624 private void setLocationPreference(String value) {
625 mPreferences.edit()
Dan Aminzade92ae10e2013-08-13 14:44:25 -0700626 .putString(CameraSettings.KEY_RECORD_LOCATION, value)
627 .apply();
Michael Kolb8872c232013-01-29 10:33:22 -0800628 // TODO: Fix this to use the actual onSharedPreferencesChanged listener
629 // instead of invoking manually
630 onSharedPreferenceChanged();
631 }
632
Michael Kolbd6954f32013-03-08 20:43:01 -0800633 private void onCameraOpened() {
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530634 if (mPaused) {
635 return;
636 }
637 Log.v(TAG, "onCameraOpened");
Michael Kolbd6954f32013-03-08 20:43:01 -0800638 openCameraCommon();
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530639 resizeForPreviewAspectRatio();
Sai Kumar Sanagavarapue354e1e2014-10-30 20:21:14 +0530640 updateFocusManager(mUI);
Michael Kolb8872c232013-01-29 10:33:22 -0800641 }
642
Michael Kolbd6954f32013-03-08 20:43:01 -0800643 private void switchCamera() {
644 if (mPaused) return;
645
646 Log.v(TAG, "Start to switch camera. id=" + mPendingSwitchCameraId);
647 mCameraId = mPendingSwitchCameraId;
648 mPendingSwitchCameraId = -1;
649 setCameraId(mCameraId);
650
651 // from onPause
652 closeCamera();
653 mUI.collapseCameraControls();
654 mUI.clearFaces();
SanthoshHEee63d7f2013-09-05 14:43:35 +0530655 disableSkinToneSeekBar();
Michael Kolbd6954f32013-03-08 20:43:01 -0800656 if (mFocusManager != null) mFocusManager.removeMessages();
657
658 // Restart the camera and initialize the UI. From onCreate.
659 mPreferences.setLocalId(mActivity, mCameraId);
660 CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
Angus Kong4f795b82013-09-16 14:25:35 -0700661 mCameraDevice = CameraUtil.openCamera(
662 mActivity, mCameraId, mHandler,
663 mActivity.getCameraOpenErrorCallback());
Erin Dahlgrencc707022013-11-12 09:39:08 -0800664
Angus Kong4f795b82013-09-16 14:25:35 -0700665 if (mCameraDevice == null) {
666 Log.e(TAG, "Failed to open camera:" + mCameraId + ", aborting.");
Michael Kolbd6954f32013-03-08 20:43:01 -0800667 return;
Doris Liu09106a42013-03-05 09:54:25 -0800668 }
Angus Kong4f795b82013-09-16 14:25:35 -0700669 mParameters = mCameraDevice.getParameters();
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530670 mInitialParams = mParameters;
Michael Kolbd6954f32013-03-08 20:43:01 -0800671 initializeCapabilities();
672 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
Doris Liu29da2db2013-08-28 14:28:45 -0700673 mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
674 mFocusManager.setMirror(mMirror);
Michael Kolbd6954f32013-03-08 20:43:01 -0800675 mFocusManager.setParameters(mInitialParams);
676 setupPreview();
677
Doris Liu6432cd62013-06-13 17:20:31 -0700678 // reset zoom value index
679 mZoomValue = 0;
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530680 resizeForPreviewAspectRatio();
Michael Kolbd6954f32013-03-08 20:43:01 -0800681 openCameraCommon();
682
Sascha Haeberling638e6f02013-09-18 14:28:51 -0700683 // Start switch camera animation. Post a message because
684 // onFrameAvailable from the old camera may already exist.
685 mHandler.sendEmptyMessage(SWITCH_CAMERA_START_ANIMATION);
Doris Liu48239f42013-03-04 22:19:10 -0800686 }
687
Michael Kolbd6954f32013-03-08 20:43:01 -0800688 protected void setCameraId(int cameraId) {
689 ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_CAMERA_ID);
690 pref.setValue("" + cameraId);
691 }
692
693 // either open a new camera or switch cameras
694 private void openCameraCommon() {
Michael Kolb8872c232013-01-29 10:33:22 -0800695 loadCameraPreferences();
Michael Kolbd6954f32013-03-08 20:43:01 -0800696
697 mUI.onCameraOpened(mPreferenceGroup, mPreferences, mParameters, this);
Angus Kong0fb819b2013-10-08 13:44:19 -0700698 if (mIsImageCaptureIntent) {
699 mUI.overrideSettings(CameraSettings.KEY_CAMERA_HDR_PLUS,
700 mActivity.getString(R.string.setting_off_value));
701 }
Ivan Evlogiev5086f852014-03-05 17:12:35 +0200702 updateCameraSettings();
Michael Kolbd6954f32013-03-08 20:43:01 -0800703 showTapToFocusToastIfNeeded();
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +0530704 resetManual3ASettings();
Michael Kolb8872c232013-01-29 10:33:22 -0800705 }
706
ztenghui7b265a62013-09-09 14:58:44 -0700707 @Override
Doris Liub3749f22013-09-25 12:22:08 -0700708 public void onScreenSizeChanged(int width, int height) {
Michael Kolbd6954f32013-03-08 20:43:01 -0800709 if (mFocusManager != null) mFocusManager.setPreviewSize(width, height);
Michael Kolbd6954f32013-03-08 20:43:01 -0800710 }
Michael Kolb8872c232013-01-29 10:33:22 -0800711
Santhosh Kumar H Edbdb7622013-12-05 16:36:52 +0530712 @Override
Doris Liu36ebcb12013-10-28 14:44:24 -0700713 public void onPreviewRectChanged(Rect previewRect) {
714 if (mFocusManager != null) mFocusManager.setPreviewRect(previewRect);
Michael Kolb8872c232013-01-29 10:33:22 -0800715 }
716
717 private void resetExposureCompensation() {
718 String value = mPreferences.getString(CameraSettings.KEY_EXPOSURE,
719 CameraSettings.EXPOSURE_DEFAULT_VALUE);
720 if (!CameraSettings.EXPOSURE_DEFAULT_VALUE.equals(value)) {
721 Editor editor = mPreferences.edit();
722 editor.putString(CameraSettings.KEY_EXPOSURE, "0");
723 editor.apply();
724 }
725 }
726
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +0530727 private void resetManual3ASettings() {
728 String manualExposureDefault = mActivity.getString(
729 R.string.pref_camera_manual_exp_default);
730 String manualExposureMode = mPreferences.getString(
731 CameraSettings.KEY_MANUAL_EXPOSURE, manualExposureDefault);
732 if (!manualExposureMode.equals(manualExposureDefault)) {
733 mUI.setPreference(
734 CameraSettings.KEY_MANUAL_EXPOSURE, manualExposureDefault);
735 UpdateManualExposureSettings();
736 }
737 String manualFocusDefault = mActivity.getString(
738 R.string.pref_camera_manual_focus_default);
739 String manualFocusMode = mPreferences.getString(
740 CameraSettings.KEY_MANUAL_FOCUS, manualFocusDefault);
741 if (!manualFocusMode.equals(manualFocusDefault)) {
742 mUI.setPreference(
743 CameraSettings.KEY_MANUAL_FOCUS, manualFocusDefault);
744 UpdateManualFocusSettings();
745 }
746 String manualWBDefault = mActivity.getString(
747 R.string.pref_camera_manual_wb_default);
748 String manualWBMode = mPreferences.getString(
749 CameraSettings.KEY_MANUAL_WB, manualWBDefault);
750 if (!manualWBMode.equals(manualWBDefault)) {
751 mUI.setPreference(
752 CameraSettings.KEY_MANUAL_WB, manualWBDefault);
753 UpdateManualWBSettings();
754 }
755 mManual3AEnabled = 0;
756 }
757
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530758 void setPreviewFrameLayoutCameraOrientation(){
759 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
760 //if camera mount angle is 0 or 180, we want to resize preview
761 if (info.orientation % 180 == 0){
762 mUI.cameraOrientationPreviewResize(true);
763 } else{
764 mUI.cameraOrientationPreviewResize(false);
765 }
766 }
767
Santhosh Kumar H Ef7e9b672013-11-12 14:42:09 +0530768 @Override
769 public void resizeForPreviewAspectRatio() {
Santhosh Kumar Thimmanna Bhattar2bacfda2014-01-10 16:23:17 +0530770 if ( mCameraDevice == null || mParameters == null) {
771 Log.e(TAG, "Camera not yet initialized");
772 return;
773 }
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530774 setPreviewFrameLayoutCameraOrientation();
Vladimir Petrovdb90ccc2014-01-30 16:58:53 +0200775 Size size = mParameters.getPreviewSize();
Likai Ding40d36372014-11-20 08:00:28 +0800776 Log.e(TAG,"Width = "+ size.width+ "Height = "+size.height);
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530777 mUI.setAspectRatio((float) size.width / size.height);
778 }
779
kaiyizde529662014-07-21 16:47:27 +0800780 @Override
781 public void onSwitchSavePath() {
782 mUI.setPreference(CameraSettings.KEY_CAMERA_SAVEPATH, "1");
783 Toast.makeText(mActivity, R.string.on_switch_save_path_to_sdcard,
784 Toast.LENGTH_SHORT).show();
785 }
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +0530786
Michael Kolb8872c232013-01-29 10:33:22 -0800787 private void keepMediaProviderInstance() {
788 // We want to keep a reference to MediaProvider in camera's lifecycle.
789 // TODO: Utilize mMediaProviderClient instance to replace
790 // ContentResolver calls.
791 if (mMediaProviderClient == null) {
792 mMediaProviderClient = mContentResolver
793 .acquireContentProviderClient(MediaStore.AUTHORITY);
794 }
795 }
796
797 // Snapshots can only be taken after this is called. It should be called
798 // once only. We could have done these things in onCreate() but we want to
799 // make preview screen appear as soon as possible.
800 private void initializeFirstTime() {
Sascha Haeberling330dafb2013-10-10 19:00:41 -0700801 if (mFirstTimeInitialized || mPaused) {
802 return;
803 }
Michael Kolb8872c232013-01-29 10:33:22 -0800804
805 // Initialize location service.
806 boolean recordLocation = RecordLocationPreference.get(
807 mPreferences, mContentResolver);
808 mLocationManager.recordLocation(recordLocation);
809
810 keepMediaProviderInstance();
811
Michael Kolbd6954f32013-03-08 20:43:01 -0800812 mUI.initializeFirstTime();
Angus Kong86d36312013-01-31 18:22:44 -0800813 MediaSaveService s = mActivity.getMediaSaveService();
814 // We set the listener only when both service and shutterbutton
815 // are initialized.
816 if (s != null) {
817 s.setListener(this);
818 }
Michael Kolb8872c232013-01-29 10:33:22 -0800819
Michael Kolb8872c232013-01-29 10:33:22 -0800820 mNamedImages = new NamedImages();
Abhishek Pantcb4748b2013-12-04 15:51:48 +0530821 mGraphView = (GraphView)mRootView.findViewById(R.id.graph_view);
822 mDrawAutoHDR = (DrawAutoHDR )mRootView.findViewById(R.id.autohdr_view);
823 if (mGraphView == null || mDrawAutoHDR == null){
824 Log.e(TAG, "mGraphView or mDrawAutoHDR is null");
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530825 } else{
826 mGraphView.setPhotoModuleObject(this);
Abhishek Pantcb4748b2013-12-04 15:51:48 +0530827 mDrawAutoHDR.setPhotoModuleObject(this);
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530828 }
Michael Kolb8872c232013-01-29 10:33:22 -0800829
830 mFirstTimeInitialized = true;
Gaoxiang Chend29d0d62014-04-16 15:15:05 +0800831 Log.d(TAG, "addIdleHandler in first time initialization");
Michael Kolb8872c232013-01-29 10:33:22 -0800832 addIdleHandler();
833
Michael Kolb8872c232013-01-29 10:33:22 -0800834 }
835
Michael Kolbd6954f32013-03-08 20:43:01 -0800836 // If the activity is paused and resumed, this method will be called in
837 // onResume.
838 private void initializeSecondTime() {
839 // Start location update if needed.
840 boolean recordLocation = RecordLocationPreference.get(
841 mPreferences, mContentResolver);
842 mLocationManager.recordLocation(recordLocation);
843 MediaSaveService s = mActivity.getMediaSaveService();
844 if (s != null) {
845 s.setListener(this);
846 }
847 mNamedImages = new NamedImages();
Suman Mukherjeefb1b9d02013-12-17 09:42:53 +0530848 if (!mIsImageCaptureIntent) {
849 mUI.showSwitcher();
850 }
Michael Kolbd6954f32013-03-08 20:43:01 -0800851 mUI.initializeSecondTime(mParameters);
852 keepMediaProviderInstance();
853 }
854
Michael Kolb8872c232013-01-29 10:33:22 -0800855 private void showTapToFocusToastIfNeeded() {
856 // Show the tap to focus toast if this is the first start.
857 if (mFocusAreaSupported &&
858 mPreferences.getBoolean(CameraSettings.KEY_CAMERA_FIRST_USE_HINT_SHOWN, true)) {
859 // Delay the toast for one second to wait for orientation.
860 mHandler.sendEmptyMessageDelayed(SHOW_TAP_TO_FOCUS_TOAST, 1000);
861 }
862 }
863
864 private void addIdleHandler() {
Gaoxiang Chend29d0d62014-04-16 15:15:05 +0800865 if (mIdleHandler == null) {
866 mIdleHandler = new MessageQueue.IdleHandler() {
867 @Override
868 public boolean queueIdle() {
869 Storage.ensureOSXCompatible();
870 return false;
871 }
872 };
873
874 MessageQueue queue = Looper.myQueue();
875 queue.addIdleHandler(mIdleHandler);
876 }
877 }
878
879 private void removeIdleHandler() {
880 if (mIdleHandler != null) {
881 MessageQueue queue = Looper.myQueue();
882 queue.removeIdleHandler(mIdleHandler);
883 mIdleHandler = null;
884 }
Michael Kolb8872c232013-01-29 10:33:22 -0800885 }
886
Michael Kolb8872c232013-01-29 10:33:22 -0800887 @Override
888 public void startFaceDetection() {
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +0530889 if (mCameraDevice == null) return;
890
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530891 if (mFaceDetectionEnabled == false
892 || mFaceDetectionStarted || mCameraState != IDLE) return;
Michael Kolb8872c232013-01-29 10:33:22 -0800893 if (mParameters.getMaxNumDetectedFaces() > 0) {
894 mFaceDetectionStarted = true;
Michael Kolb8872c232013-01-29 10:33:22 -0800895 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
Michael Kolbd6954f32013-03-08 20:43:01 -0800896 mUI.onStartFaceDetection(mDisplayOrientation,
897 (info.facing == CameraInfo.CAMERA_FACING_FRONT));
Angus Kong9e765522013-07-31 14:05:20 -0700898 mCameraDevice.setFaceDetectionCallback(mHandler, mUI);
Michael Kolb8872c232013-01-29 10:33:22 -0800899 mCameraDevice.startFaceDetection();
900 }
901 }
902
Michael Kolb8872c232013-01-29 10:33:22 -0800903 @Override
904 public void stopFaceDetection() {
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530905 if (mFaceDetectionEnabled == false || !mFaceDetectionStarted) return;
Michael Kolb8872c232013-01-29 10:33:22 -0800906 if (mParameters.getMaxNumDetectedFaces() > 0) {
907 mFaceDetectionStarted = false;
Angus Kong9e765522013-07-31 14:05:20 -0700908 mCameraDevice.setFaceDetectionCallback(null, null);
Santhosh Kumar H E41924d92014-08-28 14:44:23 +0530909 mUI.pauseFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800910 mCameraDevice.stopFaceDetection();
kaiyiz222b96c2014-07-14 15:51:30 +0800911 mUI.onStopFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -0800912 }
913 }
914
Fei Zhang3d391b52014-06-04 14:51:41 +0800915 private boolean isLongshotNeedCancel() {
916
917 long totalMemory = Runtime.getRuntime().totalMemory() / mMB;
918 long maxMemory = Runtime.getRuntime().maxMemory() / mMB;
919 long remainMemory = maxMemory - totalMemory;
920
921 mMemInfoReader.readMemInfo();
922 long availMem = mMemInfoReader.getFreeSize() + mMemInfoReader.getCachedSize()
923 - SECONDARY_SERVER_MEM;
924 availMem = availMem/ mMB;
925
926 if(availMem <= 0 ||
927 remainMemory <= LONGSHOT_CANCEL_THRESHOLD) {
928 Log.d(TAG, "memory used up, need cancel longshot.");
929 mLongshotActive = false;
930 Toast.makeText(mActivity,R.string.msg_cancel_longshot_for_limited_memory,
931 Toast.LENGTH_SHORT).show();
932 return true;
933 }
934
935 return false;
936 }
937
Alok Kediyaf5b11812013-11-07 13:53:09 +0530938 private final class LongshotShutterCallback
939 implements CameraShutterCallback {
940
941 @Override
942 public void onShutter(CameraProxy camera) {
943 mShutterCallbackTime = System.currentTimeMillis();
944 mShutterLag = mShutterCallbackTime - mCaptureStartTime;
945 Log.e(TAG, "[KPI Perf] PROFILE_SHUTTER_LAG mShutterLag = " + mShutterLag + "ms");
946 synchronized(mCameraDevice) {
947
Fei Zhang3d391b52014-06-04 14:51:41 +0800948 if (mCameraState != LONGSHOT ||
949 !mLongshotActive) {
950 return;
951 }
952
953 if(isLongshotNeedCancel()) {
Alok Kediyaf5b11812013-11-07 13:53:09 +0530954 return;
955 }
956
957 if (mLongshotSave) {
958 mCameraDevice.takePicture(mHandler,
959 new LongshotShutterCallback(),
960 mRawPictureCallback, mPostViewPictureCallback,
961 new LongshotPictureCallback(null));
962 } else {
963 mCameraDevice.takePicture(mHandler,new LongshotShutterCallback(),
964 mRawPictureCallback, mPostViewPictureCallback,
965 new JpegPictureCallback(null));
966 }
967 }
968 }
969 }
970
Michael Kolb8872c232013-01-29 10:33:22 -0800971 private final class ShutterCallback
Angus Kong9ef99252013-07-18 18:04:19 -0700972 implements CameraShutterCallback {
Angus Kongdcb0ef12013-03-25 23:11:43 -0700973
Sascha Haeberling37f36112013-08-06 14:31:52 -0700974 private boolean mNeedsAnimation;
Angus Kongdcb0ef12013-03-25 23:11:43 -0700975
Sascha Haeberling37f36112013-08-06 14:31:52 -0700976 public ShutterCallback(boolean needsAnimation) {
977 mNeedsAnimation = needsAnimation;
Angus Kongdcb0ef12013-03-25 23:11:43 -0700978 }
979
Michael Kolb8872c232013-01-29 10:33:22 -0800980 @Override
Angus Kong9ef99252013-07-18 18:04:19 -0700981 public void onShutter(CameraProxy camera) {
Michael Kolb8872c232013-01-29 10:33:22 -0800982 mShutterCallbackTime = System.currentTimeMillis();
983 mShutterLag = mShutterCallbackTime - mCaptureStartTime;
Alok Kediya2bc105d2013-09-28 18:17:41 +0530984 Log.e(TAG, "[KPI Perf] PROFILE_SHUTTER_LAG mShutterLag = " + mShutterLag + "ms");
Sascha Haeberling37f36112013-08-06 14:31:52 -0700985 if (mNeedsAnimation) {
986 mActivity.runOnUiThread(new Runnable() {
987 @Override
988 public void run() {
989 animateAfterShutter();
990 }
991 });
Angus Kongdcb0ef12013-03-25 23:11:43 -0700992 }
Michael Kolb8872c232013-01-29 10:33:22 -0800993 }
994 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +0530995 private final class StatsCallback
996 implements android.hardware.Camera.CameraDataCallback {
997 @Override
998 public void onCameraData(int [] data, android.hardware.Camera camera) {
999 //if(!mPreviewing || !mHiston || !mFirstTimeInitialized){
1000 if(!mHiston || !mFirstTimeInitialized){
1001 return;
1002 }
1003 /*The first element in the array stores max hist value . Stats data begin from second value*/
1004 synchronized(statsdata) {
1005 System.arraycopy(data,0,statsdata,0,STATS_DATA);
1006 }
1007 mActivity.runOnUiThread(new Runnable() {
1008 public void run() {
1009 if(mGraphView != null)
1010 mGraphView.PreviewChanged();
1011 }
1012 });
1013 }
1014 }
Abhishek Pantcb4748b2013-12-04 15:51:48 +05301015
1016 private final class MetaDataCallback
1017 implements android.hardware.Camera.CameraMetaDataCallback{
1018 @Override
1019 public void onCameraMetaData (byte[] data, android.hardware.Camera camera) {
1020 int metadata[] = new int[3];
1021 if (data.length <= 12) {
1022 for (int i =0;i<3;i++) {
1023 metadata[i] = byteToInt( (byte []) data, i*4);
1024 }
1025 if (metadata[2] == 1) {
1026 mAutoHdrEnable = true;
1027 mActivity.runOnUiThread(new Runnable() {
1028 public void run() {
1029 if (mDrawAutoHDR != null)
1030 mDrawAutoHDR.AutoHDR();
1031 }
1032 });
1033 }
1034 else {
1035 mAutoHdrEnable = false;
1036 mActivity.runOnUiThread(new Runnable() {
1037 public void run() {
1038 if (mDrawAutoHDR != null)
1039 mDrawAutoHDR.AutoHDR();
1040 }
1041 });
1042 }
1043 }
1044 }
1045
1046 private int byteToInt (byte[] b, int offset) {
1047 int value = 0;
1048 for (int i = 0; i < 4; i++) {
1049 int shift = (4 - 1 - i) * 8;
1050 value += (b[(3-i) + offset] & 0x000000FF) << shift;
1051 }
1052 return value;
1053 }
1054 }
1055
Angus Kong9ef99252013-07-18 18:04:19 -07001056 private final class PostViewPictureCallback
1057 implements CameraPictureCallback {
Michael Kolb8872c232013-01-29 10:33:22 -08001058 @Override
Angus Kong9ef99252013-07-18 18:04:19 -07001059 public void onPictureTaken(byte [] data, CameraProxy camera) {
Michael Kolb8872c232013-01-29 10:33:22 -08001060 mPostViewPictureCallbackTime = System.currentTimeMillis();
1061 Log.v(TAG, "mShutterToPostViewCallbackTime = "
1062 + (mPostViewPictureCallbackTime - mShutterCallbackTime)
1063 + "ms");
1064 }
1065 }
1066
Angus Kong9ef99252013-07-18 18:04:19 -07001067 private final class RawPictureCallback
1068 implements CameraPictureCallback {
Michael Kolb8872c232013-01-29 10:33:22 -08001069 @Override
Angus Kong9ef99252013-07-18 18:04:19 -07001070 public void onPictureTaken(byte [] rawData, CameraProxy camera) {
Michael Kolb8872c232013-01-29 10:33:22 -08001071 mRawPictureCallbackTime = System.currentTimeMillis();
1072 Log.v(TAG, "mShutterToRawCallbackTime = "
1073 + (mRawPictureCallbackTime - mShutterCallbackTime) + "ms");
1074 }
1075 }
1076
Alok Kediyaf5b11812013-11-07 13:53:09 +05301077 private final class LongshotPictureCallback implements CameraPictureCallback {
1078 Location mLocation;
1079
1080 public LongshotPictureCallback(Location loc) {
1081 mLocation = loc;
1082 }
1083
1084 @Override
1085 public void onPictureTaken(final byte [] jpegData, CameraProxy camera) {
1086 if (mPaused) {
1087 return;
1088 }
1089
1090 mFocusManager.updateFocusUI(); // Ensure focus indicator is hidden.
1091
1092 String jpegFilePath = new String(jpegData);
1093 mNamedImages.nameNewImage(mCaptureStartTime);
1094 NamedEntity name = mNamedImages.getNextNameEntity();
1095 String title = (name == null) ? null : name.title;
1096 long date = (name == null) ? -1 : name.date;
1097
1098 if (title == null) {
1099 Log.e(TAG, "Unbalanced name/data pair");
1100 return;
1101 }
1102
1103
1104 if (date == -1 ) {
1105 Log.e(TAG, "Invalid filename date");
1106 return;
1107 }
1108
1109 String dstPath = Storage.DIRECTORY;
1110 File sdCard = android.os.Environment.getExternalStorageDirectory();
1111 File dstFile = new File(dstPath);
1112 if (dstFile == null) {
1113 Log.e(TAG, "Destination file path invalid");
1114 return;
1115 }
1116
1117 File srcFile = new File(jpegFilePath);
1118 if (srcFile == null) {
1119 Log.e(TAG, "Source file path invalid");
1120 return;
1121 }
1122
1123 if ( srcFile.renameTo(dstFile) ) {
1124 Size s = mParameters.getPictureSize();
1125 String pictureFormat = mParameters.get(KEY_PICTURE_FORMAT);
1126 mActivity.getMediaSaveService().addImage(
1127 null, title, date, mLocation, s.width, s.height,
1128 0, null, mOnMediaSavedListener, mContentResolver, pictureFormat);
1129 } else {
1130 Log.e(TAG, "Failed to move jpeg file");
1131 }
1132 }
1133 }
1134
Angus Kong9ef99252013-07-18 18:04:19 -07001135 private final class JpegPictureCallback
1136 implements CameraPictureCallback {
Michael Kolb8872c232013-01-29 10:33:22 -08001137 Location mLocation;
1138
1139 public JpegPictureCallback(Location loc) {
1140 mLocation = loc;
1141 }
1142
1143 @Override
Angus Kong9ef99252013-07-18 18:04:19 -07001144 public void onPictureTaken(final byte [] jpegData, CameraProxy camera) {
Sascha Haeberling88901942013-08-28 17:49:00 -07001145 mUI.enableShutter(true);
Michael Kolb8872c232013-01-29 10:33:22 -08001146 if (mPaused) {
1147 return;
1148 }
Doris Liu6432cd62013-06-13 17:20:31 -07001149 if (mIsImageCaptureIntent) {
1150 stopPreview();
kaiyiza93bcab2014-07-09 16:09:30 +08001151 } else if (mSceneMode == CameraUtil.SCENE_MODE_HDR) {
Doris Liu6432cd62013-06-13 17:20:31 -07001152 mUI.showSwitcher();
1153 mUI.setSwipingEnabled(true);
Michael Kolb8872c232013-01-29 10:33:22 -08001154 }
1155
Alok Kediya28c31962013-09-28 16:43:35 +05301156 mReceivedSnapNum = mReceivedSnapNum + 1;
Michael Kolb8872c232013-01-29 10:33:22 -08001157 mJpegPictureCallbackTime = System.currentTimeMillis();
Alok Kediya28c31962013-09-28 16:43:35 +05301158 if(mSnapshotMode == CameraInfo.CAMERA_SUPPORT_MODE_ZSL) {
1159 Log.v(TAG, "JpegPictureCallback : in zslmode");
1160 mParameters = mCameraDevice.getParameters();
1161 mBurstSnapNum = mParameters.getInt("num-snaps-per-shutter");
1162 }
1163 Log.v(TAG, "JpegPictureCallback: Received = " + mReceivedSnapNum +
1164 "Burst count = " + mBurstSnapNum);
Michael Kolb8872c232013-01-29 10:33:22 -08001165 // If postview callback has arrived, the captured image is displayed
1166 // in postview callback. If not, the captured image is displayed in
1167 // raw picture callback.
1168 if (mPostViewPictureCallbackTime != 0) {
1169 mShutterToPictureDisplayedTime =
1170 mPostViewPictureCallbackTime - mShutterCallbackTime;
1171 mPictureDisplayedToJpegCallbackTime =
1172 mJpegPictureCallbackTime - mPostViewPictureCallbackTime;
1173 } else {
1174 mShutterToPictureDisplayedTime =
1175 mRawPictureCallbackTime - mShutterCallbackTime;
1176 mPictureDisplayedToJpegCallbackTime =
1177 mJpegPictureCallbackTime - mRawPictureCallbackTime;
1178 }
1179 Log.v(TAG, "mPictureDisplayedToJpegCallbackTime = "
1180 + mPictureDisplayedToJpegCallbackTime + "ms");
1181
Michael Kolb8872c232013-01-29 10:33:22 -08001182 mFocusManager.updateFocusUI(); // Ensure focus indicator is hidden.
Alok Kediya28c31962013-09-28 16:43:35 +05301183
1184 boolean needRestartPreview = !mIsImageCaptureIntent
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001185 && !mPreviewRestartSupport
1186 && (mCameraState != LONGSHOT)
1187 && (mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL)
1188 && (mReceivedSnapNum == mBurstSnapNum);
Alok Kediya28c31962013-09-28 16:43:35 +05301189 if (needRestartPreview) {
Sascha Haeberling638e6f02013-09-18 14:28:51 -07001190 setupPreview();
Kerong Sui058d69a2014-03-12 17:51:13 +08001191 if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(
1192 mFocusManager.getFocusMode())) {
1193 mCameraDevice.cancelAutoFocus();
1194 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001195 } else if ((mReceivedSnapNum == mBurstSnapNum)
Alok Kediyaf5b11812013-11-07 13:53:09 +05301196 && (mCameraState != LONGSHOT)){
Alok Kediya28c31962013-09-28 16:43:35 +05301197 mFocusManager.resetTouchFocus();
Emilian Peev110c9262013-09-02 15:53:22 -07001198 if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(
1199 mFocusManager.getFocusMode())) {
1200 mCameraDevice.cancelAutoFocus();
1201 }
Emilian Peevc3644f12013-11-25 17:22:03 +02001202 mUI.resumeFaceDetection();
Likai Ding03b724c2014-06-12 16:22:14 +08001203 if (!mIsImageCaptureIntent) {
1204 setCameraState(IDLE);
1205 }
Santhosh Kumar H E047b7d32014-09-01 12:31:11 +05301206 startFaceDetection();
Michael Kolb8872c232013-01-29 10:33:22 -08001207 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001208 if ((mRefocus) && (mReceivedSnapNum == 6)) {
Michael Kolb8872c232013-01-29 10:33:22 -08001209 Size s = mParameters.getPictureSize();
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001210 mNamedImages.nameNewImage(mCaptureStartTime, mRefocus);
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001211 NamedEntity name = mNamedImages.getNextNameEntity();
1212 String title = (name == null) ? null : name.title;
1213 long date = (name == null) ? -1 : name.date;
Michael Kolb8872c232013-01-29 10:33:22 -08001214 if (title == null) {
1215 Log.e(TAG, "Unbalanced name/data pair");
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001216 return;
Michael Kolb8872c232013-01-29 10:33:22 -08001217 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001218 if (date == -1) {
1219 Log.e(TAG, "Invalid filename date");
1220 return;
Vijay kumar Tumati04a155f2013-12-19 15:00:29 +05301221 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001222 mActivity.getMediaSaveService().addImage(
1223 jpegData, title, date, mLocation, s.width, s.height,
1224 0, null, mOnMediaSavedListener, mContentResolver, ".jpeg");
1225
Michael Kolb8872c232013-01-29 10:33:22 -08001226 } else {
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001227 ExifInterface exif = Exif.getExif(jpegData);
1228 int orientation = Exif.getOrientation(exif);
1229 if (!mIsImageCaptureIntent) {
1230 // Burst snapshot. Generate new image name.
1231 if (mReceivedSnapNum > 1) {
1232 mNamedImages.nameNewImage(mCaptureStartTime, mRefocus);
1233 }
1234 // Calculate the width and the height of the jpeg.
1235 Size s = mParameters.getPictureSize();
1236 int width, height;
1237 if ((mJpegRotation + orientation) % 180 == 0) {
1238 width = s.width;
1239 height = s.height;
1240 } else {
1241 width = s.height;
1242 height = s.width;
1243 }
1244 String pictureFormat = mParameters.get(KEY_PICTURE_FORMAT);
1245 if (pictureFormat != null && !pictureFormat.equalsIgnoreCase(PIXEL_FORMAT_JPEG)) {
1246 // overwrite width and height if raw picture
1247 String pair = mParameters.get(KEY_QC_RAW_PICUTRE_SIZE);
1248 if (pair != null) {
1249 int pos = pair.indexOf('x');
1250 if (pos != -1) {
1251 width = Integer.parseInt(pair.substring(0, pos));
1252 height = Integer.parseInt(pair.substring(pos + 1));
1253 }
Alok Kediyaa4bd0a62013-09-28 16:10:53 +05301254 }
1255 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001256 NamedEntity name = mNamedImages.getNextNameEntity();
1257 String title = (name == null) ? null : name.title;
1258 long date = (name == null) ? -1 : name.date;
1259 // Handle debug mode outputs
1260 if (mDebugUri != null) {
1261 // If using a debug uri, save jpeg there.
1262 saveToDebugUri(jpegData);
1263 // Adjust the title of the debug image shown in mediastore.
1264 if (title != null) {
1265 title = DEBUG_IMAGE_PREFIX + title;
1266 }
1267 }
1268 if (title == null) {
1269 Log.e(TAG, "Unbalanced name/data pair");
1270 } else {
1271 if (date == -1) {
1272 date = mCaptureStartTime;
1273 }
1274 if (mHeading >= 0) {
1275 // heading direction has been updated by the sensor.
1276 ExifTag directionRefTag = exif.buildTag(
1277 ExifInterface.TAG_GPS_IMG_DIRECTION_REF,
1278 ExifInterface.GpsTrackRef.MAGNETIC_DIRECTION);
1279 ExifTag directionTag = exif.buildTag(
1280 ExifInterface.TAG_GPS_IMG_DIRECTION,
1281 new Rational(mHeading, 1));
1282 exif.setTag(directionRefTag);
1283 exif.setTag(directionTag);
1284 }
1285 String mPictureFormat = mParameters.get(KEY_PICTURE_FORMAT);
1286 mActivity.getMediaSaveService().addImage(
1287 jpegData, title, date, mLocation, width, height,
1288 orientation, exif, mOnMediaSavedListener,
1289 mContentResolver, mPictureFormat);
1290 }
1291 // Animate capture with real jpeg data instead of a preview frame.
1292 if (mCameraState != LONGSHOT) {
1293 Size pic_size = mParameters.getPictureSize();
1294 if ((pic_size.width <= 352) && (pic_size.height<= 288)) {
1295 mUI.setDownFactor(2); //Downsample by 2 for CIF & below
1296 } else {
1297 mUI.setDownFactor(4);
1298 }
1299 mUI.animateCapture(jpegData, orientation, mMirror);
1300 }
1301 } else {
1302 mJpegImageData = jpegData;
1303 if (!mQuickCapture) {
1304 mUI.showCapturedImageForReview(jpegData, orientation, mMirror);
1305 } else {
1306 onCaptureDone();
1307 }
1308 }
1309 // Check this in advance of each shot so we don't add to shutter
1310 // latency. It's true that someone else could write to the SD card in
1311 // the mean time and fill it, but that could have happened between the
1312 // shutter press and saving the JPEG too.
1313 mActivity.updateStorageSpaceAndHint();
1314 long now = System.currentTimeMillis();
1315 mJpegCallbackFinishTime = now - mJpegPictureCallbackTime;
1316 Log.v(TAG, "mJpegCallbackFinishTime = "
1317 + mJpegCallbackFinishTime + "ms");
1318
1319 if (mReceivedSnapNum == mBurstSnapNum) {
1320 mJpegPictureCallbackTime = 0;
1321 }
1322
1323 if (mHiston && (mSnapshotMode ==CameraInfo.CAMERA_SUPPORT_MODE_ZSL)) {
1324 mActivity.runOnUiThread(new Runnable() {
1325 public void run() {
1326 if (mGraphView != null) {
1327 mGraphView.setVisibility(View.VISIBLE);
1328 mGraphView.PreviewChanged();
1329 }
1330 }
1331 });
1332 }
1333 if (mSnapshotMode == CameraInfo.CAMERA_SUPPORT_MODE_ZSL &&
1334 mCameraState != LONGSHOT &&
1335 mReceivedSnapNum == mBurstSnapNum &&
1336 !mIsImageCaptureIntent) {
1337 cancelAutoFocus();
1338 }
Raghu DP9c7f37e2013-11-08 11:27:28 +05301339 }
Michael Kolb8872c232013-01-29 10:33:22 -08001340 }
1341 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001342
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301343 private OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {
1344 public void onStartTrackingTouch(SeekBar bar) {
1345 // no support
1346 }
1347 public void onProgressChanged(SeekBar bar, int progress, boolean fromtouch) {
1348 }
1349 public void onStopTrackingTouch(SeekBar bar) {
1350 }
1351 };
Michael Kolb8872c232013-01-29 10:33:22 -08001352
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301353 private OnSeekBarChangeListener mskinToneSeekListener = new OnSeekBarChangeListener() {
1354 public void onStartTrackingTouch(SeekBar bar) {
1355 // no support
1356 }
1357
1358 public void onProgressChanged(SeekBar bar, int progress, boolean fromtouch) {
1359 int value = (progress + MIN_SCE_FACTOR) * SCE_FACTOR_STEP;
1360 if(progress > (MAX_SCE_FACTOR - MIN_SCE_FACTOR)/2){
1361 RightValue.setText(String.valueOf(value));
1362 LeftValue.setText("");
1363 } else if (progress < (MAX_SCE_FACTOR - MIN_SCE_FACTOR)/2){
1364 LeftValue.setText(String.valueOf(value));
1365 RightValue.setText("");
1366 } else {
1367 LeftValue.setText("");
1368 RightValue.setText("");
1369 }
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +05301370 if (value != mskinToneValue && mCameraDevice != null) {
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301371 mskinToneValue = value;
Santhosh Kumar H Ed7dfbf82013-10-25 14:32:17 +05301372 Message msg = mHandler.obtainMessage(CONFIGURE_SKIN_TONE_FACTOR, mskinToneValue, 0);
1373 mHandler.sendMessage(msg);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301374 }
1375 }
1376
1377 public void onStopTrackingTouch(SeekBar bar) {
1378 Log.v(TAG, "Set onStopTrackingTouch mskinToneValue = " + mskinToneValue);
1379 Editor editor = mPreferences.edit();
1380 editor.putString(CameraSettings.KEY_SKIN_TONE_ENHANCEMENT_FACTOR,
1381 Integer.toString(mskinToneValue));
1382 editor.apply();
1383 }
1384 };
Angus Kong9ef99252013-07-18 18:04:19 -07001385 private final class AutoFocusCallback implements CameraAFCallback {
Michael Kolb8872c232013-01-29 10:33:22 -08001386 @Override
1387 public void onAutoFocus(
Angus Kong9ef99252013-07-18 18:04:19 -07001388 boolean focused, CameraProxy camera) {
Michael Kolb8872c232013-01-29 10:33:22 -08001389 if (mPaused) return;
1390
1391 mAutoFocusTime = System.currentTimeMillis() - mFocusStartTime;
1392 Log.v(TAG, "mAutoFocusTime = " + mAutoFocusTime + "ms");
Santhosh Kumar Thimmanna Bhattarcc254382014-01-13 12:22:44 +05301393 //don't reset the camera state while capture is in progress
1394 //otherwise, it might result in another takepicture
1395 switch (mCameraState) {
1396 case PhotoController.LONGSHOT:
1397 case SNAPSHOT_IN_PROGRESS:
1398 break;
1399 default:
1400 setCameraState(IDLE);
1401 break;
1402 }
Michael Kolbd6954f32013-03-08 20:43:01 -08001403 mFocusManager.onAutoFocus(focused, mUI.isShutterPressed());
Michael Kolb8872c232013-01-29 10:33:22 -08001404 }
1405 }
1406
Sascha Haeberling638e6f02013-09-18 14:28:51 -07001407 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Michael Kolb8872c232013-01-29 10:33:22 -08001408 private final class AutoFocusMoveCallback
Angus Kong9ef99252013-07-18 18:04:19 -07001409 implements CameraAFMoveCallback {
Michael Kolb8872c232013-01-29 10:33:22 -08001410 @Override
1411 public void onAutoFocusMoving(
Dan Aminzade92ae10e2013-08-13 14:44:25 -07001412 boolean moving, CameraProxy camera) {
1413 mFocusManager.onAutoFocusMoving(moving);
Michael Kolb8872c232013-01-29 10:33:22 -08001414 }
1415 }
1416
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001417 /**
1418 * This class is just a thread-safe queue for name,date holder objects.
1419 */
1420 public static class NamedImages {
1421 private Vector<NamedEntity> mQueue;
Michael Kolb8872c232013-01-29 10:33:22 -08001422
1423 public NamedImages() {
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001424 mQueue = new Vector<NamedEntity>();
Michael Kolb8872c232013-01-29 10:33:22 -08001425 }
1426
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001427 public void nameNewImage(long date) {
Michael Kolb8872c232013-01-29 10:33:22 -08001428 NamedEntity r = new NamedEntity();
Angus Kongb50b5cb2013-08-09 14:55:20 -07001429 r.title = CameraUtil.createJpegName(date);
Michael Kolb8872c232013-01-29 10:33:22 -08001430 r.date = date;
1431 mQueue.add(r);
1432 }
1433
Emilian Peevde5dd902014-03-17 16:34:20 -07001434 public void nameNewImage(long date, boolean refocus) {
1435 NamedEntity r = new NamedEntity();
1436 r.title = CameraUtil.createJpegName(date, refocus);
1437 r.date = date;
1438 mQueue.add(r);
1439 }
1440
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001441 public NamedEntity getNextNameEntity() {
1442 synchronized(mQueue) {
1443 if (!mQueue.isEmpty()) {
1444 return mQueue.remove(0);
1445 }
Michael Kolb8872c232013-01-29 10:33:22 -08001446 }
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001447 return null;
Michael Kolb8872c232013-01-29 10:33:22 -08001448 }
1449
Ruben Brunka9d66bd2013-09-06 11:56:32 -07001450 public static class NamedEntity {
1451 public String title;
1452 public long date;
Michael Kolb8872c232013-01-29 10:33:22 -08001453 }
1454 }
1455
1456 private void setCameraState(int state) {
1457 mCameraState = state;
1458 switch (state) {
Dan Aminzade92ae10e2013-08-13 14:44:25 -07001459 case PhotoController.PREVIEW_STOPPED:
1460 case PhotoController.SNAPSHOT_IN_PROGRESS:
Alok Kediyaf5b11812013-11-07 13:53:09 +05301461 case PhotoController.LONGSHOT:
Dan Aminzade92ae10e2013-08-13 14:44:25 -07001462 case PhotoController.SWITCHING_CAMERA:
1463 mUI.enableGestures(false);
1464 break;
1465 case PhotoController.IDLE:
1466 mUI.enableGestures(true);
1467 break;
Michael Kolb8872c232013-01-29 10:33:22 -08001468 }
1469 }
1470
Sascha Haeberling37f36112013-08-06 14:31:52 -07001471 private void animateAfterShutter() {
Michael Kolb8872c232013-01-29 10:33:22 -08001472 // Only animate when in full screen capture mode
1473 // i.e. If monkey/a user swipes to the gallery during picture taking,
1474 // don't show animation
Doris Liuc2e9abd2013-06-19 14:20:51 -07001475 if (!mIsImageCaptureIntent) {
1476 mUI.animateFlash();
Doris Liuc2e9abd2013-06-19 14:20:51 -07001477 }
Michael Kolb8872c232013-01-29 10:33:22 -08001478 }
1479
1480 @Override
1481 public boolean capture() {
1482 // If we are already in the middle of taking a snapshot or the image save request
1483 // is full then ignore.
1484 if (mCameraDevice == null || mCameraState == SNAPSHOT_IN_PROGRESS
Angus Kong86d36312013-01-31 18:22:44 -08001485 || mCameraState == SWITCHING_CAMERA
Sascha Haeberlingba1b30b2013-11-04 12:11:34 -08001486 || mActivity.getMediaSaveService() == null
Angus Kong86d36312013-01-31 18:22:44 -08001487 || mActivity.getMediaSaveService().isQueueFull()) {
Michael Kolb8872c232013-01-29 10:33:22 -08001488 return false;
1489 }
1490 mCaptureStartTime = System.currentTimeMillis();
1491 mPostViewPictureCallbackTime = 0;
1492 mJpegImageData = null;
1493
Angus Kongb50b5cb2013-08-09 14:55:20 -07001494 final boolean animateBefore = (mSceneMode == CameraUtil.SCENE_MODE_HDR);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301495 if(mHiston) {
1496 if (mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL) {
1497 mHiston = false;
1498 mCameraDevice.setHistogramMode(null);
1499 }
1500 mActivity.runOnUiThread(new Runnable() {
1501 public void run() {
1502 if(mGraphView != null)
1503 mGraphView.setVisibility(View.INVISIBLE);
1504 }
1505 });
1506 }
Michael Kolb8872c232013-01-29 10:33:22 -08001507
1508 if (animateBefore) {
Sascha Haeberling37f36112013-08-06 14:31:52 -07001509 animateAfterShutter();
Michael Kolb8872c232013-01-29 10:33:22 -08001510 }
1511
1512 // Set rotation and gps data.
Doris Liu3cf565c2013-02-15 10:55:37 -08001513 int orientation;
1514 // We need to be consistent with the framework orientation (i.e. the
1515 // orientation of the UI.) when the auto-rotate screen setting is on.
1516 if (mActivity.isAutoRotateScreen()) {
1517 orientation = (360 - mDisplayRotation) % 360;
1518 } else {
1519 orientation = mOrientation;
1520 }
Angus Kongb50b5cb2013-08-09 14:55:20 -07001521 mJpegRotation = CameraUtil.getJpegRotation(mCameraId, orientation);
Michael Kolb8872c232013-01-29 10:33:22 -08001522 mParameters.setRotation(mJpegRotation);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301523 String pictureFormat = mParameters.get(KEY_PICTURE_FORMAT);
1524 Location loc = null;
1525 if (pictureFormat != null &&
1526 PIXEL_FORMAT_JPEG.equalsIgnoreCase(pictureFormat)) {
1527 loc = mLocationManager.getCurrentLocation();
1528 }
Angus Kongb50b5cb2013-08-09 14:55:20 -07001529 CameraUtil.setGpsParameters(mParameters, loc);
Emilian Peevde5dd902014-03-17 16:34:20 -07001530
1531 if (mRefocus) {
1532 mParameters.set(CameraSettings.KEY_QC_LEGACY_BURST,
1533 CameraSettings.KEY_QC_RE_FOCUS_COUNT);
1534 } else {
1535 mParameters.remove(CameraSettings.KEY_QC_LEGACY_BURST);
1536 }
1537
Michael Kolb8872c232013-01-29 10:33:22 -08001538 mCameraDevice.setParameters(mParameters);
Alok Kediya28c31962013-09-28 16:43:35 +05301539 mParameters = mCameraDevice.getParameters();
1540
1541 mBurstSnapNum = mParameters.getInt("num-snaps-per-shutter");
1542 mReceivedSnapNum = 0;
Emilian Peevbfd8f312013-12-17 17:16:36 +02001543 mPreviewRestartSupport = SystemProperties.getBoolean(
1544 PERSIST_PREVIEW_RESTART, false);
1545 mPreviewRestartSupport &= CameraSettings.isInternalPreviewSupported(
1546 mParameters);
1547 mPreviewRestartSupport &= (mBurstSnapNum == 1);
1548 mPreviewRestartSupport &= PIXEL_FORMAT_JPEG.equalsIgnoreCase(
1549 pictureFormat);
Michael Kolb8872c232013-01-29 10:33:22 -08001550
Sascha Haeberling88901942013-08-28 17:49:00 -07001551 // We don't want user to press the button again while taking a
Sai Kumar Sanagavarapufb60d5d2014-07-25 12:51:03 +05301552 // multi-second HDR photo. For longshot, no need to disable.
1553 if (mCameraState != LONGSHOT) {
1554 mUI.enableShutter(false);
1555 }
Alok Kediyaf5b11812013-11-07 13:53:09 +05301556
1557 if (mCameraState == LONGSHOT) {
1558 if(mLongshotSave) {
1559 mCameraDevice.takePicture(mHandler,
1560 new LongshotShutterCallback(),
1561 mRawPictureCallback, mPostViewPictureCallback,
1562 new LongshotPictureCallback(loc));
1563 } else {
1564 mCameraDevice.takePicture(mHandler,
1565 new LongshotShutterCallback(),
1566 mRawPictureCallback, mPostViewPictureCallback,
1567 new JpegPictureCallback(loc));
1568 }
1569 } else {
1570 mCameraDevice.takePicture(mHandler,
1571 new ShutterCallback(!animateBefore),
1572 mRawPictureCallback, mPostViewPictureCallback,
1573 new JpegPictureCallback(loc));
1574 setCameraState(SNAPSHOT_IN_PROGRESS);
1575 }
Michael Kolb8872c232013-01-29 10:33:22 -08001576
Emilian Peevde5dd902014-03-17 16:34:20 -07001577 mNamedImages.nameNewImage(mCaptureStartTime, mRefocus);
Michael Kolb8872c232013-01-29 10:33:22 -08001578
Santhosh Kumar H E8bc7d872013-11-20 18:36:54 +05301579 if (mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL) {
1580 mFaceDetectionStarted = false;
1581 }
Bobby Georgescu301b6462013-04-01 15:33:17 -07001582 UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA,
Seth Raphaelcbd82672013-11-05 10:12:36 -08001583 UsageStatistics.ACTION_CAPTURE_DONE, "Photo", 0,
Seth Raphael35740262013-11-27 14:29:24 -08001584 UsageStatistics.hashFileName(mNamedImages.mQueue.lastElement().title + ".jpg"));
Michael Kolb8872c232013-01-29 10:33:22 -08001585 return true;
1586 }
1587
1588 @Override
1589 public void setFocusParameters() {
1590 setCameraParameters(UPDATE_PARAM_PREFERENCE);
1591 }
1592
1593 private int getPreferredCameraId(ComboPreferences preferences) {
Angus Kongb50b5cb2013-08-09 14:55:20 -07001594 int intentCameraId = CameraUtil.getCameraFacingIntentExtras(mActivity);
Michael Kolb8872c232013-01-29 10:33:22 -08001595 if (intentCameraId != -1) {
1596 // Testing purpose. Launch a specific camera through the intent
1597 // extras.
1598 return intentCameraId;
1599 } else {
1600 return CameraSettings.readPreferredCameraId(preferences);
1601 }
1602 }
1603
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05301604 private void updateCommonManual3ASettings() {
1605 String touchAfAec = mParameters.TOUCH_AF_AEC_OFF;
1606 mSceneMode = Parameters.SCENE_MODE_AUTO;
1607 String flashMode = Parameters.FLASH_MODE_OFF;
1608 String redeyeReduction = mActivity.getString(R.string.
1609 pref_camera_redeyereduction_entry_disable);
1610 String aeBracketing = mActivity.getString(R.string.
1611 pref_camera_ae_bracket_hdr_entry_off);
1612 String colorEffect = mActivity.getString(R.string.
1613 pref_camera_coloreffect_default);
1614 String exposureCompensation = CameraSettings.EXPOSURE_DEFAULT_VALUE;
1615
1616 if (mManual3AEnabled > 0) {
1617 overrideCameraSettings(flashMode, null, null,
1618 exposureCompensation, touchAfAec,
1619 mParameters.getAutoExposure(),
1620 Integer.toString(mParameters.getSaturation()),
1621 Integer.toString(mParameters.getContrast()),
1622 Integer.toString(mParameters.getSharpness()),
1623 colorEffect,
1624 mSceneMode, redeyeReduction, aeBracketing);
1625 mUI.overrideSettings(CameraSettings.KEY_LONGSHOT,
1626 mActivity.getString(R.string.setting_off_value));
1627 } else {
1628 //enable all
1629 touchAfAec = mActivity.getString(
1630 R.string.pref_camera_touchafaec_default);
1631 overrideCameraSettings(null, null, null,
1632 null, touchAfAec, null,
1633 null, null, null, null,
1634 null, null, null);
1635 mUI.overrideSettings(CameraSettings.KEY_LONGSHOT, null);
1636 }
1637
1638 String isoMode = mParameters.getISOValue();
1639 final String isoManual = CameraSettings.KEY_MANUAL_ISO;
1640 if (isoMode.equals(isoManual)) {
1641 final String isoPref = mPreferences.getString(
1642 CameraSettings.KEY_ISO,
1643 mActivity.getString(R.string.pref_camera_iso_default));
1644 mUI.overrideSettings(CameraSettings.KEY_ISO, isoPref);
1645 }
1646 if ((mManual3AEnabled & MANUAL_WB) != 0) {
1647 String whiteBalance = mPreferences.getString(
1648 CameraSettings.KEY_WHITE_BALANCE,
1649 mActivity.getString(R.string.pref_camera_whitebalance_default));
1650 mUI.overrideSettings(CameraSettings.KEY_WHITE_BALANCE, whiteBalance);
1651 }
1652 if ((mManual3AEnabled & MANUAL_FOCUS) != 0) {
1653 mUI.overrideSettings(CameraSettings.KEY_FOCUS_MODE,
1654 mFocusManager.getFocusMode());
1655 }
1656 }
1657
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001658 private void updateCameraSettings() {
Emilian Peevfcf86352014-04-08 15:34:46 -07001659 String sceneMode = null;
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001660 String flashMode = null;
1661 String redeyeReduction = null;
1662 String aeBracketing = null;
1663 String focusMode = null;
1664 String colorEffect = null;
1665 String exposureCompensation = null;
1666 String touchAfAec = null;
Ivan Evlogiev9b88eba2014-10-07 11:28:03 +03001667 boolean disableLongShot = false;
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001668
1669 String ubiFocusOn = mActivity.getString(R.string.
1670 pref_camera_advanced_feature_value_ubifocus_on);
kaiyiz43971182014-05-31 09:26:50 +08001671 String continuousShotOn =
1672 mActivity.getString(R.string.setting_on_value);
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001673 String reFocusOn = mActivity.getString(R.string.
1674 pref_camera_advanced_feature_value_refocus_on);
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001675 String chromaFlashOn = mActivity.getString(R.string.
1676 pref_camera_advanced_feature_value_chromaflash_on);
1677 String optiZoomOn = mActivity.getString(R.string.
1678 pref_camera_advanced_feature_value_optizoom_on);
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05301679 String fssrOn = mActivity.getString(R.string.
1680 pref_camera_advanced_feature_value_FSSR_on);
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05301681 String truPortraitOn = mActivity.getString(R.string.
1682 pref_camera_advanced_feature_value_trueportrait_on);
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05301683 String multiTouchFocusOn = mActivity.getString(R.string.
1684 pref_camera_advanced_feature_value_multi_touch_focus_on);
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001685 String optiZoom =
1686 mParameters.get(CameraSettings.KEY_QC_OPTI_ZOOM);
1687 String chromaFlash =
1688 mParameters.get(CameraSettings.KEY_QC_CHROMA_FLASH);
1689 String ubiFocus =
1690 mParameters.get(CameraSettings.KEY_QC_AF_BRACKETING);
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05301691 String fssr =
1692 mParameters.get(CameraSettings.KEY_QC_FSSR);
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05301693 String truePortrait =
1694 mParameters.get(CameraSettings.KEY_QC_TP);
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05301695 String multiTouchFocus =
1696 mParameters.get(CameraSettings.KEY_QC_MULTI_TOUCH_FOCUS);
1697 String continuousShot =
1698 mParameters.get("long-shot");
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05301699
1700 if (mManual3AEnabled > 0) {
1701 disableLongShot = true;
1702 }
1703
kaiyiz43971182014-05-31 09:26:50 +08001704 if ((continuousShot != null) && continuousShot.equals(continuousShotOn)) {
1705 String pictureFormat = mActivity.getString(R.string.
1706 pref_camera_picture_format_value_jpeg);
1707 mUI.overrideSettings(CameraSettings.KEY_PICTURE_FORMAT, pictureFormat);
1708 } else {
1709 mUI.overrideSettings(CameraSettings.KEY_PICTURE_FORMAT, null);
1710 }
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001711 String reFocus =
1712 mParameters.get(CameraSettings.KEY_QC_RE_FOCUS);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05301713
1714 if (mFocusManager.isZslEnabled()) {
1715 String pictureFormat = mActivity.getString(R.string.
1716 pref_camera_picture_format_value_jpeg);
1717 mUI.overrideSettings(CameraSettings.KEY_PICTURE_FORMAT, pictureFormat);
1718 } else {
1719 mUI.overrideSettings(CameraSettings.KEY_PICTURE_FORMAT, null);
1720 }
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001721 if ((ubiFocus != null && ubiFocus.equals(ubiFocusOn)) ||
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05301722 (multiTouchFocus != null && multiTouchFocus.equals(multiTouchFocusOn)) ||
Ivan Evlogiev3d32e202014-06-24 16:47:11 +03001723 (reFocus != null && reFocus.equals(reFocusOn)) ||
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001724 (chromaFlash != null && chromaFlash.equals(chromaFlashOn)) ||
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05301725 (optiZoom != null && optiZoom.equals(optiZoomOn)) ||
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05301726 (fssr != null && fssr.equals(fssrOn)) ||
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05301727 (truePortrait != null && truePortrait.equals(truPortraitOn))) {
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001728 mSceneMode = sceneMode = Parameters.SCENE_MODE_AUTO;
1729 flashMode = Parameters.FLASH_MODE_OFF;
1730 focusMode = Parameters.FOCUS_MODE_INFINITY;
1731 redeyeReduction = mActivity.getString(R.string.
1732 pref_camera_redeyereduction_entry_disable);
1733 aeBracketing = mActivity.getString(R.string.
1734 pref_camera_ae_bracket_hdr_entry_off);
1735 colorEffect = mActivity.getString(R.string.
1736 pref_camera_coloreffect_default);
1737 exposureCompensation = CameraSettings.EXPOSURE_DEFAULT_VALUE;
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001738
1739 overrideCameraSettings(flashMode, null, focusMode,
1740 exposureCompensation, touchAfAec, null,
1741 null, null, null, colorEffect,
1742 sceneMode, redeyeReduction, aeBracketing);
Ivan Evlogiev9b88eba2014-10-07 11:28:03 +03001743 disableLongShot = true;
1744 Toast.makeText(mActivity, R.string.advanced_capture_disable_continuous_shot,
1745 Toast.LENGTH_LONG).show();
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001746 }
1747
Santhosh Kumar H E63503512013-12-31 15:44:12 +05301748 // If scene mode is set, for flash mode, white balance and focus mode
1749 // read settings from preferences so we retain user preferences.
Michael Kolb8872c232013-01-29 10:33:22 -08001750 if (!Parameters.SCENE_MODE_AUTO.equals(mSceneMode)) {
kaiyiz45c81752014-06-16 16:36:15 +08001751 flashMode = mParameters.getFlashMode();
kaiyiz5de31222014-06-30 16:31:14 +08001752 String whiteBalance = Parameters.WHITE_BALANCE_AUTO;
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001753 focusMode = mFocusManager.getFocusMode();
1754 colorEffect = mParameters.getColorEffect();
1755 exposureCompensation =
1756 Integer.toString(mParameters.getExposureCompensation());
1757 touchAfAec = mCurrTouchAfAec;
Santhosh Kumar H E63503512013-12-31 15:44:12 +05301758
1759 overrideCameraSettings(flashMode, whiteBalance, focusMode,
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001760 exposureCompensation, touchAfAec,
1761 mParameters.getAutoExposure(),
Santhosh Kumar Thimmanna Bhattarfce03ba2014-01-10 11:30:38 +05301762 Integer.toString(mParameters.getSaturation()),
Rajaram Gudivada44f14682014-02-26 21:25:41 +05301763 Integer.toString(mParameters.getContrast()),
1764 Integer.toString(mParameters.getSharpness()),
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001765 colorEffect,
1766 sceneMode, redeyeReduction, aeBracketing);
kaiyiz0ca51ec2014-05-28 17:01:33 +08001767 if (CameraUtil.SCENE_MODE_HDR.equals(mSceneMode)) {
Ivan Evlogiev9b88eba2014-10-07 11:28:03 +03001768 disableLongShot = true;
kaiyiz0ca51ec2014-05-28 17:01:33 +08001769 }
Emilian Peev3091b022013-08-19 12:32:23 +03001770 } else if (mFocusManager.isZslEnabled()) {
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001771 focusMode = mParameters.getFocusMode();
1772 overrideCameraSettings(flashMode, null, focusMode,
1773 exposureCompensation, touchAfAec, null,
1774 null, null, null, colorEffect,
1775 sceneMode, redeyeReduction, aeBracketing);
Michael Kolb8872c232013-01-29 10:33:22 -08001776 } else {
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05301777 if (mManual3AEnabled > 0) {
1778 updateCommonManual3ASettings();
1779 } else {
1780 overrideCameraSettings(flashMode, null, focusMode,
1781 exposureCompensation, touchAfAec, null,
1782 null, null, null, colorEffect,
1783 sceneMode, redeyeReduction, aeBracketing);
1784 }
Michael Kolb8872c232013-01-29 10:33:22 -08001785 }
Suman Mukherjeede8bbe72014-05-22 13:35:24 +05301786 /* Disable focus if aebracket is ON */
1787 String aeBracket = mParameters.get(CameraSettings.KEY_QC_AE_BRACKETING);
1788 if (!aeBracket.equalsIgnoreCase("off")) {
1789 String fMode = Parameters.FLASH_MODE_OFF;
1790 mUI.overrideSettings(CameraSettings.KEY_FLASH_MODE, fMode);
1791 mParameters.setFlashMode(fMode);
1792 }
Ivan Evlogiev9b88eba2014-10-07 11:28:03 +03001793 if (disableLongShot) {
1794 mUI.overrideSettings(CameraSettings.KEY_LONGSHOT,
1795 mActivity.getString(R.string.setting_off_value));
1796 } else {
kaiyiz0ca51ec2014-05-28 17:01:33 +08001797 mUI.overrideSettings(CameraSettings.KEY_LONGSHOT, null);
1798 }
Sai Kumar Sanagavarapua48f6312014-09-05 16:12:19 +05301799
1800 boolean disableQcomMiscSetting =
1801 SystemProperties.getBoolean("camera.qcom.misc.disable", false);
1802 if (disableQcomMiscSetting) {
1803 mUI.overrideSettings(CameraSettings.KEY_ZSL, Parameters.ZSL_OFF);
1804 mUI.overrideSettings(CameraSettings.KEY_FACE_DETECTION, Parameters.FACE_DETECTION_OFF);
1805 mUI.overrideSettings(CameraSettings.KEY_TOUCH_AF_AEC, Parameters.TOUCH_AF_AEC_OFF);
1806 mUI.overrideSettings(CameraSettings.KEY_FOCUS_MODE, Parameters.FOCUS_MODE_AUTO);
1807 mUI.overrideSettings(CameraSettings.KEY_FLASH_MODE, Parameters.FLASH_MODE_OFF);
1808 mUI.overrideSettings(CameraSettings.KEY_DENOISE, Parameters.DENOISE_OFF);
1809 }
Michael Kolb8872c232013-01-29 10:33:22 -08001810 }
1811
1812 private void overrideCameraSettings(final String flashMode,
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301813 final String whiteBalance, final String focusMode,
1814 final String exposureMode, final String touchMode,
Santhosh Kumar Thimmanna Bhattarfce03ba2014-01-10 11:30:38 +05301815 final String autoExposure, final String saturation,
Rajaram Gudivada44f14682014-02-26 21:25:41 +05301816 final String contrast, final String sharpness,
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001817 final String coloreffect, final String sceneMode,
1818 final String redeyeReduction, final String aeBracketing) {
Michael Kolbd6954f32013-03-08 20:43:01 -08001819 mUI.overrideSettings(
1820 CameraSettings.KEY_FLASH_MODE, flashMode,
1821 CameraSettings.KEY_WHITE_BALANCE, whiteBalance,
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301822 CameraSettings.KEY_FOCUS_MODE, focusMode,
1823 CameraSettings.KEY_EXPOSURE, exposureMode,
1824 CameraSettings.KEY_TOUCH_AF_AEC, touchMode,
Santhosh Kumar Thimmanna Bhattarfce03ba2014-01-10 11:30:38 +05301825 CameraSettings.KEY_AUTOEXPOSURE, autoExposure,
1826 CameraSettings.KEY_SATURATION, saturation,
Rajaram Gudivada44f14682014-02-26 21:25:41 +05301827 CameraSettings.KEY_CONTRAST, contrast,
1828 CameraSettings.KEY_SHARPNESS, sharpness,
Ivan Evlogiev5086f852014-03-05 17:12:35 +02001829 CameraSettings.KEY_COLOR_EFFECT, coloreffect,
1830 CameraSettings.KEY_SCENE_MODE, sceneMode,
1831 CameraSettings.KEY_REDEYE_REDUCTION, redeyeReduction,
1832 CameraSettings.KEY_AE_BRACKET_HDR, aeBracketing);
Michael Kolb8872c232013-01-29 10:33:22 -08001833 }
1834
1835 private void loadCameraPreferences() {
1836 CameraSettings settings = new CameraSettings(mActivity, mInitialParams,
1837 mCameraId, CameraHolder.instance().getCameraInfo());
1838 mPreferenceGroup = settings.getPreferenceGroup(R.xml.camera_preferences);
Vijay kumar Tumatiefabd532014-03-24 18:45:35 +05301839
1840 int numOfCams = Camera.getNumberOfCameras();
1841 int backCamId = CameraHolder.instance().getBackCameraId();
1842 int frontCamId = CameraHolder.instance().getFrontCameraId();
1843 // We need to swap the list preference contents if back camera and front camera
1844 // IDs are not 0 and 1 respectively
1845 if ((numOfCams == 2) && ((backCamId != CameraInfo.CAMERA_FACING_BACK)
1846 || (frontCamId != CameraInfo.CAMERA_FACING_FRONT))) {
1847 Log.e(TAG,"loadCameraPreferences() updating camera_id pref");
1848
1849 IconListPreference switchIconPref =
1850 (IconListPreference)mPreferenceGroup.findPreference(
1851 CameraSettings.KEY_CAMERA_ID);
1852
1853 int[] iconIds = {R.drawable.ic_switch_front, R.drawable.ic_switch_back};
1854 switchIconPref.setIconIds(iconIds);
1855
1856 String[] entries = {mActivity.getResources().getString(
1857 R.string.pref_camera_id_entry_front), mActivity.getResources().
1858 getString(R.string.pref_camera_id_entry_back)};
1859 switchIconPref.setEntries(entries);
1860
1861 String[] labels = {mActivity.getResources().getString(
1862 R.string.pref_camera_id_label_front), mActivity.getResources().
1863 getString(R.string.pref_camera_id_label_back)};
1864 switchIconPref.setLabels(labels);
1865
1866 int[] largeIconIds = {R.drawable.ic_switch_front, R.drawable.ic_switch_back};
1867 switchIconPref.setLargeIconIds(largeIconIds);
1868 }
Michael Kolb8872c232013-01-29 10:33:22 -08001869 }
1870
1871 @Override
Michael Kolb8872c232013-01-29 10:33:22 -08001872 public void onOrientationChanged(int orientation) {
1873 // We keep the last known orientation. So if the user first orient
1874 // the camera then point the camera to floor or sky, we still have
1875 // the correct orientation.
1876 if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
Alok Kediya4b6f3f92013-09-28 17:39:13 +05301877 int oldOrientation = mOrientation;
Angus Kongb50b5cb2013-08-09 14:55:20 -07001878 mOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05301879 if (oldOrientation != mOrientation &&
1880 oldOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
Alok Kediya4b6f3f92013-09-28 17:39:13 +05301881 Log.v(TAG, "onOrientationChanged, update parameters");
1882 if (mParameters != null && mCameraDevice != null) {
Santhosh Kumar H E823c8f42014-10-16 11:20:34 +05301883 setFlipValue();
1884 mCameraDevice.setParameters(mParameters);
Alok Kediya4b6f3f92013-09-28 17:39:13 +05301885 }
1886 }
Michael Kolb8872c232013-01-29 10:33:22 -08001887
1888 // Show the toast after getting the first orientation changed.
1889 if (mHandler.hasMessages(SHOW_TAP_TO_FOCUS_TOAST)) {
1890 mHandler.removeMessages(SHOW_TAP_TO_FOCUS_TOAST);
1891 showTapToFocusToast();
1892 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05301893
1894 // need to re-initialize mGraphView to show histogram on rotate
1895 mGraphView = (GraphView)mRootView.findViewById(R.id.graph_view);
1896 if(mGraphView != null){
1897 mGraphView.setPhotoModuleObject(this);
1898 mGraphView.PreviewChanged();
1899 }
Michael Kolb8872c232013-01-29 10:33:22 -08001900 }
1901
1902 @Override
1903 public void onStop() {
1904 if (mMediaProviderClient != null) {
1905 mMediaProviderClient.release();
1906 mMediaProviderClient = null;
1907 }
1908 }
1909
Michael Kolbd6954f32013-03-08 20:43:01 -08001910 @Override
1911 public void onCaptureCancelled() {
1912 mActivity.setResultEx(Activity.RESULT_CANCELED, new Intent());
1913 mActivity.finish();
Michael Kolb8872c232013-01-29 10:33:22 -08001914 }
1915
Michael Kolbd6954f32013-03-08 20:43:01 -08001916 @Override
1917 public void onCaptureRetake() {
Michael Kolb8872c232013-01-29 10:33:22 -08001918 if (mPaused)
1919 return;
Michael Kolbd6954f32013-03-08 20:43:01 -08001920 mUI.hidePostCaptureAlert();
Michael Kolb8872c232013-01-29 10:33:22 -08001921 setupPreview();
1922 }
1923
Michael Kolbd6954f32013-03-08 20:43:01 -08001924 @Override
1925 public void onCaptureDone() {
Michael Kolb8872c232013-01-29 10:33:22 -08001926 if (mPaused) {
1927 return;
1928 }
1929
1930 byte[] data = mJpegImageData;
1931
1932 if (mCropValue == null) {
1933 // First handle the no crop case -- just return the value. If the
1934 // caller specifies a "save uri" then write the data to its
1935 // stream. Otherwise, pass back a scaled down version of the bitmap
1936 // directly in the extras.
1937 if (mSaveUri != null) {
1938 OutputStream outputStream = null;
1939 try {
1940 outputStream = mContentResolver.openOutputStream(mSaveUri);
1941 outputStream.write(data);
1942 outputStream.close();
1943
1944 mActivity.setResultEx(Activity.RESULT_OK);
1945 mActivity.finish();
1946 } catch (IOException ex) {
1947 // ignore exception
1948 } finally {
Angus Kongb50b5cb2013-08-09 14:55:20 -07001949 CameraUtil.closeSilently(outputStream);
Michael Kolb8872c232013-01-29 10:33:22 -08001950 }
1951 } else {
Angus Kong0d00a892013-03-26 11:40:40 -07001952 ExifInterface exif = Exif.getExif(data);
1953 int orientation = Exif.getOrientation(exif);
Angus Kongb50b5cb2013-08-09 14:55:20 -07001954 Bitmap bitmap = CameraUtil.makeBitmap(data, 50 * 1024);
1955 bitmap = CameraUtil.rotate(bitmap, orientation);
Michael Kolb8872c232013-01-29 10:33:22 -08001956 mActivity.setResultEx(Activity.RESULT_OK,
1957 new Intent("inline-data").putExtra("data", bitmap));
1958 mActivity.finish();
1959 }
1960 } else {
1961 // Save the image to a temp file and invoke the cropper
1962 Uri tempUri = null;
1963 FileOutputStream tempStream = null;
1964 try {
1965 File path = mActivity.getFileStreamPath(sTempCropFilename);
1966 path.delete();
1967 tempStream = mActivity.openFileOutput(sTempCropFilename, 0);
1968 tempStream.write(data);
1969 tempStream.close();
1970 tempUri = Uri.fromFile(path);
1971 } catch (FileNotFoundException ex) {
1972 mActivity.setResultEx(Activity.RESULT_CANCELED);
1973 mActivity.finish();
1974 return;
1975 } catch (IOException ex) {
1976 mActivity.setResultEx(Activity.RESULT_CANCELED);
1977 mActivity.finish();
1978 return;
1979 } finally {
Angus Kongb50b5cb2013-08-09 14:55:20 -07001980 CameraUtil.closeSilently(tempStream);
Michael Kolb8872c232013-01-29 10:33:22 -08001981 }
1982
1983 Bundle newExtras = new Bundle();
1984 if (mCropValue.equals("circle")) {
1985 newExtras.putString("circleCrop", "true");
1986 }
1987 if (mSaveUri != null) {
1988 newExtras.putParcelable(MediaStore.EXTRA_OUTPUT, mSaveUri);
1989 } else {
Angus Kongb50b5cb2013-08-09 14:55:20 -07001990 newExtras.putBoolean(CameraUtil.KEY_RETURN_DATA, true);
Michael Kolb8872c232013-01-29 10:33:22 -08001991 }
1992 if (mActivity.isSecureCamera()) {
Angus Kongb50b5cb2013-08-09 14:55:20 -07001993 newExtras.putBoolean(CameraUtil.KEY_SHOW_WHEN_LOCKED, true);
Michael Kolb8872c232013-01-29 10:33:22 -08001994 }
1995
Sascha Haeberling37f36112013-08-06 14:31:52 -07001996 // TODO: Share this constant.
Sascha Haeberling8e963a52013-08-06 11:43:02 -07001997 final String CROP_ACTION = "com.android.camera.action.CROP";
1998 Intent cropIntent = new Intent(CROP_ACTION);
Michael Kolb8872c232013-01-29 10:33:22 -08001999
2000 cropIntent.setData(tempUri);
2001 cropIntent.putExtras(newExtras);
2002
2003 mActivity.startActivityForResult(cropIntent, REQUEST_CROP);
2004 }
2005 }
2006
Michael Kolb8872c232013-01-29 10:33:22 -08002007 @Override
2008 public void onShutterButtonFocus(boolean pressed) {
Michael Kolbd6954f32013-03-08 20:43:01 -08002009 if (mPaused || mUI.collapseCameraControls()
Michael Kolb8872c232013-01-29 10:33:22 -08002010 || (mCameraState == SNAPSHOT_IN_PROGRESS)
2011 || (mCameraState == PREVIEW_STOPPED)) return;
2012
Alok Kediyaf5b11812013-11-07 13:53:09 +05302013 synchronized(mCameraDevice) {
2014 if (mCameraState == LONGSHOT) {
Fei Zhang3d391b52014-06-04 14:51:41 +08002015 mLongshotActive = false;
Alok Kediyaf5b11812013-11-07 13:53:09 +05302016 mCameraDevice.setLongshot(false);
2017 if (!mFocusManager.isZslEnabled()) {
2018 setupPreview();
2019 } else {
2020 setCameraState(IDLE);
2021 mFocusManager.resetTouchFocus();
Emilian Peev110c9262013-09-02 15:53:22 -07002022 if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(
2023 mFocusManager.getFocusMode())) {
2024 mCameraDevice.cancelAutoFocus();
2025 }
Emilian Peevc3644f12013-11-25 17:22:03 +02002026 mUI.resumeFaceDetection();
Alok Kediyaf5b11812013-11-07 13:53:09 +05302027 }
2028 }
2029 }
2030
Michael Kolb8872c232013-01-29 10:33:22 -08002031 // Do not do focus if there is not enough storage.
2032 if (pressed && !canTakePicture()) return;
2033
2034 if (pressed) {
Michael Kolb8872c232013-01-29 10:33:22 -08002035 mFocusManager.onShutterDown();
2036 } else {
Doris Liuda50e052013-02-07 14:36:32 -08002037 // for countdown mode, we need to postpone the shutter release
2038 // i.e. lock the focus during countdown.
Michael Kolbd6954f32013-03-08 20:43:01 -08002039 if (!mUI.isCountingDown()) {
Doris Liuda50e052013-02-07 14:36:32 -08002040 mFocusManager.onShutterUp();
2041 }
Michael Kolb8872c232013-01-29 10:33:22 -08002042 }
2043 }
2044
2045 @Override
2046 public void onShutterButtonClick() {
Michael Kolbd6954f32013-03-08 20:43:01 -08002047 if (mPaused || mUI.collapseCameraControls()
Michael Kolb8872c232013-01-29 10:33:22 -08002048 || (mCameraState == SWITCHING_CAMERA)
2049 || (mCameraState == PREVIEW_STOPPED)) return;
2050
2051 // Do not take the picture if there is not enough storage.
Angus Kong2dcc0a92013-09-25 13:00:08 -07002052 if (mActivity.getStorageSpaceBytes() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) {
Michael Kolb8872c232013-01-29 10:33:22 -08002053 Log.i(TAG, "Not enough space or storage not ready. remaining="
Angus Kong2dcc0a92013-09-25 13:00:08 -07002054 + mActivity.getStorageSpaceBytes());
Michael Kolb8872c232013-01-29 10:33:22 -08002055 return;
2056 }
2057 Log.v(TAG, "onShutterButtonClick: mCameraState=" + mCameraState);
2058
Angus Kongb50b5cb2013-08-09 14:55:20 -07002059 if (mSceneMode == CameraUtil.SCENE_MODE_HDR) {
Doris Liu6432cd62013-06-13 17:20:31 -07002060 mUI.hideSwitcher();
2061 mUI.setSwipingEnabled(false);
Doris Liu9cdfe002013-04-16 09:50:56 -07002062 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302063
2064 //Need to disable focus for ZSL mode
2065 if(mSnapshotMode == CameraInfo.CAMERA_SUPPORT_MODE_ZSL) {
2066 mFocusManager.setZslEnable(true);
2067 } else {
2068 mFocusManager.setZslEnable(false);
2069 }
2070
Michael Kolb8872c232013-01-29 10:33:22 -08002071 // If the user wants to do a snapshot while the previous one is still
2072 // in progress, remember the fact and do it after we finish the previous
2073 // one and re-start the preview. Snapshot in progress also includes the
2074 // state that autofocus is focusing and a picture will be taken when
2075 // focus callback arrives.
2076 if ((mFocusManager.isFocusingSnapOnFinish() || mCameraState == SNAPSHOT_IN_PROGRESS)
2077 && !mIsImageCaptureIntent) {
2078 mSnapshotOnIdle = true;
2079 return;
2080 }
2081
2082 String timer = mPreferences.getString(
2083 CameraSettings.KEY_TIMER,
2084 mActivity.getString(R.string.pref_camera_timer_default));
2085 boolean playSound = mPreferences.getString(CameraSettings.KEY_TIMER_SOUND_EFFECTS,
2086 mActivity.getString(R.string.pref_camera_timer_sound_default))
2087 .equals(mActivity.getString(R.string.setting_on_value));
2088
2089 int seconds = Integer.parseInt(timer);
2090 // When shutter button is pressed, check whether the previous countdown is
2091 // finished. If not, cancel the previous countdown and start a new one.
Michael Kolbd6954f32013-03-08 20:43:01 -08002092 if (mUI.isCountingDown()) {
2093 mUI.cancelCountDown();
2094 }
2095 if (seconds > 0) {
Kerong Sui755b4b72014-04-28 14:51:19 +08002096 String zsl = mPreferences.getString(CameraSettings.KEY_ZSL,
Likai Ding4b5db0d2014-05-28 14:36:23 +08002097 mActivity.getString(R.string.pref_camera_zsl_default));
2098 mUI.overrideSettings(CameraSettings.KEY_ZSL, zsl);
Michael Kolbd6954f32013-03-08 20:43:01 -08002099 mUI.startCountDown(seconds, playSound);
Michael Kolb8872c232013-01-29 10:33:22 -08002100 } else {
Dan Aminzade92ae10e2013-08-13 14:44:25 -07002101 mSnapshotOnIdle = false;
2102 mFocusManager.doSnap();
Michael Kolb8872c232013-01-29 10:33:22 -08002103 }
2104 }
2105
2106 @Override
Alok Kediyaf5b11812013-11-07 13:53:09 +05302107 public void onShutterButtonLongClick() {
Vijay kumar Tumatia1812372014-05-23 15:39:08 +05302108 // Do not take the picture if there is not enough storage.
2109 if (mActivity.getStorageSpaceBytes() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) {
2110 Log.i(TAG, "Not enough space or storage not ready. remaining="
2111 + mActivity.getStorageSpaceBytes());
2112 return;
2113 }
2114
Vijay kumar Tumaticb2ad042013-11-25 16:48:37 +05302115 if ((null != mCameraDevice) && ((mCameraState == IDLE) || (mCameraState == FOCUSING))) {
Fei Zhang28bcccd2014-03-27 13:55:24 +08002116 //Add on/off Menu for longshot
2117 String longshot_enable = mPreferences.getString(
2118 CameraSettings.KEY_LONGSHOT,
2119 mActivity.getString(R.string.pref_camera_longshot_default));
2120
2121 Log.d(TAG, "longshot_enable = " + longshot_enable);
2122 if (longshot_enable.equals("on")) {
2123 boolean enable = SystemProperties.getBoolean(PERSIST_LONG_SAVE, false);
Alok Kediyaf5b11812013-11-07 13:53:09 +05302124 mLongshotSave = enable;
Fei Zhang3d391b52014-06-04 14:51:41 +08002125
2126 //check whether current memory is enough for longshot.
2127 if(isLongshotNeedCancel()) {
2128 return;
2129 }
2130 mLongshotActive = true;
Alok Kediyaf5b11812013-11-07 13:53:09 +05302131 mCameraDevice.setLongshot(true);
2132 setCameraState(PhotoController.LONGSHOT);
2133 mFocusManager.doSnap();
2134 }
2135 }
2136 }
2137
2138 @Override
Michael Kolb8872c232013-01-29 10:33:22 -08002139 public void installIntentFilter() {
Sascha Haeberling4de78802013-10-06 18:07:07 -07002140 // Do nothing.
Michael Kolb8872c232013-01-29 10:33:22 -08002141 }
2142
2143 @Override
2144 public boolean updateStorageHintOnResume() {
2145 return mFirstTimeInitialized;
2146 }
2147
2148 @Override
Michael Kolb8872c232013-01-29 10:33:22 -08002149 public void onResumeBeforeSuper() {
2150 mPaused = false;
2151 }
2152
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302153 private void openCamera() {
Angus Kong4f795b82013-09-16 14:25:35 -07002154 // We need to check whether the activity is paused before long
2155 // operations to ensure that onPause() can be done ASAP.
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302156 if (mPaused) {
2157 return;
2158 }
Andy Huibersdf2b0812013-11-19 15:10:04 -08002159 Log.v(TAG, "Open camera device.");
Angus Kong4f795b82013-09-16 14:25:35 -07002160 mCameraDevice = CameraUtil.openCamera(
2161 mActivity, mCameraId, mHandler,
2162 mActivity.getCameraOpenErrorCallback());
2163 if (mCameraDevice == null) {
2164 Log.e(TAG, "Failed to open camera:" + mCameraId);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302165 mHandler.sendEmptyMessage(OPEN_CAMERA_FAIL);
2166 return;
Angus Kongdcccc512013-08-08 17:06:03 -07002167 }
Angus Kong4f795b82013-09-16 14:25:35 -07002168 mParameters = mCameraDevice.getParameters();
Angus Kong4f795b82013-09-16 14:25:35 -07002169 mCameraPreviewParamsReady = true;
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302170 mInitialParams = mParameters;
2171 if (mFocusManager == null) initializeFocusManager();
2172 initializeCapabilities();
2173 mHandler.sendEmptyMessageDelayed(CAMERA_OPEN_DONE,100);
2174 return;
Angus Kongdcccc512013-08-08 17:06:03 -07002175 }
2176
Michael Kolb8872c232013-01-29 10:33:22 -08002177 @Override
2178 public void onResumeAfterSuper() {
Andy Huibersdf2b0812013-11-19 15:10:04 -08002179 // Add delay on resume from lock screen only, in order to to speed up
2180 // the onResume --> onPause --> onResume cycle from lock screen.
2181 // Don't do always because letting go of thread can cause delay.
2182 String action = mActivity.getIntent().getAction();
2183 if (MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA.equals(action)
2184 || MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE.equals(action)) {
2185 Log.v(TAG, "On resume, from lock screen.");
2186 // Note: onPauseAfterSuper() will delete this runnable, so we will
2187 // at most have 1 copy queued up.
2188 mHandler.postDelayed(new Runnable() {
2189 public void run() {
2190 onResumeTasks();
2191 }
2192 }, ON_RESUME_TASKS_DELAY_MSEC);
2193 } else {
2194 Log.v(TAG, "On resume.");
2195 onResumeTasks();
2196 }
Santhosh Kumar H Eb2da1c12014-01-21 19:21:42 +05302197 mHandler.post(new Runnable(){
2198 @Override
2199 public void run(){
2200 mActivity.updateStorageSpaceAndHint();
2201 }
2202 });
Andy Huibersdf2b0812013-11-19 15:10:04 -08002203 }
2204
2205 private void onResumeTasks() {
2206 Log.v(TAG, "Executing onResumeTasks.");
Michael Kolb8872c232013-01-29 10:33:22 -08002207 if (mOpenCameraFail || mCameraDisabled) return;
2208
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302209 if (mOpenCameraThread == null) {
2210 mOpenCameraThread = new OpenCameraThread();
2211 mOpenCameraThread.start();
2212 }
2213
Michael Kolb8872c232013-01-29 10:33:22 -08002214 mJpegPictureCallbackTime = 0;
2215 mZoomValue = 0;
Michael Kolb8872c232013-01-29 10:33:22 -08002216
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302217 if (mSkinToneSeekBar != true)
2218 {
2219 Log.v(TAG, "Send tone bar: mSkinToneSeekBar = " + mSkinToneSeekBar);
2220 mHandler.sendEmptyMessage(SET_SKIN_TONE_FACTOR);
2221 }
Michael Kolb8872c232013-01-29 10:33:22 -08002222 // If first time initialization is not finished, put it in the
2223 // message queue.
2224 if (!mFirstTimeInitialized) {
2225 mHandler.sendEmptyMessage(FIRST_TIME_INIT);
2226 } else {
2227 initializeSecondTime();
2228 }
Doris Liu59390062013-10-10 17:20:56 -07002229 mUI.initDisplayChangeListener();
Michael Kolb8872c232013-01-29 10:33:22 -08002230 keepScreenOnAwhile();
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302231 mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup,
2232 mPreferences);
Michael Kolb8872c232013-01-29 10:33:22 -08002233
Bobby Georgescu0a7dd572013-03-12 22:45:17 -07002234 UsageStatistics.onContentViewChanged(
2235 UsageStatistics.COMPONENT_CAMERA, "PhotoModule");
Angus Kong0d00a892013-03-26 11:40:40 -07002236
2237 Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
2238 if (gsensor != null) {
2239 mSensorManager.registerListener(this, gsensor, SensorManager.SENSOR_DELAY_NORMAL);
2240 }
2241
2242 Sensor msensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
2243 if (msensor != null) {
2244 mSensorManager.registerListener(this, msensor, SensorManager.SENSOR_DELAY_NORMAL);
2245 }
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302246
2247 mOnResumeTime = SystemClock.uptimeMillis();
2248 checkDisplayRotation();
Michael Kolb8872c232013-01-29 10:33:22 -08002249 }
2250
Michael Kolb8872c232013-01-29 10:33:22 -08002251 @Override
2252 public void onPauseBeforeSuper() {
2253 mPaused = true;
Angus Kong0d00a892013-03-26 11:40:40 -07002254 Sensor gsensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
2255 if (gsensor != null) {
2256 mSensorManager.unregisterListener(this, gsensor);
2257 }
2258
2259 Sensor msensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
2260 if (msensor != null) {
2261 mSensorManager.unregisterListener(this, msensor);
2262 }
Gaoxiang Chend29d0d62014-04-16 15:15:05 +08002263
2264 Log.d(TAG, "remove idle handleer in onPause");
2265 removeIdleHandler();
Michael Kolb8872c232013-01-29 10:33:22 -08002266 }
2267
2268 @Override
2269 public void onPauseAfterSuper() {
Doris Liu3a45c332013-10-15 19:10:28 -07002270 Log.v(TAG, "On pause.");
2271 mUI.showPreviewCover();
Andy Huibersdf2b0812013-11-19 15:10:04 -08002272
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302273 try {
2274 if (mOpenCameraThread != null) {
2275 mOpenCameraThread.join();
2276 }
2277 } catch (InterruptedException ex) {
2278 // ignore
2279 }
2280 mOpenCameraThread = null;
Michael Kolb8872c232013-01-29 10:33:22 -08002281 // Reset the focus first. Camera CTS does not guarantee that
2282 // cancelAutoFocus is allowed after preview stops.
2283 if (mCameraDevice != null && mCameraState != PREVIEW_STOPPED) {
2284 mCameraDevice.cancelAutoFocus();
2285 }
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05302286 resetManual3ASettings();
Erin Dahlgrenb09b53e2013-11-06 11:57:51 -08002287 // If the camera has not been opened asynchronously yet,
2288 // and startPreview hasn't been called, then this is a no-op.
2289 // (e.g. onResume -> onPause -> onResume).
Michael Kolb8872c232013-01-29 10:33:22 -08002290 stopPreview();
Michael Kolb8872c232013-01-29 10:33:22 -08002291
Angus Kongce5480e2013-01-29 17:43:48 -08002292 mNamedImages = null;
Michael Kolb8872c232013-01-29 10:33:22 -08002293
2294 if (mLocationManager != null) mLocationManager.recordLocation(false);
2295
2296 // If we are in an image capture intent and has taken
2297 // a picture, we just clear it in onPause.
2298 mJpegImageData = null;
2299
Angus Kongdcccc512013-08-08 17:06:03 -07002300 // Remove the messages and runnables in the queue.
2301 mHandler.removeCallbacksAndMessages(null);
Michael Kolb8872c232013-01-29 10:33:22 -08002302
Michael Kolbd6954f32013-03-08 20:43:01 -08002303 closeCamera();
2304
2305 resetScreenOn();
2306 mUI.onPause();
2307
Michael Kolb8872c232013-01-29 10:33:22 -08002308 mPendingSwitchCameraId = -1;
2309 if (mFocusManager != null) mFocusManager.removeMessages();
Angus Kong86d36312013-01-31 18:22:44 -08002310 MediaSaveService s = mActivity.getMediaSaveService();
2311 if (s != null) {
2312 s.setListener(null);
2313 }
Doris Liu59390062013-10-10 17:20:56 -07002314 mUI.removeDisplayChangeListener();
Michael Kolb8872c232013-01-29 10:33:22 -08002315 }
2316
Michael Kolb8872c232013-01-29 10:33:22 -08002317 /**
2318 * The focus manager is the first UI related element to get initialized,
2319 * and it requires the RenderOverlay, so initialize it here
2320 */
2321 private void initializeFocusManager() {
2322 // Create FocusManager object. startPreview needs it.
Michael Kolb8872c232013-01-29 10:33:22 -08002323 // if mFocusManager not null, reuse it
2324 // otherwise create a new instance
2325 if (mFocusManager != null) {
2326 mFocusManager.removeMessages();
2327 } else {
2328 CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
Doris Liu29da2db2013-08-28 14:28:45 -07002329 mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
Michael Kolb8872c232013-01-29 10:33:22 -08002330 String[] defaultFocusModes = mActivity.getResources().getStringArray(
2331 R.array.pref_camera_focusmode_default_array);
Santhosh Kumar H E622e3cc2014-12-03 15:33:56 +05302332 synchronized (this){
2333 if (mFocusManager == null) {
2334 mFocusManager = new FocusOverlayManager(mPreferences, defaultFocusModes,
2335 mInitialParams, this, mMirror,
2336 mActivity.getMainLooper(), mUI);
2337 }
2338 }
Michael Kolb8872c232013-01-29 10:33:22 -08002339 }
Sai Kumar Sanagavarapue354e1e2014-10-30 20:21:14 +05302340 }
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302341
Sai Kumar Sanagavarapue354e1e2014-10-30 20:21:14 +05302342 private void updateFocusManager(PhotoUI mUI) {
2343 // Idea here is to let focus manager create in camera open thread
2344 // (in initializeFocusManager) even if photoUI is null by that time so
2345 // as to not block start preview process. Once UI creation is done,
2346 // we will update focus manager with proper UI.
2347 if (mFocusManager != null && mUI != null) {
2348 mFocusManager.setPhotoUI(mUI);
2349
2350 View root = mUI.getRootView();
2351 // These depend on camera parameters.
2352 int width = root.getWidth();
2353 int height = root.getHeight();
2354 mFocusManager.setPreviewSize(width, height);
2355 }
Michael Kolb8872c232013-01-29 10:33:22 -08002356 }
2357
Michael Kolb8872c232013-01-29 10:33:22 -08002358 @Override
2359 public void onConfigurationChanged(Configuration newConfig) {
2360 Log.v(TAG, "onConfigurationChanged");
2361 setDisplayOrientation();
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +05302362 resizeForPreviewAspectRatio();
Michael Kolb8872c232013-01-29 10:33:22 -08002363 }
2364
2365 @Override
Doris Liu6432cd62013-06-13 17:20:31 -07002366 public void updateCameraOrientation() {
Angus Kongb50b5cb2013-08-09 14:55:20 -07002367 if (mDisplayRotation != CameraUtil.getDisplayRotation(mActivity)) {
Doris Liu6432cd62013-06-13 17:20:31 -07002368 setDisplayOrientation();
2369 }
2370 }
2371
2372 @Override
Michael Kolb8872c232013-01-29 10:33:22 -08002373 public void onActivityResult(
2374 int requestCode, int resultCode, Intent data) {
2375 switch (requestCode) {
2376 case REQUEST_CROP: {
2377 Intent intent = new Intent();
2378 if (data != null) {
2379 Bundle extras = data.getExtras();
2380 if (extras != null) {
2381 intent.putExtras(extras);
2382 }
2383 }
2384 mActivity.setResultEx(resultCode, intent);
2385 mActivity.finish();
2386
2387 File path = mActivity.getFileStreamPath(sTempCropFilename);
2388 path.delete();
2389
2390 break;
2391 }
2392 }
2393 }
2394
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302395 protected CameraManager.CameraProxy getCamera() {
2396 return mCameraDevice;
2397 }
2398
Michael Kolb8872c232013-01-29 10:33:22 -08002399 private boolean canTakePicture() {
Angus Kong2dcc0a92013-09-25 13:00:08 -07002400 return isCameraIdle() && (mActivity.getStorageSpaceBytes() > Storage.LOW_STORAGE_THRESHOLD_BYTES);
Michael Kolb8872c232013-01-29 10:33:22 -08002401 }
2402
2403 @Override
2404 public void autoFocus() {
2405 mFocusStartTime = System.currentTimeMillis();
Angus Kong9ef99252013-07-18 18:04:19 -07002406 mCameraDevice.autoFocus(mHandler, mAutoFocusCallback);
Michael Kolb8872c232013-01-29 10:33:22 -08002407 setCameraState(FOCUSING);
2408 }
2409
2410 @Override
2411 public void cancelAutoFocus() {
Emilian Peev110c9262013-09-02 15:53:22 -07002412 if (null != mCameraDevice ) {
2413 mCameraDevice.cancelAutoFocus();
2414 setCameraState(IDLE);
2415 setCameraParameters(UPDATE_PARAM_PREFERENCE);
2416 }
Michael Kolb8872c232013-01-29 10:33:22 -08002417 }
2418
2419 // Preview area is touched. Handle touch focus.
2420 @Override
2421 public void onSingleTapUp(View view, int x, int y) {
2422 if (mPaused || mCameraDevice == null || !mFirstTimeInitialized
2423 || mCameraState == SNAPSHOT_IN_PROGRESS
2424 || mCameraState == SWITCHING_CAMERA
2425 || mCameraState == PREVIEW_STOPPED) {
2426 return;
2427 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302428 //If Touch AF/AEC is disabled in UI, return
2429 if(this.mTouchAfAecFlag == false) {
2430 return;
2431 }
Michael Kolb8872c232013-01-29 10:33:22 -08002432 // Check if metering area or focus area is supported.
2433 if (!mFocusAreaSupported && !mMeteringAreaSupported) return;
2434 mFocusManager.onSingleTapUp(x, y);
2435 }
2436
2437 @Override
2438 public boolean onBackPressed() {
Michael Kolbd6954f32013-03-08 20:43:01 -08002439 return mUI.onBackPressed();
Michael Kolb8872c232013-01-29 10:33:22 -08002440 }
2441
2442 @Override
2443 public boolean onKeyDown(int keyCode, KeyEvent event) {
2444 switch (keyCode) {
Dan Aminzade92ae10e2013-08-13 14:44:25 -07002445 case KeyEvent.KEYCODE_VOLUME_UP:
2446 case KeyEvent.KEYCODE_VOLUME_DOWN:
2447 case KeyEvent.KEYCODE_FOCUS:
2448 if (/*TODO: mActivity.isInCameraApp() &&*/ mFirstTimeInitialized) {
2449 if (event.getRepeatCount() == 0) {
2450 onShutterButtonFocus(true);
2451 }
2452 return true;
2453 }
2454 return false;
2455 case KeyEvent.KEYCODE_CAMERA:
2456 if (mFirstTimeInitialized && event.getRepeatCount() == 0) {
2457 onShutterButtonClick();
Michael Kolb8872c232013-01-29 10:33:22 -08002458 }
2459 return true;
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302460 case KeyEvent.KEYCODE_DPAD_LEFT:
kaiyiz79f9c902014-08-26 14:28:36 +08002461 if ( (mCameraState != PREVIEW_STOPPED) && (mFocusManager != null) &&
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302462 (mFocusManager.getCurrentFocusState() != mFocusManager.STATE_FOCUSING) &&
2463 (mFocusManager.getCurrentFocusState() != mFocusManager.STATE_FOCUSING_SNAP_ON_FINISH) ) {
2464 if (mbrightness > MINIMUM_BRIGHTNESS) {
2465 mbrightness-=mbrightness_step;
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05302466 synchronized (mCameraDevice) {
2467 /* Set the "luma-adaptation" parameter */
2468 mParameters = mCameraDevice.getParameters();
2469 mParameters.set("luma-adaptation", String.valueOf(mbrightness));
2470 mCameraDevice.setParameters(mParameters);
2471 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302472 }
2473 brightnessProgressBar.setProgress(mbrightness);
Santhosh Kumar H E16557922014-10-16 12:28:39 +05302474 Editor editor = mPreferences.edit();
2475 editor.putInt(CameraSettings.KEY_BRIGHTNESS, mbrightness);
2476 editor.apply();
Likai Ding546ba362014-11-21 01:52:54 +08002477 brightnessProgressBar.setVisibility(View.VISIBLE);
Suman Mukherjee752bc162014-04-28 10:36:56 +05302478 mBrightnessVisible = true;
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302479 }
2480 break;
2481 case KeyEvent.KEYCODE_DPAD_RIGHT:
kaiyiz79f9c902014-08-26 14:28:36 +08002482 if ( (mCameraState != PREVIEW_STOPPED) && (mFocusManager != null) &&
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302483 (mFocusManager.getCurrentFocusState() != mFocusManager.STATE_FOCUSING) &&
2484 (mFocusManager.getCurrentFocusState() != mFocusManager.STATE_FOCUSING_SNAP_ON_FINISH) ) {
2485 if (mbrightness < MAXIMUM_BRIGHTNESS) {
2486 mbrightness+=mbrightness_step;
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05302487 synchronized (mCameraDevice) {
2488 /* Set the "luma-adaptation" parameter */
2489 mParameters = mCameraDevice.getParameters();
2490 mParameters.set("luma-adaptation", String.valueOf(mbrightness));
2491 mCameraDevice.setParameters(mParameters);
2492 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302493 }
2494 brightnessProgressBar.setProgress(mbrightness);
Santhosh Kumar H E16557922014-10-16 12:28:39 +05302495 Editor editor = mPreferences.edit();
2496 editor.putInt(CameraSettings.KEY_BRIGHTNESS, mbrightness);
2497 editor.apply();
Likai Ding546ba362014-11-21 01:52:54 +08002498 brightnessProgressBar.setVisibility(View.VISIBLE);
Suman Mukherjee752bc162014-04-28 10:36:56 +05302499 mBrightnessVisible = true;
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302500 }
2501 break;
Dan Aminzade92ae10e2013-08-13 14:44:25 -07002502 case KeyEvent.KEYCODE_DPAD_CENTER:
2503 // If we get a dpad center event without any focused view, move
2504 // the focus to the shutter button and press it.
2505 if (mFirstTimeInitialized && event.getRepeatCount() == 0) {
2506 // Start auto-focus immediately to reduce shutter lag. After
2507 // the shutter button gets the focus, onShutterButtonFocus()
2508 // will be called again but it is fine.
2509 onShutterButtonFocus(true);
2510 mUI.pressShutterButton();
2511 }
2512 return true;
Michael Kolb8872c232013-01-29 10:33:22 -08002513 }
2514 return false;
2515 }
2516
2517 @Override
2518 public boolean onKeyUp(int keyCode, KeyEvent event) {
2519 switch (keyCode) {
Dan Aminzade92ae10e2013-08-13 14:44:25 -07002520 case KeyEvent.KEYCODE_VOLUME_UP:
2521 case KeyEvent.KEYCODE_VOLUME_DOWN:
2522 if (/*mActivity.isInCameraApp() && */ mFirstTimeInitialized) {
2523 onShutterButtonClick();
2524 return true;
2525 }
2526 return false;
2527 case KeyEvent.KEYCODE_FOCUS:
2528 if (mFirstTimeInitialized) {
2529 onShutterButtonFocus(false);
2530 }
Michael Kolb8872c232013-01-29 10:33:22 -08002531 return true;
Michael Kolb8872c232013-01-29 10:33:22 -08002532 }
2533 return false;
2534 }
2535
Michael Kolb8872c232013-01-29 10:33:22 -08002536 private void closeCamera() {
Andy Huibersdf2b0812013-11-19 15:10:04 -08002537 Log.v(TAG, "Close camera device.");
Michael Kolb8872c232013-01-29 10:33:22 -08002538 if (mCameraDevice != null) {
2539 mCameraDevice.setZoomChangeListener(null);
Sascha Haeberling638e6f02013-09-18 14:28:51 -07002540 mCameraDevice.setFaceDetectionCallback(null, null);
Michael Kolb8872c232013-01-29 10:33:22 -08002541 mCameraDevice.setErrorCallback(null);
Ruben Brunk59147832013-11-05 15:53:28 -08002542
2543 if (mActivity.isSecureCamera() && !CameraActivity.isFirstStartAfterScreenOn()) {
2544 // Blocks until camera is actually released.
2545 CameraHolder.instance().strongRelease();
2546 } else {
2547 CameraHolder.instance().release();
2548 }
2549
Michael Kolb8872c232013-01-29 10:33:22 -08002550 mFaceDetectionStarted = false;
2551 mCameraDevice = null;
2552 setCameraState(PREVIEW_STOPPED);
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302553 if (mFocusManager != null) {
2554 mFocusManager.onCameraReleased();
2555 }
Michael Kolb8872c232013-01-29 10:33:22 -08002556 }
2557 }
2558
2559 private void setDisplayOrientation() {
Angus Kongb50b5cb2013-08-09 14:55:20 -07002560 mDisplayRotation = CameraUtil.getDisplayRotation(mActivity);
2561 mDisplayOrientation = CameraUtil.getDisplayOrientation(mDisplayRotation, mCameraId);
Doris Liu6432cd62013-06-13 17:20:31 -07002562 mCameraDisplayOrientation = mDisplayOrientation;
Sai Kumar Sanagavarapue354e1e2014-10-30 20:21:14 +05302563 // This will be called again in checkDisplayRotation(), so there
2564 // should not be any problem even if mUI is null.
2565 if (mUI != null) {
2566 mUI.setDisplayOrientation(mDisplayOrientation);
2567 }
Michael Kolb8872c232013-01-29 10:33:22 -08002568 if (mFocusManager != null) {
2569 mFocusManager.setDisplayOrientation(mDisplayOrientation);
2570 }
Doris Liu6432cd62013-06-13 17:20:31 -07002571 // Change the camera display orientation
2572 if (mCameraDevice != null) {
2573 mCameraDevice.setDisplayOrientation(mCameraDisplayOrientation);
2574 }
Michael Kolb8872c232013-01-29 10:33:22 -08002575 }
2576
Sascha Haeberlingddef7792013-08-13 14:41:10 -07002577 /** Only called by UI thread. */
Michael Kolb8872c232013-01-29 10:33:22 -08002578 private void setupPreview() {
2579 mFocusManager.resetTouchFocus();
2580 startPreview();
Michael Kolb8872c232013-01-29 10:33:22 -08002581 }
2582
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302583 /** This can run on a background thread, so don't do UI updates here. Post any
2584 view updates to MainHandler or do it on onPreviewStarted() . */
Michael Kolb8872c232013-01-29 10:33:22 -08002585 private void startPreview() {
Santhosh Kumar H E08c09042015-04-02 17:41:50 +05302586 if (mPaused || mCameraDevice == null || mParameters == null) {
Angus Kongdcccc512013-08-08 17:06:03 -07002587 return;
2588 }
Michael Kolb8872c232013-01-29 10:33:22 -08002589
Likai Ding40d36372014-11-20 08:00:28 +08002590 Log.v(TAG, "startPreview");
Byunghun Jeon6ee7e412014-08-29 17:56:11 -07002591
Likai Ding40d36372014-11-20 08:00:28 +08002592 SurfaceTexture st = null;
2593 if (mUI != null) {
2594 st = mUI.getSurfaceTexture();
2595 }
2596 // Surfacetexture could be null here, but its still valid and safe to set null
2597 // surface before startpreview. This will help in basic preview setup and
2598 // surface creation in parallel. Once valid surface is ready in onPreviewUIReady()
2599 // we set the surface to camera to actually start preview.
2600 mCameraDevice.setPreviewTexture(st);
Erin Dahlgrencc707022013-11-12 09:39:08 -08002601
Michael Kolb8872c232013-01-29 10:33:22 -08002602 if (!mCameraPreviewParamsReady) {
Likai Ding40d36372014-11-20 08:00:28 +08002603 Log.w(TAG, "startPreview: parameters for preview is not ready.");
Michael Kolb8872c232013-01-29 10:33:22 -08002604 return;
2605 }
2606 mCameraDevice.setErrorCallback(mErrorCallback);
Erin Dahlgrencc707022013-11-12 09:39:08 -08002607 // ICS camera frameworks has a bug. Face detection state is not cleared 1589
Michael Kolb8872c232013-01-29 10:33:22 -08002608 // after taking a picture. Stop the preview to work around it. The bug
2609 // was fixed in JB.
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302610 if (mCameraState != PREVIEW_STOPPED && mCameraState != INIT) {
Erin Dahlgrencc707022013-11-12 09:39:08 -08002611 stopPreview();
2612 }
Michael Kolb8872c232013-01-29 10:33:22 -08002613
Santhosh Kumar H E622e3cc2014-12-03 15:33:56 +05302614 if (mFocusManager == null) initializeFocusManager();
2615
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302616 setCameraParameters(UPDATE_PARAM_ALL);
2617
2618 mCameraDevice.startPreview();
2619 mHandler.sendEmptyMessage(ON_PREVIEW_STARTED);
2620
Michael Kolb8872c232013-01-29 10:33:22 -08002621 setDisplayOrientation();
2622
2623 if (!mSnapshotOnIdle) {
2624 // If the focus mode is continuous autofocus, call cancelAutoFocus to
2625 // resume it because it may have been paused by autoFocus call.
Angus Kongb50b5cb2013-08-09 14:55:20 -07002626 if (CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusManager.getFocusMode())) {
Michael Kolb8872c232013-01-29 10:33:22 -08002627 mCameraDevice.cancelAutoFocus();
2628 }
2629 mFocusManager.setAeAwbLock(false); // Unlock AE and AWB.
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302630 } else {
Michael Kolb8872c232013-01-29 10:33:22 -08002631 mHandler.post(mDoSnapRunnable);
2632 }
2633 }
2634
Michael Kolbd6954f32013-03-08 20:43:01 -08002635 @Override
2636 public void stopPreview() {
Michael Kolb8872c232013-01-29 10:33:22 -08002637 if (mCameraDevice != null && mCameraState != PREVIEW_STOPPED) {
2638 Log.v(TAG, "stopPreview");
2639 mCameraDevice.stopPreview();
Michael Kolb8872c232013-01-29 10:33:22 -08002640 }
2641 setCameraState(PREVIEW_STOPPED);
2642 if (mFocusManager != null) mFocusManager.onPreviewStopped();
2643 }
2644
2645 @SuppressWarnings("deprecation")
2646 private void updateCameraParametersInitialize() {
2647 // Reset preview frame rate to the maximum because it may be lowered by
2648 // video camera application.
ztenghui16a35202013-09-23 11:35:36 -07002649 int[] fpsRange = CameraUtil.getPhotoPreviewFpsRange(mParameters);
2650 if (fpsRange != null && fpsRange.length > 0) {
Doris Liu6432cd62013-06-13 17:20:31 -07002651 mParameters.setPreviewFpsRange(
2652 fpsRange[Parameters.PREVIEW_FPS_MIN_INDEX],
2653 fpsRange[Parameters.PREVIEW_FPS_MAX_INDEX]);
Michael Kolb8872c232013-01-29 10:33:22 -08002654 }
2655
Angus Kongb50b5cb2013-08-09 14:55:20 -07002656 mParameters.set(CameraUtil.RECORDING_HINT, CameraUtil.FALSE);
Michael Kolb8872c232013-01-29 10:33:22 -08002657
2658 // Disable video stabilization. Convenience methods not available in API
2659 // level <= 14
2660 String vstabSupported = mParameters.get("video-stabilization-supported");
2661 if ("true".equals(vstabSupported)) {
2662 mParameters.set("video-stabilization", "false");
2663 }
2664 }
2665
2666 private void updateCameraParametersZoom() {
2667 // Set zoom.
2668 if (mParameters.isZoomSupported()) {
Alok Kediya5213f272013-10-02 17:51:19 +05302669 Parameters p = mCameraDevice.getParameters();
2670 mZoomValue = p.getZoom();
Michael Kolb8872c232013-01-29 10:33:22 -08002671 mParameters.setZoom(mZoomValue);
2672 }
2673 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302674 private boolean needRestart() {
2675 mRestartPreview = false;
2676 String zsl = mPreferences.getString(CameraSettings.KEY_ZSL,
2677 mActivity.getString(R.string.pref_camera_zsl_default));
2678 if(zsl.equals("on") && mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_ZSL
2679 && mCameraState != PREVIEW_STOPPED) {
2680 //Switch on ZSL Camera mode
2681 Log.v(TAG, "Switching to ZSL Camera Mode. Restart Preview");
2682 mRestartPreview = true;
2683 return mRestartPreview;
2684 }
2685 if(zsl.equals("off") && mSnapshotMode != CameraInfo.CAMERA_SUPPORT_MODE_NONZSL
2686 && mCameraState != PREVIEW_STOPPED) {
2687 //Switch on Normal Camera mode
2688 Log.v(TAG, "Switching to Normal Camera Mode. Restart Preview");
2689 mRestartPreview = true;
2690 return mRestartPreview;
2691 }
2692 return mRestartPreview;
2693 }
2694
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002695 private void qcomUpdateAdvancedFeatures(String ubiFocus,
2696 String chromaFlash,
Emilian Peevde5dd902014-03-17 16:34:20 -07002697 String reFocus,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302698 String optiZoom,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302699 String fssr,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302700 String truePortrait,
2701 String multiTouchFocus) {
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002702 if (CameraUtil.isSupported(ubiFocus,
2703 CameraSettings.getSupportedAFBracketingModes(mParameters))) {
2704 mParameters.set(CameraSettings.KEY_QC_AF_BRACKETING, ubiFocus);
2705 }
2706 if (CameraUtil.isSupported(chromaFlash,
2707 CameraSettings.getSupportedChromaFlashModes(mParameters))) {
2708 mParameters.set(CameraSettings.KEY_QC_CHROMA_FLASH, chromaFlash);
2709 }
2710 if (CameraUtil.isSupported(optiZoom,
2711 CameraSettings.getSupportedOptiZoomModes(mParameters))) {
2712 mParameters.set(CameraSettings.KEY_QC_OPTI_ZOOM, optiZoom);
2713 }
Emilian Peevde5dd902014-03-17 16:34:20 -07002714 if (CameraUtil.isSupported(reFocus,
2715 CameraSettings.getSupportedRefocusModes(mParameters))) {
2716 mParameters.set(CameraSettings.KEY_QC_RE_FOCUS, reFocus);
2717 }
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302718 if (CameraUtil.isSupported(fssr,
2719 CameraSettings.getSupportedFSSRModes(mParameters))) {
2720 mParameters.set(CameraSettings.KEY_QC_FSSR, fssr);
2721 }
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302722 if (CameraUtil.isSupported(truePortrait,
2723 CameraSettings.getSupportedTruePortraitModes(mParameters))) {
2724 mParameters.set(CameraSettings.KEY_QC_TP, truePortrait);
2725 }
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302726 if(CameraUtil.isSupported(multiTouchFocus,
2727 CameraSettings.getSupportedMultiTouchFocusModes(mParameters))) {
2728 mParameters.set(CameraSettings.KEY_QC_MULTI_TOUCH_FOCUS, multiTouchFocus);
2729 }
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002730 }
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05302731
2732 /** This can run on a background thread, so don't do UI updates here.*/
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302733 private void qcomUpdateCameraParametersPreference() {
2734 //qcom Related Parameter update
2735 //Set Brightness.
2736 mParameters.set("luma-adaptation", String.valueOf(mbrightness));
2737
Vijay kumar Tumati8eacbea2014-05-13 19:44:58 +05302738 String longshot_enable = mPreferences.getString(
2739 CameraSettings.KEY_LONGSHOT,
2740 mActivity.getString(R.string.pref_camera_longshot_default));
2741 mParameters.set("long-shot", longshot_enable);
2742
Fei Zhangef0f9742014-04-02 18:05:18 +08002743 if (Parameters.SCENE_MODE_AUTO.equals(mSceneMode) ||
2744 CameraUtil.SCENE_MODE_HDR.equals(mSceneMode)) {
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302745 // Set Touch AF/AEC parameter.
2746 String touchAfAec = mPreferences.getString(
2747 CameraSettings.KEY_TOUCH_AF_AEC,
2748 mActivity.getString(R.string.pref_camera_touchafaec_default));
2749 if (CameraUtil.isSupported(touchAfAec, mParameters.getSupportedTouchAfAec())) {
Alok Kediya5fdf67e2013-10-02 18:00:14 +05302750 mCurrTouchAfAec = touchAfAec;
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302751 mParameters.setTouchAfAec(touchAfAec);
2752 }
2753 } else {
2754 mParameters.setTouchAfAec(mParameters.TOUCH_AF_AEC_OFF);
2755 mFocusManager.resetTouchFocus();
2756 }
2757 try {
2758 if(mParameters.getTouchAfAec().equals(mParameters.TOUCH_AF_AEC_ON))
2759 this.mTouchAfAecFlag = true;
2760 else
2761 this.mTouchAfAecFlag = false;
2762 } catch(Exception e){
2763 Log.e(TAG, "Handled NULL pointer Exception");
2764 }
2765
2766 // Set Picture Format
2767 // Picture Formats specified in UI should be consistent with
2768 // PIXEL_FORMAT_JPEG and PIXEL_FORMAT_RAW constants
2769 String pictureFormat = mPreferences.getString(
2770 CameraSettings.KEY_PICTURE_FORMAT,
2771 mActivity.getString(R.string.pref_camera_picture_format_default));
kaiyize30f4c42014-05-26 11:43:09 +08002772
2773 //Change picture format to JPEG if camera is start from other APK by intent.
2774 if (mIsImageCaptureIntent && !pictureFormat.equals(PIXEL_FORMAT_JPEG)) {
2775 pictureFormat = PIXEL_FORMAT_JPEG;
2776 Editor editor = mPreferences.edit();
2777 editor.putString(CameraSettings.KEY_PICTURE_FORMAT,
2778 mActivity.getString(R.string.pref_camera_picture_format_value_jpeg));
2779 editor.apply();
2780 }
2781 Log.v(TAG, "Picture format value =" + pictureFormat);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302782 mParameters.set(KEY_PICTURE_FORMAT, pictureFormat);
2783
2784 // Set JPEG quality.
2785 String jpegQuality = mPreferences.getString(
2786 CameraSettings.KEY_JPEG_QUALITY,
2787 mActivity.getString(R.string.pref_camera_jpegquality_default));
2788 //mUnsupportedJpegQuality = false;
2789 Size pic_size = mParameters.getPictureSize();
2790 if (pic_size == null) {
2791 Log.e(TAG, "error getPictureSize: size is null");
2792 }
2793 else{
2794 if("100".equals(jpegQuality) && (pic_size.width >= 3200)){
2795 //mUnsupportedJpegQuality = true;
2796 }else {
2797 mParameters.setJpegQuality(JpegEncodingQualityMappings.getQualityNumber(jpegQuality));
2798 }
2799 }
2800
2801 // Set Selectable Zone Af parameter.
2802 String selectableZoneAf = mPreferences.getString(
2803 CameraSettings.KEY_SELECTABLE_ZONE_AF,
2804 mActivity.getString(R.string.pref_camera_selectablezoneaf_default));
2805 List<String> str = mParameters.getSupportedSelectableZoneAf();
2806 if (CameraUtil.isSupported(selectableZoneAf, mParameters.getSupportedSelectableZoneAf())) {
2807 mParameters.setSelectableZoneAf(selectableZoneAf);
2808 }
2809
2810 // Set wavelet denoise mode
2811 if (mParameters.getSupportedDenoiseModes() != null) {
2812 String Denoise = mPreferences.getString( CameraSettings.KEY_DENOISE,
2813 mActivity.getString(R.string.pref_camera_denoise_default));
2814 mParameters.setDenoise(Denoise);
2815 }
2816 // Set Redeye Reduction
2817 String redeyeReduction = mPreferences.getString(
2818 CameraSettings.KEY_REDEYE_REDUCTION,
2819 mActivity.getString(R.string.pref_camera_redeyereduction_default));
2820 if (CameraUtil.isSupported(redeyeReduction,
2821 mParameters.getSupportedRedeyeReductionModes())) {
2822 mParameters.setRedeyeReductionMode(redeyeReduction);
2823 }
2824 // Set ISO parameter
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05302825 if ((mManual3AEnabled & MANUAL_EXPOSURE) == 0) {
2826 String iso = mPreferences.getString(
2827 CameraSettings.KEY_ISO,
2828 mActivity.getString(R.string.pref_camera_iso_default));
2829 if (CameraUtil.isSupported(iso,
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302830 mParameters.getSupportedIsoValues())) {
2831 mParameters.setISOValue(iso);
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05302832 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05302833 }
2834 // Set color effect parameter.
2835 String colorEffect = mPreferences.getString(
2836 CameraSettings.KEY_COLOR_EFFECT,
2837 mActivity.getString(R.string.pref_camera_coloreffect_default));
2838 Log.v(TAG, "Color effect value =" + colorEffect);
2839 if (CameraUtil.isSupported(colorEffect, mParameters.getSupportedColorEffects())) {
2840 mParameters.setColorEffect(colorEffect);
2841 }
2842 //Set Saturation
2843 String saturationStr = mPreferences.getString(
2844 CameraSettings.KEY_SATURATION,
2845 mActivity.getString(R.string.pref_camera_saturation_default));
2846 int saturation = Integer.parseInt(saturationStr);
2847 Log.v(TAG, "Saturation value =" + saturation);
2848 if((0 <= saturation) && (saturation <= mParameters.getMaxSaturation())){
2849 mParameters.setSaturation(saturation);
2850 }
2851 // Set contrast parameter.
2852 String contrastStr = mPreferences.getString(
2853 CameraSettings.KEY_CONTRAST,
2854 mActivity.getString(R.string.pref_camera_contrast_default));
2855 int contrast = Integer.parseInt(contrastStr);
2856 Log.v(TAG, "Contrast value =" +contrast);
2857 if((0 <= contrast) && (contrast <= mParameters.getMaxContrast())){
2858 mParameters.setContrast(contrast);
2859 }
2860 // Set sharpness parameter
2861 String sharpnessStr = mPreferences.getString(
2862 CameraSettings.KEY_SHARPNESS,
2863 mActivity.getString(R.string.pref_camera_sharpness_default));
2864 int sharpness = Integer.parseInt(sharpnessStr) *
2865 (mParameters.getMaxSharpness()/MAX_SHARPNESS_LEVEL);
2866 Log.v(TAG, "Sharpness value =" + sharpness);
2867 if((0 <= sharpness) && (sharpness <= mParameters.getMaxSharpness())){
2868 mParameters.setSharpness(sharpness);
2869 }
Alok Kediya7e531092013-09-28 16:30:15 +05302870 // Set Face Recognition
2871 String faceRC = mPreferences.getString(
2872 CameraSettings.KEY_FACE_RECOGNITION,
2873 mActivity.getString(R.string.pref_camera_facerc_default));
2874 Log.v(TAG, "Face Recognition value = " + faceRC);
2875 if (CameraUtil.isSupported(faceRC,
2876 CameraSettings.getSupportedFaceRecognitionModes(mParameters))) {
2877 mParameters.set(CameraSettings.KEY_QC_FACE_RECOGNITION, faceRC);
2878 }
Alok Kediyac862c8b2013-09-28 16:23:35 +05302879 // Set AE Bracketing
2880 String aeBracketing = mPreferences.getString(
2881 CameraSettings.KEY_AE_BRACKET_HDR,
2882 mActivity.getString(R.string.pref_camera_ae_bracket_hdr_default));
2883 Log.v(TAG, "AE Bracketing value =" + aeBracketing);
2884 if (CameraUtil.isSupported(aeBracketing,
2885 CameraSettings.getSupportedAEBracketingModes(mParameters))) {
2886 mParameters.set(CameraSettings.KEY_QC_AE_BRACKETING, aeBracketing);
2887 }
Ivan Evlogiev73c0fb72014-08-14 11:47:07 +03002888
Dimitar Borisov19656472014-09-24 17:32:06 +03002889 // Set CDS
2890 String cds = mPreferences.getString(
2891 CameraSettings.KEY_CDS_MODE,
2892 mActivity.getString(R.string.pref_camera_cds_default));
2893 if ((mPrevSavedCDS == null) && (cds != null)) {
2894 mPrevSavedCDS = cds;
2895 }
2896 if (CameraUtil.isSupported(cds,
2897 CameraSettings.getSupportedCDSModes(mParameters))) {
2898 mParameters.set(CameraSettings.KEY_QC_CDS_MODE, cds);
2899 }
2900
2901 // Set TNR
2902 String tnr = mPreferences.getString(
2903 CameraSettings.KEY_TNR_MODE,
2904 mActivity.getString(R.string.pref_camera_tnr_default));
2905 if (CameraUtil.isSupported(tnr,
2906 CameraSettings.getSupportedTNRModes(mParameters))) {
2907 if (!tnr.equals(mActivity.getString(R.string.
2908 pref_camera_tnr_value_off))) {
2909 mParameters.set(CameraSettings.KEY_QC_CDS_MODE,
2910 mActivity.getString(R.string.pref_camera_cds_value_off));
2911 mUI.overrideSettings(CameraSettings.KEY_QC_CDS_MODE,
2912 mActivity.getString(R.string.pref_camera_cds_value_off));
2913 if (cds != null) {
2914 mPrevSavedCDS = cds;
2915 }
2916 isTNREnabled = true;
2917 } else if (isTNREnabled) {
2918 mParameters.set(CameraSettings.KEY_QC_CDS_MODE, mPrevSavedCDS);
2919 mUI.overrideSettings(CameraSettings.KEY_QC_CDS_MODE, mPrevSavedCDS);
2920 isTNREnabled = false;
2921 }
2922 mParameters.set(CameraSettings.KEY_QC_TNR_MODE, tnr);
2923 }
2924
Ivan Evlogiev73c0fb72014-08-14 11:47:07 +03002925 // Set hdr mode
2926 String hdrMode = mPreferences.getString(
2927 CameraSettings.KEY_HDR_MODE,
2928 mActivity.getString(R.string.pref_camera_hdr_mode_default));
2929 Log.v(TAG, "HDR Mode value =" + hdrMode);
2930 if (CameraUtil.isSupported(hdrMode,
2931 CameraSettings.getSupportedHDRModes(mParameters))) {
2932 mParameters.set(CameraSettings.KEY_SNAPCAM_HDR_MODE, hdrMode);
2933 }
2934
Ivan Evlogievec449be2014-09-11 13:31:11 +03002935 // Set hdr need 1x
2936 String hdrNeed1x = mPreferences.getString(
2937 CameraSettings.KEY_HDR_NEED_1X,
2938 mActivity.getString(R.string.pref_camera_hdr_need_1x_default));
2939 Log.v(TAG, "HDR need 1x value =" + hdrNeed1x);
2940 if (CameraUtil.isSupported(hdrNeed1x,
2941 CameraSettings.getSupportedHDRNeed1x(mParameters))) {
2942 mParameters.set(CameraSettings.KEY_SNAPCAM_HDR_NEED_1X, hdrNeed1x);
2943 }
2944
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002945 // Set Advanced features.
2946 String advancedFeature = mPreferences.getString(
2947 CameraSettings.KEY_ADVANCED_FEATURES,
2948 mActivity.getString(R.string.pref_camera_advanced_feature_default));
Emilian Peevde5dd902014-03-17 16:34:20 -07002949 Log.e(TAG, " advancedFeature value =" + advancedFeature);
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002950
Emilian Peevde5dd902014-03-17 16:34:20 -07002951 mRefocus = false;
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002952 if(advancedFeature != null) {
2953 String ubiFocusOff = mActivity.getString(R.string.
2954 pref_camera_advanced_feature_value_ubifocus_off);
2955 String chromaFlashOff = mActivity.getString(R.string.
2956 pref_camera_advanced_feature_value_chromaflash_off);
2957 String optiZoomOff = mActivity.getString(R.string.
2958 pref_camera_advanced_feature_value_optizoom_off);
Emilian Peevde5dd902014-03-17 16:34:20 -07002959 String reFocusOff = mActivity.getString(R.string.
2960 pref_camera_advanced_feature_value_refocus_off);
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302961 String fssrOff = mActivity.getString(R.string.
2962 pref_camera_advanced_feature_value_FSSR_off);
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302963 String truePortraitOff = mActivity.getString(R.string.
2964 pref_camera_advanced_feature_value_trueportrait_off);
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302965 String multiTouchFocusOff = mActivity.getString(R.string.
2966 pref_camera_advanced_feature_value_multi_touch_focus_off);
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002967
2968 if (advancedFeature.equals(mActivity.getString(R.string.
2969 pref_camera_advanced_feature_value_ubifocus_on))) {
2970 qcomUpdateAdvancedFeatures(advancedFeature,
2971 chromaFlashOff,
Emilian Peevde5dd902014-03-17 16:34:20 -07002972 reFocusOff,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302973 optiZoomOff,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302974 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302975 truePortraitOff,
2976 multiTouchFocusOff);
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002977 } else if (advancedFeature.equals(mActivity.getString(R.string.
2978 pref_camera_advanced_feature_value_chromaflash_on))) {
2979 qcomUpdateAdvancedFeatures(ubiFocusOff,
2980 advancedFeature,
Emilian Peevde5dd902014-03-17 16:34:20 -07002981 reFocusOff,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302982 optiZoomOff,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302983 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302984 truePortraitOff,
2985 multiTouchFocusOff);
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002986 } else if (advancedFeature.equals(mActivity.getString(R.string.
Emilian Peevde5dd902014-03-17 16:34:20 -07002987 pref_camera_advanced_feature_value_refocus_on))) {
2988 qcomUpdateAdvancedFeatures(ubiFocusOff,
2989 chromaFlashOff,
2990 advancedFeature,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05302991 optiZoomOff,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05302992 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05302993 truePortraitOff,
2994 multiTouchFocusOff);
Emilian Peevde5dd902014-03-17 16:34:20 -07002995 mRefocus = true;
2996 } else if (advancedFeature.equals(mActivity.getString(R.string.
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08002997 pref_camera_advanced_feature_value_optizoom_on))) {
2998 qcomUpdateAdvancedFeatures(ubiFocusOff,
2999 chromaFlashOff,
Emilian Peevde5dd902014-03-17 16:34:20 -07003000 reFocusOff,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05303001 advancedFeature,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05303002 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05303003 truePortraitOff,
3004 multiTouchFocusOff);
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05303005 } else if (advancedFeature.equals(mActivity.getString(R.string.
3006 pref_camera_advanced_feature_value_FSSR_on))) {
3007 qcomUpdateAdvancedFeatures(ubiFocusOff,
3008 chromaFlashOff,
3009 reFocusOff,
3010 optiZoomOff,
3011 advancedFeature,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05303012 truePortraitOff,
3013 multiTouchFocusOff);
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05303014 } else if (advancedFeature.equals(mActivity.getString(R.string.
3015 pref_camera_advanced_feature_value_trueportrait_on))) {
3016 qcomUpdateAdvancedFeatures(ubiFocusOff,
3017 chromaFlashOff,
3018 reFocusOff,
3019 optiZoomOff,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05303020 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05303021 advancedFeature,
3022 multiTouchFocusOff);
3023 } else if (advancedFeature.equals(mActivity.getString(R.string.
3024 pref_camera_advanced_feature_value_multi_touch_focus_on))) {
3025 qcomUpdateAdvancedFeatures(ubiFocusOff,
3026 chromaFlashOff,
3027 reFocusOff,
3028 optiZoomOff,
3029 fssrOff,
3030 truePortraitOff,
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08003031 advancedFeature);
3032 } else {
3033 qcomUpdateAdvancedFeatures(ubiFocusOff,
3034 chromaFlashOff,
Emilian Peevde5dd902014-03-17 16:34:20 -07003035 reFocusOff,
Sai Kumar Sanagavarapu5b88d562014-06-04 13:53:37 +05303036 optiZoomOff,
Santhosh Kumar Thimmanna Bhattar22795c22014-10-15 15:14:45 +05303037 fssrOff,
Santhosh Kumar Thimmanna Bhattare6efb5b2014-10-15 15:31:06 +05303038 truePortraitOff,
3039 multiTouchFocusOff);
Ajit Singh Solanki2e1e3f92013-11-07 01:56:47 -08003040 }
3041 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303042 // Set auto exposure parameter.
3043 String autoExposure = mPreferences.getString(
3044 CameraSettings.KEY_AUTOEXPOSURE,
3045 mActivity.getString(R.string.pref_camera_autoexposure_default));
3046 Log.v(TAG, "autoExposure value =" + autoExposure);
3047 if (CameraUtil.isSupported(autoExposure, mParameters.getSupportedAutoexposure())) {
3048 mParameters.setAutoExposure(autoExposure);
3049 }
3050
3051 // Set anti banding parameter.
3052 String antiBanding = mPreferences.getString(
3053 CameraSettings.KEY_ANTIBANDING,
3054 mActivity.getString(R.string.pref_camera_antibanding_default));
3055 Log.v(TAG, "antiBanding value =" + antiBanding);
3056 if (CameraUtil.isSupported(antiBanding, mParameters.getSupportedAntibanding())) {
3057 mParameters.setAntibanding(antiBanding);
3058 }
3059
3060 String zsl = mPreferences.getString(CameraSettings.KEY_ZSL,
3061 mActivity.getString(R.string.pref_camera_zsl_default));
Abhishek Pantcb4748b2013-12-04 15:51:48 +05303062 String auto_hdr = mPreferences.getString(CameraSettings.KEY_AUTO_HDR,
3063 mActivity.getString(R.string.pref_camera_hdr_default));
3064 if (CameraUtil.isAutoHDRSupported(mParameters)) {
3065 mParameters.setAutoHDRMode(auto_hdr);
3066 if (auto_hdr.equals("enable")) {
3067 mActivity.runOnUiThread(new Runnable() {
3068 public void run() {
3069 if (mDrawAutoHDR != null) {
3070 mDrawAutoHDR.setVisibility(View.VISIBLE);
3071 }
3072 }
3073 });
3074 mParameters.setSceneMode("asd");
3075 mCameraDevice.setMetadataCb(mMetaDataCallback);
3076 }
3077 else {
3078 mAutoHdrEnable = false;
3079 mActivity.runOnUiThread( new Runnable() {
3080 public void run () {
3081 if (mDrawAutoHDR != null) {
3082 mDrawAutoHDR.setVisibility (View.INVISIBLE);
3083 }
3084 }
3085 });
3086 }
3087 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303088 mParameters.setZSLMode(zsl);
3089 if(zsl.equals("on")) {
3090 //Switch on ZSL Camera mode
3091 mSnapshotMode = CameraInfo.CAMERA_SUPPORT_MODE_ZSL;
3092 mParameters.setCameraMode(1);
3093 mFocusManager.setZslEnable(true);
3094
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303095 //Raw picture format is not supported under ZSL mode
Vijay kumar Tumati9e10f592014-05-06 15:34:24 +05303096 mParameters.set(KEY_PICTURE_FORMAT, PIXEL_FORMAT_JPEG);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303097
Emilian Peev3091b022013-08-19 12:32:23 +03003098 //Try to set CAF for ZSL
3099 if(CameraUtil.isSupported(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE,
3100 mParameters.getSupportedFocusModes()) && !mFocusManager.isTouch()) {
3101 mFocusManager.overrideFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
3102 mParameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
3103 } else if (mFocusManager.isTouch()) {
3104 mFocusManager.overrideFocusMode(null);
3105 mParameters.setFocusMode(mFocusManager.getFocusMode());
3106 } else {
3107 // If not supported use the current mode
3108 mFocusManager.overrideFocusMode(mFocusManager.getFocusMode());
3109 }
3110
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303111 if(!pictureFormat.equals(PIXEL_FORMAT_JPEG)) {
3112 mActivity.runOnUiThread(new Runnable() {
3113 public void run() {
3114 Toast.makeText(mActivity, R.string.error_app_unsupported_raw,
3115 Toast.LENGTH_SHORT).show();
3116 }
3117 });
3118 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303119 } else if(zsl.equals("off")) {
3120 mSnapshotMode = CameraInfo.CAMERA_SUPPORT_MODE_NONZSL;
3121 mParameters.setCameraMode(0);
3122 mFocusManager.setZslEnable(false);
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05303123 if ((mManual3AEnabled & MANUAL_FOCUS) == 0) {
3124 mFocusManager.overrideFocusMode(null);
3125 mParameters.setFocusMode(mFocusManager.getFocusMode());
3126 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303127 }
3128 // Set face detetction parameter.
3129 String faceDetection = mPreferences.getString(
3130 CameraSettings.KEY_FACE_DETECTION,
3131 mActivity.getString(R.string.pref_camera_facedetection_default));
3132
3133 if (CameraUtil.isSupported(faceDetection, mParameters.getSupportedFaceDetectionModes())) {
3134 mParameters.setFaceDetectionMode(faceDetection);
3135 if(faceDetection.equals("on") && mFaceDetectionEnabled == false) {
3136 mFaceDetectionEnabled = true;
3137 startFaceDetection();
3138 }
3139 if(faceDetection.equals("off") && mFaceDetectionEnabled == true) {
3140 stopFaceDetection();
3141 mFaceDetectionEnabled = false;
3142 }
3143 }
SanthoshHEee63d7f2013-09-05 14:43:35 +05303144 // skin tone ie enabled only for auto,party and portrait BSM
3145 // when color effects are not enabled
3146 if((Parameters.SCENE_MODE_PARTY.equals(mSceneMode) ||
3147 Parameters.SCENE_MODE_PORTRAIT.equals(mSceneMode)) &&
3148 (Parameters.EFFECT_NONE.equals(colorEffect))) {
3149 //Set Skin Tone Correction factor
3150 Log.v(TAG, "set tone bar: mSceneMode = " + mSceneMode);
3151 if(mSeekBarInitialized == true)
3152 mHandler.sendEmptyMessage(SET_SKIN_TONE_FACTOR);
3153 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303154
3155 //Set Histogram
3156 String histogram = mPreferences.getString(
3157 CameraSettings.KEY_HISTOGRAM,
3158 mActivity.getString(R.string.pref_camera_histogram_default));
3159 if (CameraUtil.isSupported(histogram,
3160 mParameters.getSupportedHistogramModes()) && mCameraDevice != null) {
3161 // Call for histogram
3162 if(histogram.equals("enable")) {
3163 mActivity.runOnUiThread(new Runnable() {
3164 public void run() {
3165 if(mGraphView != null) {
3166 mGraphView.setVisibility(View.VISIBLE);
3167 mGraphView.PreviewChanged();
3168 }
3169 }
3170 });
3171 mCameraDevice.setHistogramMode(mStatsCallback);
3172 mHiston = true;
3173 } else {
3174 mHiston = false;
3175 mActivity.runOnUiThread(new Runnable() {
3176 public void run() {
3177 if (mGraphView != null)
3178 mGraphView.setVisibility(View.INVISIBLE);
3179 }
3180 });
3181 mCameraDevice.setHistogramMode(null);
3182 }
3183 }
Santhosh Kumar H E823c8f42014-10-16 11:20:34 +05303184
3185 setFlipValue();
3186
3187 /* Disable focus if aebracket is ON */
3188 String aeBracket = mParameters.get(CameraSettings.KEY_QC_AE_BRACKETING);
3189 if (!aeBracket.equalsIgnoreCase("off")) {
3190 String fMode = Parameters.FLASH_MODE_OFF;
3191 mParameters.setFlashMode(fMode);
3192 }
3193 }
3194
3195 private void setFlipValue() {
Alok Kediya4b6f3f92013-09-28 17:39:13 +05303196 // Read Flip mode from adb command
3197 //value: 0(default) - FLIP_MODE_OFF
3198 //value: 1 - FLIP_MODE_H
3199 //value: 2 - FLIP_MODE_V
3200 //value: 3 - FLIP_MODE_VH
3201 int preview_flip_value = SystemProperties.getInt("debug.camera.preview.flip", 0);
3202 int video_flip_value = SystemProperties.getInt("debug.camera.video.flip", 0);
3203 int picture_flip_value = SystemProperties.getInt("debug.camera.picture.flip", 0);
3204 int rotation = CameraUtil.getJpegRotation(mCameraId, mOrientation);
3205 mParameters.setRotation(rotation);
3206 if (rotation == 90 || rotation == 270) {
3207 // in case of 90 or 270 degree, V/H flip should reverse
3208 if (preview_flip_value == 1) {
3209 preview_flip_value = 2;
3210 } else if (preview_flip_value == 2) {
3211 preview_flip_value = 1;
3212 }
3213 if (video_flip_value == 1) {
3214 video_flip_value = 2;
3215 } else if (video_flip_value == 2) {
3216 video_flip_value = 1;
3217 }
Dimitar Borisovcd17bf82014-11-05 12:23:16 +02003218 if (picture_flip_value == 1) {
3219 picture_flip_value = 2;
3220 } else if (picture_flip_value == 2) {
3221 picture_flip_value = 1;
Alok Kediya4b6f3f92013-09-28 17:39:13 +05303222 }
3223 }
3224 String preview_flip = CameraUtil.getFilpModeString(preview_flip_value);
3225 String video_flip = CameraUtil.getFilpModeString(video_flip_value);
3226 String picture_flip = CameraUtil.getFilpModeString(picture_flip_value);
3227 if(CameraUtil.isSupported(preview_flip, CameraSettings.getSupportedFlipMode(mParameters))){
3228 mParameters.set(CameraSettings.KEY_QC_PREVIEW_FLIP, preview_flip);
3229 }
3230 if(CameraUtil.isSupported(video_flip, CameraSettings.getSupportedFlipMode(mParameters))){
3231 mParameters.set(CameraSettings.KEY_QC_VIDEO_FLIP, video_flip);
3232 }
3233 if(CameraUtil.isSupported(picture_flip, CameraSettings.getSupportedFlipMode(mParameters))){
3234 mParameters.set(CameraSettings.KEY_QC_SNAPSHOT_PICTURE_FLIP, picture_flip);
3235 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303236 }
Santhosh Kumar H E823c8f42014-10-16 11:20:34 +05303237
Sascha Haeberling638e6f02013-09-18 14:28:51 -07003238 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Michael Kolb8872c232013-01-29 10:33:22 -08003239 private void setAutoExposureLockIfSupported() {
3240 if (mAeLockSupported) {
3241 mParameters.setAutoExposureLock(mFocusManager.getAeAwbLock());
3242 }
3243 }
3244
Sascha Haeberling638e6f02013-09-18 14:28:51 -07003245 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Michael Kolb8872c232013-01-29 10:33:22 -08003246 private void setAutoWhiteBalanceLockIfSupported() {
3247 if (mAwbLockSupported) {
3248 mParameters.setAutoWhiteBalanceLock(mFocusManager.getAeAwbLock());
3249 }
3250 }
3251
Michael Kolb8872c232013-01-29 10:33:22 -08003252 private void setFocusAreasIfSupported() {
3253 if (mFocusAreaSupported) {
3254 mParameters.setFocusAreas(mFocusManager.getFocusAreas());
3255 }
3256 }
3257
Michael Kolb8872c232013-01-29 10:33:22 -08003258 private void setMeteringAreasIfSupported() {
3259 if (mMeteringAreaSupported) {
Michael Kolb8872c232013-01-29 10:33:22 -08003260 mParameters.setMeteringAreas(mFocusManager.getMeteringAreas());
3261 }
3262 }
3263
Sai Kumar Sanagavarapu87b4a402014-07-02 11:59:05 +05303264 /** This can run on a background thread, so don't do UI updates here.*/
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003265 private boolean updateCameraParametersPreference() {
Michael Kolb8872c232013-01-29 10:33:22 -08003266 setAutoExposureLockIfSupported();
3267 setAutoWhiteBalanceLockIfSupported();
3268 setFocusAreasIfSupported();
3269 setMeteringAreasIfSupported();
3270
Michael Kolb7993f452013-07-12 11:36:47 -07003271 // initialize focus mode
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05303272 if ((mManual3AEnabled & MANUAL_FOCUS) == 0) {
3273 mFocusManager.overrideFocusMode(null);
3274 mParameters.setFocusMode(mFocusManager.getFocusMode());
3275 }
Michael Kolb7993f452013-07-12 11:36:47 -07003276
Michael Kolb8872c232013-01-29 10:33:22 -08003277 // Set picture size.
3278 String pictureSize = mPreferences.getString(
3279 CameraSettings.KEY_PICTURE_SIZE, null);
3280 if (pictureSize == null) {
3281 CameraSettings.initialCameraPictureSize(mActivity, mParameters);
3282 } else {
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303283 Size old_size = mParameters.getPictureSize();
3284 Log.v(TAG, "old picture_size = " + old_size.width + " x " + old_size.height);
Michael Kolb8872c232013-01-29 10:33:22 -08003285 List<Size> supported = mParameters.getSupportedPictureSizes();
3286 CameraSettings.setCameraPictureSize(
3287 pictureSize, supported, mParameters);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303288 Size size = mParameters.getPictureSize();
3289 Log.v(TAG, "new picture_size = " + size.width + " x " + size.height);
3290 if (old_size != null && size != null) {
3291 if(!size.equals(old_size) && mCameraState != PREVIEW_STOPPED) {
3292 Log.v(TAG, "Picture Size changed. Restart Preview");
3293 mRestartPreview = true;
3294 }
3295 }
Michael Kolb8872c232013-01-29 10:33:22 -08003296 }
3297 Size size = mParameters.getPictureSize();
3298
3299 // Set a preview size that is closest to the viewfinder height and has
3300 // the right aspect ratio.
3301 List<Size> sizes = mParameters.getSupportedPreviewSizes();
Angus Kongb50b5cb2013-08-09 14:55:20 -07003302 Size optimalSize = CameraUtil.getOptimalPreviewSize(mActivity, sizes,
Michael Kolb8872c232013-01-29 10:33:22 -08003303 (double) size.width / size.height);
Suman Mukherjeebd3d72f2014-11-03 10:22:08 +05303304
3305 //Read Preview Resolution from adb command
3306 //value: 0(default) - Default value as per snapshot aspect ratio
3307 //value: 1 - 640x480
3308 //value: 2 - 720x480
3309 //value: 3 - 1280x720
3310 //value: 4 - 1920x1080
3311 int preview_resolution = SystemProperties.getInt("persist.camera.preview.size", 0);
3312 switch (preview_resolution) {
3313 case 1: {
3314 optimalSize.width = 640;
3315 optimalSize.height = 480;
3316 Log.v(TAG, "Preview resolution hardcoded to 640x480");
3317 break;
3318 }
3319 case 2: {
3320 optimalSize.width = 720;
3321 optimalSize.height = 480;
3322 Log.v(TAG, "Preview resolution hardcoded to 720x480");
3323 break;
3324 }
3325 case 3: {
3326 optimalSize.width = 1280;
3327 optimalSize.height = 720;
3328 Log.v(TAG, "Preview resolution hardcoded to 1280x720");
3329 break;
3330 }
3331 case 4: {
3332 optimalSize.width = 1920;
3333 optimalSize.height = 1080;
3334 Log.v(TAG, "Preview resolution hardcoded to 1920x1080");
3335 break;
3336 }
3337 default: {
3338 Log.v(TAG, "Preview resolution as per Snapshot aspect ratio");
3339 break;
3340 }
3341 }
3342
Michael Kolb8872c232013-01-29 10:33:22 -08003343 Size original = mParameters.getPreviewSize();
3344 if (!original.equals(optimalSize)) {
3345 mParameters.setPreviewSize(optimalSize.width, optimalSize.height);
Doris Liu6432cd62013-06-13 17:20:31 -07003346
Michael Kolb8872c232013-01-29 10:33:22 -08003347 // Zoom related settings will be changed for different preview
3348 // sizes, so set and read the parameters to get latest values
Michael Kolb4a4d4ef2013-05-30 08:35:26 -07003349 if (mHandler.getLooper() == Looper.myLooper()) {
3350 // On UI thread only, not when camera starts up
3351 setupPreview();
3352 } else {
3353 mCameraDevice.setParameters(mParameters);
3354 }
Michael Kolb8872c232013-01-29 10:33:22 -08003355 mParameters = mCameraDevice.getParameters();
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303356 Log.v(TAG, "Preview Size changed. Restart Preview");
3357 mRestartPreview = true;
Michael Kolb8872c232013-01-29 10:33:22 -08003358 }
Doris Liu95405742013-11-05 15:25:26 -08003359
Michael Kolb8872c232013-01-29 10:33:22 -08003360 Log.v(TAG, "Preview size is " + optimalSize.width + "x" + optimalSize.height);
satyavaraprasad yerramsettic2248d72014-10-31 15:01:39 +05303361 size = mParameters.getPictureSize();
3362
3363 // Set jpegthumbnail size
3364 // Set a jpegthumbnail size that is closest to the Picture height and has
3365 // the right aspect ratio.
3366 List<Size> supported = mParameters.getSupportedJpegThumbnailSizes();
3367 optimalSize = CameraUtil.getOptimalJpegThumbnailSize(supported,
3368 (double) size.width / size.height);
3369 original = mParameters.getJpegThumbnailSize();
3370 if (!original.equals(optimalSize)) {
3371 mParameters.setJpegThumbnailSize(optimalSize.width, optimalSize.height);
3372 }
3373
3374 Log.v(TAG, "Thumbnail size is " + optimalSize.width + "x" + optimalSize.height);
Michael Kolb8872c232013-01-29 10:33:22 -08003375
3376 // Since changing scene mode may change supported values, set scene mode
3377 // first. HDR is a scene mode. To promote it in UI, it is stored in a
3378 // separate preference.
Sascha Haeberling98f38bb2013-09-24 18:58:34 -07003379 String onValue = mActivity.getString(R.string.setting_on_value);
Michael Kolb8872c232013-01-29 10:33:22 -08003380 String hdr = mPreferences.getString(CameraSettings.KEY_CAMERA_HDR,
3381 mActivity.getString(R.string.pref_camera_hdr_default));
Sascha Haeberling9bf0fd62013-10-03 12:10:48 -07003382 String hdrPlus = mPreferences.getString(CameraSettings.KEY_CAMERA_HDR_PLUS,
3383 mActivity.getString(R.string.pref_camera_hdr_plus_default));
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003384 boolean hdrOn = onValue.equals(hdr);
Sascha Haeberling9bf0fd62013-10-03 12:10:48 -07003385 boolean hdrPlusOn = onValue.equals(hdrPlus);
Sascha Haeberling98f38bb2013-09-24 18:58:34 -07003386
3387 boolean doGcamModeSwitch = false;
Sascha Haeberling9bf0fd62013-10-03 12:10:48 -07003388 if (hdrPlusOn && GcamHelper.hasGcamCapture()) {
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003389 // Kick off mode switch to gcam.
3390 doGcamModeSwitch = true;
Michael Kolb8872c232013-01-29 10:33:22 -08003391 } else {
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003392 if (hdrOn) {
3393 mSceneMode = CameraUtil.SCENE_MODE_HDR;
Kerong Sui7333d202014-06-13 17:16:14 +08003394 if (!(Parameters.SCENE_MODE_AUTO).equals(mParameters.getSceneMode())
3395 && !(Parameters.SCENE_MODE_HDR).equals(mParameters.getSceneMode())) {
Santhosh Kumar Thimmanna Bhattarb228ec62014-04-29 19:02:24 +05303396 mParameters.setSceneMode(Parameters.SCENE_MODE_AUTO);
3397 mCameraDevice.setParameters(mParameters);
3398 mParameters = mCameraDevice.getParameters();
3399 }
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003400 } else {
3401 mSceneMode = mPreferences.getString(
3402 CameraSettings.KEY_SCENE_MODE,
3403 mActivity.getString(R.string.pref_camera_scenemode_default));
3404 }
Michael Kolb8872c232013-01-29 10:33:22 -08003405 }
Angus Kongb50b5cb2013-08-09 14:55:20 -07003406 if (CameraUtil.isSupported(mSceneMode, mParameters.getSupportedSceneModes())) {
Michael Kolb8872c232013-01-29 10:33:22 -08003407 if (!mParameters.getSceneMode().equals(mSceneMode)) {
3408 mParameters.setSceneMode(mSceneMode);
3409
3410 // Setting scene mode will change the settings of flash mode,
3411 // white balance, and focus mode. Here we read back the
3412 // parameters, so we can know those settings.
3413 mCameraDevice.setParameters(mParameters);
3414 mParameters = mCameraDevice.getParameters();
3415 }
3416 } else {
3417 mSceneMode = mParameters.getSceneMode();
3418 if (mSceneMode == null) {
3419 mSceneMode = Parameters.SCENE_MODE_AUTO;
3420 }
3421 }
3422
3423 // Set JPEG quality.
3424 int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(mCameraId,
3425 CameraProfile.QUALITY_HIGH);
3426 mParameters.setJpegQuality(jpegQuality);
3427
3428 // For the following settings, we need to check if the settings are
3429 // still supported by latest driver, if not, ignore the settings.
3430
3431 // Set exposure compensation
3432 int value = CameraSettings.readExposure(mPreferences);
3433 int max = mParameters.getMaxExposureCompensation();
3434 int min = mParameters.getMinExposureCompensation();
3435 if (value >= min && value <= max) {
3436 mParameters.setExposureCompensation(value);
3437 } else {
3438 Log.w(TAG, "invalid exposure range: " + value);
3439 }
3440
3441 if (Parameters.SCENE_MODE_AUTO.equals(mSceneMode)) {
3442 // Set flash mode.
3443 String flashMode = mPreferences.getString(
3444 CameraSettings.KEY_FLASH_MODE,
3445 mActivity.getString(R.string.pref_camera_flashmode_default));
3446 List<String> supportedFlash = mParameters.getSupportedFlashModes();
Angus Kongb50b5cb2013-08-09 14:55:20 -07003447 if (CameraUtil.isSupported(flashMode, supportedFlash)) {
Michael Kolb8872c232013-01-29 10:33:22 -08003448 mParameters.setFlashMode(flashMode);
3449 } else {
3450 flashMode = mParameters.getFlashMode();
3451 if (flashMode == null) {
3452 flashMode = mActivity.getString(
3453 R.string.pref_camera_flashmode_no_flash);
3454 }
3455 }
3456
3457 // Set white balance parameter.
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05303458 if ((mManual3AEnabled & MANUAL_WB) == 0) {
3459 String whiteBalance = mPreferences.getString(
3460 CameraSettings.KEY_WHITE_BALANCE,
3461 mActivity.getString(R.string.pref_camera_whitebalance_default));
3462 if (CameraUtil.isSupported(whiteBalance,
3463 mParameters.getSupportedWhiteBalance())) {
3464 mParameters.setWhiteBalance(whiteBalance);
3465 } else {
3466 whiteBalance = mParameters.getWhiteBalance();
3467 if (whiteBalance == null) {
3468 whiteBalance = Parameters.WHITE_BALANCE_AUTO;
3469 }
Michael Kolb8872c232013-01-29 10:33:22 -08003470 }
3471 }
3472
3473 // Set focus mode.
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05303474 if ((mManual3AEnabled & MANUAL_FOCUS) == 0) {
3475 mFocusManager.overrideFocusMode(null);
3476 mParameters.setFocusMode(mFocusManager.getFocusMode());
3477 }
Michael Kolb8872c232013-01-29 10:33:22 -08003478 } else {
3479 mFocusManager.overrideFocusMode(mParameters.getFocusMode());
Kerong Sui4d6af652014-04-11 14:15:56 +08003480 if (hdrOn)
3481 mParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
kaiyiz45c81752014-06-16 16:36:15 +08003482 else {
3483 mParameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
3484 }
kaiyiz5de31222014-06-30 16:31:14 +08003485 if (CameraUtil.isSupported(Parameters.WHITE_BALANCE_AUTO,
3486 mParameters.getSupportedWhiteBalance())) {
3487 mParameters.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);
3488 }
Michael Kolb8872c232013-01-29 10:33:22 -08003489 }
3490
Angus Kongdcccc512013-08-08 17:06:03 -07003491 if (mContinuousFocusSupported && ApiHelper.HAS_AUTO_FOCUS_MOVE_CALLBACK) {
Michael Kolb8872c232013-01-29 10:33:22 -08003492 updateAutoFocusMoveCallback();
3493 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303494 //QCom related parameters updated here.
3495 qcomUpdateCameraParametersPreference();
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003496 return doGcamModeSwitch;
Michael Kolb8872c232013-01-29 10:33:22 -08003497 }
3498
Sascha Haeberling638e6f02013-09-18 14:28:51 -07003499 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
Michael Kolb8872c232013-01-29 10:33:22 -08003500 private void updateAutoFocusMoveCallback() {
Angus Kongb50b5cb2013-08-09 14:55:20 -07003501 if (mParameters.getFocusMode().equals(CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE)) {
Angus Kong9ef99252013-07-18 18:04:19 -07003502 mCameraDevice.setAutoFocusMoveCallback(mHandler,
Angus Kong4f795b82013-09-16 14:25:35 -07003503 (CameraAFMoveCallback) mAutoFocusMoveCallback);
Michael Kolb8872c232013-01-29 10:33:22 -08003504 } else {
Angus Kong9ef99252013-07-18 18:04:19 -07003505 mCameraDevice.setAutoFocusMoveCallback(null, null);
Michael Kolb8872c232013-01-29 10:33:22 -08003506 }
3507 }
3508
3509 // We separate the parameters into several subsets, so we can update only
3510 // the subsets actually need updating. The PREFERENCE set needs extra
3511 // locking because the preference can be changed from GLThread as well.
3512 private void setCameraParameters(int updateSet) {
Vladimir Petrov0ddcbe52014-06-05 12:58:42 +03003513 if (mCameraDevice == null) {
3514 return;
3515 }
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303516 synchronized (mCameraDevice) {
3517 boolean doModeSwitch = false;
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003518
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303519 if ((updateSet & UPDATE_PARAM_INITIALIZE) != 0) {
3520 updateCameraParametersInitialize();
3521 }
Michael Kolb8872c232013-01-29 10:33:22 -08003522
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303523 if ((updateSet & UPDATE_PARAM_ZOOM) != 0) {
3524 updateCameraParametersZoom();
3525 }
Michael Kolb8872c232013-01-29 10:33:22 -08003526
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303527 if ((updateSet & UPDATE_PARAM_PREFERENCE) != 0) {
3528 doModeSwitch = updateCameraParametersPreference();
3529 }
Michael Kolb8872c232013-01-29 10:33:22 -08003530
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303531 mCameraDevice.setParameters(mParameters);
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003532
Santhosh Kumar Thimmanna Bhattaredc737a2014-01-10 14:50:30 +05303533 // Switch to gcam module if HDR+ was selected
3534 if (doModeSwitch && !mIsImageCaptureIntent) {
3535 mHandler.sendEmptyMessage(SWITCH_TO_GCAM_MODULE);
3536 }
Ruben Brunk4601f5d2013-09-24 18:35:22 -07003537 }
Michael Kolb8872c232013-01-29 10:33:22 -08003538 }
3539
3540 // If the Camera is idle, update the parameters immediately, otherwise
3541 // accumulate them in mUpdateSet and update later.
3542 private void setCameraParametersWhenIdle(int additionalUpdateSet) {
3543 mUpdateSet |= additionalUpdateSet;
3544 if (mCameraDevice == null) {
3545 // We will update all the parameters when we open the device, so
3546 // we don't need to do anything now.
3547 mUpdateSet = 0;
3548 return;
3549 } else if (isCameraIdle()) {
3550 setCameraParameters(mUpdateSet);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303551 if(mRestartPreview && mCameraState != PREVIEW_STOPPED) {
3552 Log.v(TAG, "Restarting Preview...");
3553 stopPreview();
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +05303554 resizeForPreviewAspectRatio();
Alok Kediya0dc64ff2013-09-27 20:22:45 +05303555 startPreview();
3556 setCameraState(IDLE);
3557 }
3558 mRestartPreview = false;
Ivan Evlogiev5086f852014-03-05 17:12:35 +02003559 updateCameraSettings();
Michael Kolb8872c232013-01-29 10:33:22 -08003560 mUpdateSet = 0;
3561 } else {
3562 if (!mHandler.hasMessages(SET_CAMERA_PARAMETERS_WHEN_IDLE)) {
3563 mHandler.sendEmptyMessageDelayed(
3564 SET_CAMERA_PARAMETERS_WHEN_IDLE, 1000);
3565 }
3566 }
3567 }
3568
ztenghui7b265a62013-09-09 14:58:44 -07003569 @Override
Michael Kolbd6954f32013-03-08 20:43:01 -08003570 public boolean isCameraIdle() {
Michael Kolb8872c232013-01-29 10:33:22 -08003571 return (mCameraState == IDLE) ||
3572 (mCameraState == PREVIEW_STOPPED) ||
3573 ((mFocusManager != null) && mFocusManager.isFocusCompleted()
3574 && (mCameraState != SWITCHING_CAMERA));
3575 }
3576
ztenghui7b265a62013-09-09 14:58:44 -07003577 @Override
Michael Kolbd6954f32013-03-08 20:43:01 -08003578 public boolean isImageCaptureIntent() {
Michael Kolb8872c232013-01-29 10:33:22 -08003579 String action = mActivity.getIntent().getAction();
3580 return (MediaStore.ACTION_IMAGE_CAPTURE.equals(action)
Angus Kong6a8e8a12013-07-19 14:55:07 -07003581 || CameraActivity.ACTION_IMAGE_CAPTURE_SECURE.equals(action));
Michael Kolb8872c232013-01-29 10:33:22 -08003582 }
3583
3584 private void setupCaptureParams() {
3585 Bundle myExtras = mActivity.getIntent().getExtras();
3586 if (myExtras != null) {
3587 mSaveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT);
3588 mCropValue = myExtras.getString("crop");
3589 }
3590 }
3591
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05303592 private void UpdateManualFocusSettings() {
3593 //dismiss all popups first, because we need to show edit dialog
3594 mUI.collapseCameraControls();
3595 final AlertDialog.Builder alert = new AlertDialog.Builder(mActivity);
3596 LinearLayout linear = new LinearLayout(mActivity);
3597 linear.setOrientation(1);
3598 alert.setTitle("Manual Focus Settings");
3599 alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener()
3600 {
3601 public void onClick(DialogInterface dialog,int id)
3602 {
3603 dialog.cancel();
3604 }
3605 });
3606 final TextView focusPositionText = new TextView(mActivity);
3607 String scaleMode = mActivity.getString(
3608 R.string.pref_camera_manual_focus_value_scale_mode);
3609 String diopterMode = mActivity.getString(
3610 R.string.pref_camera_manual_focus_value_diopter_mode);
3611 String manualFocusMode = mPreferences.getString(
3612 CameraSettings.KEY_MANUAL_FOCUS,
3613 mActivity.getString(R.string.pref_camera_manual_focus_default));
3614
3615 Log.v(TAG, "manualFocusMode selected = " + manualFocusMode);
3616 if (manualFocusMode.equals(scaleMode)) {
3617 final SeekBar focusbar = new SeekBar(mActivity);
3618 final int minFocusPos = mParameters.getInt(CameraSettings.KEY_MIN_FOCUS_SCALE);
3619 final int maxFocusPos = mParameters.getInt(CameraSettings.KEY_MAX_FOCUS_SCALE);
3620 //update mparameters to fetch latest focus position
3621 mParameters = mCameraDevice.getParameters();
3622 final int CurFocusPos = mParameters.getInt(CameraSettings.KEY_MANUAL_FOCUS_SCALE);
3623 focusbar.setProgress(CurFocusPos);
3624 focusPositionText.setText("Current focus position is " + CurFocusPos);
3625
3626 alert.setMessage("Enter focus position in the range of " + minFocusPos
3627 + " to " + maxFocusPos);
3628
3629 focusbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
3630 @Override
3631 public void onStopTrackingTouch(SeekBar seekBar) {
3632 }
3633
3634 @Override
3635 public void onStartTrackingTouch(SeekBar seekBar) {
3636 }
3637
3638 @Override
3639 public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
3640 focusPositionText.setText("Current focus position is " + progress);
3641 }
3642 });
3643 linear.addView(focusbar);
3644 linear.addView(focusPositionText);
3645 alert.setView(linear);
3646 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3647 {
3648 public void onClick(DialogInterface dialog,int id)
3649 {
3650 int focusPos = focusbar.getProgress();
3651 Log.v(TAG, "Setting focus position : " + focusPos);
3652 mManual3AEnabled |= MANUAL_FOCUS;
3653 mParameters.setFocusMode(Parameters.FOCUS_MODE_MANUAL_POSITION);
3654 mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_TYPE, 2); // 2 for scale mode
3655 mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_POSITION, focusPos);
3656 updateCommonManual3ASettings();
3657 onSharedPreferenceChanged();
3658 }
3659 });
3660 alert.show();
3661 } else if (manualFocusMode.equals(diopterMode)) {
3662 String minFocusStr = mParameters.get(CameraSettings.KEY_MIN_FOCUS_DIOPTER);
3663 String maxFocusStr = mParameters.get(CameraSettings.KEY_MAX_FOCUS_DIOPTER);
3664 final double minFocusPos = Double.parseDouble(minFocusStr);
3665 final double maxFocusPos = Double.parseDouble(maxFocusStr);
3666 final EditText input = new EditText(mActivity);
3667 int floatType = InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER;
3668 input.setInputType(floatType);
3669 alert.setMessage("Enter focus position in the range of " + minFocusPos
3670 + " to " + maxFocusPos);
3671 //update mparameters to fetch latest focus position
3672 mParameters = mCameraDevice.getParameters();
3673 final String CurFocusPos = mParameters.get(CameraSettings.KEY_MANUAL_FOCUS_DIOPTER);
3674 focusPositionText.setText("Current focus position is " + CurFocusPos);
3675 linear.addView(input);
3676 linear.addView(focusPositionText);
3677 alert.setView(linear);
3678 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3679 {
3680 public void onClick(DialogInterface dialog,int id)
3681 {
3682 double focuspos = 0;
3683 String focusStr = input.getText().toString();
3684 if (focusStr.length() > 0) {
3685 focuspos = Double.parseDouble(focusStr);
3686 } else {
3687 Toast.makeText(mActivity, "Invalid focus position",
3688 Toast.LENGTH_SHORT).show();
3689 return;
3690 }
3691 if (focuspos >= minFocusPos && focuspos <= maxFocusPos) {
3692 Log.v(TAG, "Setting focus position : " + focusStr);
3693 mManual3AEnabled |= MANUAL_FOCUS;
3694 mParameters.setFocusMode(Parameters.FOCUS_MODE_MANUAL_POSITION);
3695 //focus type 3 is diopter mode
3696 mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_TYPE, 3);
3697 mParameters.set(CameraSettings.KEY_MANUAL_FOCUS_POSITION, focusStr);
3698 updateCommonManual3ASettings();
3699 onSharedPreferenceChanged();
3700 } else {
3701 Toast.makeText(mActivity, "Invalid focus position",
3702 Toast.LENGTH_SHORT).show();
3703 }
3704 }
3705 });
3706 alert.show();
3707 } else {
3708 mManual3AEnabled &= ~MANUAL_FOCUS;
3709 mParameters.setFocusMode(mFocusManager.getFocusMode());
3710 mUI.overrideSettings(CameraSettings.KEY_FOCUS_MODE, null);
3711 updateCommonManual3ASettings();
3712 onSharedPreferenceChanged();
3713 }
3714 }
3715
3716 private void UpdateManualWBSettings() {
3717 //dismiss all popups first, because we need to show edit dialog
3718 mUI.collapseCameraControls();
3719 final AlertDialog.Builder alert = new AlertDialog.Builder(mActivity);
3720 LinearLayout linear = new LinearLayout(mActivity);
3721 linear.setOrientation(1);
3722 alert.setTitle("Manual White Balance Settings");
3723 alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener()
3724 {
3725 public void onClick(DialogInterface dialog,int id)
3726 {
3727 dialog.cancel();
3728 }
3729 });
3730
3731 String cctMode = mActivity.getString(
3732 R.string.pref_camera_manual_wb_value_color_temperature);
3733 String rgbGainMode = mActivity.getString(
3734 R.string.pref_camera_manual_wb_value_rbgb_gains);
3735 String manualWBMode = mPreferences.getString(
3736 CameraSettings.KEY_MANUAL_WB,
3737 mActivity.getString(R.string.pref_camera_manual_wb_default));
3738 final String wbPref = mPreferences.getString(
3739 CameraSettings.KEY_WHITE_BALANCE,
3740 mActivity.getString(R.string.pref_camera_whitebalance_default));
3741 Log.v(TAG, "manualWBMode selected = " + manualWBMode);
3742 if (manualWBMode.equals(cctMode)) {
3743 final TextView CCTtext = new TextView(mActivity);
3744 final EditText CCTinput = new EditText(mActivity);
3745 CCTinput.setInputType(InputType.TYPE_CLASS_NUMBER);
3746 final int minCCT = mParameters.getInt(CameraSettings.KEY_MIN_WB_CCT);
3747 final int maxCCT = mParameters.getInt(CameraSettings.KEY_MAX_WB_CCT);
3748
3749 //refresh camera parameters to get latest CCT value
3750 mParameters = mCameraDevice.getParameters();
3751 String currentCCT = mParameters.get(CameraSettings.KEY_MANUAL_WB_CCT);
3752 if (currentCCT != null) {
3753 CCTtext.setText("Current CCT is " + currentCCT);
3754 }
3755 alert.setMessage("Enter CCT value in the range of " + minCCT+ " to " + maxCCT);
3756 linear.addView(CCTinput);
3757 linear.addView(CCTtext);
3758 alert.setView(linear);
3759 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3760 {
3761 public void onClick(DialogInterface dialog,int id)
3762 {
3763 int newCCT = -1;
3764 String cct = CCTinput.getText().toString();
3765 if (cct.length() > 0) {
3766 newCCT = Integer.parseInt(cct);
3767 }
3768 if (newCCT <= maxCCT && newCCT >= minCCT) {
3769 mManual3AEnabled |= MANUAL_WB;
3770 Log.v(TAG, "Setting CCT value : " + newCCT);
3771 mParameters.setWhiteBalance(CameraSettings.KEY_MANUAL_WHITE_BALANCE);
3772 //0 corresponds to manual CCT mode
3773 mParameters.set(CameraSettings.KEY_MANUAL_WB_TYPE, 0);
3774 mParameters.set(CameraSettings.KEY_MANUAL_WB_VALUE, newCCT);
3775 updateCommonManual3ASettings();
3776 onSharedPreferenceChanged();
3777 } else {
3778 Toast.makeText(mActivity, "Invalid CCT", Toast.LENGTH_SHORT).show();
3779 }
3780 }
3781 });
3782 alert.show();
3783 } else if (manualWBMode.equals(rgbGainMode)) {
3784 final TextView RGBtext = new TextView(mActivity);
3785 final EditText Rinput = new EditText(mActivity);
3786 Rinput.setHint("Enter R gain here");
3787 final EditText Ginput = new EditText(mActivity);
3788 Ginput.setHint("Enter G gain here");
3789 final EditText Binput = new EditText(mActivity);
3790 Binput.setHint("Enter B gain here");
3791
3792 int floatType = InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER;
3793 Rinput.setInputType(floatType);
3794 Ginput.setInputType(floatType);
3795 Binput.setInputType(floatType);
3796
3797 String minGainStr = mParameters.get(CameraSettings.KEY_MIN_WB_GAIN);
3798 final double minGain = Double.parseDouble(minGainStr);
3799 String maxGainStr = mParameters.get(CameraSettings.KEY_MAX_WB_GAIN);
3800 final double maxGain = Double.parseDouble(maxGainStr);
3801
3802 //refresh camera parameters to get latest WB gains
3803 mParameters = mCameraDevice.getParameters();
3804 String currentGains = mParameters.get(CameraSettings.KEY_MANUAL_WB_GAINS);
3805 if (currentGains != null) {
3806 RGBtext.setText("Current RGB gains are " + currentGains);
3807 }
3808
3809 alert.setMessage("Enter RGB gains in the range of " + minGain
3810 + " to " + maxGain);
3811 linear.addView(Rinput);
3812 linear.addView(Ginput);
3813 linear.addView(Binput);
3814 linear.addView(RGBtext);
3815 alert.setView(linear);
3816 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3817 {
3818 public void onClick(DialogInterface dialog,int id)
3819 {
3820 String Rgain = Rinput.getText().toString();
3821 String Ggain = Ginput.getText().toString();
3822 String Bgain = Binput.getText().toString();
3823 if (Rgain.length() > 0 && Ggain.length() > 0 && Bgain.length() > 0) {
3824 double Rgainf = Double.parseDouble(Rgain);
3825 double Ggainf = Double.parseDouble(Ggain);
3826 double Bgainf = Double.parseDouble(Bgain);
3827 String RGBGain = Rgain + "," + Ggain + "," + Bgain;
3828 if (Rgainf <= maxGain && Rgainf >= minGain &&
3829 Ggainf <= maxGain && Ggainf >= minGain &&
3830 Bgainf <= maxGain && Bgainf >= minGain) {
3831 Log.v(TAG, "Setting RGB gains : " + RGBGain);
3832 mManual3AEnabled |= MANUAL_WB;
3833 mParameters.setWhiteBalance(CameraSettings.KEY_MANUAL_WHITE_BALANCE);
3834 // 1 corresponds to manual WB gain mode
3835 mParameters.set(CameraSettings.KEY_MANUAL_WB_TYPE, 1);
3836 mParameters.set(CameraSettings.KEY_MANUAL_WB_VALUE, RGBGain);
3837 updateCommonManual3ASettings();
3838 onSharedPreferenceChanged();
3839 } else {
3840 Toast.makeText(mActivity, "Invalid RGB gains",
3841 Toast.LENGTH_SHORT).show();
3842 }
3843 } else {
3844 Toast.makeText(mActivity, "Invalid RGB gains",
3845 Toast.LENGTH_SHORT).show();
3846 }
3847 }
3848 });
3849 alert.show();
3850 } else {
3851 //reset white balance
3852 mManual3AEnabled &= ~MANUAL_WB;
3853 mUI.overrideSettings(CameraSettings.KEY_WHITE_BALANCE, null);
3854 updateCommonManual3ASettings();
3855 onSharedPreferenceChanged();
3856 }
3857 }
3858
3859 private void UpdateManualExposureSettings() {
3860 //dismiss all popups first, because we need to show edit dialog
3861 mUI.collapseCameraControls();
3862 final AlertDialog.Builder alert = new AlertDialog.Builder(mActivity);
3863 LinearLayout linear = new LinearLayout(mActivity);
3864 linear.setOrientation(1);
3865 final TextView ISOtext = new TextView(mActivity);
3866 final EditText ISOinput = new EditText(mActivity);
3867 final TextView ExpTimeText = new TextView(mActivity);
3868 final EditText ExpTimeInput = new EditText(mActivity);
3869 ISOinput.setInputType(InputType.TYPE_CLASS_NUMBER);
3870 int floatType = InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER;
3871 ExpTimeInput.setInputType(floatType);
3872 alert.setTitle("Manual Exposure Settings");
3873 alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener()
3874 {
3875 public void onClick(DialogInterface dialog,int id)
3876 {
3877 dialog.cancel();
3878 }
3879 });
3880
3881 mParameters = mCameraDevice.getParameters();
3882 final int minISO = mParameters.getInt(CameraSettings.KEY_MIN_ISO);
3883 final int maxISO = mParameters.getInt(CameraSettings.KEY_MAX_ISO);
3884 String isoMode = mParameters.getISOValue();
3885 final String isoManual = CameraSettings.KEY_MANUAL_ISO;
3886 String currentISO = mParameters.get(CameraSettings.KEY_CURRENT_ISO);
3887 if (currentISO != null) {
3888 ISOtext.setText("Current ISO is " + currentISO);
3889 }
3890
3891 final String minExpTime = mParameters.get(CameraSettings.KEY_MIN_EXPOSURE_TIME);
3892 final String maxExpTime = mParameters.get(CameraSettings.KEY_MAX_EXPOSURE_TIME);
3893 String currentExpTime = mParameters.get(CameraSettings.KEY_CURRENT_EXPOSURE_TIME);
3894 if (currentExpTime != null) {
3895 ExpTimeText.setText("Current exposure time is " + currentExpTime);
3896 }
3897
3898 String isoPriority = mActivity.getString(
3899 R.string.pref_camera_manual_exp_value_ISO_priority);
3900 String expTimePriority = mActivity.getString(
3901 R.string.pref_camera_manual_exp_value_exptime_priority);
3902 String userSetting = mActivity.getString(
3903 R.string.pref_camera_manual_exp_value_user_setting);
3904 String manualExposureMode = mPreferences.getString(
3905 CameraSettings.KEY_MANUAL_EXPOSURE,
3906 mActivity.getString(R.string.pref_camera_manual_exp_default));
3907 Log.v(TAG, "manual Exposure Mode selected = " + manualExposureMode);
3908 if (manualExposureMode.equals(isoPriority)) {
3909 alert.setMessage("Enter ISO in the range of " + minISO + " to " + maxISO);
3910 linear.addView(ISOinput);
3911 linear.addView(ISOtext);
3912 alert.setView(linear);
3913 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3914 {
3915 public void onClick(DialogInterface dialog,int id)
3916 {
3917 int newISO = -1;
3918 String iso = ISOinput.getText().toString();
3919 Log.v(TAG, "string iso length " + iso.length());
3920 if (iso.length() > 0) {
3921 newISO = Integer.parseInt(iso);
3922 }
3923 if (newISO <= maxISO && newISO >= minISO) {
3924 Log.v(TAG, "Setting ISO : " + newISO);
3925 mManual3AEnabled |= MANUAL_EXPOSURE;
3926 mParameters.setISOValue(isoManual);
3927 mParameters.set(CameraSettings.KEY_CONTINUOUS_ISO, newISO);
3928 mParameters.set(CameraSettings.KEY_EXPOSURE_TIME, "0");
3929 updateCommonManual3ASettings();
3930 onSharedPreferenceChanged();
3931 } else {
3932 Toast.makeText(mActivity, "Invalid ISO", Toast.LENGTH_SHORT).show();
3933 }
3934 }
3935 });
3936 alert.show();
3937 } else if (manualExposureMode.equals(expTimePriority)) {
3938 alert.setMessage("Enter exposure time in the range of " + minExpTime
3939 + "ms to " + maxExpTime + "ms");
3940 linear.addView(ExpTimeInput);
3941 linear.addView(ExpTimeText);
3942 alert.setView(linear);
3943 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3944 {
3945 public void onClick(DialogInterface dialog,int id)
3946 {
3947 double newExpTime = -1;
3948 String expTime = ExpTimeInput.getText().toString();
3949 if (expTime.length() > 0) {
3950 newExpTime = Double.parseDouble(expTime);
3951 }
3952 if (newExpTime <= Double.parseDouble(maxExpTime) &&
3953 newExpTime >= Double.parseDouble(minExpTime)) {
3954 Log.v(TAG, "Setting Exposure time : " + newExpTime);
3955 mManual3AEnabled |= MANUAL_EXPOSURE;
3956 mParameters.set(CameraSettings.KEY_EXPOSURE_TIME, expTime);
3957 mParameters.setISOValue(Parameters.ISO_AUTO);
3958 mUI.setPreference(CameraSettings.KEY_ISO, Parameters.ISO_AUTO);
3959 mUI.overrideSettings(CameraSettings.KEY_ISO, null);
3960 updateCommonManual3ASettings();
3961 onSharedPreferenceChanged();
3962 } else {
3963 Toast.makeText(mActivity, "Invalid exposure time",
3964 Toast.LENGTH_SHORT).show();
3965 }
3966 }
3967 });
3968 alert.show();
3969 } else if (manualExposureMode.equals(userSetting)) {
3970 alert.setMessage("Full manual mode - Enter both ISO and Exposure Time");
3971 final TextView ISORangeText = new TextView(mActivity);
3972 final TextView ExpTimeRangeText = new TextView(mActivity);
3973 ISORangeText.setText("Enter ISO in the range of " + minISO + " to " + maxISO);
3974 ExpTimeRangeText.setText("Enter exposure time in the range of " + minExpTime
3975 + "ms to " + maxExpTime + "ms");
3976 linear.addView(ISORangeText);
3977 linear.addView(ISOinput);
3978 linear.addView(ISOtext);
3979 linear.addView(ExpTimeRangeText);
3980 linear.addView(ExpTimeInput);
3981 linear.addView(ExpTimeText);
3982 alert.setView(linear);
3983 alert.setPositiveButton("Ok",new DialogInterface.OnClickListener()
3984 {
3985 public void onClick(DialogInterface dialog,int id)
3986 {
3987 int newISO = -1;
3988 String iso = ISOinput.getText().toString();
3989 Log.v(TAG, "string iso length " + iso.length());
3990 if (iso.length() > 0) {
3991 newISO = Integer.parseInt(iso);
3992 }
3993 double newExpTime = -1;
3994 String expTime = ExpTimeInput.getText().toString();
3995 if (expTime.length() > 0) {
3996 newExpTime = Double.parseDouble(expTime);
3997 }
3998 if (newISO <= maxISO && newISO >= minISO &&
3999 newExpTime <= Double.parseDouble(maxExpTime) &&
4000 newExpTime >= Double.parseDouble(minExpTime)) {
4001 mManual3AEnabled |= MANUAL_EXPOSURE;
4002 Log.v(TAG, "Setting ISO : " + newISO);
4003 mParameters.setISOValue(isoManual);
4004 mParameters.set(CameraSettings.KEY_CONTINUOUS_ISO, newISO);
4005 Log.v(TAG, "Setting Exposure time : " + newExpTime);
4006 mParameters.set(CameraSettings.KEY_EXPOSURE_TIME, expTime);
4007 updateCommonManual3ASettings();
4008 onSharedPreferenceChanged();
4009 } else {
4010 Toast.makeText(mActivity, "Invalid input", Toast.LENGTH_SHORT).show();
4011 }
4012 }
4013 });
4014 alert.show();
4015 } else {
4016 mManual3AEnabled &= ~MANUAL_EXPOSURE;
4017 //auto exposure mode - reset both exposure time and ISO
4018 mParameters.set(CameraSettings.KEY_EXPOSURE_TIME, "0");
4019 mUI.overrideSettings(CameraSettings.KEY_ISO, null);
4020 updateCommonManual3ASettings();
4021 onSharedPreferenceChanged();
4022 }
4023 }
4024
Sai Kumar Sanagavarapu35125312014-05-16 19:42:48 +05304025 // Return true if the preference has the specified key but not the value.
4026 private static boolean notSame(ListPreference pref, String key, String value) {
4027 return (key.equals(pref.getKey()) && !value.equals(pref.getValue()));
4028 }
4029
4030 @Override
4031 public void onSharedPreferenceChanged(ListPreference pref) {
4032 // ignore the events after "onPause()"
4033 if (mPaused) return;
4034
4035 //filter off unsupported settings
4036 final String settingOff = mActivity.getString(R.string.setting_off_value);
4037 if (!CameraSettings.isZSLHDRSupported(mParameters)) {
4038 if (notSame(pref, CameraSettings.KEY_CAMERA_HDR, settingOff)) {
4039 mUI.setPreference(CameraSettings.KEY_ZSL,settingOff);
4040 } else if (notSame(pref,CameraSettings.KEY_ZSL,settingOff)) {
4041 mUI.setPreference(CameraSettings.KEY_CAMERA_HDR, settingOff);
4042 }
4043 }
4044
Sai Kumar Sanagavarapubf809d32014-10-01 20:44:47 +05304045 if(CameraSettings.KEY_MANUAL_EXPOSURE.equals(pref.getKey())) {
4046 UpdateManualExposureSettings();
4047 return;
4048 }
4049 if (CameraSettings.KEY_MANUAL_WB.equals(pref.getKey())) {
4050 UpdateManualWBSettings();
4051 return;
4052 }
4053 if (CameraSettings.KEY_MANUAL_FOCUS.equals(pref.getKey())) {
4054 UpdateManualFocusSettings();
4055 return;
4056 }
4057
Sai Kumar Sanagavarapu35125312014-05-16 19:42:48 +05304058 //call generic onSharedPreferenceChanged
4059 onSharedPreferenceChanged();
4060 }
4061
Michael Kolb8872c232013-01-29 10:33:22 -08004062 @Override
4063 public void onSharedPreferenceChanged() {
4064 // ignore the events after "onPause()"
4065 if (mPaused) return;
4066
4067 boolean recordLocation = RecordLocationPreference.get(
4068 mPreferences, mContentResolver);
4069 mLocationManager.recordLocation(recordLocation);
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304070 if(needRestart()){
Likai Ding40d36372014-11-20 08:00:28 +08004071 Log.v(TAG, "Restarting Preview... Camera Mode Changhed");
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304072 stopPreview();
4073 startPreview();
4074 setCameraState(IDLE);
4075 mRestartPreview = false;
4076 }
Alok Kediya3c9da9a2013-10-03 15:12:43 +05304077 /* Check if the PhotoUI Menu is initialized or not. This
4078 * should be initialized during onCameraOpen() which should
4079 * have been called by now. But for some reason that is not
4080 * executed till now, then schedule these functionality for
4081 * later by posting a message to the handler */
4082 if (mUI.mMenuInitialized) {
4083 setCameraParametersWhenIdle(UPDATE_PARAM_PREFERENCE);
4084 mUI.updateOnScreenIndicators(mParameters, mPreferenceGroup,
4085 mPreferences);
4086 } else {
4087 mHandler.sendEmptyMessage(SET_PHOTO_UI_PARAMS);
4088 }
Santhosh Kumar H E6bc53a12013-10-25 13:14:10 +05304089 resizeForPreviewAspectRatio();
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304090 if (mSeekBarInitialized == true){
4091 Log.v(TAG, "onSharedPreferenceChanged Skin tone bar: change");
4092 // skin tone is enabled only for party and portrait BSM
4093 // when color effects are not enabled
4094 String colorEffect = mPreferences.getString(
4095 CameraSettings.KEY_COLOR_EFFECT,
4096 mActivity.getString(R.string.pref_camera_coloreffect_default));
4097 if((Parameters.SCENE_MODE_PARTY.equals(mSceneMode) ||
4098 Parameters.SCENE_MODE_PORTRAIT.equals(mSceneMode)) &&
4099 (Parameters.EFFECT_NONE.equals(colorEffect))) {
4100 Log.v(TAG, "Party/Portrait + No effect, SkinToneBar enabled");
4101 } else {
4102 disableSkinToneSeekBar();
4103 }
4104 }
Santhosh Kumar H Eb2da1c12014-01-21 19:21:42 +05304105 Storage.setSaveSDCard(
4106 mPreferences.getString(CameraSettings.KEY_CAMERA_SAVEPATH, "0").equals("1"));
Michael Kolb8872c232013-01-29 10:33:22 -08004107 }
4108
4109 @Override
4110 public void onCameraPickerClicked(int cameraId) {
4111 if (mPaused || mPendingSwitchCameraId != -1) return;
4112
4113 mPendingSwitchCameraId = cameraId;
Doris Liu6432cd62013-06-13 17:20:31 -07004114
4115 Log.v(TAG, "Start to switch camera. cameraId=" + cameraId);
4116 // We need to keep a preview frame for the animation before
4117 // releasing the camera. This will trigger onPreviewTextureCopied.
4118 //TODO: Need to animate the camera switch
4119 switchCamera();
Michael Kolb8872c232013-01-29 10:33:22 -08004120 }
4121
Michael Kolb8872c232013-01-29 10:33:22 -08004122 // Preview texture has been copied. Now camera can be released and the
4123 // animation can be started.
4124 @Override
4125 public void onPreviewTextureCopied() {
4126 mHandler.sendEmptyMessage(SWITCH_CAMERA);
4127 }
4128
4129 @Override
4130 public void onCaptureTextureCopied() {
4131 }
4132
4133 @Override
4134 public void onUserInteraction() {
Dan Aminzade92ae10e2013-08-13 14:44:25 -07004135 if (!mActivity.isFinishing()) keepScreenOnAwhile();
Michael Kolb8872c232013-01-29 10:33:22 -08004136 }
4137
4138 private void resetScreenOn() {
4139 mHandler.removeMessages(CLEAR_SCREEN_DELAY);
4140 mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
4141 }
4142
4143 private void keepScreenOnAwhile() {
4144 mHandler.removeMessages(CLEAR_SCREEN_DELAY);
4145 mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
4146 mHandler.sendEmptyMessageDelayed(CLEAR_SCREEN_DELAY, SCREEN_DELAY);
4147 }
4148
Michael Kolb8872c232013-01-29 10:33:22 -08004149 @Override
4150 public void onOverriddenPreferencesClicked() {
4151 if (mPaused) return;
Michael Kolbd6954f32013-03-08 20:43:01 -08004152 mUI.showPreferencesToast();
Michael Kolb8872c232013-01-29 10:33:22 -08004153 }
4154
4155 private void showTapToFocusToast() {
4156 // TODO: Use a toast?
4157 new RotateTextToast(mActivity, R.string.tap_to_focus, 0).show();
4158 // Clear the preference.
4159 Editor editor = mPreferences.edit();
4160 editor.putBoolean(CameraSettings.KEY_CAMERA_FIRST_USE_HINT_SHOWN, false);
4161 editor.apply();
4162 }
4163
4164 private void initializeCapabilities() {
Angus Kongb50b5cb2013-08-09 14:55:20 -07004165 mFocusAreaSupported = CameraUtil.isFocusAreaSupported(mInitialParams);
4166 mMeteringAreaSupported = CameraUtil.isMeteringAreaSupported(mInitialParams);
4167 mAeLockSupported = CameraUtil.isAutoExposureLockSupported(mInitialParams);
4168 mAwbLockSupported = CameraUtil.isAutoWhiteBalanceLockSupported(mInitialParams);
Angus Kongdcccc512013-08-08 17:06:03 -07004169 mContinuousFocusSupported = mInitialParams.getSupportedFocusModes().contains(
Angus Kongb50b5cb2013-08-09 14:55:20 -07004170 CameraUtil.FOCUS_MODE_CONTINUOUS_PICTURE);
Michael Kolb8872c232013-01-29 10:33:22 -08004171 }
4172
Michael Kolb8872c232013-01-29 10:33:22 -08004173 @Override
4174 public void onCountDownFinished() {
4175 mSnapshotOnIdle = false;
4176 mFocusManager.doSnap();
Doris Liuda50e052013-02-07 14:36:32 -08004177 mFocusManager.onShutterUp();
Likai Ding4b5db0d2014-05-28 14:36:23 +08004178 mUI.overrideSettings(CameraSettings.KEY_ZSL, null);
Michael Kolb8872c232013-01-29 10:33:22 -08004179 }
4180
Michael Kolb8872c232013-01-29 10:33:22 -08004181 @Override
Michael Kolb8872c232013-01-29 10:33:22 -08004182 public void onShowSwitcherPopup() {
Michael Kolbd6954f32013-03-08 20:43:01 -08004183 mUI.onShowSwitcherPopup();
Michael Kolb8872c232013-01-29 10:33:22 -08004184 }
4185
Angus Kongce5480e2013-01-29 17:43:48 -08004186 @Override
Michael Kolbd6954f32013-03-08 20:43:01 -08004187 public int onZoomChanged(int index) {
4188 // Not useful to change zoom value when the activity is paused.
4189 if (mPaused) return index;
4190 mZoomValue = index;
4191 if (mParameters == null || mCameraDevice == null) return index;
4192 // Set zoom parameters asynchronously
4193 mParameters.setZoom(mZoomValue);
Angus Kong36ed8672013-04-15 12:11:15 -07004194 mCameraDevice.setParameters(mParameters);
Michael Kolbd6954f32013-03-08 20:43:01 -08004195 Parameters p = mCameraDevice.getParameters();
4196 if (p != null) return p.getZoom();
4197 return index;
Angus Kongce5480e2013-01-29 17:43:48 -08004198 }
4199
4200 @Override
Michael Kolbd6954f32013-03-08 20:43:01 -08004201 public int getCameraState() {
4202 return mCameraState;
4203 }
4204
4205 @Override
4206 public void onQueueStatus(boolean full) {
4207 mUI.enableShutter(!full);
Angus Kongce5480e2013-01-29 17:43:48 -08004208 }
Angus Kong86d36312013-01-31 18:22:44 -08004209
4210 @Override
4211 public void onMediaSaveServiceConnected(MediaSaveService s) {
4212 // We set the listener only when both service and shutterbutton
4213 // are initialized.
Michael Kolbd6954f32013-03-08 20:43:01 -08004214 if (mFirstTimeInitialized) {
4215 s.setListener(this);
4216 }
Angus Kong86d36312013-01-31 18:22:44 -08004217 }
Angus Kong0d00a892013-03-26 11:40:40 -07004218
4219 @Override
4220 public void onAccuracyChanged(Sensor sensor, int accuracy) {
4221 }
4222
4223 @Override
4224 public void onSensorChanged(SensorEvent event) {
4225 int type = event.sensor.getType();
4226 float[] data;
4227 if (type == Sensor.TYPE_ACCELEROMETER) {
4228 data = mGData;
4229 } else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
4230 data = mMData;
4231 } else {
4232 // we should not be here.
4233 return;
4234 }
4235 for (int i = 0; i < 3 ; i++) {
4236 data[i] = event.values[i];
4237 }
4238 float[] orientation = new float[3];
4239 SensorManager.getRotationMatrix(mR, null, mGData, mMData);
4240 SensorManager.getOrientation(mR, orientation);
4241 mHeading = (int) (orientation[0] * 180f / Math.PI) % 360;
4242 if (mHeading < 0) {
4243 mHeading += 360;
4244 }
Angus Kong0d00a892013-03-26 11:40:40 -07004245 }
Doris Liu6432cd62013-06-13 17:20:31 -07004246 @Override
ztenghui7b265a62013-09-09 14:58:44 -07004247 public void onPreviewFocusChanged(boolean previewFocused) {
4248 mUI.onPreviewFocusChanged(previewFocused);
Doris Liu6432cd62013-06-13 17:20:31 -07004249 }
Manish Kumara9942e82013-10-30 19:55:01 +05304250 // TODO: Delete this function after old camera code is removed
Doris Liu6432cd62013-06-13 17:20:31 -07004251 @Override
4252 public void onRestorePreferencesClicked() {}
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304253 private void setSkinToneFactor() {
4254 if(mCameraDevice == null || mParameters == null || skinToneSeekBar == null)
4255 return;
Doris Liu6432cd62013-06-13 17:20:31 -07004256
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304257 String skinToneEnhancementPref = "enable";
4258 if(CameraUtil.isSupported(skinToneEnhancementPref,
4259 mParameters.getSupportedSkinToneEnhancementModes())) {
4260 if(skinToneEnhancementPref.equals("enable")) {
4261 int skinToneValue =0;
4262 int progress;
4263 //get the value for the first time!
4264 if (mskinToneValue ==0) {
4265 String factor = mPreferences.getString(
4266 CameraSettings.KEY_SKIN_TONE_ENHANCEMENT_FACTOR, "0");
4267 skinToneValue = Integer.parseInt(factor);
4268 }
4269
4270 Log.v(TAG, "Skin tone bar: enable = " + mskinToneValue);
4271 enableSkinToneSeekBar();
4272 //As a wrokaround set progress again to show the actually progress on screen.
4273 if (skinToneValue != 0) {
4274 progress = (skinToneValue/SCE_FACTOR_STEP)-MIN_SCE_FACTOR;
4275 skinToneSeekBar.setProgress(progress);
4276 }
4277 } else {
4278 Log.v(TAG, "Skin tone bar: disable");
4279 disableSkinToneSeekBar();
4280 }
4281 } else {
4282 Log.v(TAG, "Skin tone bar: Not supported");
4283 skinToneSeekBar.setVisibility(View.INVISIBLE);
4284 }
4285 }
4286
4287 private void enableSkinToneSeekBar() {
4288 int progress;
4289 if(brightnessProgressBar != null)
4290 brightnessProgressBar.setVisibility(View.INVISIBLE);
4291 skinToneSeekBar.setMax(MAX_SCE_FACTOR-MIN_SCE_FACTOR);
4292 skinToneSeekBar.setVisibility(View.VISIBLE);
4293 skinToneSeekBar.requestFocus();
4294 if (mskinToneValue != 0) {
4295 progress = (mskinToneValue/SCE_FACTOR_STEP)-MIN_SCE_FACTOR;
4296 mskinToneSeekListener.onProgressChanged(skinToneSeekBar, progress, false);
4297 } else {
4298 progress = (MAX_SCE_FACTOR-MIN_SCE_FACTOR)/2;
4299 RightValue.setText("");
4300 LeftValue.setText("");
4301 }
4302 skinToneSeekBar.setProgress(progress);
Manish Kumara9942e82013-10-30 19:55:01 +05304303 mActivity.findViewById(R.id.linear).bringToFront();
4304 skinToneSeekBar.bringToFront();
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304305 Title.setText("Skin Tone Enhancement");
4306 Title.setVisibility(View.VISIBLE);
4307 RightValue.setVisibility(View.VISIBLE);
4308 LeftValue.setVisibility(View.VISIBLE);
4309 mSkinToneSeekBar = true;
4310 }
4311
4312 private void disableSkinToneSeekBar() {
4313 skinToneSeekBar.setVisibility(View.INVISIBLE);
4314 Title.setVisibility(View.INVISIBLE);
4315 RightValue.setVisibility(View.INVISIBLE);
4316 LeftValue.setVisibility(View.INVISIBLE);
4317 mskinToneValue = 0;
4318 mSkinToneSeekBar = false;
4319 Editor editor = mPreferences.edit();
4320 editor.putString(CameraSettings.KEY_SKIN_TONE_ENHANCEMENT_FACTOR,
4321 Integer.toString(mskinToneValue - MIN_SCE_FACTOR));
4322 editor.apply();
Suman Mukherjee752bc162014-04-28 10:36:56 +05304323 if ((brightnessProgressBar != null) && mBrightnessVisible)
Likai Ding546ba362014-11-21 01:52:54 +08004324 brightnessProgressBar.setVisibility(View.VISIBLE);
Manish Kumara9942e82013-10-30 19:55:01 +05304325}
4326
4327/*
4328 * Provide a mapping for Jpeg encoding quality levels
4329 * from String representation to numeric representation.
4330 */
4331 @Override
4332 public boolean arePreviewControlsVisible() {
4333 return mUI.arePreviewControlsVisible();
4334 }
4335
4336 // For debugging only.
4337 public void setDebugUri(Uri uri) {
4338 mDebugUri = uri;
4339 }
4340
4341 // For debugging only.
4342 private void saveToDebugUri(byte[] data) {
4343 if (mDebugUri != null) {
4344 OutputStream outputStream = null;
4345 try {
4346 outputStream = mContentResolver.openOutputStream(mDebugUri);
4347 outputStream.write(data);
4348 outputStream.close();
4349 } catch (IOException e) {
4350 Log.e(TAG, "Exception while writing debug jpeg file", e);
4351 } finally {
4352 CameraUtil.closeSilently(outputStream);
4353 }
4354 }
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304355 }
4356}
Manish Kumara9942e82013-10-30 19:55:01 +05304357
4358/* Below is no longer needed, except to get rid of compile error
4359 * TODO: Remove these
4360 */
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304361class JpegEncodingQualityMappings {
4362 private static final String TAG = "JpegEncodingQualityMappings";
4363 private static final int DEFAULT_QUALITY = 85;
4364 private static HashMap<String, Integer> mHashMap =
4365 new HashMap<String, Integer>();
4366
4367 static {
4368 mHashMap.put("normal", CameraProfile.QUALITY_LOW);
4369 mHashMap.put("fine", CameraProfile.QUALITY_MEDIUM);
4370 mHashMap.put("superfine", CameraProfile.QUALITY_HIGH);
4371 }
4372
4373 // Retrieve and return the Jpeg encoding quality number
4374 // for the given quality level.
4375 public static int getQualityNumber(String jpegQuality) {
4376 try{
4377 int qualityPercentile = Integer.parseInt(jpegQuality);
4378 if(qualityPercentile >= 0 && qualityPercentile <=100)
4379 return qualityPercentile;
4380 else
4381 return DEFAULT_QUALITY;
4382 } catch(NumberFormatException nfe){
4383 //chosen quality is not a number, continue
4384 }
4385 Integer quality = mHashMap.get(jpegQuality);
4386 if (quality == null) {
4387 Log.w(TAG, "Unknown Jpeg quality: " + jpegQuality);
4388 return DEFAULT_QUALITY;
4389 }
4390 return CameraProfile.getJpegEncodingQualityParameter(quality.intValue());
4391 }
4392}
4393
4394class GraphView extends View {
Vijay kumar Tumati535a39dd2014-06-17 21:10:33 +05304395 private Bitmap mBitmap;
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304396 private Paint mPaint = new Paint();
4397 private Paint mPaintRect = new Paint();
4398 private Canvas mCanvas = new Canvas();
4399 private float mScale = (float)3;
4400 private float mWidth;
4401 private float mHeight;
4402 private PhotoModule mPhotoModule;
4403 private CameraManager.CameraProxy mGraphCameraDevice;
4404 private float scaled;
4405 private static final int STATS_SIZE = 256;
4406 private static final String TAG = "GraphView";
4407
4408
4409 public GraphView(Context context, AttributeSet attrs) {
4410 super(context,attrs);
4411
4412 mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
4413 mPaintRect.setColor(0xFFFFFFFF);
4414 mPaintRect.setStyle(Paint.Style.FILL);
4415 }
4416 @Override
4417 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
4418 mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
4419 mCanvas.setBitmap(mBitmap);
4420 mWidth = w;
4421 mHeight = h;
4422 super.onSizeChanged(w, h, oldw, oldh);
4423 }
4424 @Override
4425 protected void onDraw(Canvas canvas) {
4426 Log.v(TAG, "in Camera.java ondraw");
Alok Kediya0dc64ff2013-09-27 20:22:45 +05304427 if(mPhotoModule == null || !mPhotoModule.mHiston ) {
4428 Log.e(TAG, "returning as histogram is off ");
4429 return;
4430 }
4431
4432 if (mBitmap != null) {
4433 final Paint paint = mPaint;
4434 final Canvas cavas = mCanvas;
4435 final float border = 5;
4436 float graphheight = mHeight - (2 * border);
4437 float graphwidth = mWidth - (2 * border);
4438 float left,top,right,bottom;
4439 float bargap = 0.0f;
4440 float barwidth = graphwidth/STATS_SIZE;
4441
4442 cavas.drawColor(0xFFAAAAAA);
4443 paint.setColor(Color.BLACK);
4444
4445 for (int k = 0; k <= (graphheight /32) ; k++) {
4446 float y = (float)(32 * k)+ border;
4447 cavas.drawLine(border, y, graphwidth + border , y, paint);
4448 }
4449 for (int j = 0; j <= (graphwidth /32); j++) {
4450 float x = (float)(32 * j)+ border;
4451 cavas.drawLine(x, border, x, graphheight + border, paint);
4452 }
4453 synchronized(PhotoModule.statsdata) {
4454 //Assumption: The first element contains
4455 // the maximum value.
4456 int maxValue = Integer.MIN_VALUE;
4457 if ( 0 == PhotoModule.statsdata[0] ) {
4458 for ( int i = 1 ; i <= STATS_SIZE ; i++ ) {
4459 if ( maxValue < PhotoModule.statsdata[i] ) {
4460 maxValue = PhotoModule.statsdata[i];
4461 }
4462 }
4463 } else {
4464 maxValue = PhotoModule.statsdata[0];
4465 }
4466 mScale = ( float ) maxValue;
4467 for(int i=1 ; i<=STATS_SIZE ; i++) {
4468 scaled = (PhotoModule.statsdata[i]/mScale)*STATS_SIZE;
4469 if(scaled >= (float)STATS_SIZE)
4470 scaled = (float)STATS_SIZE;
4471 left = (bargap * (i+1)) + (barwidth * i) + border;
4472 top = graphheight + border;
4473 right = left + barwidth;
4474 bottom = top - scaled;
4475 cavas.drawRect(left, top, right, bottom, mPaintRect);
4476 }
4477 }
4478 canvas.drawBitmap(mBitmap, 0, 0, null);
4479 }
4480 if (mPhotoModule.mHiston && mPhotoModule!= null) {
4481 mGraphCameraDevice = mPhotoModule.getCamera();
4482 if (mGraphCameraDevice != null){
4483 mGraphCameraDevice.sendHistogramData();
4484 }
4485 }
4486 }
4487 public void PreviewChanged() {
4488 invalidate();
4489 }
4490 public void setPhotoModuleObject(PhotoModule photoModule) {
4491 mPhotoModule = photoModule;
4492 }
Michael Kolb8872c232013-01-29 10:33:22 -08004493}
Abhishek Pantcb4748b2013-12-04 15:51:48 +05304494
4495class DrawAutoHDR extends View{
4496
4497 private static final String TAG = "AutoHdrView";
4498 private PhotoModule mPhotoModule;
4499
4500 public DrawAutoHDR (Context context, AttributeSet attrs) {
4501 super(context,attrs);
4502 }
4503
4504 @Override
4505 protected void onDraw (Canvas canvas) {
4506 if (mPhotoModule == null)
4507 return;
4508 if (mPhotoModule.mAutoHdrEnable) {
4509 Paint AutoHDRPaint = new Paint();
4510 AutoHDRPaint.setColor(Color.WHITE);
4511 AutoHDRPaint.setAlpha (0);
4512 canvas.drawPaint(AutoHDRPaint);
4513 AutoHDRPaint.setStyle(Paint.Style.STROKE);
4514 AutoHDRPaint.setColor(Color.MAGENTA);
4515 AutoHDRPaint.setStrokeWidth(1);
4516 AutoHDRPaint.setTextSize(16);
4517 AutoHDRPaint.setAlpha (255);
4518 canvas.drawText("HDR On",200,100,AutoHDRPaint);
4519 }
4520 else {
4521 super.onDraw(canvas);
4522 return;
4523 }
4524 }
4525
4526 public void AutoHDR () {
4527 invalidate();
4528 }
4529
4530 public void setPhotoModuleObject (PhotoModule photoModule) {
4531 mPhotoModule = photoModule;
4532 }
4533
4534}