diff options
author | Wu-cheng Li <wuchengli@google.com> | 2009-08-03 22:25:29 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2009-08-11 16:15:02 +0800 |
commit | 5945773c664ada754ce5eb9239bd4c8bd95ee4b4 (patch) | |
tree | 485e4be3e2e2abb05dd5bc9f6b45034c9c962f28 /src | |
parent | 6db7f8e12af8def5ddaa49aed55d006d868f81ef (diff) | |
download | packages_apps_LegacyCamera-5945773c664ada754ce5eb9239bd4c8bd95ee4b4.zip packages_apps_LegacyCamera-5945773c664ada754ce5eb9239bd4c8bd95ee4b4.tar.gz packages_apps_LegacyCamera-5945773c664ada754ce5eb9239bd4c8bd95ee4b4.tar.bz2 |
Add flash mode setting.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/camera/Camera.java | 53 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 47 |
2 files changed, 80 insertions, 20 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index ff0471c..e14c3d9 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -71,6 +71,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; +import java.util.StringTokenizer; /** * Activity of the Camera which used to see preview and take pictures. @@ -115,8 +116,10 @@ public class Camera extends Activity implements View.OnClickListener, public static final String PARM_GPS_LONGITUDE = "gps-longitude"; public static final String PARM_GPS_ALTITUDE = "gps-altitude"; public static final String PARM_GPS_TIMESTAMP = "gps-timestamp"; + public static final String PARM_FLASH_MODE = "flash-mode"; public static final String SUPPORTED_ZOOM = "zoom-values"; public static final String SUPPORTED_PICTURE_SIZE = "picture-size-values"; + public static final String SUPPORTED_FLASH_MODE = "flash-mode-values"; private OrientationEventListener mOrientationListener; private int mLastOrientation = OrientationEventListener.ORIENTATION_UNKNOWN; @@ -1381,24 +1384,58 @@ public class Camera extends Activity implements View.OnClickListener, clearFocusState(); } + private ArrayList<String> getParameterArrayList(String supportedParamKey) { + String supportedParamStr = mParameters.get(supportedParamKey); + if (supportedParamStr == null) return null; + + StringTokenizer tokenizer = new StringTokenizer(supportedParamStr, ","); + ArrayList<String> supportedParam = new ArrayList<String>(); + while (tokenizer.hasMoreElements()) { + supportedParam.add(tokenizer.nextToken()); + } + return supportedParam; + } + + private boolean parameterExists(String supportedParamKey, + String paramValue) { + ArrayList<String> parameters = getParameterArrayList(supportedParamKey); + if (parameters == null) return false; + + return (parameters.indexOf(paramValue) != -1); + } + private void setCameraParameter() { - // request the preview size, the hardware may not honor it, - // if we depended on it we would have to query the size again mParameters = mCameraDevice.getParameters(); + + // Set preview size. mParameters.setPreviewSize(mViewFinderWidth, mViewFinderHeight); - // Set picture size parameter. - String pictureSize = mPreferences.getString( - CameraSettings.KEY_PICTURE_SIZE, - getString(R.string.pref_camera_picturesize_default)); - mParameters.set(PARM_PICTURE_SIZE, pictureSize); + // Set picture size. + if (mParameters.get(Camera.SUPPORTED_PICTURE_SIZE) != null) { + String pictureSize = mPreferences.getString( + CameraSettings.KEY_PICTURE_SIZE, + getString(R.string.pref_camera_picturesize_default)); + if (parameterExists(Camera.SUPPORTED_PICTURE_SIZE, pictureSize)) { + mParameters.set(PARM_PICTURE_SIZE, pictureSize); + } + } - // Set JPEG quality parameter. + // Set JPEG quality. String jpegQuality = mPreferences.getString( CameraSettings.KEY_JPEG_QUALITY, getString(R.string.pref_camera_jpegquality_default)); mParameters.set(PARM_JPEG_QUALITY, jpegQuality); + // Set flash mode. + if (mParameters.get(Camera.SUPPORTED_FLASH_MODE) != null) { + String flashMode = mPreferences.getString( + CameraSettings.KEY_FLASH_MODE, + getString(R.string.pref_camera_flashmode_default)); + if (parameterExists(Camera.SUPPORTED_FLASH_MODE, flashMode)) { + mParameters.set(PARM_FLASH_MODE, flashMode); + } + } + mCameraDevice.setParameters(mParameters); } diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 3533a2e..1f015bd 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -21,7 +21,9 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.hardware.Camera.Parameters; import android.os.Bundle; import android.preference.ListPreference; +import android.preference.Preference; import android.preference.PreferenceActivity; +import android.preference.PreferenceGroup; import java.util.ArrayList; import java.util.StringTokenizer; @@ -38,6 +40,7 @@ public class CameraSettings extends PreferenceActivity implements public static final String KEY_PICTURE_SIZE = "pref_camera_picturesize_key"; 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 boolean DEFAULT_VIDEO_QUALITY_VALUE = true; public static final int DEFAULT_VIDEO_DURATION_VALUE = 1; // 1 minute @@ -46,6 +49,7 @@ public class CameraSettings extends PreferenceActivity implements private ListPreference mPictureSize; private ListPreference mJpegQuality; private ListPreference mFocusMode; + private ListPreference mFlashMode; private Parameters mParameters; @Override @@ -65,15 +69,16 @@ public class CameraSettings extends PreferenceActivity implements updatePictureSizeSummary(); updateJpegQualitySummary(); updateFocusModeSummary(); + updateFlashModeSummary(); } private void initUI() { mVideoQuality = (ListPreference) findPreference(KEY_VIDEO_QUALITY); mVideoDuration = (ListPreference) findPreference(KEY_VIDEO_DURATION); - mPictureSize = (ListPreference) findPreference(KEY_PICTURE_SIZE); mJpegQuality = (ListPreference) findPreference(KEY_JPEG_QUALITY); mFocusMode = (ListPreference) findPreference(KEY_FOCUS_MODE); + mFlashMode = (ListPreference) findPreference(KEY_FLASH_MODE); getPreferenceScreen().getSharedPreferences(). registerOnSharedPreferenceChangeListener(this); @@ -83,9 +88,7 @@ public class CameraSettings extends PreferenceActivity implements CameraHolder.instance().release(); // Create picture size settings. - createSettings(mPictureSize, Camera.SUPPORTED_PICTURE_SIZE, - R.array.pref_camera_picturesize_entries, - R.array.pref_camera_picturesize_entryvalues); + createSettings(mPictureSize, Camera.SUPPORTED_PICTURE_SIZE); // Set default JPEG quality value if it is empty. if (mJpegQuality.getValue() == null) { @@ -98,15 +101,30 @@ public class CameraSettings extends PreferenceActivity implements mFocusMode.setValue(getString( R.string.pref_camera_focusmode_default)); } + + // Create flash mode settings. + createSettings(mFlashMode, Camera.SUPPORTED_FLASH_MODE); } - private void createSettings( - ListPreference pref, String paramName, int prefEntriesResId, - int prefEntryValuesResId) { - // Disable the preference if the parameter is not supported. + private boolean removePreference(PreferenceGroup group, Preference remove) { + if (group.removePreference(remove)) return true; + + for (int i = 0; i < group.getPreferenceCount(); i++) { + final Preference child = group.getPreference(i); + if (child instanceof PreferenceGroup) { + if (removePreference((PreferenceGroup)child, remove)) { + return true; + } + } + } + return false; + } + + private void createSettings(ListPreference pref, String paramName) { + // Remove the preference if the parameter is not supported. String supportedParamStr = mParameters.get(paramName); if (supportedParamStr == null) { - pref.setEnabled(false); + removePreference(getPreferenceScreen(), pref); return; } @@ -118,9 +136,8 @@ public class CameraSettings extends PreferenceActivity implements } // Prepare setting entries and entry values. - String[] allEntries = getResources().getStringArray(prefEntriesResId); - String[] allEntryValues = getResources().getStringArray( - prefEntryValuesResId); + CharSequence[] allEntries = pref.getEntries(); + CharSequence[] allEntryValues = pref.getEntryValues(); ArrayList<CharSequence> entries = new ArrayList<CharSequence>(); ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>(); for (int i = 0, len = allEntryValues.length; i < len; i++) { @@ -164,6 +181,10 @@ public class CameraSettings extends PreferenceActivity implements mFocusMode.setSummary(mFocusMode.getEntry()); } + private void updateFlashModeSummary() { + mFlashMode.setSummary(mFlashMode.getEntry()); + } + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(KEY_VIDEO_QUALITY)) { @@ -176,6 +197,8 @@ public class CameraSettings extends PreferenceActivity implements updateJpegQualitySummary(); } else if (key.equals(KEY_FOCUS_MODE)) { updateFocusModeSummary(); + } else if (key.equals(KEY_FLASH_MODE)) { + updateFlashModeSummary(); } } } |