OSDN Git Service

Support panorama orientation toggle in mode options.
authorErin Dahlgren <edahlgren@google.com>
Tue, 18 Feb 2014 19:20:34 +0000 (11:20 -0800)
committerErin Dahlgren <edahlgren@google.com>
Tue, 18 Feb 2014 19:20:34 +0000 (11:20 -0800)
Bug: 12977732
Change-Id: I945d53e1f0a6e3ff4e831c9907936f4d4456def6

res/layout/mode_options_bottombar.xml
src/com/android/camera/ButtonManager.java
src/com/android/camera/MultiToggleImageButton.java
src/com/android/camera/app/CameraAppUI.java
src/com/android/camera/settings/SettingsManager.java
src_pd/com/android/camera/util/PhotoSphereHelper.java

index 0ea1f09..055895f 100644 (file)
             android:gravity="center"
             android:visibility="invisible"
             android:background="#4C000000" >
-          <ImageButton
-              android:id="@+id/pano_horizontal_button"
-              style="@style/ModeOption" />
-          <ImageButton
-              android:id="@+id/pano_vertical_button"
+          <!-- pano image ids and descriptions are added at runtime -->
+          <com.android.camera.MultiToggleImageButton
+              android:id="@+id/pano_orientation_toggle_button"
               style="@style/ModeOption" />
           <com.android.camera.MultiToggleImageButton
               android:id="@+id/grid_lines_toggle_button"
index d5e01d5..18be6e6 100644 (file)
@@ -24,7 +24,7 @@ import com.android.camera.ShutterButton;
 import com.android.camera.app.AppController;
 import com.android.camera.module.ModuleController;
 import com.android.camera.settings.SettingsManager;
-
+import com.android.camera.util.PhotoSphereHelper;
 
 import com.android.camera2.R;
 
@@ -43,9 +43,8 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
     public static final int BUTTON_DONE = 7;
     public static final int BUTTON_RETAKE = 8;
     public static final int BUTTON_REVIEW = 9;
-    public static final int BUTTON_PANO_HORIZONTAL = 10;
-    public static final int BUTTON_PANO_VERTICAL = 11;
-    public static final int BUTTON_GRID_LINES = 12;
+    public static final int BUTTON_PANO_ORIENTATION = 10;
+    public static final int BUTTON_GRID_LINES = 11;
 
     /** For two state MultiToggleImageButtons, the off index. */
     public static final int OFF = 0;
@@ -60,8 +59,7 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
     private MultiToggleImageButton mButtonFlash;
     private MultiToggleImageButton mButtonHdr;
     private MultiToggleImageButton mButtonGridlines;
-    private ImageButton mButtonPanoVertical;
-    private ImageButton mButtonPanoHorizontal;
+    private MultiToggleImageButton mButtonPanoOrientation;
 
     /** Intent UI buttons. */
     private ImageButton mButtonCancel;
@@ -135,10 +133,8 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
             = (MultiToggleImageButton) root.findViewById(R.id.hdr_plus_toggle_button);
         mButtonGridlines
             = (MultiToggleImageButton) root.findViewById(R.id.grid_lines_toggle_button);
-        mButtonPanoVertical
-            = (ImageButton) root.findViewById(R.id.pano_vertical_button);
-        mButtonPanoHorizontal
-            = (ImageButton) root.findViewById(R.id.pano_horizontal_button);
+        mButtonPanoOrientation
+            = (MultiToggleImageButton) root.findViewById(R.id.pano_orientation_toggle_button);
         mButtonCancel
             = (ImageButton) root.findViewById(R.id.cancel_button);
         mButtonDone
@@ -180,6 +176,11 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
                 button = getButtonOrError(BUTTON_GRID_LINES);
                 break;
             }
+            case SettingsManager.SETTING_CAMERA_PANO_ORIENTATION: {
+                index = mSettingsManager.getStringValueIndex(id);
+                button = getButtonOrError(BUTTON_PANO_ORIENTATION);
+                break;
+            }
             default: {
                 // Do nothing.
             }
@@ -239,6 +240,11 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
                     throw new IllegalStateException("Grid lines button could not be found.");
                 }
                 return mButtonGridlines;
+            case BUTTON_PANO_ORIENTATION:
+                if (mButtonPanoOrientation == null) {
+                    throw new IllegalStateException("Pano orientation button could not be found.");
+                }
+                return mButtonPanoOrientation;
             default:
                 throw new IllegalArgumentException("button not known by id=" + buttonId);
         }
@@ -251,16 +257,6 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
      */
     private ImageButton getImageButtonOrError(int buttonId) {
         switch (buttonId) {
-            case BUTTON_PANO_VERTICAL:
-                if (mButtonPanoVertical == null) {
-                    throw new IllegalStateException("Flash button could not be found.");
-                }
-                return (ImageButton) mButtonPanoVertical;
-            case BUTTON_PANO_HORIZONTAL:
-                if (mButtonPanoHorizontal == null) {
-                    throw new IllegalStateException("Flash button could not be found.");
-                }
-                return (ImageButton) mButtonPanoHorizontal;
             case BUTTON_CANCEL:
                 if (mButtonCancel == null) {
                     throw new IllegalStateException("Cancel button could not be found.");
@@ -311,6 +307,10 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
             case BUTTON_GRID_LINES:
                 enableGridLinesButton(button, cb, R.array.grid_lines_icons);
                 break;
+            case BUTTON_PANO_ORIENTATION:
+                enablePanoOrientationButton(button, cb,
+                    PhotoSphereHelper.getPanoramaOrientationOptionArrayId());
+                break;
             default:
                 throw new IllegalArgumentException("button not known by id=" + buttonId);
         }
@@ -580,4 +580,31 @@ public class ButtonManager implements SettingsManager.OnSettingChangedListener {
             SettingsManager.SETTING_CAMERA_GRID_LINES);
         button.setState(index >= 0 ? index : 0, true);
     }
+
+   /**
+     * Enable a panorama orientation button.
+     */
+    private void enablePanoOrientationButton(MultiToggleImageButton button,
+            final ButtonCallback cb, int resIdImages) {
+
+        if (resIdImages > 0) {
+            button.overrideImageIds(resIdImages);
+        }
+        button.overrideContentDescriptions(
+            PhotoSphereHelper.getPanoramaOrientationDescriptions());
+        button.setOnStateChangeListener(new MultiToggleImageButton.OnStateChangeListener() {
+            @Override
+            public void stateChanged(View view, int state) {
+                mSettingsManager.setStringValueIndex(
+                    SettingsManager.SETTING_CAMERA_PANO_ORIENTATION, state);
+                if (cb != null) {
+                    cb.onStateChanged(state);
+                }
+            }
+        });
+
+        int index = mSettingsManager.getStringValueIndex(
+            SettingsManager.SETTING_CAMERA_PANO_ORIENTATION);
+        button.setState(index >= 0 ? index : 0, true);
+    }
 }
index 361eefa..bb62c9f 100644 (file)
@@ -108,15 +108,19 @@ public class MultiToggleImageButton extends ImageButton {
      */
     public void setState(int state, boolean callListener) {
         mState = state;
-        setImageResource(mImageIds[mState]);
-        String oldContentDescription = String.valueOf(getContentDescription());
-        String newContentDescription = getResources().getString(mDescIds[mState]);
-        if (oldContentDescription != null && !oldContentDescription.isEmpty()
-                && !oldContentDescription.equals(newContentDescription)) {
-            setContentDescription(newContentDescription);
-            String announceChange = getResources().getString(
+        if (mImageIds != null) {
+            setImageResource(mImageIds[mState]);
+        }
+        if (mDescIds != null) {
+            String oldContentDescription = String.valueOf(getContentDescription());
+            String newContentDescription = getResources().getString(mDescIds[mState]);
+            if (oldContentDescription != null && !oldContentDescription.isEmpty()
+                    && !oldContentDescription.equals(newContentDescription)) {
+                setContentDescription(newContentDescription);
+                String announceChange = getResources().getString(
                     R.string.button_change_announcement, newContentDescription);
-            announceForAccessibility(announceChange);
+                announceForAccessibility(announceChange);
+            }
         }
         super.setImageLevel(mLevel);
         if (callListener && mOnStateChangeListener != null) {
@@ -147,11 +151,13 @@ public class MultiToggleImageButton extends ImageButton {
             R.styleable.MultiToggleImageButton,
             0, 0);
         int imageIds = a.getResourceId(R.styleable.MultiToggleImageButton_imageIds, 0);
-        overrideImageIds(imageIds);
-
+        if (imageIds > 0) {
+            overrideImageIds(imageIds);
+        }
         int descIds = a.getResourceId(R.styleable.MultiToggleImageButton_contentDescriptionIds, 0);
-        overrideContentDescriptions(descIds);
-
+        if (descIds > 0) {
+            overrideContentDescriptions(descIds);
+        }
         a.recycle();
     }
 
index 4827763..d963d8b 100644 (file)
@@ -265,18 +265,11 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
         public boolean hideGridLines;
 
         /**
-         * Set true if the panorama horizontal option should be visible.
+         * Set true if the panorama orientation option should be visible.
          *
          * This option is not constrained by hardware limitations.
          */
-        public boolean enablePanoHorizontal;
-
-        /**
-         * Set true if the panorama vertical option should be visible.
-         *
-         * This option is not constrained by hardware limitations.
-         */
-        public boolean enablePanoVertical;
+        public boolean enablePanoOrientation;
 
         /** Intent UI */
 
@@ -300,46 +293,39 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
         /** Mode options callbacks */
 
         /**
-         * A {@link android.com.android.camera.ButtonManager.ButtonCallback}
+         * A {@link com.android.camera.ButtonManager.ButtonCallback}
          * that will be executed when the camera option is pressed. This
          * callback can be null.
          */
         public ButtonManager.ButtonCallback cameraCallback;
 
         /**
-         * A {@link android.com.android.camera.ButtonManager.ButtonCallback}
+         * A {@link com.android.camera.ButtonManager.ButtonCallback}
          * that will be executed when the flash option is pressed. This
          * callback can be null.
          */
         public ButtonManager.ButtonCallback flashCallback;
 
         /**
-         * A {@link android.com.android.camera.ButtonManager.ButtonCallback}
+         * A {@link com.android.camera.ButtonManager.ButtonCallback}
          * that will be executed when the hdr/hdr+ option is pressed. This
          * callback can be null.
          */
         public ButtonManager.ButtonCallback hdrCallback;
 
         /**
-         * A {@link android.com.android.camera.ButtonManager.ButtonCallback}
+         * A {@link com.android.camera.ButtonManager.ButtonCallback}
          * that will be executed when the grid lines option is pressed. This
          * callback can be null.
          */
         public ButtonManager.ButtonCallback gridLinesCallback;
 
         /**
-         * A {@link android.view.View.OnClickListener} that will execute
-         * when the panorama horizontal option is pressed.
-         * This callback can be null.
-         */
-        public View.OnClickListener panoHorizontalCallback;
-
-        /**
-         * A {@link android.view.View.OnClickListener} that will execute
-         * when the panorama vertical option is pressed.
+         * A {@link com.android.camera.ButtonManager.ButtonCallback}
+         * that will execute when the panorama orientation option is pressed.
          * This callback can be null.
          */
-        public View.OnClickListener panoVerticalCallback;
+        public ButtonManager.ButtonCallback panoOrientationCallback;
 
         /** Intent UI callbacks */
 
@@ -1493,22 +1479,12 @@ public class CameraAppUI implements ModeListView.ModeSwitchListener,
             }
         }
 
-        if (bottomBarSpec.enablePanoHorizontal
-                && PhotoSphereHelper.getPanoramaHorizontalDrawableId() > 0) {
-            buttonManager.enablePushButton(ButtonManager.BUTTON_PANO_HORIZONTAL,
-                bottomBarSpec.panoHorizontalCallback,
-                PhotoSphereHelper.getPanoramaHorizontalDrawableId());
-        } else {
-            buttonManager.hideButton(ButtonManager.BUTTON_PANO_HORIZONTAL);
-        }
-
-        if (bottomBarSpec.enablePanoVertical
-                && PhotoSphereHelper.getPanoramaVerticalDrawableId() > 0) {
-            buttonManager.enablePushButton(ButtonManager.BUTTON_PANO_VERTICAL,
-                bottomBarSpec.panoVerticalCallback,
-                PhotoSphereHelper.getPanoramaVerticalDrawableId());
+        if (bottomBarSpec.enablePanoOrientation
+                && PhotoSphereHelper.getPanoramaOrientationOptionArrayId() > 0) {
+            buttonManager.enableButton(ButtonManager.BUTTON_PANO_ORIENTATION,
+                bottomBarSpec.panoOrientationCallback);
         } else {
-            buttonManager.hideButton(ButtonManager.BUTTON_PANO_VERTICAL);
+            buttonManager.hideButton(ButtonManager.BUTTON_PANO_ORIENTATION);
         }
 
         /** Intent UI */
index fe6a007..2b866c4 100644 (file)
@@ -834,6 +834,15 @@ public class SettingsManager {
         return gridLinesOn.equals(SettingsManager.VALUE_ON);
     }
 
+    /**
+     * Returns whether pano orientation is horizontal.
+     */
+    public boolean isPanoOrientationHorizontal() {
+        String orientation = get(SettingsManager.SETTING_CAMERA_PANO_ORIENTATION);
+        String horizontal = mContext.getString(R.string.pano_orientation_horizontal);
+        return orientation.equals(horizontal);
+    }
+
     // TODO: refactor this into a separate utils module.
 
     /**
index 5d0e54e..971ada4 100644 (file)
@@ -125,9 +125,16 @@ public class PhotoSphereHelper {
     }
 
     /**
-     * Get the resource id of the panorama indicator icon array.
+     * Get the resource id of the panorama orientation option icon array.
      */
-    public static int getPanoramaIndicatorArrayId() {
+    public static int getPanoramaOrientationOptionArrayId() {
+        return 0;
+    }
+
+    /**
+     * Get the resource id of the panorama orientation descriptions array.
+     */
+    public static int getPanoramaOrientationDescriptions() {
         return 0;
     }
 }