Home | History | Annotate | Download | only in util
      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  */
     16 
     17 package com.android.tv.settings.util;
     18 
     19 import android.animation.ObjectAnimator;
     20 import android.content.res.Resources;
     21 import android.util.TypedValue;
     22 
     23 import com.android.tv.settings.R;
     24 
     25 /**
     26  * Utility class for handling transition animations.
     27  */
     28 public class TransitionUtils {
     29 
     30     /**
     31      * Creates an object animator that use implements the alpha fade-in for an
     32      * Activity's background.
     33      */
     34     public static ObjectAnimator createActivityFadeInAnimator(Resources res, boolean useFloats) {
     35         TypedValue startAlpha = new TypedValue();
     36         res.getValue(R.dimen.alpha_activity_in_bkg_start, startAlpha, true);
     37 
     38         TypedValue endAlpha = new TypedValue();
     39         res.getValue(R.dimen.alpha_activity_in_bkg_end, endAlpha, true);
     40 
     41         ObjectAnimator animator = new ObjectAnimator();
     42         animator.setPropertyName("alpha");
     43         if (useFloats) {
     44             animator.setFloatValues(startAlpha.getFloat(), endAlpha.getFloat());
     45         } else {
     46             animator.setIntValues(Float.valueOf(startAlpha.getFloat() * 255).intValue(),
     47                     Float.valueOf(endAlpha.getFloat() * 255).intValue());
     48         }
     49         animator.setDuration(res.getInteger(R.integer.alpha_activity_in_bkg_duration));
     50         animator.setStartDelay(res.getInteger(R.integer.alpha_activity_in_bkg_delay));
     51         return animator;
     52     }
     53 
     54     public static ObjectAnimator createActivityFadeOutAnimator(Resources res, boolean useFloats) {
     55         TypedValue startAlpha = new TypedValue();
     56         res.getValue(R.dimen.alpha_activity_out_bkg_start, startAlpha, true);
     57 
     58         TypedValue endAlpha = new TypedValue();
     59         res.getValue(R.dimen.alpha_activity_out_bkg_end, endAlpha, true);
     60 
     61         ObjectAnimator animator = new ObjectAnimator();
     62         animator.setPropertyName("alpha");
     63         if (useFloats) {
     64             animator.setFloatValues(startAlpha.getFloat(), endAlpha.getFloat());
     65         } else {
     66             animator.setIntValues(Float.valueOf(startAlpha.getFloat() * 255).intValue(),
     67                     Float.valueOf(endAlpha.getFloat() * 255).intValue());
     68         }
     69         animator.setDuration(res.getInteger(R.integer.alpha_activity_out_bkg_duration));
     70         animator.setStartDelay(res.getInteger(R.integer.alpha_activity_out_bkg_delay));
     71         return animator;
     72     }
     73 }
     74