summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/AndroidCameraManagerImpl.java7
-rwxr-xr-xsrc/com/android/camera/CameraHolder.java87
-rwxr-xr-xsrc/com/android/camera/CameraSettings.java4
-rw-r--r--src/com/android/camera/DisableCameraReceiver.java16
-rwxr-xr-xsrc/com/android/camera/PhotoModule.java30
-rw-r--r--src/com/android/camera/VideoModule.java28
6 files changed, 84 insertions, 88 deletions
diff --git a/src/com/android/camera/AndroidCameraManagerImpl.java b/src/com/android/camera/AndroidCameraManagerImpl.java
index b7288db..414ff81 100644
--- a/src/com/android/camera/AndroidCameraManagerImpl.java
+++ b/src/com/android/camera/AndroidCameraManagerImpl.java
@@ -243,12 +243,13 @@ class AndroidCameraManagerImpl implements CameraManager {
final int cameraId = msg.arg1;
Context context = CameraApp.getContext();
- CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
+ CameraHolder.CameraInfo info =
+ CameraHolder.instance().getCameraInfo()[cameraId];
final boolean isBackCamera =
- info.facing == CameraInfo.CAMERA_FACING_BACK;
+ info.facing == CameraHolder.CameraInfo.CAMERA_FACING_BACK;
final boolean isFrontCamera =
- info.facing == CameraInfo.CAMERA_FACING_FRONT;
+ info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT;
final boolean useOpenLegacyForBackCamera = context.getResources()
.getBoolean(R.bool.back_camera_open_legacy);
final boolean useOpenLegacyForFrontCamera = context.getResources()
diff --git a/src/com/android/camera/CameraHolder.java b/src/com/android/camera/CameraHolder.java
index 6d5ef1a..0a35456 100755
--- a/src/com/android/camera/CameraHolder.java
+++ b/src/com/android/camera/CameraHolder.java
@@ -173,55 +173,49 @@ public class CameraHolder {
HandlerThread ht = new HandlerThread("CameraHolder");
ht.start();
mHandler = new MyHandler(ht.getLooper());
- if (mCam2On) {
- android.hardware.camera2.CameraManager manager =
- (android.hardware.camera2.CameraManager) mContext.getSystemService(
- Context.CAMERA_SERVICE);
- String[] cameraIdList = null;
- try {
- cameraIdList = manager.getCameraIdList();
- for (int i = 0; i < cameraIdList.length; i++) {
- String cameraId = cameraIdList[i];
- CameraCharacteristics characteristics
- = manager.getCameraCharacteristics(cameraId);
- Log.d(TAG,"cameraIdList size ="+cameraIdList.length);
- int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
- if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
- CaptureModule.FRONT_ID = i;
- mFrontCameraId = i;
- } else if (mBackCameraId != -1) {
- mBackCameraId = i;
- }
- mCharacteristics.add(i, characteristics);
- }
- } catch (CameraAccessException e) {
- e.printStackTrace();
- }
- mNumberOfCameras = cameraIdList == null ? 0 : cameraIdList.length;
- } else {
- if (mMockCameraInfo != null) {
- mNumberOfCameras = mMockCameraInfo.length;
- mInfo = mMockCameraInfo;
- } else {
- mNumberOfCameras = android.hardware.Camera.getNumberOfCameras();
- mInfo = new CameraInfo[mNumberOfCameras];
- for (int i = 0; i < mNumberOfCameras; i++) {
- mInfo[i] = new CameraInfo();
- android.hardware.Camera.getCameraInfo(i, mInfo[i]);
- }
- }
- // get the first (smallest) back and first front camera id
- for (int i = 0; i < mNumberOfCameras; i++) {
- if (mBackCameraId == -1 && mInfo[i].facing == CameraInfo.CAMERA_FACING_BACK) {
- mBackCameraId = i;
- } else if (mFrontCameraId == -1 &&
- mInfo[i].facing == CameraInfo.CAMERA_FACING_FRONT) {
+ android.hardware.camera2.CameraManager manager =
+ (android.hardware.camera2.CameraManager) mContext.getSystemService(
+ Context.CAMERA_SERVICE);
+ String[] cameraIdList = null;
+ try {
+ cameraIdList = manager.getCameraIdList();
+ mInfo = new CameraInfo[cameraIdList.length];
+ for (int i = 0; i < cameraIdList.length; i++) {
+ String cameraId = cameraIdList[i];
+ CameraCharacteristics characteristics
+ = manager.getCameraCharacteristics(cameraId);
+ Log.d(TAG,"cameraIdList size ="+cameraIdList.length);
+ int facing = characteristics.get(CameraCharacteristics.LENS_FACING);
+ if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
+ CaptureModule.FRONT_ID = i;
mFrontCameraId = i;
+ } else if (mBackCameraId != -1) {
+ mBackCameraId = i;
}
+ addCameraInfo(i, characteristics);
+ mCharacteristics.add(i, characteristics);
+ }
+ } catch (CameraAccessException e) {
+ e.printStackTrace();
+ }
+ mNumberOfCameras = cameraIdList == null ? 0 : cameraIdList.length;
+ // get the first (smallest) back and first front camera id
+ for (int i = 0; i < mNumberOfCameras; i++) {
+ if (mBackCameraId == -1 && mInfo[i].facing == CameraCharacteristics.LENS_FACING_BACK) {
+ mBackCameraId = i;
+ } else if (mFrontCameraId == -1 &&
+ mInfo[i].facing == CameraCharacteristics.LENS_FACING_FRONT) {
+ mFrontCameraId = i;
}
}
}
+ private void addCameraInfo(int index, CameraCharacteristics characteristics) {
+ mInfo[index] = new CameraInfo();
+ mInfo[index].facing = characteristics.get(CameraCharacteristics.LENS_FACING);
+ mInfo[index].orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
+ }
+
public CameraCharacteristics getCameraCharacteristics(int id) {
return mCharacteristics.get(id);
}
@@ -361,4 +355,11 @@ public class CameraHolder {
public int getFrontCameraId() {
return mFrontCameraId;
}
+
+ public class CameraInfo {
+ public static final int CAMERA_FACING_FRONT = CameraCharacteristics.LENS_FACING_FRONT;
+ public static final int CAMERA_FACING_BACK = CameraCharacteristics.LENS_FACING_BACK;
+ public int facing;
+ public int orientation;
+ }
}
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java
index 5b10d85..012a22d 100755
--- a/src/com/android/camera/CameraSettings.java
+++ b/src/com/android/camera/CameraSettings.java
@@ -295,7 +295,7 @@ public class CameraSettings {
private final Context mContext;
private final Parameters mParameters;
- private final CameraInfo[] mCameraInfo;
+ private final CameraHolder.CameraInfo[] mCameraInfo;
private final int mCameraId;
public static String mKeyIso = null;
@@ -467,7 +467,7 @@ public class CameraSettings {
}
public CameraSettings(Activity activity, Parameters parameters,
- int cameraId, CameraInfo[] cameraInfo) {
+ int cameraId, CameraHolder.CameraInfo[] cameraInfo) {
mContext = activity;
mParameters = parameters;
mCameraId = cameraId;
diff --git a/src/com/android/camera/DisableCameraReceiver.java b/src/com/android/camera/DisableCameraReceiver.java
index 4cef85f..3551a43 100644
--- a/src/com/android/camera/DisableCameraReceiver.java
+++ b/src/com/android/camera/DisableCameraReceiver.java
@@ -53,23 +53,15 @@ public class DisableCameraReceiver extends BroadcastReceiver {
}
private boolean hasCamera() {
- int n = android.hardware.Camera.getNumberOfCameras();
+ int n = CameraHolder.instance().getNumberOfCameras();
Log.i(TAG, "number of camera: " + n);
return (n > 0);
}
private boolean hasBackCamera() {
- int n = android.hardware.Camera.getNumberOfCameras();
- CameraInfo info = new CameraInfo();
- for (int i = 0; i < n; i++) {
- android.hardware.Camera.getCameraInfo(i, info);
- if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
- Log.i(TAG, "back camera found: " + i);
- return true;
- }
- }
- Log.i(TAG, "no back camera");
- return false;
+ int backCameraId = CameraHolder.instance().getBackCameraId();
+ Log.i(TAG, backCameraId == -1 ? "no back camera" : ("back camera found: " + backCameraId));
+ return backCameraId != -1;
}
private void disableComponent(Context context, String klass) {
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index 97b57c2..6040a0e 100755
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -787,8 +787,8 @@ public class PhotoModule
mParameters = mCameraDevice.getParameters();
mInitialParams = mCameraDevice.getParameters();
initializeCapabilities();
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ mMirror = (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT);
mFocusManager.setMirror(mMirror);
mFocusManager.setParameters(mInitialParams);
setupPreview();
@@ -893,7 +893,7 @@ public class PhotoModule
}
void setPreviewFrameLayoutCameraOrientation(){
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
//if camera mount angle is 0 or 180, we want to resize preview
if (info.orientation % 180 == 0){
mUI.cameraOrientationPreviewResize(true);
@@ -1022,9 +1022,9 @@ public class PhotoModule
|| mFaceDetectionStarted || mCameraState != IDLE) return;
if (mParameters.getMaxNumDetectedFaces() > 0) {
mFaceDetectionStarted = true;
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
mUI.onStartFaceDetection(mDisplayOrientation,
- (info.facing == CameraInfo.CAMERA_FACING_FRONT));
+ (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT));
mCameraDevice.setFaceDetectionCallback(mHandler, mUI);
mCameraDevice.startFaceDetection();
}
@@ -1443,11 +1443,13 @@ public class PhotoModule
needRestartPreview |= (isLongshotDone() && !mFocusManager.isZslEnabled());
needRestartPreview |= mLgeHdrMode && (mCameraState != LONGSHOT);
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- final boolean isAuxCamera = info.facing > CameraInfo.CAMERA_FACING_FRONT;
- final boolean isBackCamera = info.facing == CameraInfo.CAMERA_FACING_BACK;
- final boolean isFrontCamera = info.facing == CameraInfo.CAMERA_FACING_FRONT;
+ final boolean isAuxCamera = info.facing > CameraHolder.CameraInfo.CAMERA_FACING_FRONT;
+ final boolean isBackCamera =
+ info.facing == CameraHolder.CameraInfo.CAMERA_FACING_BACK;
+ final boolean isFrontCamera =
+ info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT;
boolean auxCameraRestartPreviewOnPictureTaken = false;
boolean backCameraRestartPreviewOnPictureTaken = false;
boolean frontCameraRestartPreviewOnPictureTaken = false;
@@ -2238,7 +2240,7 @@ public class PhotoModule
mCameraId, CameraHolder.instance().getCameraInfo());
mPreferenceGroup = settings.getPreferenceGroup(R.xml.camera_preferences);
- int numOfCams = Camera.getNumberOfCameras();
+ int numOfCams = CameraHolder.instance().getNumberOfCameras();
Log.e(TAG,"loadCameraPreferences() updating camera_id pref");
@@ -2256,8 +2258,8 @@ public class PhotoModule
int[] largeIconIds = new int[numOfCams];
for(int i=0;i<numOfCams;i++) {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[i];
- if(info.facing == CameraInfo.CAMERA_FACING_BACK) {
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[i];
+ if(info.facing == CameraHolder.CameraInfo.CAMERA_FACING_BACK) {
iconIds[i] = R.drawable.ic_switch_back;
entries[i] = mActivity.getResources().getString(R.string.pref_camera_id_entry_back);
labels[i] = mActivity.getResources().getString(R.string.pref_camera_id_label_back);
@@ -2820,8 +2822,8 @@ public class PhotoModule
if (mFocusManager != null) {
mFocusManager.removeMessages();
} else {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- mMirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ mMirror = (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT);
String[] defaultFocusModes = mActivity.getResources().getStringArray(
R.array.pref_camera_focusmode_default_array);
synchronized (this) {
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 64effe2..1f3228b 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -715,7 +715,7 @@ public class VideoModule implements CameraModule,
mPreferenceGroup = filterPreferenceScreenByIntent(
settings.getPreferenceGroup(R.xml.video_preferences));
- int numOfCams = Camera.getNumberOfCameras();
+ int numOfCams = CameraHolder.instance().getNumberOfCameras();
//TODO: If numOfCams > 2 then corresponding entries needs to be added to the media_profiles.xml
@@ -735,8 +735,8 @@ public class VideoModule implements CameraModule,
int[] largeIconIds = new int[numOfCams];
for(int i=0;i<numOfCams;i++) {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[i];
- if(info.facing == CameraInfo.CAMERA_FACING_BACK) {
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[i];
+ if(info.facing == CameraHolder.CameraInfo.CAMERA_FACING_BACK) {
iconIds[i] = R.drawable.ic_switch_back;
entries[i] = mActivity.getResources().getString(R.string.pref_camera_id_entry_back);
labels[i] = mActivity.getResources().getString(R.string.pref_camera_id_label_back);
@@ -1201,7 +1201,7 @@ public class VideoModule implements CameraModule,
}
void setPreviewFrameLayoutCameraOrientation(){
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
//if camera mount angle is 0 or 180, we want to resize preview
if (info.orientation % 180 == 0)
@@ -1491,8 +1491,8 @@ public class VideoModule implements CameraModule,
if (mFocusManager != null) {
mFocusManager.removeMessages();
} else {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ boolean mirror = (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT);
String[] defaultFocusModes = mActivity.getResources().getStringArray(
R.array.pref_video_focusmode_default_array);
mFocusManager = new FocusOverlayManager(mPreferences, defaultFocusModes,
@@ -1854,8 +1854,8 @@ public class VideoModule implements CameraModule,
// which is the orientation the graphics need to rotate in order to render correctly.
int rotation = 0;
if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ if (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT) {
rotation = (info.orientation - mOrientation - mOrientationOffset + 360) % 360;
} else { // back-facing camera
rotation = (info.orientation + mOrientation + mOrientationOffset) % 360;
@@ -2168,8 +2168,8 @@ public class VideoModule implements CameraModule,
if (bitmap != null) {
// MetadataRetriever already rotates the thumbnail. We should rotate
// it to match the UI orientation (and mirror if it is front-facing camera).
- CameraInfo[] info = CameraHolder.instance().getCameraInfo();
- boolean mirror = (info[mCameraId].facing == CameraInfo.CAMERA_FACING_FRONT);
+ CameraHolder.CameraInfo[] info = CameraHolder.instance().getCameraInfo();
+ boolean mirror = (info[mCameraId].facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT);
bitmap = CameraUtil.rotateAndMirror(bitmap, 0, mirror);
}
return bitmap;
@@ -3140,8 +3140,8 @@ public class VideoModule implements CameraModule,
CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
openCamera();
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
- boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ boolean mirror = (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT);
mParameters = mCameraDevice.getParameters();
mFocusManager.setMirror(mirror);
mFocusManager.setParameters(mParameters);
@@ -3406,9 +3406,9 @@ public class VideoModule implements CameraModule,
|| mFaceDetectionStarted) return;
if (mParameters.getMaxNumDetectedFaces() > 0) {
mFaceDetectionStarted = true;
- CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
+ CameraHolder.CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
mUI.onStartFaceDetection(mCameraDisplayOrientation,
- (info.facing == CameraInfo.CAMERA_FACING_FRONT));
+ (info.facing == CameraHolder.CameraInfo.CAMERA_FACING_FRONT));
mCameraDevice.setFaceDetectionCallback(mHandler, mUI);
Log.d(TAG, "start face detection Video "+mParameters.getMaxNumDetectedFaces());
mCameraDevice.startFaceDetection();