summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/Camera.java
diff options
context:
space:
mode:
authorChung-yih Wang <cywang@google.com>2011-10-14 16:48:02 +0800
committerChung-yih Wang <cywang@google.com>2011-10-14 21:57:25 +0800
commit6bfe6df5ea40684d56f4736da76b5680515f05ae (patch)
tree9e1fc2c7d4523524d7c5118dafd548902eacff83 /src/com/android/camera/Camera.java
parent6baaa42a5bb88fdae55efa8dc6b7805b187f1d02 (diff)
downloadLegacyCamera-6bfe6df5ea40684d56f4736da76b5680515f05ae.zip
LegacyCamera-6bfe6df5ea40684d56f4736da76b5680515f05ae.tar.gz
LegacyCamera-6bfe6df5ea40684d56f4736da76b5680515f05ae.tar.bz2
Improve the launch time.
bug:5446617 Since there are two major blocking operations(openCamera and startPreview) which are dependent and time-consuming, we have to take advantage of this blocking intervals to do the layout inflation(setContentView) and indicator initialization concurrently to reduce the launch time. Change-Id: Ibbc3563ad3e8ccea409f61a5af9a8bdae0352579
Diffstat (limited to 'src/com/android/camera/Camera.java')
-rw-r--r--src/com/android/camera/Camera.java126
1 files changed, 80 insertions, 46 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java
index f9a3687..79ab74f 100644
--- a/src/com/android/camera/Camera.java
+++ b/src/com/android/camera/Camera.java
@@ -985,9 +985,49 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
return true;
}
+ private void getPreferredCameraId() {
+ mPreferences = new ComboPreferences(this);
+ CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal());
+ mCameraId = CameraSettings.readPreferredCameraId(mPreferences);
+
+ // Testing purpose. Launch a specific camera through the intent extras.
+ int intentCameraId = Util.getCameraFacingIntentExtras(this);
+ if (intentCameraId != -1) {
+ mCameraId = intentCameraId;
+ }
+ }
+
+ Thread mCameraOpenThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ mCameraDevice = Util.openCamera(Camera.this, mCameraId);
+ } catch (CameraHardwareException e) {
+ mOpenCameraFail = true;
+ } catch (CameraDisabledException e) {
+ mCameraDisabled = true;
+ }
+ }
+ });
+
+ Thread mCameraPreviewThread = new Thread(new Runnable() {
+ public void run() {
+ initializeCapabilities();
+ startPreview();
+ }
+ });
+
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ getPreferredCameraId();
+ mFocusManager = new FocusManager(mPreferences,
+ getString(R.string.pref_camera_focusmode_default));
+
+ /*
+ * To reduce startup time, we start the camera open and preview threads.
+ * We make sure the preview is started at the end of onCreate.
+ */
+ mCameraOpenThread.start();
mIsImageCaptureIntent = isImageCaptureIntent();
setContentView(R.layout.camera);
@@ -1000,19 +1040,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
mThumbnailView.setVisibility(View.VISIBLE);
}
- mPreferences = new ComboPreferences(this);
- CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal());
- mFocusManager = new FocusManager(mPreferences,
- getString(R.string.pref_camera_focusmode_default));
-
- mCameraId = CameraSettings.readPreferredCameraId(mPreferences);
-
- // Testing purpose. Launch a specific camera through the intent extras.
- int intentCameraId = Util.getCameraFacingIntentExtras(this);
- if (intentCameraId != -1) {
- mCameraId = intentCameraId;
- }
-
mPreferences.setLocalId(this, mCameraId);
CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
@@ -1022,25 +1049,6 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
// we need to reset exposure for the preview
resetExposureCompensation();
- /*
- * To reduce startup time, we start the preview in another thread.
- * We make sure the preview is started at the end of onCreate.
- */
- Thread startPreviewThread = new Thread(new Runnable() {
- public void run() {
- try {
- mCameraDevice = Util.openCamera(Camera.this, mCameraId);
- initializeCapabilities();
- startPreview();
- } catch (CameraHardwareException e) {
- mOpenCameraFail = true;
- } catch (CameraDisabledException e) {
- mCameraDisabled = true;
- }
- }
- });
- startPreviewThread.start();
-
Util.enterLightsOutMode(getWindow());
// don't set mSurfaceHolder here. We have it set ONLY within
@@ -1051,21 +1059,10 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- if (mIsImageCaptureIntent) {
- setupCaptureParams();
- } else {
- mModePicker = (ModePicker) findViewById(R.id.mode_picker);
- mModePicker.setVisibility(View.VISIBLE);
- mModePicker.setOnModeChangeListener(this);
- mModePicker.setCurrentMode(ModePicker.MODE_CAMERA);
- }
-
- mZoomControl = (ZoomControl) findViewById(R.id.zoom_control);
- mLocationManager = new LocationManager(this, this);
-
- // Make sure preview is started.
+ // Make sure camera device is opened.
try {
- startPreviewThread.join();
+ mCameraOpenThread.join();
+ mCameraOpenThread = null;
if (mOpenCameraFail) {
Util.showErrorAndFinish(this, R.string.cannot_connect_camera);
return;
@@ -1076,13 +1073,43 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
} catch (InterruptedException ex) {
// ignore
}
+ mCameraPreviewThread.start();
+
+ if (mIsImageCaptureIntent) {
+ setupCaptureParams();
+ } else {
+ mModePicker = (ModePicker) findViewById(R.id.mode_picker);
+ mModePicker.setVisibility(View.VISIBLE);
+ mModePicker.setOnModeChangeListener(this);
+ mModePicker.setCurrentMode(ModePicker.MODE_CAMERA);
+ }
+
+ mZoomControl = (ZoomControl) findViewById(R.id.zoom_control);
+ mLocationManager = new LocationManager(this, this);
mBackCameraId = CameraHolder.instance().getBackCameraId();
mFrontCameraId = CameraHolder.instance().getFrontCameraId();
+ // Wait until the camera settings are retrieved.
+ synchronized (mCameraPreviewThread) {
+ try {
+ mCameraPreviewThread.wait();
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ }
+
// Do this after starting preview because it depends on camera
// parameters.
initializeIndicatorControl();
+
+ // Make sure preview is started.
+ try {
+ mCameraPreviewThread.join();
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+ mCameraPreviewThread = null;
}
private void overrideCameraSettings(final String flashMode,
@@ -1719,6 +1746,13 @@ public class Camera extends ActivityBase implements FocusManager.Listener,
mCameraDevice.cancelAutoFocus();
}
+ // Inform the mainthread to go on the UI initialization.
+ if (mCameraPreviewThread != null) {
+ synchronized (mCameraPreviewThread) {
+ mCameraPreviewThread.notify();
+ }
+ }
+
try {
Log.v(TAG, "startPreview");
mCameraDevice.startPreview();