blob: d35a6dc745e545fadb8e5e27d497670deba627a4 [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.view.View;
22import 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 */
28public 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 Haasefaebd8f2012-05-18 14:17:57 -070038 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 Haase2ea7f8b2013-06-21 15:00:05 -070047 view.setRotation(startRotation);
Chet Haasefaebd8f2012-05-18 14:17:57 -070048 return ObjectAnimator.ofFloat(view, View.ROTATION,
49 startRotation, endRotation);
50 }
51 return null;
52 }
53}