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/com/android/camera/ui/CameraPicker.java | |
parent | 1461b5333aab31faee65272d64c2ac7f9809d4d0 (diff) | |
download | LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.zip LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.tar.gz LegacyCamera-3ae6814e3017ea25a57a0f885579022c4faf4e84.tar.bz2 |
Fix NPE when only front cameras are available.
bug:6643208
Change-Id: Ie4eef4a671091cd9557d1c51ab5c3919b6b30652
Diffstat (limited to 'src/com/android/camera/ui/CameraPicker.java')
-rw-r--r-- | src/com/android/camera/ui/CameraPicker.java | 16 |
1 files changed, 4 insertions, 12 deletions
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(); } } |