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.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  * @hide
29  */
30 public class Rotate extends Transition {
31 
32     private static final String PROPNAME_ROTATION = "android:rotate:rotation";
33 
34     @Override
captureStartValues(TransitionValues transitionValues)35     public void captureStartValues(TransitionValues transitionValues) {
36         transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
37     }
38 
39     @Override
captureEndValues(TransitionValues transitionValues)40     public void captureEndValues(TransitionValues transitionValues) {
41         transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
42     }
43 
44     @Override
createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)45     public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
46             TransitionValues endValues) {
47         if (startValues == null || endValues == null) {
48             return null;
49         }
50         final View view = endValues.view;
51         float startRotation = (Float) startValues.values.get(PROPNAME_ROTATION);
52         float endRotation = (Float) endValues.values.get(PROPNAME_ROTATION);
53         if (startRotation != endRotation) {
54             view.setRotation(startRotation);
55             return ObjectAnimator.ofFloat(view, View.ROTATION,
56                     startRotation, endRotation);
57         }
58         return null;
59     }
60 }
61