• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 android.transition;
18 
19 import android.animation.Animator;
20 import android.animation.ObjectAnimator;
21 import android.animation.TimeInterpolator;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.view.animation.AccelerateInterpolator;
25 import android.view.animation.DecelerateInterpolator;
26 
27 /**
28  * This transition captures the visibility of target objects before and
29  * after a scene change and animates any changes by sliding the target
30  * objects into or out of place.
31  *
32  * @hide
33  */
34 public class Slide extends Visibility {
35 
36     // TODO: Add parameter for sliding factor - it's hard-coded below
37 
38     private static final TimeInterpolator sAccelerator = new AccelerateInterpolator();
39     private static final TimeInterpolator sDecelerator = new DecelerateInterpolator();
40 
41     @Override
onAppear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility)42     public Animator onAppear(ViewGroup sceneRoot,
43             TransitionValues startValues, int startVisibility,
44             TransitionValues endValues, int endVisibility) {
45         View endView = (endValues != null) ? endValues.view : null;
46         endView.setTranslationY(-2 * endView.getHeight());
47         ObjectAnimator anim = ObjectAnimator.ofFloat(endView, View.TRANSLATION_Y,
48                 -2 * endView.getHeight(), 0);
49         anim.setInterpolator(sDecelerator);
50         return anim;
51     }
52 
53     @Override
onDisappear(ViewGroup sceneRoot, TransitionValues startValues, int startVisibility, TransitionValues endValues, int endVisibility)54     public Animator onDisappear(ViewGroup sceneRoot,
55             TransitionValues startValues, int startVisibility,
56             TransitionValues endValues, int endVisibility) {
57         View startView = (startValues != null) ? startValues.view : null;
58         startView.setTranslationY(0);
59         ObjectAnimator anim = ObjectAnimator.ofFloat(startView, View.TRANSLATION_Y, 0,
60                 -2 * startView.getHeight());
61         anim.setInterpolator(sAccelerator);
62         return anim;
63     }
64 
65 }
66