blob: b2f5db5ea52291b8e81beada1b7165a47141d4b7 [file] [log] [blame]
Chet Haasefaebd8f2012-05-18 14:17:57 -07001/*
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 */
Chet Haase6ebe3de2013-06-17 16:50:50 -070016
Chet Haasefaebd8f2012-05-18 14:17:57 -070017package android.view.transition;
18
19import android.animation.Animator;
20import android.animation.ObjectAnimator;
21import android.animation.TimeInterpolator;
22import android.view.View;
23import android.view.ViewGroup;
24import android.view.animation.AccelerateInterpolator;
25import 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 */
32public class Slide extends Visibility {
33
34 // TODO: Add parameter for sliding factor - it's hard-coded below
35
36 private static final TimeInterpolator sAccelerator = new AccelerateInterpolator();
37 private static final TimeInterpolator sDecelerator = new DecelerateInterpolator();
38
39 @Override
Chet Haase6ebe3de2013-06-17 16:50:50 -070040 protected Animator appear(ViewGroup sceneRoot,
41 TransitionValues startValues, int startVisibility,
42 TransitionValues endValues, int endVisibility) {
43 View endView = (endValues != null) ? endValues.view : null;
Chet Haase2ea7f8b2013-06-21 15:00:05 -070044 endView.setTranslationY(-2 * endView.getHeight());
Chet Haasefaebd8f2012-05-18 14:17:57 -070045 ObjectAnimator anim = ObjectAnimator.ofFloat(endView, View.TRANSLATION_Y,
46 -2 * endView.getHeight(), 0);
47 anim.setInterpolator(sDecelerator);
48 return anim;
49 }
50
51 @Override
Chet Haase6ebe3de2013-06-17 16:50:50 -070052 protected Animator disappear(ViewGroup sceneRoot,
53 TransitionValues startValues, int startVisibility,
54 TransitionValues endValues, int endVisibility) {
55 View startView = (startValues != null) ? startValues.view : null;
Chet Haase2ea7f8b2013-06-21 15:00:05 -070056 startView.setTranslationY(0);
Chet Haasefaebd8f2012-05-18 14:17:57 -070057 ObjectAnimator anim = ObjectAnimator.ofFloat(startView, View.TRANSLATION_Y, 0,
58 -2 * startView.getHeight());
59 anim.setInterpolator(sAccelerator);
60 return anim;
61 }
62
63}