Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 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 | */ |
Chet Haase | 6ebe3de | 2013-06-17 16:50:50 -0700 | [diff] [blame] | 16 | |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 17 | package android.view.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 | public 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 Haase | 6ebe3de | 2013-06-17 16:50:50 -0700 | [diff] [blame] | 40 | protected Animator appear(ViewGroup sceneRoot, |
| 41 | TransitionValues startValues, int startVisibility, |
| 42 | TransitionValues endValues, int endVisibility) { |
| 43 | View endView = (endValues != null) ? endValues.view : null; |
Chet Haase | 2ea7f8b | 2013-06-21 15:00:05 -0700 | [diff] [blame] | 44 | endView.setTranslationY(-2 * endView.getHeight()); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 45 | 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 Haase | 6ebe3de | 2013-06-17 16:50:50 -0700 | [diff] [blame] | 52 | protected Animator disappear(ViewGroup sceneRoot, |
| 53 | TransitionValues startValues, int startVisibility, |
| 54 | TransitionValues endValues, int endVisibility) { |
| 55 | View startView = (startValues != null) ? startValues.view : null; |
Chet Haase | 2ea7f8b | 2013-06-21 15:00:05 -0700 | [diff] [blame] | 56 | startView.setTranslationY(0); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 57 | ObjectAnimator anim = ObjectAnimator.ofFloat(startView, View.TRANSLATION_Y, 0, |
| 58 | -2 * startView.getHeight()); |
| 59 | anim.setInterpolator(sAccelerator); |
| 60 | return anim; |
| 61 | } |
| 62 | |
| 63 | } |