diff options
author | Wu-cheng Li <> | 2009-04-02 01:39:36 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-02 01:39:36 -0700 |
commit | 87341536812081826656040ac81f8f386c6c1407 (patch) | |
tree | c653d12247ea5cc125c09ef0c1777e4795f63045 /src/com/android/camera/CameraSettings.java | |
parent | 063f09da3fe6e7ff3587be07574ab234ecf7048e (diff) | |
download | LegacyCamera-87341536812081826656040ac81f8f386c6c1407.zip LegacyCamera-87341536812081826656040ac81f8f386c6c1407.tar.gz LegacyCamera-87341536812081826656040ac81f8f386c6c1407.tar.bz2 |
AI 144187: Initial implementation of manual white-balance setting.
BUG=1742461
Automated import of CL 144187
Diffstat (limited to 'src/com/android/camera/CameraSettings.java')
-rw-r--r-- | src/com/android/camera/CameraSettings.java | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/com/android/camera/CameraSettings.java b/src/com/android/camera/CameraSettings.java index 0145d64..13952b8 100644 --- a/src/com/android/camera/CameraSettings.java +++ b/src/com/android/camera/CameraSettings.java @@ -18,10 +18,15 @@ package com.android.camera; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; +import android.hardware.Camera; +import android.hardware.Camera.Parameters; import android.os.Bundle; import android.preference.ListPreference; import android.preference.PreferenceActivity; +import java.util.ArrayList; +import java.util.StringTokenizer; + /** * CameraSettings */ @@ -29,9 +34,12 @@ public class CameraSettings extends PreferenceActivity implements OnSharedPreferenceChangeListener { public static final String KEY_VIDEO_QUALITY = "pref_camera_videoquality_key"; + public static final String KEY_WHITE_BALANCE = "pref_camera_whitebalance_key"; public static final boolean DEFAULT_VIDEO_QUALITY_VALUE = true; private ListPreference mVideoQuality; + private ListPreference mWhiteBalance; + private Parameters mParameters; public CameraSettings() { @@ -45,16 +53,26 @@ public class CameraSettings extends PreferenceActivity addPreferencesFromResource(R.xml.camera_preferences); initUI(); + + // Get parameters. + android.hardware.Camera device = android.hardware.Camera.open(); + mParameters = device.getParameters(); + device.release(); + + createWhiteBalanceSettings(); } @Override protected void onResume() { super.onResume(); + updateVideoQuality(); + updateWhiteBalance(); } private void initUI() { mVideoQuality = (ListPreference) findPreference(KEY_VIDEO_QUALITY); + mWhiteBalance = (ListPreference) findPreference(KEY_WHITE_BALANCE); getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); } @@ -67,6 +85,48 @@ public class CameraSettings extends PreferenceActivity mVideoQuality.setSummary(vidQuality); } + private void createWhiteBalanceSettings() { + // Get the supported white balance settings. + String supportedWbStr = mParameters.get("whitebalance-values"); + StringTokenizer tokenizer = new StringTokenizer(supportedWbStr, ","); + ArrayList<CharSequence> supportedWb = new ArrayList<CharSequence>(); + while (tokenizer.hasMoreElements()) { + supportedWb.add(tokenizer.nextToken()); + } + + // Prepare white balance entries and entry values. + String[] allWbEntries = getResources().getStringArray( + R.array.pref_camera_whitebalance_entries); + String[] allWbEntryValues = getResources().getStringArray( + R.array.pref_camera_whitebalance_entryvalues); + ArrayList<CharSequence> wbEntries = new ArrayList<CharSequence>(); + ArrayList<CharSequence> wbEntryValues = new ArrayList<CharSequence>(); + for (int i = 0, len = allWbEntryValues.length; i < len; i++) { + int found = supportedWb.indexOf(allWbEntryValues[i]); + if (found != -1) { + wbEntries.add(allWbEntries[i]); + wbEntryValues.add(allWbEntryValues[i]); + } + } + + // Set white balance entries and entry values to list preference. + mWhiteBalance.setEntries(wbEntries.toArray( + new CharSequence[wbEntries.size()])); + mWhiteBalance.setEntryValues(wbEntryValues.toArray( + new CharSequence[wbEntryValues.size()])); + + String value = mWhiteBalance.getValue(); + int index = mWhiteBalance.findIndexOfValue(value); + if (index == -1) { + mWhiteBalance.setValueIndex(0); + } + } + + private void updateWhiteBalance() { + // Set preference summary. + mWhiteBalance.setSummary(mWhiteBalance.getEntry()); + } + private static int getIntPreference(ListPreference preference, int defaultValue) { String s = preference.getValue(); int result = defaultValue; @@ -84,10 +144,11 @@ public class CameraSettings extends PreferenceActivity public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (key.equals(KEY_VIDEO_QUALITY)) { - updateVideoQuality(); - } - + if (key.equals(KEY_VIDEO_QUALITY)) { + updateVideoQuality(); + } else if (key.equals(KEY_WHITE_BALANCE)) { + updateWhiteBalance(); + } } } |