119312c5f247559a9483d874e62150c49d36aa478Dake Gu/* 2254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu * Copyright (C) 2015 The Android Open Source Project 319312c5f247559a9483d874e62150c49d36aa478Dake Gu * 419312c5f247559a9483d874e62150c49d36aa478Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 519312c5f247559a9483d874e62150c49d36aa478Dake Gu * in compliance with the License. You may obtain a copy of the License at 619312c5f247559a9483d874e62150c49d36aa478Dake Gu * 719312c5f247559a9483d874e62150c49d36aa478Dake Gu * http://www.apache.org/licenses/LICENSE-2.0 819312c5f247559a9483d874e62150c49d36aa478Dake Gu * 919312c5f247559a9483d874e62150c49d36aa478Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License 1019312c5f247559a9483d874e62150c49d36aa478Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1119312c5f247559a9483d874e62150c49d36aa478Dake Gu * or implied. See the License for the specific language governing permissions and limitations under 1219312c5f247559a9483d874e62150c49d36aa478Dake Gu * the License. 1319312c5f247559a9483d874e62150c49d36aa478Dake Gu */ 1419312c5f247559a9483d874e62150c49d36aa478Dake Gupackage android.support.v17.leanback.widget; 1519312c5f247559a9483d874e62150c49d36aa478Dake Gu 16b10662684a404989de6058e146565e5f39e7897dDake Guimport android.graphics.Outline; 178f886fe8c7e23fe6ccb8734167c960c2ed3429c3Alan Viveretteimport android.support.annotation.RequiresApi; 1869e74bd8956577d9a3414b81ec661fd5fee42e19Craig Stoutimport android.view.View; 19b10662684a404989de6058e146565e5f39e7897dDake Guimport android.view.ViewOutlineProvider; 2019312c5f247559a9483d874e62150c49d36aa478Dake Gu 218f886fe8c7e23fe6ccb8734167c960c2ed3429c3Alan Viverette@RequiresApi(21) 2219312c5f247559a9483d874e62150c49d36aa478Dake Guclass ShadowHelperApi21 { 2319312c5f247559a9483d874e62150c49d36aa478Dake Gu 24f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout static class ShadowImpl { 25254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu View mShadowContainer; 26f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout float mNormalZ; 27f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout float mFocusedZ; 28f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout } 29f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout 30b10662684a404989de6058e146565e5f39e7897dDake Gu static final ViewOutlineProvider sOutlineProvider = new ViewOutlineProvider() { 31b10662684a404989de6058e146565e5f39e7897dDake Gu @Override 32b10662684a404989de6058e146565e5f39e7897dDake Gu public void getOutline(View view, Outline outline) { 33b10662684a404989de6058e146565e5f39e7897dDake Gu outline.setRect(0, 0, view.getWidth(), view.getHeight()); 34b10662684a404989de6058e146565e5f39e7897dDake Gu outline.setAlpha(1.0f); 35b10662684a404989de6058e146565e5f39e7897dDake Gu } 36b10662684a404989de6058e146565e5f39e7897dDake Gu }; 3719312c5f247559a9483d874e62150c49d36aa478Dake Gu 3819312c5f247559a9483d874e62150c49d36aa478Dake Gu /* add shadows and return a implementation detail object */ 39f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout public static Object addDynamicShadow( 4085833087b2288e0f002de6b4ebcbc0564839a217Dake Gu View shadowContainer, float unfocusedZ, float focusedZ, int roundedCornerRadius) { 4185833087b2288e0f002de6b4ebcbc0564839a217Dake Gu if (roundedCornerRadius > 0) { 4285833087b2288e0f002de6b4ebcbc0564839a217Dake Gu RoundedRectHelperApi21.setClipToRoundedOutline(shadowContainer, true, 4385833087b2288e0f002de6b4ebcbc0564839a217Dake Gu roundedCornerRadius); 444f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout } else { 454f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout shadowContainer.setOutlineProvider(sOutlineProvider); 464f34a05cdf73b68c3b2eb8678f740ab15225126aCraig Stout } 47f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout ShadowImpl impl = new ShadowImpl(); 48f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout impl.mShadowContainer = shadowContainer; 49f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout impl.mNormalZ = unfocusedZ; 50f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout impl.mFocusedZ = focusedZ; 51f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout shadowContainer.setZ(impl.mNormalZ); 52f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout return impl; 5319312c5f247559a9483d874e62150c49d36aa478Dake Gu } 5419312c5f247559a9483d874e62150c49d36aa478Dake Gu 5519312c5f247559a9483d874e62150c49d36aa478Dake Gu /* set shadow focus level 0 for unfocused 1 for fully focused */ 56f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout public static void setShadowFocusLevel(Object object, float level) { 57f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout ShadowImpl impl = (ShadowImpl) object; 58f4acd3cf076435ce836a6d4a9027b73ec3050defCraig Stout impl.mShadowContainer.setZ(impl.mNormalZ + level * (impl.mFocusedZ - impl.mNormalZ)); 5919312c5f247559a9483d874e62150c49d36aa478Dake Gu } 6069e74bd8956577d9a3414b81ec661fd5fee42e19Craig Stout 61c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout public static void setZ(View view, float z) { 62c62efa44831b1c60dcbdfd968735e27ac8294439Craig Stout view.setZ(z); 63adf55abedd17eb9484d03da4b521209f15724f1fCraig Stout } 6419312c5f247559a9483d874e62150c49d36aa478Dake Gu} 65