Class DynamicViewUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicViewUtils
Helper class to perform
View
operations.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a view to the view group.static void
Add a view to the view group.static void
applyWindowInsets
(View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets padding for the supplied view.static void
applyWindowInsetsBottom
(View view) Apply bottom window insets padding for the supplied view.static void
applyWindowInsetsBottom
(View view, boolean consume) Apply bottom window insets padding for the supplied view.static void
Apply horizontal window insets padding for the supplied view.static void
applyWindowInsetsHorizontal
(View view, boolean consume) Apply horizontal window insets padding for the supplied view.static void
Apply horizontal and bottom window insets padding for the supplied view.static void
applyWindowInsetsHorizontalBottom
(View view, boolean consume) Apply horizontal and bottom window insets padding for the supplied view.static void
applyWindowInsetsMargin
(View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets margin for the supplied view.static void
Apply bottom window insets margin for the supplied view.static void
applyWindowInsetsMarginBottom
(View view, boolean consume) Apply bottom window insets margin for the supplied view.static void
Apply horizontal window insets margin for the supplied view.static void
applyWindowInsetsMarginHorizontal
(View view, boolean consume) Apply horizontal window insets margin for the supplied view.static void
Apply horizontal and bottom window insets margin for the supplied view.static void
applyWindowInsetsMarginHorizontalBottom
(View view, boolean consume) Apply horizontal and bottom window insets margin for the supplied view.static void
Apply vertical window insets margin for the supplied view.static void
applyWindowInsetsMarginVertical
(View view, boolean consume) Apply vertical window insets margin for the supplied view.static void
Apply vertical window insets padding for the supplied view.static void
applyWindowInsetsVertical
(View view, boolean consume) Apply vertical window insets padding for the supplied view.static boolean
isEdgeToEdge
(View view) Deprecated.static boolean
isLayoutRtl
(View view) Checks whether the layout direction is RTL (right-to-left).static <T extends View>
booleanisRootLayout
(T view) Checks if the supplied view is the only root layout in the view hierarchy.static void
manageScrollIndicators
(View view, View upIndicator, View downIndicator) Manage scroll indicators for a view according to its current state.static void
requestApplyWindowInsets
(View view) Request to apply window insets for a viewstatic void
Set the alpha for the supplied view.static void
setAlpha
(RemoteViews remoteViews, int viewId, int alpha) Set the alpha for the remote views.static void
setBackgroundColor
(RemoteViews remoteViews, int viewId, int color) Set the background color for the remote views.static void
setColorFilter
(RemoteViews remoteViews, int viewId, int color) Set the color filter for the remote views.static void
setEdgeToEdge
(View view, boolean edgeToEdge) Deprecated.UseDynamicWindowUtils.setEdgeToEdge(Window, boolean)
to support latest API levels.static void
setEnabled
(RemoteViews remoteViews, int viewId, boolean enabled) Set the enabled state for the remote views.static void
setLightNavigationBar
(View view, boolean light) Set light navigation bar on API 26 and above.static void
setLightNavigationBar
(Window window, View view, boolean light) Set light navigation bar on API 26 and above.static void
setLightNavigationBarLegacy
(View view, boolean light) Set light navigation bar on API 26 and above.static void
setLightStatusBar
(View view, boolean light) Set light status bar on API 23 and above.static void
setLightStatusBar
(Window window, View view, boolean light) Set light status bar on API 23 and above.static void
setLightStatusBarLegacy
(View view, boolean light) Set light status bar by using the legacy method on API 23 and above.static void
setTextSwitcherText
(TextSwitcher view, CharSequence text) Set the text switcher text and animate only if there is a text change.static void
setTextViewAllCaps
(RemoteViews remoteViews, int viewId, boolean allCaps) Set the text view all caps for the remote views.static void
setTextViewAllCaps
(TextView textView, boolean allCaps) Set the text view all caps.static void
setTextViewColors
(RemoteViews remoteViews, int viewId, int color, int linkColor) Set the text view colors for the remote views.static void
setTextViewLinkColor
(RemoteViews remoteViews, int viewId, int color) Set the text view link color for the remote views.static void
setTextViewMaxLines
(RemoteViews remoteViews, int viewId, int lines) Set the text view max lines for the remote views.static void
setTextViewText
(RemoteViews remoteViews, int viewId, CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.static void
setTextViewText
(RemoteViews remoteViews, int viewId, CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.static void
setTextViewTextHtml
(RemoteViews remoteViews, int viewId, CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.static void
setTextViewTextHtml
(RemoteViews remoteViews, int viewId, CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.static void
setTextViewTextSize
(RemoteViews remoteViews, int viewId, int units, float size) Equivalent to callingTextView.setTextSize(int, float)
.static void
setTextViewTextSize
(TextView textView, int units, float size) Equivalent to callingTextView.setTextSize(int, float)
.
-
Constructor Details
-
DynamicViewUtils
public DynamicViewUtils()
-
-
Method Details
-
isRootLayout
Checks if the supplied view is the only root layout in the view hierarchy.- Type Parameters:
T
- The type of the view.- Parameters:
view
- The view to be checked.- Returns:
true
if the supplied view is the only root layout in the view hierarchy.
-
setEdgeToEdge
Deprecated.UseDynamicWindowUtils.setEdgeToEdge(Window, boolean)
to support latest API levels.Set the hide navigation flag for edge-to-edge content on API 23 and above.- Parameters:
view
- The view to get the system ui flags.edgeToEdge
-true
to hide the layout navigation.
-
isEdgeToEdge
Deprecated.Try to useWindowInsetsControllerCompat
if possible.Checks whether the hide navigation flag is enabled for edge-to-edge content on API 23 and above.- Parameters:
view
- The view to get the system ui flags.- Returns:
true
if hide navigation flag is enabled for edge-to-edge content on API 23 and above.
-
setLightStatusBar
Set light status bar on API 23 and above.- Parameters:
window
- The window to which the view is attached.view
- The view to get the system ui flags.light
-true
to set the light status bar.- See Also:
-
setLightStatusBar
Set light status bar on API 23 and above.- Parameters:
view
- The view to get the system ui flags.light
-true
to set the light status bar.- See Also:
-
setLightStatusBarLegacy
Set light status bar by using the legacy method on API 23 and above.- Parameters:
view
- The view to get the system ui flags.light
-true
to set the light status bar.
-
addView
public static void addView(@Nullable ViewGroup viewGroup, @Nullable View view, boolean removePrevious) Add a view to the view group.- Parameters:
viewGroup
- The view group to add the view.view
- The view to be added.removePrevious
-true
to remove all the previous views of the view group.
-
addView
public static void addView(@Nullable ViewGroup viewGroup, @LayoutRes int layoutRes, boolean removePrevious) Add a view to the view group.- Parameters:
viewGroup
- The view group to add the view.layoutRes
- The layout resource to be added.removePrevious
-true
to remove all the previous views of the view group.
-
manageScrollIndicators
public static void manageScrollIndicators(@Nullable View view, @Nullable View upIndicator, @Nullable View downIndicator) Manage scroll indicators for a view according to its current state.- Parameters:
view
- The view to show or hide the scroll indicators accordingly.upIndicator
- The indicator to show if the view can be scrolled upwards.downIndicator
- The indicator to show if the view can be scrolled downwards.
-
isLayoutRtl
Checks whether the layout direction is RTL (right-to-left).- Parameters:
view
- The view to be used.- Returns:
true
if the layout direction is RTL (right-to-left).- See Also:
-
applyWindowInsets
public static void applyWindowInsets(@Nullable View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.left
-true
to apply the left window inset padding.top
-true
to apply the top window inset padding.right
-true
to apply the right window inset padding.bottom
-true
to apply the bottom window inset padding.consume
-true
to consume the applied window insets.
-
applyWindowInsetsHorizontal
Apply horizontal window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsHorizontal
Apply horizontal window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.- See Also:
-
applyWindowInsetsVertical
Apply vertical window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsVertical
Apply vertical window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.- See Also:
-
applyWindowInsetsBottom
Apply bottom window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsBottom
Apply bottom window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.- See Also:
-
applyWindowInsetsHorizontalBottom
Apply horizontal and bottom window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsHorizontalBottom
Apply horizontal and bottom window insets padding for the supplied view.- Parameters:
view
- The view to set the insets padding.- See Also:
-
applyWindowInsetsMargin
public static void applyWindowInsetsMargin(@Nullable View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.left
-true
to apply the left window inset margin.top
-true
to apply the top window inset margin.right
-true
to apply the right window inset margin.bottom
-true
to apply the bottom window inset margin.consume
-true
to consume the applied window margin.
-
applyWindowInsetsMarginHorizontal
Apply horizontal window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsMarginHorizontal
Apply horizontal window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.- See Also:
-
applyWindowInsetsMarginVertical
Apply vertical window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsMarginVertical
Apply vertical window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.- See Also:
-
applyWindowInsetsMarginBottom
Apply bottom window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsMarginBottom
Apply bottom window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.- See Also:
-
applyWindowInsetsMarginHorizontalBottom
Apply horizontal and bottom window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.consume
-true
to consume the applied window insets.- See Also:
-
applyWindowInsetsMarginHorizontalBottom
Apply horizontal and bottom window insets margin for the supplied view.- Parameters:
view
- The view to set the insets margin.- See Also:
-
requestApplyWindowInsets
Request to apply window insets for a view- Parameters:
view
- The view to request the window insets.
-
setTextSwitcherText
Set the text switcher text and animate only if there is a text change.- Parameters:
view
- The view switcher to be used.text
- The text to be set.- See Also:
-
setTextViewTextSize
Equivalent to callingTextView.setTextSize(int, float)
.- Parameters:
textView
- The text view to be used.units
- The units of size (e.g. COMPLEX_UNIT_SP).size
- The size of the text.
-
setTextViewTextSize
public static void setTextViewTextSize(@Nullable RemoteViews remoteViews, @IdRes int viewId, int units, float size) Equivalent to callingTextView.setTextSize(int, float)
.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.units
- The units of size (e.g. COMPLEX_UNIT_SP).size
- The size of the text.
-
setTextViewMaxLines
public static void setTextViewMaxLines(@Nullable RemoteViews remoteViews, @IdRes int viewId, int lines) Set the text view max lines for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.lines
- The max lines to be set.- See Also:
-
setTextViewText
public static void setTextViewText(@Nullable RemoteViews remoteViews, @IdRes int viewId, @Nullable CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.text
- The text to be set.visible
-true
to make the text view visible in case of non-empty text.
-
setTextViewText
public static void setTextViewText(@Nullable RemoteViews remoteViews, @IdRes int viewId, @Nullable CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.text
- The text to be set.- See Also:
-
setTextViewTextHtml
public static void setTextViewTextHtml(@Nullable RemoteViews remoteViews, @IdRes int viewId, @Nullable CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.text
- The text to be set.visible
-true
to make the text view visible in case of non-empty text.- See Also:
-
setTextViewTextHtml
public static void setTextViewTextHtml(@Nullable RemoteViews remoteViews, @IdRes int viewId, @Nullable CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)
and hide the view if the text is empty.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.text
- The text to be set.- See Also:
-
setTextViewAllCaps
public static void setTextViewAllCaps(@Nullable RemoteViews remoteViews, @IdRes int viewId, boolean allCaps) Set the text view all caps for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.allCaps
-true
to set the all caps.- See Also:
-
setTextViewAllCaps
Set the text view all caps.- Parameters:
textView
- The text view to be used.allCaps
-true
to set the all caps.- See Also:
-
setAlpha
Set the alpha for the supplied view.- Parameters:
view
- The view to set the alpha.alpha
- The alpha value to be set.- See Also:
-
setAlpha
public static void setAlpha(@Nullable RemoteViews remoteViews, @IdRes int viewId, @IntRange(from=0L,to=255L) int alpha) Set the alpha for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.alpha
- The alpha value to be set.- See Also:
-
setEnabled
public static void setEnabled(@Nullable RemoteViews remoteViews, @IdRes int viewId, boolean enabled) Set the enabled state for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.enabled
-true
to enable the view.- See Also:
-
setBackgroundColor
public static void setBackgroundColor(@Nullable RemoteViews remoteViews, @IdRes int viewId, @ColorInt int color) Set the background color for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.color
- The color value to be set.- See Also:
-
setColorFilter
public static void setColorFilter(@Nullable RemoteViews remoteViews, @IdRes int viewId, @ColorInt int color) Set the color filter for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.color
- The color value to be set.- See Also:
-
setTextViewLinkColor
public static void setTextViewLinkColor(@Nullable RemoteViews remoteViews, @IdRes int viewId, @ColorInt int color) Set the text view link color for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.color
- The color to be set.- See Also:
-
setTextViewColors
public static void setTextViewColors(@Nullable RemoteViews remoteViews, @IdRes int viewId, @ColorInt int color, @ColorInt int linkColor) Set the text view colors for the remote views.- Parameters:
remoteViews
- The remote views to be used.viewId
- The id of the view to be used.color
- The color to be set.linkColor
- The link color to be set.- See Also:
-
WindowInsetsControllerCompat
if possible.