diff options
author | Owen Lin <owenlin@google.com> | 2009-09-10 19:08:01 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2009-09-12 00:16:45 +0800 |
commit | 78f160ee416ba27ba55954950473e17ba9d20052 (patch) | |
tree | 1672ca72815b8996c96f2463a3c56a62fff050b7 /src/com/android | |
parent | 4a853fff135f3a1e96fcae06d266a84f63bb4043 (diff) | |
download | LegacyCamera-78f160ee416ba27ba55954950473e17ba9d20052.zip LegacyCamera-78f160ee416ba27ba55954950473e17ba9d20052.tar.gz LegacyCamera-78f160ee416ba27ba55954950473e17ba9d20052.tar.bz2 |
Remove CameraSettings. And then renmae CameraSettingsHelper to CameraSettings
Change-Id: I515c90bb5c4d49a2c4a761a933c0db6fbec0637b
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/camera/Camera.java | 14 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 268 | ||||
-rw-r--r-- | src/com/android/camera/CameraSettingsHelper.java | 159 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 2 |
4 files changed, 90 insertions, 353 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 7616e3e..99e20a0 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -1761,8 +1761,8 @@ public class Camera extends Activity implements View.OnClickListener, if (mSettings == null) { mSettings = new OnScreenSettings( findViewById(R.id.camera_preview)); - CameraSettingsHelper helper = - new CameraSettingsHelper(Camera.this, mParameters); + CameraSettings helper = + new CameraSettings(Camera.this, mParameters); mSettings.setPreferenceScreen(helper .getPreferenceScreen(R.xml.camera_preferences)); } @@ -1810,23 +1810,23 @@ public class Camera extends Activity implements View.OnClickListener, // ignore the events after "onPause()" if (mPausing) return; - if (CameraSettingsHelper.KEY_FLASH_MODE.equals(key)) { + if (CameraSettings.KEY_FLASH_MODE.equals(key)) { mParameters.setFlashMode(preferences.getString(key, "auto")); mCameraDevice.setParameters(mParameters); - } else if (CameraSettingsHelper.KEY_FOCUS_MODE.equals(key)) { + } else if (CameraSettings.KEY_FOCUS_MODE.equals(key)) { mFocusMode = preferences.getString(key, getString(R.string.pref_camera_focusmode_default)); - } else if (CameraSettingsHelper.KEY_PICTURE_SIZE.equals(key)) { + } else if (CameraSettings.KEY_PICTURE_SIZE.equals(key)) { String pictureSize = preferences.getString(key, getString(R.string.pref_camera_picturesize_default)); setCameraPictureSizeIfSupported(pictureSize); mCameraDevice.setParameters(mParameters); - } else if (CameraSettingsHelper.KEY_JPEG_QUALITY.equals(key)) { + } else if (CameraSettings.KEY_JPEG_QUALITY.equals(key)) { String jpegQuality = preferences.getString(key, getString(R.string.pref_camera_jpegquality_default)); mParameters.setJpegQuality(Integer.parseInt(jpegQuality)); mCameraDevice.setParameters(mParameters); - } else if (CameraSettingsHelper.KEY_RECORD_LOCATION.equals(key)) { + } else if (CameraSettings.KEY_RECORD_LOCATION.equals(key)) { mRecordLocation = preferences.getBoolean(key, false); if (mRecordLocation) { startReceivingLocationUpdates(); diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 7ed5461..1888e32 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -1,167 +1,109 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package com.android.camera; +import android.app.Activity; +import android.content.Context; import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.res.Resources; import android.hardware.Camera.Parameters; import android.hardware.Camera.Size; -import android.os.Bundle; import android.os.SystemProperties; import android.preference.ListPreference; import android.preference.Preference; -import android.preference.PreferenceActivity; import android.preference.PreferenceGroup; +import android.preference.PreferenceManager; +import android.preference.PreferenceScreen; import java.util.ArrayList; import java.util.List; -/** - * CameraSettings - */ -public class CameraSettings extends PreferenceActivity implements - OnSharedPreferenceChangeListener { +public class CameraSettings { + private static final int FIRST_REQUEST_CODE = 100; + private static final int NOT_FOUND = -1; + + public static final String KEY_VERSION = "pref_version_key"; + public static final String KEY_RECORD_LOCATION = + "pref_camera_recordlocation_key"; public static final String KEY_VIDEO_QUALITY = "pref_camera_videoquality_key"; public static final String KEY_VIDEO_DURATION = "pref_camera_video_duration_key"; - public static final String KEY_VERSION = "pref_version_key"; - public static final int CURRENT_VERSION = 1; 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 String KEY_COLOR_EFFECT = "pref_camera_coloreffect_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 String KEY_SCENE_MODE = "pref_camera_scenemode_key"; - - public static final boolean DEFAULT_VIDEO_QUALITY_VALUE = true; - - // MMS video length - public static final int DEFAULT_VIDEO_DURATION_VALUE = -1; + public static final int CURRENT_VERSION = 1; // max mms video duration in seconds. public static final int MMS_VIDEO_DURATION = SystemProperties.getInt("ro.media.enc.lprof.duration", 60); - private ListPreference mVideoQuality; - private ListPreference mVideoDuration; - private ListPreference mPictureSize; - private ListPreference mJpegQuality; - private ListPreference mFocusMode; - private ListPreference mWhiteBalance; - private ListPreference mColorEffect; - private ListPreference mSceneMode; - private Parameters mParameters; - - @Override - public void onCreate(Bundle icicle) { - super.onCreate(icicle); - addPreferencesFromResource(R.xml.camera_preferences); - - initUI(); - } - - @Override - protected void onResume() { - super.onResume(); - - updateVideoQualitySummary(); - updateVideoDurationSummary(); - updatePictureSizeSummary(); - updateJpegQualitySummary(); - updateFocusModeSummary(); - updateWhiteBalanceSummary(); - updateEffectSummary(); - updateSceneModeSummary(); - } + public static final boolean DEFAULT_VIDEO_QUALITY_VALUE = true; - private ArrayList<String> sizeToStr(List<Size> sizes) { - if (sizes == null) return null; + // MMS video length + public static final int DEFAULT_VIDEO_DURATION_VALUE = -1; - ArrayList<String> sizesInString = new ArrayList<String>(); - for (Size size : sizes) { - sizesInString.add("" + size.width + "x" + size.height); + private static final String TAG = "CameraSettings"; + + private final Context mContext; + private final Parameters mParameters; + private final PreferenceManager mManager; + + public CameraSettings(Activity activity, Parameters parameters) { + mContext = activity; + mParameters = parameters; + mManager = new PreferenceManager(activity, FIRST_REQUEST_CODE); + } + + public PreferenceScreen getPreferenceScreen(int preferenceRes) { + PreferenceScreen screen = mManager.createPreferenceScreen(mContext); + mManager.inflateFromResource(mContext, preferenceRes, screen); + initPreference(screen); + return screen; + } + + private void initPreference(PreferenceScreen screen) { + 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); + ListPreference sceneMode = + (ListPreference) screen.findPreference(KEY_SCENE_MODE); + + // Since the screen could be loaded from different resources, we need + // to check if the preference is available here + if (videoDuration != null) { + // Modify video duration settings. + // The first entry is for MMS video duration, and we need to fill + // in the device-dependent value (in seconds). + CharSequence[] entries = videoDuration.getEntries(); + entries[0] = String.format( + entries[0].toString(), MMS_VIDEO_DURATION); } - return sizesInString; - } - 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); - mWhiteBalance = (ListPreference) findPreference(KEY_WHITE_BALANCE); - mColorEffect = (ListPreference) findPreference(KEY_COLOR_EFFECT); - mSceneMode = (ListPreference) findPreference(KEY_SCENE_MODE); - - SharedPreferences pref = getPreferenceScreen().getSharedPreferences(); - upgradePreferences(pref); - pref.registerOnSharedPreferenceChangeListener(this); - - // Get parameters. - android.hardware.Camera device; - try { - device = CameraHolder.instance().open(); - } catch (CameraHardwareException e) { - Resources ress = getResources(); - Util.showFatalErrorAndFinish(this, - ress.getString(R.string.camera_error_title), - ress.getString(R.string.cannot_connect_camera)); - return; + // Filter out unsupported settings / options + if (pictureSize != null) { + filterUnsupportedOptions(screen, pictureSize, sizeListToStringList( + mParameters.getSupportedPictureSizes())); } - mParameters = device.getParameters(); - CameraHolder.instance().release(); - - // Create picture size settings. - List<Size> pictureSizes = mParameters.getSupportedPictureSizes(); - ArrayList<String> pictureSizesInString = sizeToStr(pictureSizes); - createSettings(mPictureSize, pictureSizesInString); - - // Create white balance settings. - createSettings(mWhiteBalance, mParameters.getSupportedWhiteBalance()); - - // Create color effect settings. - createSettings(mColorEffect, mParameters.getSupportedColorEffects()); - - // Create scene mode settings. - createSettings(mSceneMode, mParameters.getSupportedSceneModes()); - - // Modify video duration settings. - // The first entry is for MMS video duration, and we need to fill in the - // device-dependent value (in seconds). - CharSequence[] entries = mVideoDuration.getEntries(); - entries[0] = String.format(entries[0].toString(), MMS_VIDEO_DURATION); - - // Set default JPEG quality value if it is empty. - if (mJpegQuality.getValue() == null) { - mJpegQuality.setValue(getString( - R.string.pref_camera_jpegquality_default)); + if (whiteBalance != null) { + filterUnsupportedOptions(screen, + whiteBalance, mParameters.getSupportedWhiteBalance()); } - - // Set default focus mode value if it is empty. - if (mFocusMode.getValue() == null) { - mFocusMode.setValue(getString( - R.string.pref_camera_focusmode_default)); + if (colorEffect != null) { + filterUnsupportedOptions(screen, + colorEffect, mParameters.getSupportedColorEffects()); + } + if (sceneMode != null) { + filterUnsupportedOptions(screen, + sceneMode, mParameters.getSupportedSceneModes()); } - getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); } private boolean removePreference(PreferenceGroup group, Preference remove) { @@ -178,11 +120,12 @@ public class CameraSettings extends PreferenceActivity implements return false; } - private void createSettings( - ListPreference pref, List<String> supportedParam) { + private void filterUnsupportedOptions(PreferenceScreen screen, + ListPreference pref, List<String> supported) { + // Remove the preference if the parameter is not supported. - if (supportedParam == null) { - removePreference(getPreferenceScreen(), pref); + if (supported == null) { + removePreference(screen, pref); return; } @@ -192,8 +135,7 @@ public class CameraSettings extends PreferenceActivity implements ArrayList<CharSequence> entries = new ArrayList<CharSequence>(); ArrayList<CharSequence> entryValues = new ArrayList<CharSequence>(); for (int i = 0, len = allEntryValues.length; i < len; i++) { - int found = supportedParam.indexOf(allEntryValues[i]); - if (found != -1) { + if (supported.indexOf(allEntryValues[i].toString()) != NOT_FOUND) { entries.add(allEntries[i]); entryValues.add(allEntryValues[i]); } @@ -206,63 +148,17 @@ public class CameraSettings extends PreferenceActivity implements // Set the value to the first entry if it is invalid. String value = pref.getValue(); - int index = pref.findIndexOfValue(value); - if (index == -1) { + if (pref.findIndexOfValue(value) == NOT_FOUND) { pref.setValueIndex(0); } } - private void updateVideoQualitySummary() { - mVideoQuality.setSummary(mVideoQuality.getEntry()); - } - - private void updateVideoDurationSummary() { - mVideoDuration.setSummary(mVideoDuration.getEntry()); - } - - private void updatePictureSizeSummary() { - mPictureSize.setSummary(mPictureSize.getEntry()); - } - - private void updateJpegQualitySummary() { - mJpegQuality.setSummary(mJpegQuality.getEntry()); - } - - private void updateWhiteBalanceSummary() { - mWhiteBalance.setSummary(mWhiteBalance.getEntry()); - } - - private void updateSceneModeSummary() { - mSceneMode.setSummary(mSceneMode.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)) { - updateVideoQualitySummary(); - } else if (key.equals(KEY_VIDEO_DURATION)) { - updateVideoDurationSummary(); - } else if (key.equals(KEY_PICTURE_SIZE)) { - updatePictureSizeSummary(); - } else if (key.equals(KEY_JPEG_QUALITY)) { - 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(); - } else if (key.equals(KEY_SCENE_MODE)) { - updateSceneModeSummary(); + private static List<String> sizeListToStringList(List<Size> sizes) { + ArrayList<String> list = new ArrayList<String>(); + for (Size size : sizes) { + list.add(String.format("%dx%d", size.width, size.height)); } + return list; } public static void upgradePreferences(SharedPreferences pref) { diff --git a/src/com/android/camera/CameraSettingsHelper.java b/src/com/android/camera/CameraSettingsHelper.java deleted file mode 100644 index fb83765..0000000 --- a/src/com/android/camera/CameraSettingsHelper.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.android.camera; - -import android.app.Activity; -import android.content.Context; -import android.hardware.Camera.Parameters; -import android.hardware.Camera.Size; -import android.os.SystemProperties; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceGroup; -import android.preference.PreferenceManager; -import android.preference.PreferenceScreen; - -import java.util.ArrayList; -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 = - "pref_camera_videoquality_key"; - public static final String KEY_VIDEO_DURATION = - "pref_camera_video_duration_key"; - 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 String KEY_COLOR_EFFECT = "pref_camera_coloreffect_key"; - public static final String KEY_WHITE_BALANCE = - "pref_camera_whitebalance_key"; - public static final String KEY_SCENE_MODE = "pref_camera_scenemode_key"; - - // max mms video duration in seconds. - public static final int MMS_VIDEO_DURATION = - SystemProperties.getInt("ro.media.enc.lprof.duration", 60); - - private static final boolean DEFAULT_VIDEO_QUALITY_VALUE = true; - - //MMS video length - private static final int DEFAULT_VIDEO_DURATION_VALUE = -1; - private static final String TAG = "CameraSettingsHelper"; - - private final Context mContext; - private final Parameters mParameters; - private final PreferenceManager mManager; - - public CameraSettingsHelper(Activity activity, Parameters parameters) { - mContext = activity; - mParameters = parameters; - mManager = new PreferenceManager(activity, FIRST_REQUEST_CODE); - } - - public PreferenceScreen getPreferenceScreen(int preferenceRes) { - PreferenceScreen screen = mManager.createPreferenceScreen(mContext); - mManager.inflateFromResource(mContext, preferenceRes, screen); - initPreference(screen); - return screen; - } - - private void initPreference(PreferenceScreen screen) { - 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); - ListPreference sceneMode = - (ListPreference) screen.findPreference(KEY_SCENE_MODE); - - // Since the screen could be loaded from different resources, we need - // to check if the preference is available here - if (videoDuration != null) { - // Modify video duration settings. - // The first entry is for MMS video duration, and we need to fill - // in the device-dependent value (in seconds). - CharSequence[] entries = videoDuration.getEntries(); - entries[0] = String.format( - entries[0].toString(), MMS_VIDEO_DURATION); - } - - // Filter out unsupported settings / options - if (pictureSize != null) { - filterUnsupportedOptions(screen, pictureSize, sizeListToStringList( - mParameters.getSupportedPictureSizes())); - } - if (whiteBalance != null) { - filterUnsupportedOptions(screen, - whiteBalance, mParameters.getSupportedWhiteBalance()); - } - if (colorEffect != null) { - filterUnsupportedOptions(screen, - colorEffect, mParameters.getSupportedColorEffects()); - } - if (sceneMode != null) { - filterUnsupportedOptions(screen, - sceneMode, mParameters.getSupportedSceneModes()); - } - } - - 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 filterUnsupportedOptions(PreferenceScreen screen, - ListPreference pref, List<String> supported) { - - // Remove the preference if the parameter is not supported. - if (supported == null) { - removePreference(screen, pref); - return; - } - - // Prepare setting entries and entry values. - 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++) { - if (supported.indexOf(allEntryValues[i].toString()) != NOT_FOUND) { - entries.add(allEntries[i]); - entryValues.add(allEntryValues[i]); - } - } - - // Set entries and entry values to list preference. - pref.setEntries(entries.toArray(new CharSequence[entries.size()])); - pref.setEntryValues(entryValues.toArray( - new CharSequence[entryValues.size()])); - - // Set the value to the first entry if it is invalid. - String value = pref.getValue(); - if (pref.findIndexOfValue(value) == NOT_FOUND) { - pref.setValueIndex(0); - } - } - - private static List<String> sizeListToStringList(List<Size> sizes) { - ArrayList<String> list = new ArrayList<String>(); - for (Size size : sizes) { - list.add(String.format("%dx%d", size.width, size.height)); - } - return list; - } -} diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index bd91165..02a2b11 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -1022,7 +1022,7 @@ public class VideoCamera extends Activity implements View.OnClickListener, if (mParameters == null) { mParameters = mCameraDevice.getParameters(); } - CameraSettingsHelper helper = new CameraSettingsHelper( + CameraSettings helper = new CameraSettings( VideoCamera.this, mParameters); mSettings.setPreferenceScreen(helper .getPreferenceScreen(R.xml.video_preferences)); |