• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.gallery3d.ui;
18 
19 import android.view.animation.AccelerateDecelerateInterpolator;
20 import android.view.animation.AccelerateInterpolator;
21 import android.view.animation.DecelerateInterpolator;
22 import android.view.animation.Interpolator;
23 
24 public class CaptureAnimation {
25     // The amount of change for zooming out.
26     private static final float ZOOM_DELTA = 0.2f;
27     // Pre-calculated value for convenience.
28     private static final float ZOOM_IN_BEGIN = 1f - ZOOM_DELTA;
29 
30     private static final Interpolator sZoomOutInterpolator =
31             new DecelerateInterpolator();
32     private static final Interpolator sZoomInInterpolator =
33             new AccelerateInterpolator();
34     private static final Interpolator sSlideInterpolator =
35         new AccelerateDecelerateInterpolator();
36 
37     // Calculate the slide factor based on the give time fraction.
calculateSlide(float fraction)38     public static float calculateSlide(float fraction) {
39         return sSlideInterpolator.getInterpolation(fraction);
40     }
41 
42     // Calculate the scale factor based on the given time fraction.
calculateScale(float fraction)43     public static float calculateScale(float fraction) {
44         float value;
45         if (fraction <= 0.5f) {
46             // Zoom in for the beginning.
47             value = 1f - ZOOM_DELTA *
48                     sZoomOutInterpolator.getInterpolation(fraction * 2);
49         } else {
50             // Zoom out for the ending.
51             value = ZOOM_IN_BEGIN + ZOOM_DELTA *
52                     sZoomInInterpolator.getInterpolation((fraction - 0.5f) * 2f);
53         }
54         return value;
55     }
56 }
57