public final class ShadowOverlayHelper extends Object
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;
}
}
...
Modifier and Type | Class and Description |
---|---|
static class |
ShadowOverlayHelper.Builder
Builder for creating ShadowOverlayHelper.
|
static class |
ShadowOverlayHelper.Options
Option values for ShadowOverlayContainer.
|
Modifier and Type | Field and Description |
---|---|
static int |
SHADOW_DYNAMIC
Shadows depend on the size, shape, and position of the view.
|
static int |
SHADOW_NONE
No shadow.
|
static int |
SHADOW_STATIC
Shadows are fixed.
|
Modifier and Type | Method and Description |
---|---|
ShadowOverlayContainer |
createShadowOverlayContainer(Context context)
Create ShadowOverlayContainer for this helper.
|
int |
getShadowType() |
boolean |
needsOverlay() |
boolean |
needsRoundedCorner() |
boolean |
needsWrapper()
Returns true if a "wrapper" ShadowOverlayContainer is needed.
|
void |
onViewCreated(View view)
Must be called when view is created for cases
needsWrapper() is false. |
void |
prepareParentForShadow(ViewGroup parent)
prepareParentForShadow(ViewGroup) must be called on parent of container
before using shadow. |
static void |
setNoneWrapperOverlayColor(View view,
int color)
Set overlay color for view other than ShadowOverlayContainer.
|
static void |
setNoneWrapperShadowFocusLevel(View view,
float level)
Set shadow focus level (0 to 1). 0 for unfocused, 1 for fully focused.
|
void |
setOverlayColor(View view,
int color)
Set overlay color for view, it can be a ShadowOverlayContainer if needsWrapper() is true,
or other view type.
|
void |
setShadowFocusLevel(View view,
float level)
Set shadow focus level (0 to 1). 0 for unfocused, 1 for fully focused.
|
static boolean |
supportsDynamicShadow()
Returns true if the platform sdk supports dynamic shadows.
|
static boolean |
supportsForeground()
Returns true if view.setForeground() is supported.
|
static boolean |
supportsRoundedCorner()
Returns true if the platform sdk supports rounded corner through outline.
|
static boolean |
supportsShadow()
Return true if the platform sdk supports shadow.
|
public static final int SHADOW_NONE
public static final int SHADOW_STATIC
public static final int SHADOW_DYNAMIC
public static boolean supportsShadow()
public static boolean supportsDynamicShadow()
public static boolean supportsRoundedCorner()
public static boolean supportsForeground()
public void prepareParentForShadow(ViewGroup parent)
prepareParentForShadow(ViewGroup)
must be called on parent of container
before using shadow. Depending on Shadow type, optical bounds might be applied.public int getShadowType()
public boolean needsOverlay()
public boolean needsRoundedCorner()
public boolean needsWrapper()
createShadowOverlayContainer(Context)
to create the wrapper.public ShadowOverlayContainer createShadowOverlayContainer(Context context)
context
- Context to create view.public static void setNoneWrapperOverlayColor(View view, int color)
ShadowOverlayContainer.setOverlayColor(int)
.public void setOverlayColor(View view, int color)
public void onViewCreated(View view)
needsWrapper()
is false.view
- public static void setNoneWrapperShadowFocusLevel(View view, float level)
ShadowOverlayContainer.setShadowFocusLevel(float)
.public void setShadowFocusLevel(View view, float level)