summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorByunghun Jeon <bjeon@codeaurora.org>2016-02-10 11:47:29 -0800
committerSteve Kondik <steve@cyngn.com>2016-08-21 18:45:51 -0700
commit2e1de0b787020d6901d5b08d0ba615793f7e98a7 (patch)
treefcbbef7661c830a2a69553664a4032aa11c8b9c3
parenta89fa03de39f2f44ae2f116d56eed56b456cbcd9 (diff)
downloadandroid_packages_apps_Snap-2e1de0b787020d6901d5b08d0ba615793f7e98a7.zip
android_packages_apps_Snap-2e1de0b787020d6901d5b08d0ba615793f7e98a7.tar.gz
android_packages_apps_Snap-2e1de0b787020d6901d5b08d0ba615793f7e98a7.tar.bz2
SnapdragonCamera: Camera2 add dual camera
Add Camera2 dual camera support to SnapdragonCamera CRs-Fixed: 989750 Change-Id: I45a749ad03a531286a39cbfcfdcb65e5cad4759e
-rw-r--r--AndroidManifest.xml2
-rw-r--r--res/layout/capture_module.xml4
-rw-r--r--res/values/qcomarrays.xml10
-rw-r--r--res/values/qcomstrings.xml46
-rw-r--r--res/xml/camera_preferences.xml7
-rw-r--r--src/com/android/camera/CameraActivity.java4
-rw-r--r--src/com/android/camera/CameraSettings.java1
-rw-r--r--src/com/android/camera/CaptureMenu.java47
-rw-r--r--src/com/android/camera/CaptureModule.java285
-rw-r--r--src/com/android/camera/CaptureUI.java18
10 files changed, 305 insertions, 119 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 57aedb1..6a5d68e 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -5,7 +5,7 @@
package="org.codeaurora.snapcam">
<uses-sdk
- android:minSdkVersion="21"
+ android:minSdkVersion="23"
android:targetSdkVersion="23" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
diff --git a/res/layout/capture_module.xml b/res/layout/capture_module.xml
index 2715dcb..02c32ac 100644
--- a/res/layout/capture_module.xml
+++ b/res/layout/capture_module.xml
@@ -40,8 +40,8 @@
<SurfaceView
android:id="@+id/mdp_preview_content2"
- android:layout_width="100dp"
- android:layout_height="100dp" />
+ android:layout_width="300dp"
+ android:layout_height="300dp" />
</FrameLayout>
<View
diff --git a/res/values/qcomarrays.xml b/res/values/qcomarrays.xml
index 5417195..b80d0fd 100644
--- a/res/values/qcomarrays.xml
+++ b/res/values/qcomarrays.xml
@@ -845,4 +845,14 @@
<item>@string/pref_camera_dual_camera_value_bayer</item>
<item>@string/pref_camera_dual_camera_value_mono</item>
</string-array>
+
+ <string-array name="pref_camera_mono_preview_entries" translatable="true">
+ <item>@string/pref_camera_mono_preview_entry_on</item>
+ <item>@string/pref_camera_mono_preview_entry_off</item>
+ </string-array>
+
+ <string-array name="pref_camera_mono_preview_entryvalues" translatable="false">
+ <item>@string/pref_camera_mono_preview_value_on</item>
+ <item>@string/pref_camera_mono_preview_value_off</item>
+ </string-array>
</resources>
diff --git a/res/values/qcomstrings.xml b/res/values/qcomstrings.xml
index b1c9b41..d8b6b6c 100644
--- a/res/values/qcomstrings.xml
+++ b/res/values/qcomstrings.xml
@@ -512,25 +512,6 @@
<!-- Toast after SeeMore has been enabled to show TNR is disabled -->
<string name="disable_TNR_during_SeeMore">Enabling SeeMore will disable TNR</string>
- <string name="pref_camera_camera2_title">Camera2 Mode</string>
- <string name="pref_camera_camera2_default">disable</string>
- <string name="pref_camera_camera2_entry_enable">Enable</string>
- <string name="pref_camera_camera2_entry_disable">Disable</string>
-
- <string name="pref_camera_camera2_value_enable">enable</string>
- <string name="pref_camera_camera2_value_disable">disable</string>
-
-
- <string name="pref_camera_dual_camera_title">Dual Camera Mode</string>
- <string name="pref_camera_dual_camera_default">bayer</string>
- <string name="pref_camera_dual_camera_entry_dual">Dual-camera Linked</string>
- <string name="pref_camera_dual_camera_entry_bayer">Single Bayer Camera</string>
- <string name="pref_camera_dual_camera_entry_mono">Single Mono Camera</string>
-
- <string name="pref_camera_dual_camera_value_dual">dual</string>
- <string name="pref_camera_dual_camera_value_bayer">bayer</string>
- <string name="pref_camera_dual_camera_value_mono">mono</string>
-
<!-- TODO: Remove these? -->
<string name="pref_camera_redeyereduction_entry_disable" translatable="false">disable</string>
@@ -551,4 +532,31 @@
<string name="pref_camera_manual_exp_value_user_setting" translatable="false">user-setting</string>
<string name="pref_camera_dis_value_disable" translatable="false">disable</string>
+
+ <string name="pref_camera_camera2_title">Camera2 Mode</string>
+ <string name="pref_camera_camera2_default">disable</string>
+ <string name="pref_camera_camera2_entry_enable">Enable</string>
+ <string name="pref_camera_camera2_entry_disable">Disable</string>
+
+ <string name="pref_camera_camera2_value_enable">enable</string>
+ <string name="pref_camera_camera2_value_disable">disable</string>
+
+ <string name="pref_camera_dual_camera_title">Dual Camera Mode</string>
+ <string name="pref_camera_dual_camera_default">dual</string>
+ <string name="pref_camera_dual_camera_entry_dual">Dual-camera Linked</string>
+ <string name="pref_camera_dual_camera_entry_bayer">Single Bayer Camera</string>
+ <string name="pref_camera_dual_camera_entry_mono">Single Mono Camera</string>
+
+ <string name="pref_camera_dual_camera_value_dual">dual</string>
+ <string name="pref_camera_dual_camera_value_bayer">bayer</string>
+ <string name="pref_camera_dual_camera_value_mono">mono</string>
+
+ <string name="pref_camera_mono_preview_title">Mono Preview</string>
+ <string name="pref_camera_mono_preview_default">off</string>
+ <string name="pref_camera_mono_preview_entry_on">On</string>
+ <string name="pref_camera_mono_preview_entry_off">Off</string>
+
+ <string name="pref_camera_mono_preview_value_on">on</string>
+ <string name="pref_camera_mono_preview_value_off">off</string>
+
</resources>
diff --git a/res/xml/camera_preferences.xml b/res/xml/camera_preferences.xml
index 4920ef1..e2d749f 100644
--- a/res/xml/camera_preferences.xml
+++ b/res/xml/camera_preferences.xml
@@ -377,4 +377,11 @@
camera:title="@string/pref_camera_dual_camera_title"
camera:entries="@array/pref_camera_dual_camera_entries"
camera:entryValues="@array/pref_camera_dual_camera_entryvalues" />
+
+ <ListPreference
+ camera:key="pref_camera_mono_preview_key"
+ camera:defaultValue="@string/pref_camera_mono_preview_default"
+ camera:title="@string/pref_camera_mono_preview_title"
+ camera:entries="@array/pref_camera_mono_preview_entries"
+ camera:entryValues="@array/pref_camera_mono_preview_entryvalues" />
</PreferenceGroup>
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java
index 0270b28..19c80a7 100644
--- a/src/com/android/camera/CameraActivity.java
+++ b/src/com/android/camera/CameraActivity.java
@@ -2019,7 +2019,9 @@ public class CameraActivity extends Activity
public void onModuleSelected(int moduleIndex) {
if (moduleIndex == 0 && CAMERA_2_ON) moduleIndex = ModuleSwitcher.CAPTURE_MODULE_INDEX;
if (mCurrentModuleIndex == moduleIndex) {
- return;
+ if (mCurrentModuleIndex != ModuleSwitcher.CAPTURE_MODULE_INDEX) {
+ return;
+ }
}
CameraHolder.instance().keep();
closeModule(mCurrentModule);
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java
index ea02d87..f2058ab 100644
--- a/src/com/android/camera/CameraSettings.java
+++ b/src/com/android/camera/CameraSettings.java
@@ -245,6 +245,7 @@ public class CameraSettings {
public static final String KEY_CAMERA2 = "pref_camera_camera2_key";
public static final String KEY_DUAL_CAMERA = "pref_camera_dual_camera_key";
+ public static final String KEY_MONO_PREVIEW = "pref_camera_mono_preview_key";
public static final String KEY_SELFIE_FLASH = "pref_selfie_flash_key";
diff --git a/src/com/android/camera/CaptureMenu.java b/src/com/android/camera/CaptureMenu.java
index dbc8132..2c5fed1 100644
--- a/src/com/android/camera/CaptureMenu.java
+++ b/src/com/android/camera/CaptureMenu.java
@@ -26,6 +26,7 @@ import android.content.SharedPreferences;
import android.graphics.Rect;
import android.preference.PreferenceManager;
import android.text.TextUtils;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -92,13 +93,15 @@ public class CaptureMenu extends MenuController
mOtherKeys1 = new String[]{
CameraSettings.KEY_FLASH_MODE,
CameraSettings.KEY_CAMERA2,
- CameraSettings.KEY_DUAL_CAMERA
+ CameraSettings.KEY_DUAL_CAMERA,
+ CameraSettings.KEY_MONO_PREVIEW
};
mOtherKeys2 = new String[]{
CameraSettings.KEY_FLASH_MODE,
CameraSettings.KEY_CAMERA2,
- CameraSettings.KEY_DUAL_CAMERA
+ CameraSettings.KEY_DUAL_CAMERA,
+ CameraSettings.KEY_MONO_PREVIEW
};
}
@@ -106,9 +109,8 @@ public class CaptureMenu extends MenuController
@Override
// Hit when an item in a popup gets selected
public void onListPrefChanged(ListPreference pref) {
- animateFadeOut(mListSubMenu, 2);
onSettingChanged(pref);
- ((ListMenu) mListMenu).resetHighlight();
+ closeView();
}
public boolean handleBackKey() {
@@ -384,6 +386,12 @@ public class CaptureMenu extends MenuController
listMenu.initialize(mPreferenceGroup, keys);
mListMenu = listMenu;
+ ListPreference pref = mPreferenceGroup.findPreference(CameraSettings.KEY_DUAL_CAMERA);
+ if (!pref.getValue().equals("dual")) {
+ setPreference(CameraSettings.KEY_MONO_PREVIEW, "off");
+ mListMenu.setPreferenceEnabled(CameraSettings.KEY_MONO_PREVIEW, false);
+ }
+
if (mListener != null) {
mListener.onSharedPreferenceChanged();
}
@@ -516,18 +524,29 @@ public class CaptureMenu extends MenuController
@Override
public void onSettingChanged(ListPreference pref) {
super.onSettingChanged(pref);
- if (same(pref, CameraSettings.KEY_CAMERA2, "enable")) {
- SharedPreferences prefs = PreferenceManager
- .getDefaultSharedPreferences(mActivity);
- prefs.edit().putBoolean(CameraSettings.KEY_CAMERA2, true).apply();
- CameraActivity.CAMERA_2_ON = true;
- mActivity.onModuleSelected(ModuleSwitcher.CAPTURE_MODULE_INDEX);
- } else if (notSame(pref, CameraSettings.KEY_CAMERA2, "enable")) {
+ String key = pref.getKey();
+ String value = pref.getValue();
+ Log.d(TAG, "" + key + " " + value);
+ //Todo: restructure by using switch and create function for each case
+ if (key.equals(CameraSettings.KEY_CAMERA2)) {
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(mActivity);
- prefs.edit().putBoolean(CameraSettings.KEY_CAMERA2, false).apply();
- CameraActivity.CAMERA_2_ON = false;
- mActivity.onModuleSelected(ModuleSwitcher.PHOTO_MODULE_INDEX);
+ if (value.equals("enable")) {
+ prefs.edit().putBoolean(CameraSettings.KEY_CAMERA2, true).apply();
+ CameraActivity.CAMERA_2_ON = true;
+ mActivity.onModuleSelected(ModuleSwitcher.CAPTURE_MODULE_INDEX);
+ } else if (value.equals("disable")) {
+ prefs.edit().putBoolean(CameraSettings.KEY_CAMERA2, false).apply();
+ CameraActivity.CAMERA_2_ON = false;
+ mActivity.onModuleSelected(ModuleSwitcher.PHOTO_MODULE_INDEX);
+ }
+ } else if (key.equals(CameraSettings.KEY_DUAL_CAMERA)) {
+ boolean changeMode = CaptureModule.setMode(value);
+ if (changeMode) mActivity.onModuleSelected(ModuleSwitcher.CAPTURE_MODULE_INDEX);
+ } else if (key.equals(CameraSettings.KEY_MONO_PREVIEW)) {
+ if (value.equals("on")) {
+ } else if (value.equals("off")) {
+ }
}
}
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 604a705..555c2e3 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -42,6 +42,8 @@ import android.media.ImageReader;
import android.net.Uri;
import android.os.Handler;
import android.os.HandlerThread;
+import android.os.Looper;
+import android.os.Message;
import android.util.Log;
import android.util.Size;
import android.util.SparseIntArray;
@@ -66,7 +68,11 @@ import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class CaptureModule implements CameraModule, PhotoController {
- private static final int NUMCAM = 1;
+ public static final int DUAL_MODE = 0;
+ public static final int BAYER_MODE = 1;
+ public static final int MONO_MODE = 2;
+ private static final int OPEN_CAMERA = 0;
+ private static final int MAX_NUM_CAM = 3;
/**
* Conversion from screen rotation to JPEG orientation.
*/
@@ -91,7 +97,11 @@ public class CaptureModule implements CameraModule, PhotoController {
* Camera state: Picture was taken.
*/
private static final int STATE_PICTURE_TAKEN = 4;
+ //Todo: Read ids from the device dynamically
+ private static final int BAYER_ID = 0;
+ private static final int MONO_ID = 1;
private static final String TAG = "SnapCam_CaptureModule";
+ private static int MODE = DUAL_MODE;
static {
ORIENTATIONS.append(Surface.ROTATION_0, 90);
@@ -100,16 +110,17 @@ public class CaptureModule implements CameraModule, PhotoController {
ORIENTATIONS.append(Surface.ROTATION_270, 180);
}
+ private boolean mInitialized = false;
private long mCaptureStartTime;
private boolean mSurfaceReady = false;
- private boolean mCameraOpened = false;
- private CameraDevice[] mCameraDevice = new CameraDevice[NUMCAM];
- private String[] mCameraId = new String[NUMCAM];
+ private boolean[] mCameraOpened = new boolean[MAX_NUM_CAM];
+ private CameraDevice[] mCameraDevice = new CameraDevice[MAX_NUM_CAM];
+ private String[] mCameraId = new String[MAX_NUM_CAM];
private CaptureUI mUI;
private CameraActivity mActivity;
private PreferenceGroup mPreferenceGroup;
private ComboPreferences mPreferences;
- private CaptureRequest.Builder[] mCaptureBuilder = new CaptureRequest.Builder[NUMCAM];
+ private CaptureRequest.Builder[] mCaptureBuilder = new CaptureRequest.Builder[MAX_NUM_CAM];
private final CameraPreference.OnPreferenceChangedListener prefListener = new
CameraPreference.OnPreferenceChangedListener() {
@Override
@@ -137,7 +148,7 @@ public class CaptureModule implements CameraModule, PhotoController {
/**
* A {@link CameraCaptureSession } for camera preview.
*/
- private CameraCaptureSession[] mCaptureSession = new CameraCaptureSession[NUMCAM];
+ private CameraCaptureSession[] mCaptureSession = new CameraCaptureSession[MAX_NUM_CAM];
/**
* An additional thread for running tasks that shouldn't block the UI.
*/
@@ -153,7 +164,7 @@ public class CaptureModule implements CameraModule, PhotoController {
/**
* An {@link ImageReader} that handles still image capture.
*/
- private ImageReader[] mImageReader = new ImageReader[NUMCAM];
+ private ImageReader[] mImageReader = new ImageReader[MAX_NUM_CAM];
private NamedImages mNamedImages;
private ContentResolver mContentResolver;
private MediaSaveService.OnMediaSavedListener mOnMediaSavedListener =
@@ -174,6 +185,7 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onImageAvailable(ImageReader reader) {
+ Log.d(TAG, "image available");
mCaptureStartTime = System.currentTimeMillis();
mNamedImages.nameNewImage(mCaptureStartTime);
NamedEntity name = mNamedImages.getNextNameEntity();
@@ -182,30 +194,31 @@ public class CaptureModule implements CameraModule, PhotoController {
Image mImage = reader.acquireNextImage();
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
+ //Todo: dont create new buffer and use the one from ImageReader
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
mActivity.getMediaSaveService().addImage(
bytes, title, date, null, reader.getWidth(), reader.getHeight(),
0, null, mOnMediaSavedListener, mContentResolver, "jpeg");
+ mImage.close();
}
};
-
/**
* {@link CaptureRequest.Builder} for the camera preview
*/
- private CaptureRequest.Builder[] mPreviewRequestBuilder = new CaptureRequest.Builder[NUMCAM];
+ private CaptureRequest.Builder[] mPreviewRequestBuilder = new CaptureRequest.Builder[MAX_NUM_CAM];
/**
* {@link CaptureRequest} generated by {@link #mPreviewRequestBuilder}
*/
- private CaptureRequest[] mPreviewRequest = new CaptureRequest[NUMCAM];
+ private CaptureRequest[] mPreviewRequest = new CaptureRequest[MAX_NUM_CAM];
/**
* The current state of camera state for taking pictures.
*
* @see #mCaptureCallback
*/
- private int mState = STATE_PREVIEW;
+ private int[] mState = new int[MAX_NUM_CAM];
/**
* A {@link Semaphore} make sure the camera open callback happens first before closing the
* camera.
@@ -218,23 +231,26 @@ public class CaptureModule implements CameraModule, PhotoController {
= new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result) {
- switch (mState) {
+ int id = (int) result.getRequest().getTag();
+ switch (mState[id]) {
case STATE_PREVIEW: {
- // We have nothing to do when the camera preview is working normally.
break;
}
case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
- if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
+ Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+ if (afState == null) {
+ captureStillPicture(id);
+ } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// CONTROL_AE_STATE can be null on some devices
- Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
- mState = STATE_PICTURE_TAKEN;
- captureStillPicture(0);
+ mState[id] = STATE_PICTURE_TAKEN;
+ captureStillPicture(id);
} else {
- runPrecaptureSequence(0);
+ runPrecaptureSequence(id);
}
}
break;
@@ -245,7 +261,7 @@ public class CaptureModule implements CameraModule, PhotoController {
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
- mState = STATE_WAITING_NON_PRECAPTURE;
+ mState[id] = STATE_WAITING_NON_PRECAPTURE;
}
break;
}
@@ -253,8 +269,8 @@ public class CaptureModule implements CameraModule, PhotoController {
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
- mState = STATE_PICTURE_TAKEN;
- captureStillPicture(0);
+ mState[id] = STATE_PICTURE_TAKEN;
+ captureStillPicture(id);
}
break;
}
@@ -274,61 +290,91 @@ public class CaptureModule implements CameraModule, PhotoController {
TotalCaptureResult result) {
process(result);
}
-
};
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(CameraDevice cameraDevice) {
int id = Integer.parseInt(cameraDevice.getId());
-
+ Log.d(TAG, "onOpened " + id);
mCameraOpenCloseLock.release();
-
- PreferenceInflater inflater = new PreferenceInflater(mActivity);
- PreferenceGroup group =
- (PreferenceGroup) inflater.inflate(R.xml.camera_preferences);
- mPreferenceGroup = group;
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- mUI.onCameraOpened(mPreferenceGroup, prefListener);
- }
-
-
- });
+ if (MODE == DUAL_MODE && id == BAYER_ID) {
+ Message msg = Message.obtain();
+ msg.what = OPEN_CAMERA;
+ msg.arg1 = MONO_ID;
+ mCameraHandler.sendMessage(msg);
+ }
+ if (!mInitialized) {
+ mInitialized = true;
+ mActivity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mUI.onCameraOpened(mPreferenceGroup, prefListener);
+ }
+ });
+ }
mCameraDevice[id] = cameraDevice;
- mCameraOpened = true;
+ mCameraOpened[id] = true;
createSession(id);
}
@Override
public void onDisconnected(CameraDevice cameraDevice) {
- mCameraOpenCloseLock.release();
+ int id = Integer.parseInt(cameraDevice.getId());
+ Log.d(TAG, "onDisconnected " + id);
cameraDevice.close();
mCameraDevice = null;
+ mCameraOpenCloseLock.release();
}
@Override
public void onError(CameraDevice cameraDevice, int error) {
int id = Integer.parseInt(cameraDevice.getId());
- mCameraOpenCloseLock.release();
+ Log.d(TAG, "onError " + id + error);
cameraDevice.close();
- mCameraDevice = null;
+ mCameraDevice[id] = null;
+ mCameraOpenCloseLock.release();
if (null != mActivity) {
mActivity.finish();
}
}
+ @Override
+ public void onClosed(CameraDevice cameraDevice) {
+ int id = Integer.parseInt(cameraDevice.getId());
+ Log.d(TAG, "onClosed " + id);
+ mCameraDevice[id] = null;
+ mCameraOpenCloseLock.release();
+ }
+
};
+ public static boolean setMode(String value) {
+ int mode = DUAL_MODE;
+ switch (value) {
+ case "dual":
+ mode = DUAL_MODE;
+ break;
+ case "bayer":
+ mode = BAYER_MODE;
+ break;
+ case "mono":
+ mode = MONO_MODE;
+ break;
+ }
+ if (MODE == mode) return false;
+ MODE = mode;
+ return true;
+ }
+
private void createSession(final int id) {
- if (!mCameraOpened || !mSurfaceReady) return;
+ if (!mCameraOpened[id] || !mSurfaceReady) return;
List<Surface> list = new LinkedList<Surface>();
mUI.hidePreviewCover();
try {
Surface surface;
- if (id == 0) {
+ if (id == BAYER_ID || (id == MONO_ID && MODE == MONO_MODE)) {
SurfaceHolder sh = mUI.getSurfaceHolder();
if (sh == null) {
return;
@@ -345,6 +391,13 @@ public class CaptureModule implements CameraModule, PhotoController {
mPreviewRequestBuilder[id] = mCameraDevice[id].createCaptureRequest(CameraDevice
.TEMPLATE_PREVIEW);
mPreviewRequestBuilder[id].addTarget(surface);
+ // Auto focus should be continuous for camera preview.
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_MODE,
+ CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
+ // Flash is automatically enabled when necessary.
+ mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE,
+ CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
+ mPreviewRequestBuilder[id].setTag(id);
// This is the CaptureRequest.Builder that we use to take a picture.
mCaptureBuilder[id] =
@@ -372,18 +425,10 @@ public class CaptureModule implements CameraModule, PhotoController {
// When the session is ready, we start displaying the preview.
mCaptureSession[id] = cameraCaptureSession;
try {
- // Auto focus should be continuous for camera preview.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_MODE,
- CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
- // Flash is automatically enabled when necessary.
- mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE,
- CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
-
// Finally, we start displaying the camera preview.
mPreviewRequest[id] = mPreviewRequestBuilder[id].build();
mCaptureSession[id].setRepeatingRequest(mPreviewRequest[id],
mCaptureCallback, mCameraHandler);
- applyAllSettings(0);
} catch (CameraAccessException e) {
e.printStackTrace();
}
@@ -401,16 +446,31 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void init(CameraActivity activity, View parent) {
- mCameraOpened = false;
+ Log.d(TAG, "init");
+ for (int i = 0; i < MAX_NUM_CAM; i++) {
+ mCameraOpened[i] = false;
+ }
mSurfaceReady = false;
+
mActivity = activity;
+ for (int i = 0; i < MAX_NUM_CAM; i++) {
+ mState[i] = STATE_PREVIEW;
+ }
mPreferences = new ComboPreferences(mActivity);
CameraSettings.upgradeGlobalPreferences(mPreferences.getGlobal(), activity);
- mPreferences.setLocalId(mActivity, 0);
+ mPreferences.setLocalId(mActivity, BAYER_ID);
CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
+ PreferenceInflater inflater = new PreferenceInflater(mActivity);
+ PreferenceGroup group =
+ (PreferenceGroup) inflater.inflate(R.xml.camera_preferences);
+ mPreferenceGroup = group;
+
+ ListPreference pref = group.findPreference(CameraSettings.KEY_DUAL_CAMERA);
+ setMode(pref.getValue());
+
mContentResolver = mActivity.getContentResolver();
mUI = new CaptureUI(activity, this, parent);
mUI.initializeControlByIntent();
@@ -421,19 +481,32 @@ public class CaptureModule implements CameraModule, PhotoController {
* Initiate a still image capture.
*/
private void takePicture() {
- lockFocus(0);
+ Log.d(TAG, "takePicture");
+ switch (MODE) {
+ case DUAL_MODE:
+ lockFocus(BAYER_ID);
+ lockFocus(MONO_ID);
+ break;
+ case BAYER_MODE:
+ lockFocus(BAYER_ID);
+ break;
+ case MONO_MODE:
+ lockFocus(MONO_ID);
+ break;
+ }
}
/**
* Lock the focus as the first step for a still image capture.
*/
private void lockFocus(int id) {
+ Log.d(TAG, "lockFocus " + id);
try {
// This is how to tell the camera to lock focus.
mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
// Tell #mCaptureCallback to wait for the lock.
- mState = STATE_WAITING_LOCK;
+ mState[id] = STATE_WAITING_LOCK;
mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
mCameraHandler);
} catch (CameraAccessException e) {
@@ -446,6 +519,7 @@ public class CaptureModule implements CameraModule, PhotoController {
* {@link #mCaptureCallback} from both {@link #lockFocus()}.
*/
private void captureStillPicture(final int id) {
+ Log.d(TAG, "captureStillPicture " + id);
try {
if (null == mActivity || null == mCameraDevice) {
return;
@@ -467,11 +541,13 @@ public class CaptureModule implements CameraModule, PhotoController {
public void onCaptureCompleted(CameraCaptureSession session,
CaptureRequest request,
TotalCaptureResult result) {
+ Log.d(TAG, "captureStillPicture onCaptureCompleted");
}
@Override
public void onCaptureSequenceCompleted(CameraCaptureSession session, int
sequenceId, long frameNumber) {
+ Log.d(TAG, "captureStillPicture onCaptureSequenceCompleted");
unlockFocus(id);
}
@@ -493,7 +569,7 @@ public class CaptureModule implements CameraModule, PhotoController {
mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
// Tell #mCaptureCallback to wait for the precapture sequence to be set.
- mState = STATE_WAITING_PRECAPTURE;
+ mState[id] = STATE_WAITING_PRECAPTURE;
mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
mCameraHandler);
} catch (CameraAccessException e) {
@@ -512,7 +588,8 @@ public class CaptureModule implements CameraModule, PhotoController {
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
try {
String[] cameraIdList = manager.getCameraIdList();
- for (int i = 0; i < NUMCAM; i++) {
+
+ for (int i = 0; i < cameraIdList.length; i++) {
String cameraId = cameraIdList[i];
CameraCharacteristics characteristics
= manager.getCameraCharacteristics(cameraId);
@@ -529,11 +606,10 @@ public class CaptureModule implements CameraModule, PhotoController {
new CompareSizesByArea());
mImageReader[i] = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
- ImageFormat.JPEG, 10);
+ ImageFormat.JPEG, 3);
mImageReader[i].setOnImageAvailableListener(
mOnImageAvailableListener, mImageAvailableHandler);
mCameraId[i] = cameraId;
- //return;
}
} catch (CameraAccessException e) {
e.printStackTrace();
@@ -546,6 +622,7 @@ public class CaptureModule implements CameraModule, PhotoController {
* finished.
*/
private void unlockFocus(int id) {
+ Log.d(TAG, "unlockFocus " + id);
try {
// Reset the auto-focus trigger
mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_TRIGGER,
@@ -555,7 +632,7 @@ public class CaptureModule implements CameraModule, PhotoController {
mCaptureSession[id].capture(mPreviewRequestBuilder[id].build(), mCaptureCallback,
mCameraHandler);
// After this, the camera will go back to the normal state of preview.
- mState = STATE_PREVIEW;
+ mState[id] = STATE_PREVIEW;
mCaptureSession[id].setRepeatingRequest(mPreviewRequest[id], mCaptureCallback,
mCameraHandler);
} catch (CameraAccessException e) {
@@ -567,24 +644,28 @@ public class CaptureModule implements CameraModule, PhotoController {
* Closes the current {@link CameraDevice}.
*/
private void closeCamera() {
+ Log.d(TAG, "closeCamera");
try {
mCameraOpenCloseLock.acquire();
- for (int i = 0; i < NUMCAM; i++) {
+ for (int i = 0; i < MAX_NUM_CAM; i++) {
if (null != mCaptureSession[i]) {
mCaptureSession[i].close();
mCaptureSession[i] = null;
}
- if (null != mCameraDevice[i]) {
- mCameraDevice[i].close();
- mCameraDevice[i] = null;
- mCameraOpened = false;
- }
if (null != mImageReader[i]) {
mImageReader[i].close();
mImageReader[i] = null;
}
}
+ for (int i = 0; i < MAX_NUM_CAM; i++) {
+ if (null != mCameraDevice[i]) {
+ mCameraDevice[i].close();
+ mCameraDevice[i] = null;
+ mCameraOpened[i] = false;
+ }
+ }
} catch (InterruptedException e) {
+ mCameraOpenCloseLock.release();
throw new RuntimeException("Interrupted while trying to lock camera closing.", e);
} finally {
mCameraOpenCloseLock.release();
@@ -602,7 +683,7 @@ public class CaptureModule implements CameraModule, PhotoController {
mCallbackThread = new HandlerThread("CameraCallback");
mCallbackThread.start();
- mCameraHandler = new Handler(mCameraThread.getLooper());
+ mCameraHandler = new MyCameraHandler(mCameraThread.getLooper());
mImageAvailableHandler = new Handler(mImageAvailableThread.getLooper());
mCallbackHandler = new Handler(mCallbackThread.getLooper());
}
@@ -638,12 +719,14 @@ public class CaptureModule implements CameraModule, PhotoController {
}
private void openCamera(int id) {
+ Log.d(TAG, "openCamera " + id);
CameraManager manager;
try {
manager = (CameraManager) mActivity.getSystemService(Context.CAMERA_SERVICE);
mCameraId[id] = manager.getCameraIdList()[id];
- if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
+ if (!mCameraOpenCloseLock.tryAcquire(5000, TimeUnit.MILLISECONDS)) {
Log.d(TAG, "Time out waiting to lock camera opening.");
+ throw new RuntimeException("Time out waiting to lock camera opening");
}
manager.openCamera(mCameraId[id], mStateCallback, mCameraHandler);
} catch (CameraAccessException e) {
@@ -665,6 +748,7 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onPauseAfterSuper() {
+ Log.d(TAG, "onPause");
mUI.showPreviewCover();
stopBackgroundThread();
closeCamera();
@@ -678,9 +762,23 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onResumeAfterSuper() {
+ Log.d(TAG, "onResume " + MODE);
setUpCameraOutputs();
- openCamera(0);
startBackgroundThread();
+ Message msg = Message.obtain();
+ msg.what = OPEN_CAMERA;
+ switch (MODE) {
+ case DUAL_MODE:
+ case BAYER_MODE:
+ msg.arg1 = BAYER_ID;
+ mCameraHandler.sendMessage(msg);
+ break;
+ case MONO_MODE:
+ msg.what = OPEN_CAMERA;
+ msg.arg1 = MONO_ID;
+ mCameraHandler.sendMessage(msg);
+ break;
+ }
mUI.hidePreviewCover();
mUI.enableShutter(true);
mUI.initializeFirstTime();
@@ -798,8 +896,20 @@ public class CaptureModule implements CameraModule, PhotoController {
@Override
public void onPreviewUIReady() {
+ Log.d(TAG, "onPreviewUIReady");
mSurfaceReady = true;
- createSession(0);
+ switch (MODE) {
+ case DUAL_MODE:
+ createSession(BAYER_ID);
+ createSession(MONO_ID);
+ break;
+ case BAYER_MODE:
+ createSession(BAYER_ID);
+ break;
+ case MONO_MODE:
+ createSession(MONO_ID);
+ break;
+ }
}
@Override
@@ -873,24 +983,26 @@ public class CaptureModule implements CameraModule, PhotoController {
}
private void applyPreference(int cameraId, ListPreference pref) {
- if (pref.getKey().equals(CameraSettings.KEY_FLASH_MODE)) {
- if (pref.getValue().equals("on")) {
+ String key = pref.getKey();
+ String value = pref.getValue();
+ if (key.equals(CameraSettings.KEY_FLASH_MODE)) {
+ if (value.equals("on")) {
mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
- } else if (pref.getValue().equals("auto")) {
+ } else if (value.equals("auto")) {
mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
- } else if (pref.getValue().equals("off")) {
+ } else if (value.equals("off")) {
mCaptureBuilder[cameraId].set(CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON);
}
+ } else if (key.equals(CameraSettings.KEY_MONO_PREVIEW)) {
+ if (value.equals("on")) {
+ } else if (value.equals("off")) {
+ }
}
}
- private void applyAllSettings(int cameraId) {
-
- }
-
/**
* Compares two {@code Size}s based on their areas.
*/
@@ -904,4 +1016,23 @@ public class CaptureModule implements CameraModule, PhotoController {
}
}
+
+ private class MyCameraHandler extends Handler {
+
+ public MyCameraHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case OPEN_CAMERA: {
+ int id = msg.arg1;
+ openCamera(id);
+ break;
+ }
+ }
+ }
+ }
+
}
diff --git a/src/com/android/camera/CaptureUI.java b/src/com/android/camera/CaptureUI.java
index 9095cd1..97db3ac 100644
--- a/src/com/android/camera/CaptureUI.java
+++ b/src/com/android/camera/CaptureUI.java
@@ -189,16 +189,12 @@ public class CaptureUI implements PieListener,
mPreviewCover = mRootView.findViewById(R.id.preview_cover);
// display the view
mSurfaceView = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content);
- mSurfaceView.setVisibility(View.VISIBLE);
mSurfaceView2 = (SurfaceView) mRootView.findViewById(R.id.mdp_preview_content2);
- //mSurfaceView2.setVisibility(View.VISIBLE);
+ mSurfaceView2.setZOrderMediaOverlay(true);
mSurfaceHolder = mSurfaceView.getHolder();
mSurfaceHolder.addCallback(this);
- //mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mSurfaceHolder2 = mSurfaceView2.getHolder();
mSurfaceHolder2.addCallback(callback);
- //mSurfaceHolder2.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
- mSurfaceView.addOnLayoutChangeListener(mLayoutListener);
Log.v(TAG, "Using mdp_preview_content (MDP path)");
mRenderOverlay = (RenderOverlay) mRootView.findViewById(R.id.render_overlay);
@@ -671,6 +667,14 @@ public class CaptureUI implements PieListener,
}
}
+ public void hideSurfaceView() {
+ mSurfaceView.setVisibility(View.INVISIBLE);
+ }
+
+ public void showSurfaceView() {
+ mSurfaceView.setVisibility(View.VISIBLE);
+ }
+
public void onPause() {
// Clear UI.
collapseCameraControls();
@@ -689,6 +693,10 @@ public class CaptureUI implements PieListener,
public void clearFaces() {
}
+ public void setPreference(String key, String value) {
+ mMenu.setPreference(key, value);
+ }
+
@Override
public void clearFocus() {
FocusIndicator indicator = getFocusIndicator();