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

Commit 2c617382 authored by Chih-Chung Chang's avatar Chih-Chung Chang
Browse files

Add capture animation in Gallery.

Change-Id: Ibf95cc64f37a4518377e64124af6606c4f14cdaa
parent 97d7d0f2
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -205,6 +205,18 @@ public class AbstractGalleryActivity extends Activity implements GalleryActivity
        }
    }

    @Override
    public void onBackPressed() {
        // send the back event to the top sub-state
        GLRoot root = getGLRoot();
        root.lockRenderThread();
        try {
            getStateManager().onBackPressed();
        } finally {
            root.unlockRenderThread();
        }
    }

    @Override
    public GalleryActionBar getGalleryActionBar() {
        if (mActionBar == null) {
+0 −12
Original line number Diff line number Diff line
@@ -232,18 +232,6 @@ public final class Gallery extends AbstractGalleryActivity implements OnCancelLi
        return getStateManager().createOptionsMenu(menu);
    }

    @Override
    public void onBackPressed() {
        // send the back event to the top sub-state
        GLRoot root = getGLRoot();
        root.lockRenderThread();
        try {
            getStateManager().onBackPressed();
        } finally {
            root.unlockRenderThread();
        }
    }

    @Override
    protected void onResume() {
        Utils.assertTrue(getStateManager().getStateCount() > 0);
+8 −1
Original line number Diff line number Diff line
@@ -403,11 +403,18 @@ public class PhotoPage extends ActivityState
    protected void onBackPressed() {
        if (mShowDetails) {
            hideDetails();
        } else {
        } else if (!switchWithCaptureAnimation(-1)) {
            super.onBackPressed();
        }
    }

    // Switch to the previous or next picture using the capture animation.
    // The offset is -1 to switch to the previous picture, 1 to switch to
    // the next picture.
    public boolean switchWithCaptureAnimation(int offset) {
        return mPhotoView.switchWithCaptureAnimation(offset);
    }

    @Override
    protected boolean onCreateActionBar(Menu menu) {
        MenuInflater inflater = ((Activity) mActivity).getMenuInflater();
+0 −12
Original line number Diff line number Diff line
@@ -77,18 +77,6 @@ public class PickerActivity extends AbstractGalleryActivity
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        // send the back event to the top sub-state
        GLRoot root = getGLRoot();
        root.lockRenderThread();
        try {
            getStateManager().getTopState().onBackPressed();
        } finally {
            root.unlockRenderThread();
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.cancel) finish();
+56 −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.ui;

import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;

public class CaptureAnimation {
    // The amount of change for zooming out.
    private static final float ZOOM_DELTA = 0.2f;
    // Pre-calculated value for convenience.
    private static final float ZOOM_IN_BEGIN = 1f - ZOOM_DELTA;

    private static final Interpolator sZoomOutInterpolator =
            new DecelerateInterpolator();
    private static final Interpolator sZoomInInterpolator =
            new AccelerateInterpolator();
    private static final Interpolator sSlideInterpolator =
        new AccelerateDecelerateInterpolator();

    // Calculate the slide factor based on the give time fraction.
    public static float calculateSlide(float fraction) {
        return sSlideInterpolator.getInterpolation(fraction);
    }

    // Calculate the scale factor based on the given time fraction.
    public static float calculateScale(float fraction) {
        float value;
        if (fraction <= 0.5f) {
            // Zoom in for the beginning.
            value = 1f - ZOOM_DELTA *
                    sZoomOutInterpolator.getInterpolation(fraction * 2);
        } else {
            // Zoom out for the ending.
            value = ZOOM_IN_BEGIN + ZOOM_DELTA *
                    sZoomInInterpolator.getInterpolation((fraction - 0.5f) * 2f);
        }
        return value;
    }
}
Loading