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.view.View; |
| 22 | import android.view.ViewGroup; |
| 23 | |
| 24 | /** |
| 25 | * This transition captures the rotation property of targets before and after |
| 26 | * the scene change and animates any changes. |
| 27 | */ |
| 28 | public class Rotate extends Transition { |
| 29 | |
| 30 | private static final String PROPNAME_ROTATION = "android:rotate:rotation"; |
| 31 | |
| 32 | @Override |
| 33 | protected void captureValues(TransitionValues values, boolean start) { |
| 34 | values.values.put(PROPNAME_ROTATION, values.view.getRotation()); |
| 35 | } |
| 36 | |
| 37 | @Override |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 38 | protected Animator play(ViewGroup sceneRoot, TransitionValues startValues, |
| 39 | TransitionValues endValues) { |
| 40 | if (startValues == null || endValues == null) { |
| 41 | return null; |
| 42 | } |
| 43 | final View view = endValues.view; |
| 44 | float startRotation = (Float) startValues.values.get(PROPNAME_ROTATION); |
| 45 | float endRotation = (Float) endValues.values.get(PROPNAME_ROTATION); |
| 46 | if (startRotation != endRotation) { |
Chet Haase | 2ea7f8b | 2013-06-21 15:00:05 -0700 | [diff] [blame] | 47 | view.setRotation(startRotation); |
Chet Haase | faebd8f | 2012-05-18 14:17:57 -0700 | [diff] [blame] | 48 | return ObjectAnimator.ofFloat(view, View.ROTATION, |
| 49 | startRotation, endRotation); |
| 50 | } |
| 51 | return null; |
| 52 | } |
| 53 | } |