OSDN Git Service

Fix the issue that focus options shown on those device without focus support.
authorCheng-Ru Lin <owenlin@google.com>
Fri, 2 Oct 2009 00:37:21 +0000 (08:37 +0800)
committerCheng-Ru Lin <owenlin@google.com>
Fri, 2 Oct 2009 21:21:04 +0000 (05:21 +0800)
This is for bug http://b/2161159

Change-Id: I8f184b8aa5040c19b4f82775b30a99fed4ca035c

src/com/android/camera/Camera.java
src/com/android/camera/CameraSettings.java

index b6a7ac5..777a0b4 100644 (file)
@@ -113,6 +113,7 @@ public class Camera extends Activity implements View.OnClickListener,
     public static final String ZOOM_SPEED = "99";
 
     private Parameters mParameters;
+    private Parameters mInitialParameters;
 
     // The non-standard parameter strings to communicate with camera driver.
     // This will be removed in the future.
@@ -973,27 +974,20 @@ public class Camera extends Activity implements View.OnClickListener,
         updateStorageHint(mPicturesRemaining);
     }
 
-    private boolean mScreenComplete = false;
 
     private void showOnScreenSettings() {
         if (mSettings == null) {
             mSettings = new OnScreenSettings(
                     findViewById(R.id.camera_preview));
-            CameraSettings helper = new CameraSettings(this, mParameters);
+            CameraSettings helper =
+                    new CameraSettings(this, mInitialParameters);
             mSettings.setPreferenceScreen(helper
                     .getPreferenceScreen(R.xml.camera_preferences));
             mSettings.setOnVisibilityChangedListener(this);
 
-            // If the current screne mode is not auto, then the supported
-            // options is not complete, we need to read it again later.
-            // For example: in the scene mode "ACTION", the supported focus mode
-            // will change from {infinite, macro, auto} to {infinite}.
             String sceneMode = mParameters.getSceneMode();
-            boolean autoSceneMode = sceneMode == null
-                    || Parameters.SCENE_MODE_AUTO.equals(sceneMode);
-            mScreenComplete = autoSceneMode;
-
-            if (autoSceneMode) {
+            if (sceneMode == null
+                    || Parameters.SCENE_MODE_AUTO.equals(sceneMode)) {
                 // If scene mode is auto, cancel override in settings
                 mSettings.overrideSettings(CameraSettings.KEY_FLASH_MODE, null);
                 mSettings.overrideSettings(CameraSettings.KEY_FOCUS_MODE, null);
@@ -1516,6 +1510,7 @@ public class Camera extends Activity implements View.OnClickListener,
     private void ensureCameraDevice() throws CameraHardwareException {
         if (mCameraDevice == null) {
             mCameraDevice = CameraHolder.instance().open();
+            mInitialParameters = mCameraDevice.getParameters();
         }
     }
 
@@ -1802,19 +1797,6 @@ public class Camera extends Activity implements View.OnClickListener,
             }
 
             mCameraDevice.setParameters(mParameters);
-
-            // The complete preference has not been read, read it now
-            if (!mScreenComplete && mSettings != null) {
-                // The current scene mode is auto and thus the supported values
-                // of the three settings (flash mode, white balance, and focus
-                // mode) are complete now. If we didn't have the complete
-                // preference screen, read it now.
-                mScreenComplete = true;
-                mParameters = mCameraDevice.getParameters();
-                CameraSettings helper = new CameraSettings(this, mParameters);
-                mSettings.setPreferenceScreen(helper
-                        .getPreferenceScreen(R.xml.camera_preferences));
-            }
         }
 
         // We post the runner because this function can be called from
index e4737be..2cdce3a 100644 (file)
@@ -126,6 +126,8 @@ public class CameraSettings {
                 (ListPreference) screen.findPreference(KEY_SCENE_MODE);
         ListPreference flashMode =
                 (ListPreference) screen.findPreference(KEY_FLASH_MODE);
+        ListPreference focusMode =
+                (ListPreference) screen.findPreference(KEY_FOCUS_MODE);
 
         // Since the screen could be loaded from different resources, we need
         // to check if the preference is available here
@@ -159,6 +161,10 @@ public class CameraSettings {
             filterUnsupportedOptions(screen,
                     flashMode, mParameters.getSupportedFlashModes());
         }
+        if (focusMode != null) {
+            filterUnsupportedOptions(screen,
+                    focusMode, mParameters.getSupportedFocusModes());
+        }
     }
 
     private static boolean removePreference(PreferenceGroup group,
@@ -179,14 +185,15 @@ public class CameraSettings {
     private void filterUnsupportedOptions(PreferenceScreen screen,
             ListPreference pref, List<String> supported) {
 
-        // Remove the preference if the parameter is not supported.
-        if (supported == null) {
+        CharSequence[] allEntries = pref.getEntries();
+
+        // Remove the preference if the parameter is not supported or there is
+        // only one options for the settings.
+        if (supported == null || allEntries.length <= 1) {
             removePreference(screen, pref);
             return;
         }
 
-        // Prepare setting entries and entry values.
-        CharSequence[] allEntries = pref.getEntries();
         CharSequence[] allEntryValues = pref.getEntryValues();
         Drawable[] allIcons = (pref instanceof IconListPreference)
                 ? ((IconListPreference) pref).getIcons()