ShadowOverlayHelper
class ShadowOverlayHelper
kotlin.Any | |
↳ | androidx.leanback.widget.ShadowOverlayHelper |
ShadowOverlayHelper is a helper class for shadow, overlay color and rounded corner. There are many choices to implement Shadow, overlay color. Initialize it with ShadowOverlayHelper.Builder and it decides the best strategy based on options user choose and current platform version.
ShadowOverlayHelper mHelper = new ShadowOverlayHelper.Builder(). .needsOverlay(true).needsRoundedCorner(true).needsShadow(true) .build(); mHelper.prepareParentForShadow(parentView); // apply optical-bounds for 9-patch shadow. mHelper.setOverlayColor(view, Color.argb(0x80, 0x80, 0x80, 0x80)); mHelper.setShadowFocusLevel(view, 1.0f); ... View initializeView(View view) { if (mHelper.needsWrapper()) { ShadowOverlayContainer wrapper = mHelper.createShadowOverlayContainer(context); wrapper.wrap(view); return wrapper; } else { mHelper.onViewCreated(view); return view; } } ...
Summary
Nested classes |
|
---|---|
Builder for creating ShadowOverlayHelper. |
|
Option values for ShadowOverlayContainer. |
Constants |
|
---|---|
static Int |
Shadows depend on the size, shape, and position of the view. |
static Int |
No shadow. |
static Int |
Shadows are fixed. |
Public methods |
|
---|---|
ShadowOverlayContainer! |
createShadowOverlayContainer(context: Context!) Create ShadowOverlayContainer for this helper. |
Int | |
Boolean | |
Boolean | |
Boolean |
Returns true if a "wrapper" ShadowOverlayContainer is needed. |
Unit |
onViewCreated(view: View!) Must be called when view is created for cases |
Unit |
prepareParentForShadow(parent: ViewGroup!)
|
static Unit |
setNoneWrapperOverlayColor(view: View!, color: Int) Set overlay color for view other than ShadowOverlayContainer. |
static Unit |
setNoneWrapperShadowFocusLevel(view: View!, level: Float) Set shadow focus level (0 to 1). |
Unit |
setOverlayColor(view: View!, color: Int) Set overlay color for view, it can be a ShadowOverlayContainer if needsWrapper() is true, or other view type. |
Unit |
setShadowFocusLevel(view: View!, level: Float) Set shadow focus level (0 to 1). |
static Boolean |
Returns true if the platform sdk supports dynamic shadows. |
static Boolean |
Returns true if view. |
static Boolean |
Returns true if the platform sdk supports rounded corner through outline. |
static Boolean |
Return true if the platform sdk supports shadow. |
Constants
SHADOW_DYNAMIC
static val SHADOW_DYNAMIC: Int
Shadows depend on the size, shape, and position of the view.
Value: 3
Public methods
createShadowOverlayContainer
fun createShadowOverlayContainer(context: Context!): ShadowOverlayContainer!
Create ShadowOverlayContainer for this helper.
Parameters | |
---|---|
context |
Context!: Context to create view. |
Return | |
---|---|
ShadowOverlayContainer!: ShadowOverlayContainer. |
getShadowType
fun getShadowType(): Int
needsOverlay
fun needsOverlay(): Boolean
needsRoundedCorner
fun needsRoundedCorner(): Boolean
needsWrapper
fun needsWrapper(): Boolean
Returns true if a "wrapper" ShadowOverlayContainer is needed. When needsWrapper() is true, call createShadowOverlayContainer(Context)
to create the wrapper.
onViewCreated
fun onViewCreated(view: View!): Unit
Must be called when view is created for cases needsWrapper()
is false.
Parameters | |
---|---|
view |
View!: |
prepareParentForShadow
fun prepareParentForShadow(parent: ViewGroup!): Unit
prepareParentForShadow(ViewGroup)
must be called on parent of container before using shadow. Depending on Shadow type, optical bounds might be applied.
setNoneWrapperOverlayColor
static fun setNoneWrapperOverlayColor(view: View!, color: Int): Unit
Set overlay color for view other than ShadowOverlayContainer. See also ShadowOverlayContainer#setOverlayColor(int)
.
setNoneWrapperShadowFocusLevel
static fun setNoneWrapperShadowFocusLevel(view: View!, level: Float): Unit
Set shadow focus level (0 to 1). 0 for unfocused, 1 for fully focused. This is for view other than ShadowOverlayContainer. See also ShadowOverlayContainer#setShadowFocusLevel(float)
.
setOverlayColor
fun setOverlayColor(view: View!, color: Int): Unit
Set overlay color for view, it can be a ShadowOverlayContainer if needsWrapper() is true, or other view type.
setShadowFocusLevel
fun setShadowFocusLevel(view: View!, level: Float): Unit
Set shadow focus level (0 to 1). 0 for unfocused, 1 for fully focused.
supportsDynamicShadow
static fun supportsDynamicShadow(): Boolean
Returns true if the platform sdk supports dynamic shadows.
supportsForeground
static fun supportsForeground(): Boolean
Returns true if view.setForeground() is supported.
supportsRoundedCorner
static fun supportsRoundedCorner(): Boolean
Returns true if the platform sdk supports rounded corner through outline.
supportsShadow
static fun supportsShadow(): Boolean
Return true if the platform sdk supports shadow.