From d028dd4908e68c7d4d0e7438efa74fa2c67e5f2a Mon Sep 17 00:00:00 2001 From: Angus Kong Date: Fri, 13 Sep 2013 18:09:18 -0700 Subject: Set correct alpha for views in filmstrip. bug:10713813 Change-Id: I2715b7c3ecb2e0c995e8f66e710c91561e9cf231 --- src/com/android/camera/ui/FilmStripView.java | 89 +++++++++++++++++++--------- 1 file changed, 60 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/com/android/camera/ui/FilmStripView.java b/src/com/android/camera/ui/FilmStripView.java index 64f8a69d4..69e9aed06 100644 --- a/src/com/android/camera/ui/FilmStripView.java +++ b/src/com/android/camera/ui/FilmStripView.java @@ -1048,7 +1048,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { * Translates the {@link ViewItem} on the left of the current one to match * the full-screen layout. In full-screen, we show only one {@link ViewItem} * which occupies the whole screen. The other left ones are put on the left - * side in full scales. + * side in full scales. Does nothing if there's no next item. * * @param currItem The item ID of the current one to be translated. * @param drawAreaWidth The width of the current draw area. @@ -1088,7 +1088,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { /** * Fade out the {@link ViewItem} on the right of the current one in - * full-screen layout. + * full-screen layout. Does nothing if there's no previous item. * * @param currItem The ID of the item to fade. */ @@ -1155,59 +1155,90 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { (mScale - FILM_STRIP_SCALE) / (FULL_SCREEN_SCALE - FILM_STRIP_SCALE)); final int fullScreenWidth = mDrawArea.width() + mViewGap; + // Decide the position for all view items on the left and the right first. + + // Left items. + for (int itemID = mCurrentItem - 1; itemID >= 0; itemID--) { + final ViewItem curr = mViewItem[itemID]; + if (curr == null) { + break; + } + + // First, layout relatively to the next one. + final int currLeft = mViewItem[itemID + 1].getLeftPosition() + - curr.getView().getMeasuredWidth() - mViewGap; + curr.setLeftPosition(currLeft); + } + // Right items. + for (int itemID = mCurrentItem + 1; itemID < BUFFER_SIZE; itemID++) { + ViewItem curr = mViewItem[itemID]; + if (curr == null) { + break; + } + + // First, layout relatively to the previous one. + ViewItem prev = mViewItem[itemID - 1]; + int currLeft = + prev.getLeftPosition() + prev.getView().getMeasuredWidth() + + mViewGap; + curr.setLeftPosition(currLeft); + } + // Layout the current ViewItem first. if (scaleFraction == 1f) { - if (mCenterX < mViewItem[mCurrentItem].getCenterX()) { - // In full-screen and it's not the first one and mCenterX is on - // the left of the center, we draw the current one to "fade down". + final ViewItem currItem = mViewItem[mCurrentItem]; + final int currCenterX = currItem.getCenterX(); + if (mCenterX < currCenterX) { + // In full-screen and mCenterX is on the left of the center, + // we draw the current one to "fade down". fadeAndScaleRightViewItem(mCurrentItem); - } else if(mCenterX > mViewItem[mCurrentItem].getCenterX()) { - // In full-screen and it's not the last one and mCenterX is on - // the right of the center, we draw the current one translated. + } else if(mCenterX > currCenterX) { + // In full-screen and mCenterX is on the right of the center, + // we draw the current one translated. translateLeftViewItem(mCurrentItem, fullScreenWidth, scaleFraction); } else { - mViewItem[mCurrentItem].layoutIn(mDrawArea, mCenterX, mScale); - mViewItem[mCurrentItem].setTranslationX(0f, mScale); - mViewItem[mCurrentItem].getView().setAlpha(1f); + currItem.layoutIn(mDrawArea, mCenterX, mScale); + currItem.setTranslationX(0f, mScale); + currItem.getView().setAlpha(1f); } } else { + final ViewItem currItem = mViewItem[mCurrentItem]; // The normal filmstrip has no translation for the current item. If it has // translation before, gradually set it to zero. - mViewItem[mCurrentItem].setTranslationX( - mViewItem[mCurrentItem].getScaledTranslationX(mScale) * scaleFraction, + currItem.setTranslationX( + currItem.getScaledTranslationX(mScale) * scaleFraction, mScale); - mViewItem[mCurrentItem].layoutIn(mDrawArea, mCenterX, mScale); + currItem.layoutIn(mDrawArea, mCenterX, mScale); + if (mViewItem[mCurrentItem - 1] == null) { + currItem.getView().setAlpha(1f); + } else { + final int currCenterX = currItem.getCenterX(); + final int prevCenterX = mViewItem[mCurrentItem - 1].getCenterX(); + final float fadeDownFraction = + ((float) mCenterX - prevCenterX) / (currCenterX - prevCenterX); + currItem.getView().setAlpha( + (1 - fadeDownFraction) * (1 - scaleFraction) + fadeDownFraction); + } } // Layout the rest dependent on the current scale. - // images on the left + // Items on the left for (int itemID = mCurrentItem - 1; itemID >= 0; itemID--) { final ViewItem curr = mViewItem[itemID]; if (curr == null) { break; } - - // First, layout relatively to the next one. - final int currLeft = mViewItem[itemID + 1].getLeftPosition() - - curr.getView().getMeasuredWidth() - mViewGap; - curr.setLeftPosition(currLeft); translateLeftViewItem(itemID, fullScreenWidth, scaleFraction); } - // images on the right + // Items on the right for (int itemID = mCurrentItem + 1; itemID < BUFFER_SIZE; itemID++) { ViewItem curr = mViewItem[itemID]; if (curr == null) { - continue; + break; } - // First, layout relatively to the previous one. - ViewItem prev = mViewItem[itemID - 1]; - int currLeft = - prev.getLeftPosition() + prev.getView().getMeasuredWidth() - + mViewGap; - curr.setLeftPosition(currLeft); curr.layoutIn(mDrawArea, mCenterX, mScale); View currView = curr.getView(); if (scaleFraction == 1) { @@ -1227,7 +1258,7 @@ public class FilmStripView extends ViewGroup implements BottomControlsListener { } } curr.setTranslationX( - (mViewItem[mCurrentItem].getLeftPosition() - currLeft) + (mViewItem[mCurrentItem].getLeftPosition() - curr.getLeftPosition()) * scaleFraction, mScale); } } -- cgit v1.2.3