Scale.java revision 0fff85d7f9dee67ec5116f3cba4e8b3961f805a7
1/* 2 * Copyright (C) 2014 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 */ 16package android.support.v17.leanback.transition; 17 18import android.animation.Animator; 19import android.animation.ValueAnimator; 20import android.view.View; 21import android.view.ViewGroup; 22import android.transition.Transition; 23import android.transition.TransitionValues; 24 25class Scale extends Transition { 26 private static final String PROPNAME_SCALE = "android:leanback:scale"; 27 28 public Scale() { 29 } 30 31 private void captureValues(TransitionValues values) { 32 View view = values.view; 33 values.values.put(PROPNAME_SCALE, view.getScaleX()); 34 } 35 36 @Override 37 public void captureStartValues(TransitionValues transitionValues) { 38 captureValues(transitionValues); 39 } 40 41 @Override 42 public void captureEndValues(TransitionValues transitionValues) { 43 captureValues(transitionValues); 44 } 45 46 @Override 47 public Animator createAnimator(final ViewGroup sceneRoot, TransitionValues startValues, 48 TransitionValues endValues) { 49 if (startValues == null || endValues == null) { 50 return null; 51 } 52 53 final float startScale = (Float) startValues.values.get(PROPNAME_SCALE); 54 final float endScale = (Float) endValues.values.get(PROPNAME_SCALE); 55 56 final View view = startValues.view; 57 view.setScaleX(startScale); 58 view.setScaleY(startScale); 59 60 ValueAnimator animator = ValueAnimator.ofFloat(startScale, endScale); 61 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 62 @Override 63 public void onAnimationUpdate(ValueAnimator animation) { 64 final float scale = (Float) animation.getAnimatedValue(); 65 view.setScaleX(scale); 66 view.setScaleY(scale); 67 } 68 }); 69 return animator; 70 } 71} 72