Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46720ce0 authored by Bobby Georgescu's avatar Bobby Georgescu Committed by Android Git Automerger
Browse files

am 74d5dfd6: Merge "Consistent animations & up button behavior in Gallery" into gb-ub-photos-arches

* commit '74d5dfd6':
  Consistent animations & up button behavior in Gallery
parents 324a7804 74d5dfd6
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.gallery3d.anim;

import android.view.animation.DecelerateInterpolator;

import com.android.gallery3d.ui.GLCanvas;
import com.android.gallery3d.ui.GLView;
import com.android.gallery3d.ui.RawTexture;

public class StateTransitionAnimation extends Animation {
    private static final float BACKGROUND_ALPHA_FROM = 1f;
    private static final float BACKGROUND_ALPHA_TO = 0f;
    private static final float BACKGROUND_SCALE_FROM = 1f;
    private static final float BACKGROUND_SCALE_TO = 0f;
    private static final float FOREGROUND_ALPHA_FROM = 0.9f;
    private static final float FOREGROUND_ALPHA_TO = 1f;
    private static final float FOREGROUND_SCALE_FROM = 3f;
    private static final float FOREGROUND_SCALE_TO = 1f;

    private float mCurrentForegroundScale;
    private float mCurrentBackgroundScale;
    private float mCurrentBackgroundAlpha;
    private float mCurrentForegroundAlpha;

    public StateTransitionAnimation(int duration) {
        setDuration(duration);
        setInterpolator(new DecelerateInterpolator());
    }

    @Override
    protected void onCalculate(float progress) {
        mCurrentForegroundScale = FOREGROUND_SCALE_FROM
                + (FOREGROUND_SCALE_TO - FOREGROUND_SCALE_FROM) * progress;
        mCurrentForegroundAlpha = FOREGROUND_ALPHA_FROM
                + (FOREGROUND_ALPHA_TO - FOREGROUND_ALPHA_FROM) * progress;
        mCurrentBackgroundAlpha = BACKGROUND_ALPHA_FROM
                + (BACKGROUND_ALPHA_TO - BACKGROUND_ALPHA_FROM) * progress;
        mCurrentBackgroundScale = BACKGROUND_SCALE_FROM
                + (BACKGROUND_SCALE_TO - BACKGROUND_SCALE_FROM) * progress;
    }

    public void applyBackground(GLView view, GLCanvas canvas, RawTexture fadeTexture) {
        canvas.clearBuffer(view.getBackgroundColor());
        canvas.save();
        canvas.setAlpha(mCurrentBackgroundAlpha);
        int xOffset = view.getWidth() / 2;
        int yOffset = view.getHeight() / 2;
        canvas.translate(xOffset, yOffset);
        canvas.scale(mCurrentBackgroundScale, mCurrentBackgroundScale, 1);
        fadeTexture.draw(canvas, -xOffset, -yOffset);
        canvas.restore();
    }

    public void applyForegroundTransformation(GLView view, GLCanvas canvas) {
        int xOffset = view.getWidth() / 2;
        int yOffset = view.getHeight() / 2;
        canvas.translate(xOffset, yOffset);
        canvas.scale(mCurrentForegroundScale, mCurrentForegroundScale, 1);
        canvas.translate(-xOffset, -yOffset);
        canvas.setAlpha(mCurrentForegroundAlpha);
    }
}
+31 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import android.view.WindowManager;

import com.android.gallery3d.R;
import com.android.gallery3d.ui.GLView;
import com.android.gallery3d.ui.PreparePageFadeoutTexture;
import com.android.gallery3d.ui.RawTexture;
import com.android.gallery3d.util.GalleryUtils;

abstract public class ActivityState {
@@ -66,11 +68,24 @@ abstract public class ActivityState {
    private boolean mPlugged = false;
    boolean mIsFinishing = false;

    private static final String KEY_TRANSITION_IN = "transition-in";

    private RawTexture mFadeOutTexture;
    private GLView mContentPane;
    private boolean mWantFadeOut = false;
    private boolean mTransitionIn;

    protected ActivityState() {
    }

    protected void setContentPane(GLView content) {
        mActivity.getGLRoot().setContentPane(content);
        mContentPane = content;
        if (mTransitionIn) {
            mContentPane.setFadeOutTexture(mFadeOutTexture);
            mFadeOutTexture = null;
        }
        mContentPane.setBackgroundColor(getBackgroundColor());
        mActivity.getGLRoot().setContentPane(mContentPane);
    }

    void initialize(AbstractGalleryActivity activity, Bundle data) {
@@ -84,6 +99,9 @@ abstract public class ActivityState {
    }

    protected void onBackPressed() {
        if (mActivity.getStateManager().getStateCount() > 1) {
            fadeOutOnNextPause();
        }
        mActivity.getStateManager().finishState(this);
    }

@@ -157,10 +175,19 @@ abstract public class ActivityState {
        win.setAttributes(params);
    }

    protected void fadeOutOnNextPause() {
        mWantFadeOut = true;
    }

    protected void onPause() {
        if (0 != (mFlags & FLAG_SCREEN_ON_WHEN_PLUGGED)) {
            ((Activity) mActivity).unregisterReceiver(mPowerIntentReceiver);
        }
        if (mWantFadeOut) {
            mWantFadeOut = false;
            mActivity.getTransitionStore().put(KEY_TRANSITION_IN, true);
            PreparePageFadeoutTexture.prepareFadeOutTexture(mActivity, mContentPane);
        }
    }

    // should only be called by StateManager
@@ -214,6 +241,9 @@ abstract public class ActivityState {

    // a subclass of ActivityState should override the method to resume itself
    protected void onResume() {
        mFadeOutTexture = mActivity.getTransitionStore().get(
                PreparePageFadeoutTexture.KEY_FADE_TEXTURE);
        mTransitionIn = mActivity.getTransitionStore().get(KEY_TRANSITION_IN, false);
    }

    protected boolean onCreateActionBar(Menu menu) {
+7 −20
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ import com.android.gallery3d.ui.GLCanvas;
import com.android.gallery3d.ui.GLRoot;
import com.android.gallery3d.ui.GLView;
import com.android.gallery3d.ui.PhotoFallbackEffect;
import com.android.gallery3d.ui.PreparePageFadeoutTexture;
import com.android.gallery3d.ui.RelativePosition;
import com.android.gallery3d.ui.SelectionManager;
import com.android.gallery3d.ui.SlotView;
@@ -138,11 +137,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
    private final GLView mRootPane = new GLView() {
        private final float mMatrix[] = new float[16];

        @Override
        protected void renderBackground(GLCanvas view) {
            view.clearBuffer(getBackgroundColor());
        }

        @Override
        protected void onLayout(
                boolean changed, int left, int top, int right, int bottom) {
@@ -254,8 +248,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
        } else {
            // Render transition in pressed state
            mAlbumView.setPressedIndex(slotIndex);
            PreparePageFadeoutTexture.prepareFadeOutTexture(mActivity, mRootPane);
            mAlbumView.setPressedIndex(-1);

            pickPhoto(slotIndex);
        }
@@ -300,10 +292,14 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
            data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP,
                    startInFilmstrip);
            data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, mMediaSet.isCameraRoll());
            if (startInFilmstrip) {
                mActivity.getStateManager().switchState(this, PhotoPage.class, data);
            } else {
                mActivity.getStateManager().startStateForResult(
                            PhotoPage.class, REQUEST_PHOTO, data);
            }
        }
    }

    private void onGetContent(final MediaItem item) {
        DataManager dm = mActivity.getDataManager();
@@ -373,15 +369,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
        mLaunchedFromPhotoPage =
                mActivity.getStateManager().hasStateClass(PhotoPage.class);
        mInCameraApp = data.getBoolean(PhotoPage.KEY_APP_BRIDGE, false);

        // Don't show animation if it is restored or switched from filmstrip
        if (!mLaunchedFromPhotoPage && restoreState == null && data != null) {
            int[] center = data.getIntArray(KEY_SET_CENTER);
            if (center != null) {
                mOpenCenter.setAbsolutePosition(center[0], center[1]);
                mSlotView.startScatteringAnimation(mOpenCenter);
            }
        }
    }

    @Override
@@ -411,6 +398,7 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
        mAlbumDataAdapter.resume();

        mAlbumView.resume();
        mAlbumView.setPressedIndex(-1);
        mActionModeHandler.resume();
        if (!mInitialSynced) {
            setLoadingBit(BIT_LOADING_SYNC);
@@ -561,7 +549,6 @@ public class AlbumPage extends ActivityState implements GalleryActionBar.Cluster
        if (mAlbumDataAdapter == null || !mAlbumDataAdapter.isActive(slotIndex)) return;
        MediaItem item = mAlbumDataAdapter.get(slotIndex);
        if (item == null) return;
        PreparePageFadeoutTexture.prepareFadeOutTexture(mActivity, mRootPane);
        TransitionStore transitions = mActivity.getTransitionStore();
        transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex);
        transitions.put(PhotoPage.KEY_OPEN_ANIMATION_RECT,
+0 −7
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.gallery3d.ui.FadeTexture;
import com.android.gallery3d.ui.GLCanvas;
import com.android.gallery3d.ui.GLRoot;
import com.android.gallery3d.ui.GLView;
import com.android.gallery3d.ui.PreparePageFadeoutTexture;
import com.android.gallery3d.ui.SelectionManager;
import com.android.gallery3d.ui.SlotView;
import com.android.gallery3d.ui.SynchronizedHandler;
@@ -129,11 +128,6 @@ public class AlbumSetPage extends ActivityState implements
    private final GLView mRootPane = new GLView() {
        private final float mMatrix[] = new float[16];

        @Override
        protected void renderBackground(GLCanvas view) {
            view.clearBuffer(getBackgroundColor());
        }

        @Override
        protected void onLayout(
                boolean changed, int left, int top, int right, int bottom) {
@@ -273,7 +267,6 @@ public class AlbumSetPage extends ActivityState implements
                    & MediaObject.SUPPORT_IMPORT) != 0) {
                data.putBoolean(AlbumPage.KEY_AUTO_SELECT_ALL, true);
            } else if (!mGetContent && albumShouldOpenInFilmstrip(targetSet)) {
                PreparePageFadeoutTexture.prepareFadeOutTexture(mActivity, mRootPane);
                data.putParcelable(PhotoPage.KEY_OPEN_ANIMATION_RECT,
                        mSlotView.getSlotRect(slotIndex, mRootPane));
                data.putInt(PhotoPage.KEY_INDEX_HINT, 0);
+6 −58
Original line number Diff line number Diff line
@@ -34,12 +34,10 @@ import android.os.Message;
import android.os.SystemClock;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.AccelerateInterpolator;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.android.gallery3d.R;
import com.android.gallery3d.anim.FloatAnimation;
import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.common.Utils;
import com.android.gallery3d.data.ComboAlbum;
@@ -61,7 +59,6 @@ import com.android.gallery3d.data.SnailItem;
import com.android.gallery3d.data.SnailSource;
import com.android.gallery3d.picasasource.PicasaSource;
import com.android.gallery3d.ui.AnimationTime;
import com.android.gallery3d.ui.TiledScreenNail;
import com.android.gallery3d.ui.DetailsHelper;
import com.android.gallery3d.ui.DetailsHelper.CloseListener;
import com.android.gallery3d.ui.DetailsHelper.DetailsSource;
@@ -73,8 +70,6 @@ import com.android.gallery3d.ui.ImportCompleteListener;
import com.android.gallery3d.ui.MenuExecutor;
import com.android.gallery3d.ui.PhotoFallbackEffect;
import com.android.gallery3d.ui.PhotoView;
import com.android.gallery3d.ui.PreparePageFadeoutTexture;
import com.android.gallery3d.ui.RawTexture;
import com.android.gallery3d.ui.SelectionManager;
import com.android.gallery3d.ui.SynchronizedHandler;
import com.android.gallery3d.util.GalleryUtils;
@@ -166,7 +161,6 @@ public class PhotoPage extends ActivityState implements
    private boolean mTreatBackAsUp;
    private boolean mStartInFilmstrip;
    private boolean mInCameraRoll;
    private boolean mStartedFromAlbumPage;
    private boolean mRecenterCameraOnResume = true;

    private long mCameraSwitchCutoff = 0;
@@ -177,9 +171,7 @@ public class PhotoPage extends ActivityState implements
    private boolean mDeferredUpdateWaiting = false;
    private long mDeferUpdateUntil = Long.MAX_VALUE;

    private RawTexture mFadeOutTexture;
    private Rect mOpenAnimationRect;
    public static final int ANIM_TIME_OPENING = 300;

    // The item that is deleted (but it can still be undeleted before commiting)
    private Path mDeletePath;
@@ -221,13 +213,6 @@ public class PhotoPage extends ActivityState implements
        }
    }

    private static class BackgroundFadeOut extends FloatAnimation {
        public BackgroundFadeOut() {
            super(1f, 0f, ANIM_TIME_OPENING);
            setInterpolator(new AccelerateInterpolator(2f));
        }
    }

    private class UpdateProgressListener implements StitchingChangeListener {

        @Override
@@ -254,36 +239,12 @@ public class PhotoPage extends ActivityState implements
        }
    };

    private final FloatAnimation mBackgroundFade = new BackgroundFadeOut();

    @Override
    protected int getBackgroundColorId() {
        return R.color.photo_background;
    }

    private final GLView mRootPane = new GLView() {
        @Override
        protected void renderBackground(GLCanvas view) {
            if (mFadeOutTexture != null) {
                if (mBackgroundFade.calculate(AnimationTime.get())) invalidate();
                if (!mBackgroundFade.isActive()) {
                    mFadeOutTexture = null;
                    mOpenAnimationRect = null;
                    TiledScreenNail.enableDrawPlaceholder();
                } else {
                    float fadeAlpha = mBackgroundFade.get();
                    if (fadeAlpha < 1f) {
                        view.clearBuffer(getBackgroundColor());
                        view.setAlpha(fadeAlpha);
                    }
                    mFadeOutTexture.draw(view, 0, 0);
                    view.setAlpha(1f - fadeAlpha);
                    return;
                }
            }
            view.clearBuffer(getBackgroundColor());
        }

        @Override
        protected void onLayout(
                boolean changed, int left, int top, int right, int bottom) {
@@ -402,9 +363,6 @@ public class PhotoPage extends ActivityState implements
        mTreatBackAsUp = data.getBoolean(KEY_TREAT_BACK_AS_UP, false);
        mStartInFilmstrip = data.getBoolean(KEY_START_IN_FILMSTRIP, false);
        mInCameraRoll = data.getBoolean(KEY_IN_CAMERA_ROLL, false);
        mStartedFromAlbumPage =
                data.getInt(KEY_ALBUMPAGE_TRANSITION,
                        MSG_ALBUMPAGE_NONE) == MSG_ALBUMPAGE_STARTED;
        mCurrentIndex = data.getInt(KEY_INDEX_HINT, 0);
        if (mSetPathString != null) {
            mShowSpinner = true;
@@ -970,11 +928,10 @@ public class PhotoPage extends ActivityState implements
    };

    private void switchToGrid() {
        if (mStartedFromAlbumPage) {
        if (mActivity.getStateManager().hasStateClass(AlbumPage.class)) {
            onUpPressed();
        } else {
            if (mOriginalSetPathString == null) return;
            preparePhotoFallbackView();
            Bundle data = new Bundle(getData());
            data.putString(AlbumPage.KEY_MEDIA_PATH, mOriginalSetPathString);
            data.putString(AlbumPage.KEY_PARENT_MEDIA_PATH,
@@ -993,7 +950,11 @@ public class PhotoPage extends ActivityState implements
            mActivity.getTransitionStore().put(KEY_RETURN_INDEX_HINT,
                    mAppBridge != null ? mCurrentIndex - 1 : mCurrentIndex);

            if (mInCameraRoll && mAppBridge != null) {
                mActivity.getStateManager().startState(AlbumPage.class, data);
            } else {
                mActivity.getStateManager().switchState(this, AlbumPage.class, data);
            }
        }
    }

@@ -1304,7 +1265,6 @@ public class PhotoPage extends ActivityState implements
        // Hide the detail dialog on exit
        if (mShowDetails) hideDetails();
        if (mModel != null) {
            if (isFinishing()) preparePhotoFallbackView();
            mModel.pause();
        }
        mPhotoView.pause();
@@ -1368,18 +1328,6 @@ public class PhotoPage extends ActivityState implements
        } else if (albumPageTransition == MSG_ALBUMPAGE_PICKED) {
            mPhotoView.setFilmMode(false);
        }

        mFadeOutTexture = transitions.get(PreparePageFadeoutTexture.KEY_FADE_TEXTURE);
        if (mFadeOutTexture != null) {
            mBackgroundFade.start();
            TiledScreenNail.disableDrawPlaceholder();
            mOpenAnimationRect =
                    albumPageTransition == MSG_ALBUMPAGE_NONE ?
                    (Rect) mData.getParcelable(KEY_OPEN_ANIMATION_RECT) :
                    (Rect) transitions.get(KEY_OPEN_ANIMATION_RECT);
            mPhotoView.setOpenAnimationRect(mOpenAnimationRect);
            mBackgroundFade.start();
        }
    }

    @Override
Loading