• 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.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.view.View;
24 import android.view.ViewGroup;
25 
26 /**
27  * This transition captures the rotation property of targets before and after
28  * the scene change and animates any changes.
29  *
30  * @hide
31  */
32 public class Rotate extends Transition {
33 
34     private static final String PROPNAME_ROTATION = "android:rotate:rotation";
35 
36     @Override
captureStartValues(TransitionValues transitionValues)37     public void captureStartValues(TransitionValues transitionValues) {
38         transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
39     }
40 
41     @Override
captureEndValues(TransitionValues transitionValues)42     public void captureEndValues(TransitionValues transitionValues) {
43         transitionValues.values.put(PROPNAME_ROTATION, transitionValues.view.getRotation());
44     }
45 
46     @Nullable
47     @Override
createAnimator(@onNull ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues)48     public Animator createAnimator(@NonNull ViewGroup sceneRoot,
49             @Nullable TransitionValues startValues,
50             @Nullable TransitionValues endValues) {
51         if (startValues == null || endValues == null) {
52             return null;
53         }
54         final View view = endValues.view;
55         float startRotation = (Float) startValues.values.get(PROPNAME_ROTATION);
56         float endRotation = (Float) endValues.values.get(PROPNAME_ROTATION);
57         if (startRotation != endRotation) {
58             view.setRotation(startRotation);
59             return ObjectAnimator.ofFloat(view, View.ROTATION,
60                     startRotation, endRotation);
61         }
62         return null;
63     }
64 }
65