1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package android.support.v17.leanback.transition; 15 16import android.animation.AnimatorInflater; 17import android.content.Context; 18import android.os.Build; 19import android.support.v17.leanback.R; 20import android.view.Gravity; 21import android.view.View; 22import android.view.animation.DecelerateInterpolator; 23import android.view.animation.Interpolator; 24 25/** 26 * Helper class to load Leanback specific transition. 27 * @hide 28 */ 29public class LeanbackTransitionHelper { 30 31 static interface LeanbackTransitionHelperVersion { 32 33 public Object loadTitleInTransition(Context context, TransitionHelper helper); 34 35 public Object loadTitleOutTransition(Context context, TransitionHelper helper); 36 } 37 38 /* 39 * Kitkat does not allow load custom transition from resource, calling 40 * LeanbackTransitionHelperKitKat to build custom transition in code. 41 */ 42 static class LeanbackTransitionHelperKitKatImpl implements LeanbackTransitionHelperVersion { 43 44 @Override 45 public Object loadTitleInTransition(Context context, TransitionHelper helper) { 46 return LeanbackTransitionHelperKitKat.loadTitleInTransition(context); 47 } 48 49 @Override 50 public Object loadTitleOutTransition(Context context, TransitionHelper helper) { 51 return LeanbackTransitionHelperKitKat.loadTitleOutTransition(context); 52 } 53 } 54 55 /* 56 * Load transition from resource or just return stub for API17. 57 */ 58 static class LeanbackTransitionHelperDefault implements LeanbackTransitionHelperVersion { 59 60 @Override 61 public Object loadTitleInTransition(Context context, TransitionHelper helper) { 62 return helper.loadTransition(context, R.transition.lb_title_in); 63 } 64 65 @Override 66 public Object loadTitleOutTransition(Context context, TransitionHelper helper) { 67 return helper.loadTransition(context, R.transition.lb_title_out); 68 } 69 } 70 71 static LeanbackTransitionHelperVersion sImpl; 72 73 static { 74 if (Build.VERSION.SDK_INT >= 21) { 75 sImpl = new LeanbackTransitionHelperDefault(); 76 } else if (Build.VERSION.SDK_INT >= 19) { 77 sImpl = new LeanbackTransitionHelperKitKatImpl(); 78 } else { 79 // Helper will create a stub object for transition in this case. 80 sImpl = new LeanbackTransitionHelperDefault(); 81 } 82 } 83 84 static public Object loadTitleInTransition(Context context, TransitionHelper helper) { 85 return sImpl.loadTitleInTransition(context, helper); 86 } 87 88 static public Object loadTitleOutTransition(Context context, TransitionHelper helper) { 89 return sImpl.loadTitleOutTransition(context, helper); 90 } 91} 92