From 5f6484a74fe019337e436e6e0dcb07375a74af25 Mon Sep 17 00:00:00 2001 From: President Li Date: Thu, 2 Apr 2009 02:38:09 -0700 Subject: [PATCH] Cherry pick two commits that implements color effect and white-balance settings and then make it workable. Change-Id: I519bff761db4b2b0acc1a61a8f901fafcd4b2586 --- res/values/arrays.xml | 61 ++++++++++++++++++++++++ res/values/strings.xml | 47 +++++++++++++++++- res/xml/camera_preferences.xml | 16 +++++++ src/com/android/camera/Camera.java | 32 ++++++++++++- src/com/android/camera/CameraSettings.java | 34 +++++++++++-- src/com/android/camera/CameraSettingsHelper.java | 59 ++++++++++++++--------- 6 files changed, 221 insertions(+), 28 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index b1668fc..d4b2912 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -84,4 +84,65 @@ @string/pref_camera_focusmode_value_infinity + + + @string/pref_camera_whitebalance_entry_auto + @string/pref_camera_whitebalance_entry_incandescent + @string/pref_camera_whitebalance_entry_daylight + @string/pref_camera_whitebalance_entry_fluorescent + @string/pref_camera_whitebalance_entry_cloudy + @string/pref_camera_whitebalance_entry_twilight + @string/pref_camera_whitebalance_entry_shade + @string/pref_camera_whitebalance_entry_warm_fluorescent + @string/pref_camera_whitebalance_entry_halogen + + + + + auto + incandescent + daylight + fluorescent + cloudy + twilight + shade + warm-fluorescent + halogen + + + + + @string/pref_camera_coloreffect_entry_none + @string/pref_camera_coloreffect_entry_mono + @string/pref_camera_coloreffect_entry_sepia + @string/pref_camera_coloreffect_entry_negative + @string/pref_camera_coloreffect_entry_solarize + @string/pref_camera_coloreffect_entry_posterize + @string/pref_camera_coloreffect_entry_whiteboard + @string/pref_camera_coloreffect_entry_blackboard + @string/pref_camera_coloreffect_entry_aqua + @string/pref_camera_coloreffect_entry_pastel + @string/pref_camera_coloreffect_entry_mosaic + @string/pref_camera_coloreffect_entry_redtint + @string/pref_camera_coloreffect_entry_bluetint + @string/pref_camera_coloreffect_entry_greentint + + + + + none + mono + sepia + negative + solarize + posterize + whiteboard + blackboard + aqua + pastel + mosaic + red-tint + blue-tint + green-tint + diff --git a/res/values/strings.xml b/res/values/strings.xml index 7e0920e..7b6c566 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -414,6 +414,51 @@ Focus mode + + auto + + + White balance + + + White balance + + + Auto + Incandescent + Daylight + Fluorescent + Cloudy + Twilight + Shade + Warm Fluorescent + Halogen + + + Color effect + + + none + + + Color effect + + + None + Mono + Sepia + Negative + Solarize + Posterize + Whiteboard + Blackboard + Aqua + Pastel + Mosaic + Red Tint + Blue Tint + Green Tint + Settings @@ -427,7 +472,7 @@ Show confirmation before deleting a picture or video - + myvideo diff --git a/res/xml/camera_preferences.xml b/res/xml/camera_preferences.xml index 6da66c7..432c80b 100644 --- a/res/xml/camera_preferences.xml +++ b/res/xml/camera_preferences.xml @@ -73,6 +73,22 @@ android:entries="@array/pref_camera_focusmode_entries" android:entryValues="@array/pref_camera_focusmode_entryvalues" android:dialogTitle="@string/pref_camera_focusmode_dialogtitle" /> + + + + diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 5deb0d6..76aefa0 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -107,6 +107,8 @@ public class Camera extends Activity implements View.OnClickListener, public static final double ZOOM_MIN = 1.0; public static final String ZOOM_SPEED = "99"; + private Parameters mParameters; + // The parameter strings to communicate with camera driver. public static final String PARM_ZOOM_STATE = "zoom-state"; public static final String PARM_ZOOM_STEP = "zoom-step"; @@ -114,8 +116,6 @@ public class Camera extends Activity implements View.OnClickListener, public static final String PARM_ZOOM_SPEED = "zoom-speed"; public static final String PARM_ZOOM_MAX = "max-picture-continuous-zoom"; - private Parameters mParameters; - private OrientationEventListener mOrientationListener; private int mLastOrientation = OrientationEventListener.ORIENTATION_UNKNOWN; private SharedPreferences mPreferences; @@ -413,6 +413,7 @@ public class Camera extends Activity implements View.OnClickListener, private class ZoomGestureListener extends GestureDetector.SimpleOnGestureListener { + @Override public boolean onDown(MotionEvent e) { // Show zoom buttons only when preview is started and snapshot // is not in progress. mZoomButtons may be null if it is not @@ -424,6 +425,7 @@ public class Camera extends Activity implements View.OnClickListener, return true; } + @Override public boolean onDoubleTap(MotionEvent e) { // Perform zoom only when preview is started and snapshot is not in // progress. @@ -1596,6 +1598,22 @@ public class Camera extends Activity implements View.OnClickListener, mParameters.setFlashMode(flashMode); } + // Set white balance parameter. + if (mParameters.getSupportedWhiteBalance() != null) { + String whiteBalance = mPreferences.getString( + CameraSettings.KEY_WHITE_BALANCE, + getString(R.string.pref_camera_whitebalance_default)); + mParameters.setWhiteBalance(whiteBalance); + } + + // Set color effect parameter. + if (mParameters.getSupportedColorEffects() != null) { + String colorEffect = mPreferences.getString( + CameraSettings.KEY_COLOR_EFFECT, + getString(R.string.pref_camera_coloreffect_default)); + mParameters.setColorEffect(colorEffect); + } + mCameraDevice.setParameters(mParameters); } @@ -1825,6 +1843,16 @@ public class Camera extends Activity implements View.OnClickListener, } else { stopReceivingLocationUpdates(); } + } else if (CameraSettings.KEY_COLOR_EFFECT.equals(key)) { + String colorEffect = preferences.getString(key, + getString(R.string.pref_camera_coloreffect_default)); + mParameters.setColorEffect(colorEffect); + mCameraDevice.setParameters(mParameters); + } else if (CameraSettings.KEY_WHITE_BALANCE.equals(key)) { + String whiteBalance = preferences.getString(key, + getString(R.string.pref_camera_whitebalance_default)); + mParameters.setWhiteBalance(whiteBalance); + mCameraDevice.setParameters(mParameters); } } diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index de56ce2..6cf6892 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -46,6 +46,9 @@ public class CameraSettings extends PreferenceActivity implements public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key"; public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key"; public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key"; + public static final String KEY_WHITE_BALANCE = + "pref_camera_whitebalance_key"; + public static final String KEY_COLOR_EFFECT = "pref_camera_coloreffect_key"; public static final boolean DEFAULT_VIDEO_QUALITY_VALUE = true; // MMS video length @@ -60,6 +63,8 @@ public class CameraSettings extends PreferenceActivity implements private ListPreference mPictureSize; private ListPreference mJpegQuality; private ListPreference mFocusMode; + private ListPreference mWhiteBalance; + private ListPreference mColorEffect; private Parameters mParameters; @Override @@ -79,6 +84,8 @@ public class CameraSettings extends PreferenceActivity implements updatePictureSizeSummary(); updateJpegQualitySummary(); updateFocusModeSummary(); + updateWhiteBalanceSummary(); + updateEffectSummary(); } private ArrayList sizeToStr(List sizes) { @@ -97,6 +104,9 @@ public class CameraSettings extends PreferenceActivity implements mPictureSize = (ListPreference) findPreference(KEY_PICTURE_SIZE); mJpegQuality = (ListPreference) findPreference(KEY_JPEG_QUALITY); mFocusMode = (ListPreference) findPreference(KEY_FOCUS_MODE); + mWhiteBalance = (ListPreference) findPreference(KEY_WHITE_BALANCE); + mColorEffect = (ListPreference) findPreference(KEY_COLOR_EFFECT); + SharedPreferences pref = getPreferenceScreen().getSharedPreferences(); upgradePreferences(pref); pref.registerOnSharedPreferenceChangeListener(this); @@ -120,6 +130,12 @@ public class CameraSettings extends PreferenceActivity implements ArrayList pictureSizesInString = sizeToStr(pictureSizes); createSettings(mPictureSize, pictureSizesInString); + // Create white balance settings. + createSettings(mWhiteBalance, mParameters.getSupportedWhiteBalance()); + + // Create color effect settings. + createSettings(mColorEffect, mParameters.getSupportedColorEffects()); + // Modify video duration settings. // The first entry is for MMS video duration, and we need to fill in the // device-dependent value (in seconds). @@ -137,6 +153,7 @@ public class CameraSettings extends PreferenceActivity implements mFocusMode.setValue(getString( R.string.pref_camera_focusmode_default)); } + getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); } private boolean removePreference(PreferenceGroup group, Preference remove) { @@ -153,8 +170,8 @@ public class CameraSettings extends PreferenceActivity implements return false; } - private void createSettings(ListPreference pref, - List supportedParam) { + private void createSettings( + ListPreference pref, List supportedParam) { // Remove the preference if the parameter is not supported. if (supportedParam == null) { removePreference(getPreferenceScreen(), pref); @@ -203,10 +220,18 @@ public class CameraSettings extends PreferenceActivity implements mJpegQuality.setSummary(mJpegQuality.getEntry()); } + private void updateWhiteBalanceSummary() { + mWhiteBalance.setSummary(mWhiteBalance.getEntry()); + } + private void updateFocusModeSummary() { mFocusMode.setSummary(mFocusMode.getEntry()); } + private void updateEffectSummary() { + mColorEffect.setSummary(mColorEffect.getEntry()); + } + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(KEY_VIDEO_QUALITY)) { @@ -219,10 +244,13 @@ public class CameraSettings extends PreferenceActivity implements updateJpegQualitySummary(); } else if (key.equals(KEY_FOCUS_MODE)) { updateFocusModeSummary(); + } else if (key.equals(KEY_WHITE_BALANCE)) { + updateWhiteBalanceSummary(); + } else if (key.equals(KEY_COLOR_EFFECT)) { + updateEffectSummary(); } } - private static final String TAG = "CameraSettings"; public static void upgradePreferences(SharedPreferences pref) { int version; try { diff --git a/src/com/android/camera/CameraSettingsHelper.java b/src/com/android/camera/CameraSettingsHelper.java index 6b86d8b..f0c8191 100644 --- a/src/com/android/camera/CameraSettingsHelper.java +++ b/src/com/android/camera/CameraSettingsHelper.java @@ -16,6 +16,8 @@ import java.util.List; public class CameraSettingsHelper { private static final int FIRST_REQUEST_CODE = 100; + private static final int NOT_FOUND = -1; + public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key"; public static final String KEY_VIDEO_QUALITY = @@ -26,6 +28,9 @@ public class CameraSettingsHelper { public static final String KEY_JPEG_QUALITY = "pref_camera_jpegquality_key"; public static final String KEY_FOCUS_MODE = "pref_camera_focusmode_key"; public static final String KEY_FLASH_MODE = "pref_camera_flashmode_key"; + public static final String KEY_COLOR_EFFECT = "pref_camera_coloreffect_key"; + public static final String KEY_WHITE_BALANCE = + "pref_camera_whitebalance_key"; // max mms video duration in seconds. public static final int MMS_VIDEO_DURATION = @@ -57,7 +62,7 @@ public class CameraSettingsHelper { return mScreen; } - private void setDefault(String key, int strRes) { + private void setDefaultIfNull(String key, int strRes) { ListPreference pref = (ListPreference) mScreen.findPreference(key); if (pref.getValue() == null) pref.setValue(mContext.getString(strRes)); } @@ -66,6 +71,12 @@ public class CameraSettingsHelper { ListPreference videoDuration = (ListPreference) screen.findPreference(KEY_VIDEO_DURATION); + ListPreference pictureSize = + (ListPreference) screen.findPreference(KEY_PICTURE_SIZE); + ListPreference whiteBalance = + (ListPreference) screen.findPreference(KEY_WHITE_BALANCE); + ListPreference colorEffect = + (ListPreference) screen.findPreference(KEY_COLOR_EFFECT); // Modify video duration settings. // The first entry is for MMS video duration, and we need to fill in the @@ -73,10 +84,18 @@ public class CameraSettingsHelper { CharSequence[] entries = videoDuration.getEntries(); entries[0] = String.format(entries[0].toString(), MMS_VIDEO_DURATION); - // Create picture size settings. - filterSupportedSizes(screen); - setDefault(KEY_JPEG_QUALITY, R.string.pref_camera_jpegquality_default); - setDefault(KEY_FOCUS_MODE, R.string.pref_camera_focusmode_default); + // Filter out unsupported settings / options + filterUnsupportedOptions(screen, pictureSize, + sizeListToStringList(mParameters.getSupportedPictureSizes())); + filterUnsupportedOptions(screen, + whiteBalance, mParameters.getSupportedWhiteBalance()); + filterUnsupportedOptions(screen, + colorEffect, mParameters.getSupportedColorEffects()); + + setDefaultIfNull( + KEY_JPEG_QUALITY, R.string.pref_camera_jpegquality_default); + setDefaultIfNull( + KEY_FOCUS_MODE, R.string.pref_camera_focusmode_default); } private boolean removePreference(PreferenceGroup group, Preference remove) { @@ -93,23 +112,11 @@ public class CameraSettingsHelper { return false; } - private static boolean isSupported(List supported, String required) { - int index = required.indexOf('x'); - int width = Integer.parseInt(required.substring(0, index)); - int height = Integer.parseInt(required.substring(index + 1)); - for (Size size : supported) { - if (size.width == width && size.height == height) return true; - } - return false; - } - - private void filterSupportedSizes(PreferenceScreen screen) { - ListPreference pref = - (ListPreference) screen.findPreference(KEY_PICTURE_SIZE); + private void filterUnsupportedOptions(PreferenceScreen screen, + ListPreference pref, List supported) { // Remove the preference if the parameter is not supported. - List supportedSizes = mParameters.getSupportedPictureSizes(); - if (supportedSizes == null) { + if (supported == null) { removePreference(screen, pref); return; } @@ -120,7 +127,7 @@ public class CameraSettingsHelper { ArrayList entries = new ArrayList(); ArrayList entryValues = new ArrayList(); for (int i = 0, len = allEntryValues.length; i < len; i++) { - if (isSupported(supportedSizes, allEntryValues[i].toString())) { + if (supported.indexOf(allEntryValues[i].toString()) != NOT_FOUND) { entries.add(allEntries[i]); entryValues.add(allEntryValues[i]); } @@ -133,8 +140,16 @@ public class CameraSettingsHelper { // Set the value to the first entry if it is invalid. String value = pref.getValue(); - if (pref.findIndexOfValue(value) == -1) { + if (pref.findIndexOfValue(value) == NOT_FOUND) { pref.setValueIndex(0); } } + + private static List sizeListToStringList(List sizes) { + ArrayList list = new ArrayList(); + for (Size size : sizes) { + list.add(String.format("%dx%d", size.width, size.height)); + } + return list; + } } -- 2.11.0