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.widget; 15 16import android.os.Build; 17import android.view.View; 18 19 20/** 21 * Helper for shadow. 22 */ 23final class ShadowHelper { 24 25 final static ShadowHelper sInstance = new ShadowHelper(); 26 boolean mSupportsDynamicShadow; 27 ShadowHelperVersionImpl mImpl; 28 29 /** 30 * Interface implemented by classes that support Shadow. 31 */ 32 static interface ShadowHelperVersionImpl { 33 public Object addDynamicShadow( 34 View shadowContainer, float unfocusedZ, float focusedZ, int roundedCornerRadius); 35 public void setZ(View view, float z); 36 public void setShadowFocusLevel(Object impl, float level); 37 } 38 39 /** 40 * Interface used when we do not support Shadow animations. 41 */ 42 private static final class ShadowHelperStubImpl implements ShadowHelperVersionImpl { 43 @Override 44 public Object addDynamicShadow( 45 View shadowContainer, float focusedZ, float unfocusedZ, int roundedCornerRadius) { 46 // do nothing 47 return null; 48 } 49 50 @Override 51 public void setShadowFocusLevel(Object impl, float level) { 52 // do nothing 53 } 54 55 @Override 56 public void setZ(View view, float z) { 57 // do nothing 58 } 59 } 60 61 /** 62 * Implementation used on api 21 (and above). 63 */ 64 private static final class ShadowHelperApi21Impl implements ShadowHelperVersionImpl { 65 @Override 66 public Object addDynamicShadow( 67 View shadowContainer, float unfocusedZ, float focusedZ, int roundedCornerRadius) { 68 return ShadowHelperApi21.addDynamicShadow( 69 shadowContainer, unfocusedZ, focusedZ, roundedCornerRadius); 70 } 71 72 @Override 73 public void setShadowFocusLevel(Object impl, float level) { 74 ShadowHelperApi21.setShadowFocusLevel(impl, level); 75 } 76 77 @Override 78 public void setZ(View view, float z) { 79 ShadowHelperApi21.setZ(view, z); 80 } 81 } 82 83 /** 84 * Returns the ShadowHelper. 85 */ 86 private ShadowHelper() { 87 if (Build.VERSION.SDK_INT >= 21) { 88 mSupportsDynamicShadow = true; 89 mImpl = new ShadowHelperApi21Impl(); 90 } else { 91 mImpl = new ShadowHelperStubImpl(); 92 } 93 } 94 95 public static ShadowHelper getInstance() { 96 return sInstance; 97 } 98 99 public boolean supportsDynamicShadow() { 100 return mSupportsDynamicShadow; 101 } 102 103 public Object addDynamicShadow( 104 View shadowContainer, float unfocusedZ, float focusedZ, int roundedCornerRadius) { 105 return mImpl.addDynamicShadow(shadowContainer, unfocusedZ, focusedZ, roundedCornerRadius); 106 } 107 108 public void setShadowFocusLevel(Object impl, float level) { 109 mImpl.setShadowFocusLevel(impl, level); 110 } 111 112 /** 113 * Set the view z coordinate. 114 */ 115 public void setZ(View view, float z) { 116 mImpl.setZ(view, z); 117 } 118 119} 120