OSDN Git Service

Disabling non available options instead of hiding when hw support is present (camera...
authorGabriel Nava <gnava@google.com>
Fri, 1 May 2015 16:28:50 +0000 (09:28 -0700)
committerGabriel Nava <gnava@google.com>
Fri, 1 May 2015 21:04:23 +0000 (14:04 -0700)
- Global scope property persists the support of flash and hdr for the main camera (back)
- If option is not supported at all, option is hidden
- If option is supported in at least one camera but not supported in current module, option is disabled
- If option is supported in current module, option is enabled
- Avoiding race condition where CameraAppUI.applyModuleSpecs was bein called multiple times simultaneously for the same change
- Adding a check so BottomBar UI is updated only when there's a scope (module/camera) change, unless...
- Scope check can be requested within same scope for settings change

Bug: 20630060
Change-Id: Iac5fa2658f04fe8329a2232fb0d5b11d20e566a2

src/com/android/camera/PhotoModule.java
src/com/android/camera/VideoModule.java
src/com/android/camera/app/CameraAppUI.java
src/com/android/camera/settings/Keys.java

index 9423e15..75c327b 100644 (file)
@@ -130,6 +130,7 @@ public class PhotoModule
     private int mCameraId;
     private CameraCapabilities mCameraCapabilities;
     private CameraSettings mCameraSettings;
+    private HardwareSpec mHardwareSpec;
     private boolean mPaused;
 
     private PhotoUI mUI;
@@ -611,9 +612,12 @@ public class PhotoModule
 
     @Override
     public HardwareSpec getHardwareSpec() {
-        return (mCameraSettings != null ?
-                new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
-                        mAppController.getCameraFeatureConfig(), isCameraFrontFacing()) : null);
+        if (mHardwareSpec == null) {
+            mHardwareSpec = (mCameraSettings != null ?
+                    new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
+                            mAppController.getCameraFeatureConfig(), isCameraFrontFacing()) : null);
+        }
+        return mHardwareSpec;
     }
 
     @Override
@@ -1230,6 +1234,9 @@ public class PhotoModule
         startPreview();
 
         onCameraOpened();
+
+        mHardwareSpec = new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
+                mAppController.getCameraFeatureConfig(), isCameraFrontFacing());
     }
 
     @Override
index 1d603e0..e6c915e 100644 (file)
@@ -122,6 +122,7 @@ public class VideoModule extends CameraModule
     private int mCameraId;
     private CameraSettings mCameraSettings;
     private CameraCapabilities mCameraCapabilities;
+    private HardwareSpec mHardwareSpec;
 
     private boolean mIsInReviewMode;
     private boolean mSnapshotInProgress = false;
@@ -543,9 +544,12 @@ public class VideoModule extends CameraModule
 
     @Override
     public HardwareSpec getHardwareSpec() {
-        return (mCameraSettings != null ?
-                new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
-                        mAppController.getCameraFeatureConfig(), isCameraFrontFacing()) : null);
+        if (mHardwareSpec == null) {
+            mHardwareSpec = (mCameraSettings != null ?
+                    new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
+                            mAppController.getCameraFeatureConfig(), isCameraFrontFacing()) : null);
+        }
+        return mHardwareSpec;
     }
 
     @Override
@@ -600,6 +604,9 @@ public class VideoModule extends CameraModule
         initializeVideoSnapshot();
         mUI.initializeZoom(mCameraSettings, mCameraCapabilities);
         initializeControlByIntent();
+
+        mHardwareSpec = new HardwareSpecImpl(getCameraProvider(), mCameraCapabilities,
+                mAppController.getCameraFeatureConfig(), isCameraFrontFacing());
     }
 
     private void startPlayVideoActivity() {
index cdbad48..c703b35 100644 (file)
@@ -562,6 +562,13 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
     /** Whether to prevent capture indicator from being triggered. */
     private boolean mSuppressCaptureIndicator;
 
+    /** Whether HDR is supported in at least one module. */
+    private boolean mHdrSupportedOverall;
+
+    /** Used to track the last scope used to update the bottom bar UI. */
+    private String mCurrentCameraScope;
+    private String mCurrentModuleScope;
+
     /**
      * Provides current preview frame and the controls/overlay from the module that
      * are shown on top of the preview.
@@ -1225,7 +1232,36 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
      */
     public void onChangeCamera() {
         ModuleController moduleController = mController.getCurrentModuleController();
-        applyModuleSpecs(moduleController.getHardwareSpec(), moduleController.getBottomBarSpec());
+        HardwareSpec hardwareSpec = moduleController.getHardwareSpec();
+
+        /**
+         * The current UI requires that the flash option visibility in front-
+         * facing camera be
+         *   * disabled if back facing camera supports flash
+         *   * hidden if back facing camera does not support flash
+         * We save whether back facing camera supports flash because we cannot
+         * get this in front facing camera without a camera switch.
+         *
+         * If this preference is cleared, we also need to clear the camera
+         * facing setting so we default to opening the camera in back facing
+         * camera, and can save this flash support value again.
+         */
+        if (!mController.getSettingsManager().isSet(SettingsManager.SCOPE_GLOBAL,
+                Keys.KEY_FLASH_SUPPORTED_BACK_CAMERA)) {
+            mController.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL,
+                    Keys.KEY_FLASH_SUPPORTED_BACK_CAMERA,
+                    hardwareSpec.isFlashSupported());
+        }
+        /** Similar logic applies to the HDR option. */
+        if (!mController.getSettingsManager().isSet(SettingsManager.SCOPE_GLOBAL,
+                Keys.KEY_HDR_SUPPORTED_BACK_CAMERA)) {
+            mController.getSettingsManager().set(SettingsManager.SCOPE_GLOBAL,
+                    Keys.KEY_HDR_SUPPORTED_BACK_CAMERA,
+                    hardwareSpec.isHdrSupported() || hardwareSpec.isHdrPlusSupported());
+        }
+
+        applyModuleSpecs(hardwareSpec, moduleController.getBottomBarSpec(),
+                true /*skipScopeCheck*/);
         syncModeOptionIndicators();
     }
 
@@ -1938,7 +1974,8 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
         if (key.equals(Keys.KEY_CAMERA_HDR)) {
             ModuleController moduleController = mController.getCurrentModuleController();
             applyModuleSpecs(moduleController.getHardwareSpec(),
-                             moduleController.getBottomBarSpec());
+                             moduleController.getBottomBarSpec(),
+                             true /*skipScopeCheck*/);
         }
     }
 
@@ -1952,8 +1989,13 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
      *
      * Otherwise, the option is fully enabled and clickable.
      */
-    public void applyModuleSpecs(final HardwareSpec hardwareSpec,
-           final BottomBarUISpec bottomBarSpec) {
+    public void applyModuleSpecs(HardwareSpec hardwareSpec,
+            BottomBarUISpec bottomBarSpec) {
+        applyModuleSpecs(hardwareSpec, bottomBarSpec, false /*skipScopeCheck*/);
+    }
+
+    private void applyModuleSpecs(final HardwareSpec hardwareSpec,
+           final BottomBarUISpec bottomBarSpec, boolean skipScopeCheck) {
         if (hardwareSpec == null || bottomBarSpec == null) {
             return;
         }
@@ -1963,65 +2005,101 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
 
         buttonManager.setToInitialState();
 
-        /** Standard mode options */
-        if (mController.getCameraProvider().getNumberOfCameras() > 1 &&
-                hardwareSpec.isFrontCameraSupported()) {
-            if (bottomBarSpec.enableCamera) {
-                buttonManager.initializeButton(ButtonManager.BUTTON_CAMERA,
-                        bottomBarSpec.cameraCallback);
+        if (skipScopeCheck
+                || !mController.getModuleScope().equals(mCurrentModuleScope)
+                || !mController.getCameraScope().equals(mCurrentCameraScope)) {
+
+            // Scope dependent options, update only if the module or the
+            // camera scope changed or scope-check skip was requested.
+            mCurrentModuleScope = mController.getModuleScope();
+            mCurrentCameraScope = mController.getCameraScope();
+
+            /** Standard mode options */
+            if (mController.getCameraProvider().getNumberOfCameras() > 1 &&
+                    hardwareSpec.isFrontCameraSupported()) {
+                if (bottomBarSpec.enableCamera) {
+                    buttonManager.initializeButton(ButtonManager.BUTTON_CAMERA,
+                            bottomBarSpec.cameraCallback);
+                } else {
+                    buttonManager.disableButton(ButtonManager.BUTTON_CAMERA);
+                }
             } else {
-                buttonManager.disableButton(ButtonManager.BUTTON_CAMERA);
+                // Hide camera icon if front camera not available.
+                buttonManager.hideButton(ButtonManager.BUTTON_CAMERA);
             }
-        } else {
-            // Hide camera icon if front camera not available.
-            buttonManager.hideButton(ButtonManager.BUTTON_CAMERA);
-        }
 
-        if (bottomBarSpec.hideFlash || !hardwareSpec.isFlashSupported()) {
-            // Hide both flash and torch button in flash disable logic
-            buttonManager.hideButton(ButtonManager.BUTTON_FLASH);
-            buttonManager.hideButton(ButtonManager.BUTTON_TORCH);
-        } else {
-            if (bottomBarSpec.enableFlash) {
-                buttonManager.initializeButton(ButtonManager.BUTTON_FLASH,
-                    bottomBarSpec.flashCallback);
-            } else if (bottomBarSpec.enableTorchFlash) {
-                buttonManager.initializeButton(ButtonManager.BUTTON_TORCH,
-                    bottomBarSpec.flashCallback);
-            } else if (bottomBarSpec.enableHdrPlusFlash) {
-                buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS_FLASH,
-                    bottomBarSpec.flashCallback);
+            boolean flashBackCamera = settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL,
+                    Keys.KEY_FLASH_SUPPORTED_BACK_CAMERA);
+            mHdrSupportedOverall = settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL,
+                    Keys.KEY_HDR_SUPPORTED_BACK_CAMERA);
+            if (bottomBarSpec.hideFlash
+                    || !flashBackCamera) {
+                // Hide both flash and torch button in flash disable logic
+                buttonManager.hideButton(ButtonManager.BUTTON_FLASH);
+                buttonManager.hideButton(ButtonManager.BUTTON_TORCH);
             } else {
-                // Disable both flash and torch button in flash disable logic
-                buttonManager.disableButton(ButtonManager.BUTTON_FLASH);
-                buttonManager.disableButton(ButtonManager.BUTTON_TORCH);
-            }
-        }
-
-        if (bottomBarSpec.hideHdr || mIsCaptureIntent) {
-            // Force hide hdr or hdr plus icon.
-            buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
-        } else {
-            if (hardwareSpec.isHdrPlusSupported()) {
-                if (bottomBarSpec.enableHdr) {
-                    buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS,
-                            bottomBarSpec.hdrCallback);
+                if (hardwareSpec.isFlashSupported()) {
+                    if (bottomBarSpec.enableFlash) {
+                        buttonManager.initializeButton(ButtonManager.BUTTON_FLASH,
+                                bottomBarSpec.flashCallback);
+                    } else if (bottomBarSpec.enableTorchFlash) {
+                        buttonManager.initializeButton(ButtonManager.BUTTON_TORCH,
+                                bottomBarSpec.flashCallback);
+                    } else if (bottomBarSpec.enableHdrPlusFlash) {
+                        buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS_FLASH,
+                                bottomBarSpec.flashCallback);
+                    } else {
+                        // Disable both flash and torch button in flash disable
+                        // logic. Need to ensure it's visible, it may be hidden
+                        // from previous non-flash mode.
+                        buttonManager.showButton(ButtonManager.BUTTON_FLASH);
+                        buttonManager.disableButton(ButtonManager.BUTTON_FLASH);
+                        buttonManager.disableButton(ButtonManager.BUTTON_TORCH);
+                    }
                 } else {
-                    buttonManager.disableButton(ButtonManager.BUTTON_HDR_PLUS);
+                    // Flash not supported but another module does.
+                    // Disable flash button. Need to ensure it's visible,
+                    // it may be hidden from previous non-flash mode.
+                    buttonManager.showButton(ButtonManager.BUTTON_FLASH);
+                    buttonManager.disableButton(ButtonManager.BUTTON_FLASH);
+                    buttonManager.disableButton(ButtonManager.BUTTON_TORCH);
                 }
-            } else if (hardwareSpec.isHdrSupported()) {
-                if (bottomBarSpec.enableHdr) {
-                    buttonManager.initializeButton(ButtonManager.BUTTON_HDR,
-                            bottomBarSpec.hdrCallback);
+            }
+
+            if (bottomBarSpec.hideHdr || mIsCaptureIntent) {
+                // Force hide hdr or hdr plus icon.
+                buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
+            } else {
+                if (hardwareSpec.isHdrPlusSupported()) {
+                    mHdrSupportedOverall = true;
+                    if (bottomBarSpec.enableHdr) {
+                        buttonManager.initializeButton(ButtonManager.BUTTON_HDR_PLUS,
+                                bottomBarSpec.hdrCallback);
+                    } else {
+                        buttonManager.disableButton(ButtonManager.BUTTON_HDR_PLUS);
+                    }
+                } else if (hardwareSpec.isHdrSupported()) {
+                    mHdrSupportedOverall = true;
+                    if (bottomBarSpec.enableHdr) {
+                        buttonManager.initializeButton(ButtonManager.BUTTON_HDR,
+                                bottomBarSpec.hdrCallback);
+                    } else {
+                        buttonManager.disableButton(ButtonManager.BUTTON_HDR);
+                    }
                 } else {
-                    buttonManager.disableButton(ButtonManager.BUTTON_HDR);
+                    // Hide hdr plus or hdr icon if neither are supported overall.
+                    if (!mHdrSupportedOverall) {
+                        buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
+                    } else {
+                        // Disable HDR button. Need to ensure it's visible,
+                        // it may be hidden from previous non HDR mode (eg. Video).
+                        buttonManager.showButton(ButtonManager.BUTTON_HDR_PLUS);
+                        buttonManager.disableButton(ButtonManager.BUTTON_HDR_PLUS);
+                    }
                 }
-            } else {
-                // Hide hdr plus or hdr icon if neither are supported.
-                buttonManager.hideButton(ButtonManager.BUTTON_HDR_PLUS);
             }
-        }
 
+        }
         if (bottomBarSpec.hideGridLines) {
             // Force hide grid lines icon.
             buttonManager.hideButton(ButtonManager.BUTTON_GRID_LINES);
index 6b3ce5b..89680d3 100644 (file)
@@ -62,6 +62,8 @@ public class Keys {
             "pref_release_dialog_last_shown_version";
     public static final String KEY_FLASH_SUPPORTED_BACK_CAMERA =
             "pref_flash_supported_back_camera";
+    public static final String KEY_HDR_SUPPORTED_BACK_CAMERA =
+            "pref_hdr_supported_back_camera";
     public static final String KEY_UPGRADE_VERSION = "pref_upgrade_version";
     public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus";
     public static final String KEY_SHOULD_SHOW_REFOCUS_VIEWER_CLING =