diff options
author | Angus Kong <shkong@google.com> | 2012-06-13 15:00:23 +0800 |
---|---|---|
committer | Angus Kong <shkong@google.com> | 2012-06-13 18:15:11 +0800 |
commit | 3ae6814e3017ea25a57a0f885579022c4faf4e84 (patch) | |
tree | 560ac6eb343ff8f5da9351339818ac14477b1224 /src | |
parent | 1461b5333aab31faee65272d64c2ac7f9809d4d0 (diff) | |
download | packages_apps_LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.zip packages_apps_LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.tar.gz packages_apps_LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.tar.bz2 |
Fix NPE when only front cameras are available.
bug:6643208
Change-Id: Ie4eef4a671091cd9557d1c51ab5c3919b6b30652
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 13 | ||||
-rwxr-xr-x | src/com/android/camera/VideoCamera.java | 3 | ||||
-rw-r--r-- | src/com/android/camera/ui/CameraPicker.java | 16 |
4 files changed, 9 insertions, 26 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 8c74d24..2ca7944 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -2175,8 +2175,7 @@ public class Camera extends ActivityBase implements FocusManager.Listener, .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { CameraSettings.writePreferredCameraId(mPreferences, - ((mCameraId == mFrontCameraId) - ? mBackCameraId : mFrontCameraId)); + (mCameraId + 1) % mNumberOfCameras); onSharedPreferenceChanged(); return true; } diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index c861366..2d33b69 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -225,16 +225,9 @@ public class CameraSettings { return; } - CharSequence[] entryValues = new CharSequence[2]; - for (int i = 0; i < mCameraInfo.length; ++i) { - int index = - (mCameraInfo[i].facing == CameraInfo.CAMERA_FACING_FRONT) - ? CameraInfo.CAMERA_FACING_FRONT - : CameraInfo.CAMERA_FACING_BACK; - if (entryValues[index] == null) { - entryValues[index] = "" + i; - if (entryValues[((index == 1) ? 0 : 1)] != null) break; - } + CharSequence[] entryValues = new CharSequence[numOfCameras]; + for (int i = 0; i < numOfCameras; ++i) { + entryValues[i] = "" + i; } preference.setEntryValues(entryValues); } diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index e93fbca..b2626ed 100755 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -1481,8 +1481,7 @@ public class VideoCamera extends ActivityBase .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { CameraSettings.writePreferredCameraId(mPreferences, - ((mCameraId == mFrontCameraId) - ? mBackCameraId : mFrontCameraId)); + (mCameraId + 1) % mNumberOfCameras); onSharedPreferenceChanged(); return true; } diff --git a/src/com/android/camera/ui/CameraPicker.java b/src/com/android/camera/ui/CameraPicker.java index ac8b8a8..21d3efe 100644 --- a/src/com/android/camera/ui/CameraPicker.java +++ b/src/com/android/camera/ui/CameraPicker.java @@ -33,7 +33,6 @@ public class CameraPicker extends RotateImageView implements View.OnClickListene private OnPreferenceChangedListener mListener; private ListPreference mPreference; private CharSequence[] mCameras; - private int mCameraFacing; public CameraPicker(Context context) { super(context); @@ -55,23 +54,16 @@ public class CameraPicker extends RotateImageView implements View.OnClickListene mCameras = pref.getEntryValues(); if (mCameras == null) return; setOnClickListener(this); - String cameraId = pref.getValue(); setVisibility(View.VISIBLE); - if (mCameras[CameraInfo.CAMERA_FACING_FRONT].equals(cameraId)) { - mCameraFacing = CameraInfo.CAMERA_FACING_FRONT; - } else { - mCameraFacing = CameraInfo.CAMERA_FACING_BACK; - } } @Override public void onClick(View v) { if (mCameras == null) return; - int newCameraIndex = (mCameraFacing == CameraInfo.CAMERA_FACING_BACK) - ? CameraInfo.CAMERA_FACING_FRONT - : CameraInfo.CAMERA_FACING_BACK; - mCameraFacing = newCameraIndex; - mPreference.setValue((String) mCameras[mCameraFacing]); + int index = mPreference.findIndexOfValue(mPreference.getValue()); + CharSequence[] values = mPreference.getEntryValues(); + index = (index + 1) % values.length; + mPreference.setValue((String) mCameras[index]); mListener.onSharedPreferenceChanged(); } } |