Remove StaticShadowHelper API abstractions.
Bug: 75289452
Test: ./gradlew :leanback:build :leanback:cC
Change-Id: I8c7a3d92f8f73d786cfc17e2c4bc4b512fc6efaf
diff --git a/leanback/build.gradle b/leanback/build.gradle
index fe04a8a..56b7fc5 100644
--- a/leanback/build.gradle
+++ b/leanback/build.gradle
@@ -23,7 +23,6 @@
sourceSets {
main.java.srcDirs += [
'common',
- 'jbmr2',
'kitkat',
'api21',
]
diff --git a/leanback/jbmr2/androidx/leanback/widget/ShadowHelperJbmr2.java b/leanback/jbmr2/androidx/leanback/widget/ShadowHelperJbmr2.java
deleted file mode 100644
index 49e5532..0000000
--- a/leanback/jbmr2/androidx/leanback/widget/ShadowHelperJbmr2.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package androidx.leanback.widget;
-
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.annotation.RequiresApi;
-import androidx.leanback.R;
-
-@RequiresApi(18)
-class ShadowHelperJbmr2 {
-
- static class ShadowImpl {
- View mNormalShadow;
- View mFocusShadow;
- }
-
- /* prepare parent for allowing shadows of a child */
- public static void prepareParent(ViewGroup parent) {
- parent.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS);
- }
-
- /* add shadows and return a implementation detail object */
- public static Object addShadow(ViewGroup shadowContainer) {
- shadowContainer.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS);
- LayoutInflater inflater = LayoutInflater.from(shadowContainer.getContext());
- inflater.inflate(R.layout.lb_shadow, shadowContainer, true);
- ShadowImpl impl = new ShadowImpl();
- impl.mNormalShadow = shadowContainer.findViewById(R.id.lb_shadow_normal);
- impl.mFocusShadow = shadowContainer.findViewById(R.id.lb_shadow_focused);
- return impl;
- }
-
- /* set shadow focus level 0 for unfocused 1 for fully focused */
- public static void setShadowFocusLevel(Object impl, float level) {
- ShadowImpl shadowImpl = (ShadowImpl) impl;
- shadowImpl.mNormalShadow.setAlpha(1 - level);
- shadowImpl.mFocusShadow.setAlpha(level);
- }
-}
diff --git a/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayContainer.java b/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayContainer.java
index 20abd7f..b0b45de 100644
--- a/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayContainer.java
+++ b/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayContainer.java
@@ -119,7 +119,7 @@
* Return true if the platform sdk supports shadow.
*/
public static boolean supportsShadow() {
- return StaticShadowHelper.getInstance().supportsShadow();
+ return StaticShadowHelper.supportsShadow();
}
/**
@@ -135,7 +135,7 @@
* to parent.
*/
public static void prepareParentForShadow(ViewGroup parent) {
- StaticShadowHelper.getInstance().prepareParent(parent);
+ StaticShadowHelper.prepareParent(parent);
}
/**
@@ -226,7 +226,7 @@
this, mUnfocusedZ, mFocusedZ, mRoundedCornerRadius);
break;
case SHADOW_STATIC:
- mShadowImpl = StaticShadowHelper.getInstance().addStaticShadow(this);
+ mShadowImpl = StaticShadowHelper.addStaticShadow(this);
break;
}
if (hasColorDimOverlay) {
diff --git a/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayHelper.java b/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayHelper.java
index 0299142..1dfd653 100644
--- a/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayHelper.java
+++ b/leanback/src/main/java/androidx/leanback/widget/ShadowOverlayHelper.java
@@ -280,7 +280,7 @@
* Return true if the platform sdk supports shadow.
*/
public static boolean supportsShadow() {
- return StaticShadowHelper.getInstance().supportsShadow();
+ return StaticShadowHelper.supportsShadow();
}
/**
@@ -316,7 +316,7 @@
*/
public void prepareParentForShadow(ViewGroup parent) {
if (mShadowType == SHADOW_STATIC) {
- StaticShadowHelper.getInstance().prepareParent(parent);
+ StaticShadowHelper.prepareParent(parent);
}
}
@@ -458,7 +458,7 @@
ShadowHelper.setShadowFocusLevel(impl, level);
break;
case SHADOW_STATIC:
- StaticShadowHelper.getInstance().setShadowFocusLevel(impl, level);
+ StaticShadowHelper.setShadowFocusLevel(impl, level);
break;
}
}
diff --git a/leanback/src/main/java/androidx/leanback/widget/StaticShadowHelper.java b/leanback/src/main/java/androidx/leanback/widget/StaticShadowHelper.java
index 5b3ff45..5ab0c61 100644
--- a/leanback/src/main/java/androidx/leanback/widget/StaticShadowHelper.java
+++ b/leanback/src/main/java/androidx/leanback/widget/StaticShadowHelper.java
@@ -16,107 +16,52 @@
package androidx.leanback.widget;
import android.os.Build;
+import android.view.LayoutInflater;
+import android.view.View;
import android.view.ViewGroup;
-import androidx.annotation.RequiresApi;
-
+import androidx.leanback.R;
/**
* Helper for static (nine patch) shadows.
*/
final class StaticShadowHelper {
-
- final static StaticShadowHelper sInstance = new StaticShadowHelper();
- boolean mSupportsShadow;
- ShadowHelperVersionImpl mImpl;
-
- /**
- * Interface implemented by classes that support Shadow.
- */
- static interface ShadowHelperVersionImpl {
- public void prepareParent(ViewGroup parent);
- public Object addStaticShadow(ViewGroup shadowContainer);
- public void setShadowFocusLevel(Object impl, float level);
- }
-
- /**
- * Interface used when we do not support Shadow animations.
- */
- private static final class ShadowHelperStubImpl implements ShadowHelperVersionImpl {
- ShadowHelperStubImpl() {
- }
-
- @Override
- public void prepareParent(ViewGroup parent) {
- // do nothing
- }
-
- @Override
- public Object addStaticShadow(ViewGroup shadowContainer) {
- // do nothing
- return null;
- }
-
- @Override
- public void setShadowFocusLevel(Object impl, float level) {
- // do nothing
- }
- }
-
- /**
- * Implementation used on JBMR2 (and above).
- */
- @RequiresApi(19)
- private static final class ShadowHelperJbmr2Impl implements ShadowHelperVersionImpl {
- ShadowHelperJbmr2Impl() {
- }
-
- @Override
- public void prepareParent(ViewGroup parent) {
- ShadowHelperJbmr2.prepareParent(parent);
- }
-
- @Override
- public Object addStaticShadow(ViewGroup shadowContainer) {
- return ShadowHelperJbmr2.addShadow(shadowContainer);
- }
-
- @Override
- public void setShadowFocusLevel(Object impl, float level) {
- ShadowHelperJbmr2.setShadowFocusLevel(impl, level);
- }
- }
-
- /**
- * Returns the StaticShadowHelper.
- */
private StaticShadowHelper() {
+ }
+
+ static boolean supportsShadow() {
+ return Build.VERSION.SDK_INT >= 21;
+ }
+
+ static void prepareParent(ViewGroup parent) {
if (Build.VERSION.SDK_INT >= 21) {
- mSupportsShadow = true;
- mImpl = new ShadowHelperJbmr2Impl();
- } else {
- mSupportsShadow = false;
- mImpl = new ShadowHelperStubImpl();
+ parent.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS);
}
}
- public static StaticShadowHelper getInstance() {
- return sInstance;
+ static Object addStaticShadow(ViewGroup shadowContainer) {
+ if (Build.VERSION.SDK_INT >= 21) {
+ shadowContainer.setLayoutMode(ViewGroup.LAYOUT_MODE_OPTICAL_BOUNDS);
+ LayoutInflater inflater = LayoutInflater.from(shadowContainer.getContext());
+ inflater.inflate(R.layout.lb_shadow, shadowContainer, true);
+ ShadowImpl impl = new ShadowImpl();
+ impl.mNormalShadow = shadowContainer.findViewById(R.id.lb_shadow_normal);
+ impl.mFocusShadow = shadowContainer.findViewById(R.id.lb_shadow_focused);
+ return impl;
+ }
+ return null;
}
- public boolean supportsShadow() {
- return mSupportsShadow;
+ static void setShadowFocusLevel(Object impl, float level) {
+ if (Build.VERSION.SDK_INT >= 21) {
+ ShadowImpl shadowImpl = (ShadowImpl) impl;
+ shadowImpl.mNormalShadow.setAlpha(1 - level);
+ shadowImpl.mFocusShadow.setAlpha(level);
+ }
}
- public void prepareParent(ViewGroup parent) {
- mImpl.prepareParent(parent);
- }
-
- public Object addStaticShadow(ViewGroup shadowContainer) {
- return mImpl.addStaticShadow(shadowContainer);
- }
-
- public void setShadowFocusLevel(Object impl, float level) {
- mImpl.setShadowFocusLevel(impl, level);
+ static class ShadowImpl {
+ View mNormalShadow;
+ View mFocusShadow;
}
}