1 package com.example.android.xyztouristattractions.ui; 2 3 import android.animation.Animator; 4 import android.animation.ObjectAnimator; 5 import android.animation.PropertyValuesHolder; 6 import android.annotation.TargetApi; 7 import android.content.Context; 8 import android.os.Build; 9 import android.transition.TransitionValues; 10 import android.transition.Visibility; 11 import android.util.AttributeSet; 12 import android.view.View; 13 import android.view.ViewGroup; 14 15 /** 16 * A simple scale transition class to allow an element to scale in or out. 17 * This is used by the floating action button on the attraction detail screen 18 * when it appears and disappears during the Activity transitions. 19 */ 20 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 21 public class ScaleTransition extends Visibility { 22 ScaleTransition(Context context, AttributeSet attrs)23 public ScaleTransition(Context context, AttributeSet attrs) { 24 super(context, attrs); 25 } 26 createAnimation(View view, float startScale, float endScale)27 public Animator createAnimation(View view, float startScale, float endScale) { 28 view.setScaleX(startScale); 29 view.setScaleY(startScale); 30 PropertyValuesHolder holderX = PropertyValuesHolder.ofFloat("scaleX", startScale, endScale); 31 PropertyValuesHolder holderY = PropertyValuesHolder.ofFloat("scaleY", startScale, endScale); 32 return ObjectAnimator.ofPropertyValuesHolder(view, holderX, holderY); 33 } 34 35 @Override onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues)36 public Animator onAppear(ViewGroup sceneRoot, View view, TransitionValues startValues, 37 TransitionValues endValues) { 38 return createAnimation(view, 0, 1); 39 } 40 41 @Override onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, TransitionValues endValues)42 public Animator onDisappear(ViewGroup sceneRoot, View view, TransitionValues startValues, 43 TransitionValues endValues) { 44 return createAnimation(view, 1, 0); 45 } 46 }