OSDN Git Service

Set camera controls visibility based on whether the camera preview is centered.
authorErin Dahlgren <edahlgren@google.com>
Fri, 11 Oct 2013 01:23:45 +0000 (18:23 -0700)
committerErin Dahlgren <edahlgren@google.com>
Mon, 14 Oct 2013 20:40:45 +0000 (13:40 -0700)
Bug: 10861015
Change-Id: Ib0c4945e35cee16b73a4bba913e11d0f79a26176

src/com/android/camera/CameraActivity.java
src/com/android/camera/CameraModule.java
src/com/android/camera/PhotoModule.java
src/com/android/camera/PhotoUI.java
src/com/android/camera/VideoModule.java
src/com/android/camera/VideoUI.java
src/com/android/camera/WideAnglePanoramaModule.java
src/com/android/camera/WideAnglePanoramaUI.java
src/com/android/camera/ui/FilmStripView.java

index 52d0e4d..ab46e02 100644 (file)
@@ -334,6 +334,35 @@ public class CameraActivity extends Activity
                 }
 
                 @Override
+                public void onReload() {
+                    setPreviewControlsVisibility(true);
+                }
+
+                @Override
+                public void onCurrentDataCentered(int dataID) {
+                    if (dataID != 0 && !mFilmStripView.isCameraPreview()) {
+                        // For now, We ignore all items that are not the camera preview.
+                        return;
+                    }
+
+                    if(!arePreviewControlsVisible()) {
+                        setPreviewControlsVisibility(true);
+                    }
+                }
+
+                @Override
+                public void onCurrentDataOffCentered(int dataID) {
+                    if (dataID != 0 && !mFilmStripView.isCameraPreview()) {
+                        // For now, We ignore all items that are not the camera preview.
+                        return;
+                    }
+
+                    if (arePreviewControlsVisible()) {
+                        setPreviewControlsVisibility(false);
+                    }
+                }
+
+                @Override
                 public void onDataFocusChanged(final int dataID, final boolean focused) {
                     // Delay hiding action bar if there is any user interaction
                     if (mMainHandler.hasMessages(HIDE_ACTION_BAR)) {
@@ -363,10 +392,10 @@ public class CameraActivity extends Activity
                                 hidePanoStitchingProgress();
                             } else {
                                 if (isCameraID) {
-                                    mCurrentModule.onPreviewFocusChanged(true);
                                     // Don't show the action bar in Camera
                                     // preview.
                                     CameraActivity.this.setSystemBarsVisibility(false);
+
                                     if (mPendingDeletion) {
                                         performDeletion();
                                     }
@@ -1449,6 +1478,26 @@ public class CameraActivity extends Activity
         }
     }
 
+
+    /**
+     * Check whether camera controls are visible.
+     *
+     * @return whether controls are visible.
+     */
+    private boolean arePreviewControlsVisible() {
+        return mCurrentModule.arePreviewControlsVisible();
+    }
+
+    /**
+     * Show or hide the {@link CameraControls} using the current module's
+     * implementation of {@link #onPreviewFocusChanged}.
+     *
+     * @param showControls whether to show camera controls.
+     */
+    private void setPreviewControlsVisibility(boolean showControls) {
+        mCurrentModule.onPreviewFocusChanged(showControls);
+    }
+
     // Accessor methods for getting latency times used in performance testing
     public long getAutoFocusTime() {
         return (mCurrentModule instanceof PhotoModule) ?
index 1283a98..55cae9f 100644 (file)
@@ -64,4 +64,6 @@ public interface CameraModule {
     public void onShowSwitcherPopup();
 
     public void onMediaSaveServiceConnected(MediaSaveService s);
+
+    public boolean arePreviewControlsVisible();
 }
index 8699ef0..bed8a21 100644 (file)
@@ -1944,6 +1944,11 @@ public class PhotoModule
         mUI.onPreviewFocusChanged(previewFocused);
     }
 
+    @Override
+    public boolean arePreviewControlsVisible() {
+        return mUI.arePreviewControlsVisible();
+    }
+
     // For debugging only.
     public void setDebugUri(Uri uri) {
         mDebugUri = uri;
index 9273e21..58df436 100644 (file)
@@ -398,6 +398,10 @@ public class PhotoUI implements PieListener,
         mCameraControls.setVisibility(View.VISIBLE);
     }
 
+    public boolean arePreviewControlsVisible() {
+        return (mCameraControls.getVisibility() == View.VISIBLE);
+    }
+
     public void hideSwitcher() {
         mSwitcher.closePopup();
         mSwitcher.setVisibility(View.INVISIBLE);
index 83c5faf..296385e 100644 (file)
@@ -1717,6 +1717,11 @@ public class VideoModule implements CameraModule,
         forceFlashOff(!previewFocused);
     }
 
+    @Override
+    public boolean arePreviewControlsVisible() {
+        return mUI.arePreviewControlsVisible();
+    }
+
     private final class JpegPictureCallback implements CameraPictureCallback {
         Location mLocation;
 
index f097d93..23d08db 100644 (file)
@@ -345,6 +345,10 @@ public class VideoUI implements PieRenderer.PieListener,
         mCameraControls.setVisibility(View.VISIBLE);
     }
 
+    public boolean arePreviewControlsVisible() {
+        return (mCameraControls.getVisibility() == View.VISIBLE);
+    }
+
     public void hideSwitcher() {
         mSwitcher.closePopup();
         mSwitcher.setVisibility(View.INVISIBLE);
index 189bf99..f91b41e 100644 (file)
@@ -144,6 +144,7 @@ public class WideAnglePanoramaModule
     private OrientationManager mOrientationManager;
     private ComboPreferences mPreferences;
     private boolean mMosaicPreviewConfigured;
+    private boolean mPreviewFocused;
 
     @Override
     public void onPreviewUIReady() {
@@ -308,11 +309,13 @@ public class WideAnglePanoramaModule
 
     @Override
     public void onPreviewFocusChanged(boolean previewFocused) {
-        if (previewFocused) {
-            mUI.showUI();
-        } else {
-            mUI.hideUI();
-        }
+        mPreviewFocused = previewFocused;
+        mUI.onPreviewFocusChanged(previewFocused);
+    }
+
+    @Override
+    public boolean arePreviewControlsVisible() {
+        return mUI.arePreviewControlsVisible();
     }
 
     /**
@@ -705,7 +708,9 @@ public class WideAnglePanoramaModule
         mActivity.setSwipingEnabled(true);
         // Orientation change will trigger onLayoutChange->configMosaicPreview->
         // resetToPreview. Do not show the capture UI in film strip.
-        mUI.showPreviewUI();
+        if (mPreviewFocused) {
+            mUI.showPreviewUI();
+        }
         mMosaicFrameProcessor.reset();
     }
 
index 4071609..cf2c398 100644 (file)
@@ -137,6 +137,18 @@ public class WideAnglePanoramaUI implements
         mCameraControls.setVisibility(View.VISIBLE);
     }
 
+    public void onPreviewFocusChanged(boolean previewFocused) {
+        if (previewFocused) {
+            showUI();
+        } else {
+            hideUI();
+        }
+    }
+
+    public boolean arePreviewControlsVisible() {
+        return (mCameraControls.getVisibility() == View.VISIBLE);
+    }
+
     public void showSwitcher() {
         mSwitcher.setVisibility(View.VISIBLE);
     }
index 5de2d7c..d17567d 100644 (file)
@@ -340,6 +340,27 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         public void onDataFullScreenChange(int dataID, boolean fullScreen);
 
         /**
+         * Called by {@link reload}.
+         */
+        public void onReload();
+
+        /**
+         * Called by {@link checkCurrentDataCentered} when the
+         * data is centered in the film strip.
+         *
+         * @param dataID the ID of the local data
+         */
+        public void onCurrentDataCentered(int dataID);
+
+        /**
+         * Called by {@link checkCurrentDataCentered} when the
+         * data is off centered in the film strip.
+         *
+         * @param dataID the ID of the local data
+         */
+        public void onCurrentDataOffCentered(int dataID);
+
+        /**
          * The callback when the item is centered/off-centered.
          *
          * @param dataID The ID of the image data.
@@ -712,7 +733,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
      * @param id The id of the data to check.
      * @return {@code True} if the data is currently at the center.
      */
-    protected boolean isDataAtCenter(int id) {
+    private boolean isDataAtCenter(int id) {
         if (mViewItem[mCurrentItem] == null) {
             return false;
         }
@@ -826,6 +847,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         if (nearest == BUFFER_SIZE) {
             return -1;
         }
+
         int min = Math.abs(pointX - mViewItem[nearest].getCenterX());
 
         for (int itemID = nearest + 1; itemID < BUFFER_SIZE && mViewItem[itemID] != null; itemID++) {
@@ -961,10 +983,28 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         if (stopScroll) {
             mCenterX = curr.getCenterX();
         }
+
         return stopScroll;
     }
 
     /**
+     * Checks if the item is centered in the film strip, and calls
+     * {@link #onCurrentDataCentered} or {@link #onCurrentDataOffCentered}.
+     * TODO: refactor.
+     *
+     * @param dataID the ID of the image data.
+     */
+    private void checkCurrentDataCentered(int dataID) {
+        if (mListener != null) {
+            if (isDataAtCenter(dataID)) {
+                mListener.onCurrentDataCentered(dataID);
+            } else {
+                mListener.onCurrentDataOffCentered(dataID);
+            }
+        }
+    }
+
+    /**
      * Reorders the child views to be consistent with their data ID. This
      * method should be called after adding/removing views.
      */
@@ -1688,6 +1728,10 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         return (mScale == FULL_SCREEN_SCALE);
     }
 
+    public boolean isCameraPreview() {
+        return (getCurrentViewType() == ImageData.VIEW_TYPE_STICKY);
+    }
+
     public boolean inCameraFullscreen() {
         return isDataAtCenter(0) && inFullScreen()
                 && (getCurrentViewType() == ImageData.VIEW_TYPE_STICKY);
@@ -1758,7 +1802,10 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         }
         newItem.copyGeometry(item);
         mViewItem[itemID] = newItem;
-        if (clampCenterX()) {
+
+        boolean stopScroll = clampCenterX();
+        checkCurrentDataCentered(getCurrentId());
+        if (stopScroll) {
             mController.stopScrolling(true);
         }
         adjustChildZOrder();
@@ -1883,6 +1930,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
         invalidate();
 
         if (mListener != null) {
+            mListener.onReload();
             mListener.onDataFocusChanged(mViewItem[mCurrentItem].getId(), true);
         }
     }
@@ -1917,7 +1965,10 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
                     @Override
                     public void onScrollUpdate(int currX, int currY) {
                         mCenterX = currX;
-                        if (clampCenterX()) {
+
+                        boolean stopScroll = clampCenterX();
+                        checkCurrentDataCentered(getCurrentId());
+                        if (stopScroll) {
                             mController.stopScrolling(true);
                         }
                         invalidate();
@@ -2056,7 +2107,10 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
                 return;
             }
             mCenterX += deltaX;
-            if (clampCenterX()) {
+
+            boolean stopScroll = clampCenterX();
+            checkCurrentDataCentered(getCurrentId());
+            if (stopScroll) {
                 mController.stopScrolling(true);
             }
             invalidate();
@@ -2201,6 +2255,8 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener {
             mCanStopScroll = interruptible;
             mScroller.startScroll(mCenterX, 0, position - mCenterX,
                     0, duration);
+
+            checkCurrentDataCentered(mViewItem[mCurrentItem].getId());
         }
 
         @Override