OSDN Git Service

Implement return to hdr plus after switch to front facing camera.
authorErin Dahlgren <edahlgren@google.com>
Mon, 3 Mar 2014 20:05:57 +0000 (12:05 -0800)
committerErin Dahlgren <edahlgren@google.com>
Wed, 5 Mar 2014 00:37:13 +0000 (16:37 -0800)
Bug: 12894444
Change-Id: Ia9c0cba83f0ee99f2156e9e58f4fff1af9b6100f

src/com/android/camera/CameraActivity.java
src/com/android/camera/PhotoModule.java
src/com/android/camera/app/AppController.java
src/com/android/camera/settings/SettingsCache.java
src/com/android/camera/settings/SettingsManager.java

index c5c120a..444da01 100644 (file)
@@ -1602,6 +1602,17 @@ public class CameraActivity extends Activity
     }
 
     @Override
+    public int getPreferredChildModeIndex(int modeIndex) {
+        if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo)) {
+            boolean hdrPlusOn = mSettingsManager.isHdrPlusOn();
+            if (hdrPlusOn && GcamHelper.hasGcamCapture()) {
+                modeIndex = getResources().getInteger(R.integer.camera_mode_gcam);
+            }
+        }
+        return modeIndex;
+    }
+
+    @Override
     public void onModeSelected(int modeIndex) {
         if (mCurrentModeIndex == modeIndex) {
             return;
@@ -1618,16 +1629,8 @@ public class CameraActivity extends Activity
         closeModule(mCurrentModule);
         int oldModuleIndex = mCurrentModeIndex;
 
-        // Refocus and Gcam are modes that cannot be selected
-        // from the mode list view, because they are not list items.
-        // Check whether we should interpret MODULE_CRAFT as either.
-        if (modeIndex == getResources().getInteger(R.integer.camera_mode_photo)) {
-            boolean hdrPlusOn = mSettingsManager.isHdrPlusOn();
-            if (hdrPlusOn && GcamHelper.hasGcamCapture()) {
-                modeIndex = getResources().getInteger(R.integer.camera_mode_gcam);
-            }
-        }
-
+        // Select the correct module index from the mode switcher index.
+        modeIndex = getPreferredChildModeIndex(modeIndex);
         setModuleFromModeIndex(modeIndex);
 
         mCameraAppUI.resetBottomControls(mCurrentModule, modeIndex);
index 6430447..980f6e5 100644 (file)
@@ -447,9 +447,24 @@ public class PhotoModule
             new ButtonManager.ButtonCallback() {
                 @Override
                 public void onStateChanged(int state) {
+                    // At the time this callback is fired, the camera id
+                    // has be set to the desired camera.
+
                     if (mPaused || mPendingSwitchCameraId != -1) {
                         return;
                     }
+                    // If switching to back camera, and HDR+ is still on,
+                    // switch back to gcam, otherwise handle callback normally.
+                    SettingsManager settingsManager = mActivity.getSettingsManager();
+                    if (settingsManager.isCameraBackFacing()) {
+                        if (settingsManager.requestsReturnToHdrPlus()) {
+                            settingsManager.set(SettingsManager.SETTING_CAMERA_HDR,
+                                SettingsManager.VALUE_ON);
+                            mHandler.sendEmptyMessage(MSG_SWITCH_TO_GCAM_MODULE);
+                            return;
+                        }
+                    }
+
                     mPendingSwitchCameraId = state;
 
                     Log.v(TAG, "Start to switch camera. cameraId=" + state);
index 04d08a6..df7d734 100644 (file)
@@ -109,6 +109,14 @@ public interface AppController {
     public int getQuickSwitchToModuleId(int currentModuleIndex);
 
     /**
+     * Based on a mode switcher index, choose the correct module index.
+     *
+     * @param modeIndex mode switcher index.
+     * @return module index.
+     */
+    public int getPreferredChildModeIndex(int modeIndex);
+
+    /**
      * This gets called when mode is changed.
      *
      * @param moduleIndex index of the new module to switch to
index 58ee31a..b6a6b4b 100644 (file)
@@ -133,6 +133,8 @@ public class SettingsCache {
                 SettingsManager.SETTING_FLASH_SUPPORTED_BACK_CAMERA);
         mKeyMap.put(SettingsManager.KEY_STRICT_UPGRADE_VERSION,
                 SettingsManager.SETTING_STRICT_UPGRADE_VERSION);
+        mKeyMap.put(SettingsManager.KEY_REQUEST_RETURN_HDR_PLUS,
+                SettingsManager.SETTING_REQUEST_RETURN_HDR_PLUS);
     }
 
     /**
@@ -219,6 +221,8 @@ public class SettingsCache {
                 return SettingsManager.getStrictUpgradeVersionSetting(mContext);
             case SettingsManager.SETTING_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES_INDEX:
                 return SettingsManager.getPeekAnimRemainingTimesSetting(mContext);
+            case SettingsManager.SETTING_REQUEST_RETURN_HDR_PLUS:
+                return SettingsManager.getRequestReturnHdrPlusSetting(mContext);
             default:
                 return mExtraSettings.settingFromId(id);
         }
index 82ce0f5..cb1cc3b 100644 (file)
@@ -26,6 +26,7 @@ import android.util.SparseArray;
 import com.android.camera.ListPreference;
 import com.android.camera.app.AppController;
 import com.android.camera.app.LocationManager;
+import com.android.camera.util.CameraUtil;
 import com.android.camera.util.SettingsHelper;
 import com.android.camera2.R;
 
@@ -367,6 +368,10 @@ public class SettingsManager {
     public static final int SETTING_FLASH_SUPPORTED_BACK_CAMERA = 25;
     public static final int SETTING_STRICT_UPGRADE_VERSION = 26;
     public static final int SETTING_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES_INDEX = 27;
+    // A boolean for requesting to return to HDR plus
+    // as soon as possible, if a user requests a setting/mode option
+    // that forces them to leave HDR plus.
+    public static final int SETTING_REQUEST_RETURN_HDR_PLUS = 28;
 
     // Shared preference keys.
     public static final String KEY_RECORD_LOCATION = "pref_camera_recordlocation_key";
@@ -405,6 +410,7 @@ public class SettingsManager {
     public static final String KEY_STRICT_UPGRADE_VERSION = "pref_strict_upgrade_version";
     public static final String KEY_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES =
             "pref_filmstrip_peek_anim_remaining_play_times";
+    public static final String KEY_REQUEST_RETURN_HDR_PLUS = "pref_request_return_hdr_plus";
 
     public static final int WHITE_BALANCE_DEFAULT_INDEX = 2;
 
@@ -498,7 +504,8 @@ public class SettingsManager {
             return mCameraSettings;
         }
         if (source.equals(SOURCE_MODULE)) {
-            int modeIndex = mAppController.getCurrentModuleIndex();
+            int modeIndex = CameraUtil.getCameraModeParentModeId(
+                mAppController.getCurrentModuleIndex(), mAppController.getAndroidContext());
             return getModulePreferences(modeIndex);
         }
         return null;
@@ -1099,6 +1106,12 @@ public class SettingsManager {
                 KEY_FILMSTRIP_PEEK_ANIM_REMAINING_PLAY_TIMES, null, FLUSH_OFF);
     }
 
+    public static Setting getRequestReturnHdrPlusSetting(Context context) {
+        String defaultValue = context.getString(R.string.setting_none_value);
+        return new Setting(SOURCE_MODULE, TYPE_BOOLEAN, VALUE_OFF,
+                KEY_REQUEST_RETURN_HDR_PLUS, null, FLUSH_OFF);
+    }
+
     // Utilities.
 
     /**
@@ -1119,6 +1132,13 @@ public class SettingsManager {
     }
 
     /**
+     * Returns whether the app should return to hdr plus mode if possible.
+     */
+    public boolean requestsReturnToHdrPlus() {
+        return getBoolean(SettingsManager.SETTING_REQUEST_RETURN_HDR_PLUS);
+    }
+
+    /**
      * Returns whether grid lines are set on.
      */
     public boolean areGridLinesOn() {