Class DynamicViewUtils
java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicViewUtils
Helper class to perform
View operations.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdd a view to the view group.static voidAdd a view to the view group.static voidapplyWindowInsets(View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets padding for the supplied view.static voidapplyWindowInsetsBottom(View view) Apply bottom window insets padding for the supplied view.static voidapplyWindowInsetsBottom(View view, boolean consume) Apply bottom window insets padding for the supplied view.static voidApply horizontal window insets padding for the supplied view.static voidapplyWindowInsetsHorizontal(View view, boolean consume) Apply horizontal window insets padding for the supplied view.static voidApply horizontal and bottom window insets padding for the supplied view.static voidapplyWindowInsetsHorizontalBottom(View view, boolean consume) Apply horizontal and bottom window insets padding for the supplied view.static voidapplyWindowInsetsMargin(View view, boolean left, boolean top, boolean right, boolean bottom, boolean consume) Apply window insets margin for the supplied view.static voidApply bottom window insets margin for the supplied view.static voidapplyWindowInsetsMarginBottom(View view, boolean consume) Apply bottom window insets margin for the supplied view.static voidApply horizontal window insets margin for the supplied view.static voidapplyWindowInsetsMarginHorizontal(View view, boolean consume) Apply horizontal window insets margin for the supplied view.static voidApply horizontal and bottom window insets margin for the supplied view.static voidapplyWindowInsetsMarginHorizontalBottom(View view, boolean consume) Apply horizontal and bottom window insets margin for the supplied view.static voidApply vertical window insets margin for the supplied view.static voidapplyWindowInsetsMarginVertical(View view, boolean consume) Apply vertical window insets margin for the supplied view.static voidApply vertical window insets padding for the supplied view.static voidapplyWindowInsetsVertical(View view, boolean consume) Apply vertical window insets padding for the supplied view.static booleanisEdgeToEdge(View view) Deprecated.static booleanisLayoutRtl(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 voidmanageScrollIndicators(View view, View upIndicator, View downIndicator) Manage scroll indicators for a view according to its current state.static voidrequestApplyWindowInsets(View view) Request to apply window insets for a viewstatic voidSet the alpha for the supplied view.static voidsetAlpha(RemoteViews remoteViews, int viewId, int alpha) Set the alpha for the remote views.static voidsetBackgroundColor(RemoteViews remoteViews, int viewId, int color) Set the background color for the remote views.static voidsetColorFilter(RemoteViews remoteViews, int viewId, int color) Set the color filter for the remote views.static voidsetEdgeToEdge(View view, boolean edgeToEdge) Deprecated.UseDynamicWindowUtils.setEdgeToEdge(Window, boolean)to support latest API levels.static voidsetEnabled(RemoteViews remoteViews, int viewId, boolean enabled) Set the enabled state for the remote views.static voidsetLightNavigationBar(View view, boolean light) Set light navigation bar on API 26 and above.static voidsetLightNavigationBar(Window window, View view, boolean light) Set light navigation bar on API 26 and above.static voidsetLightNavigationBarLegacy(View view, boolean light) Set light navigation bar on API 26 and above.static voidsetLightStatusBar(View view, boolean light) Set light status bar on API 23 and above.static voidsetLightStatusBar(Window window, View view, boolean light) Set light status bar on API 23 and above.static voidsetLightStatusBarLegacy(View view, boolean light) Set light status bar by using the legacy method on API 23 and above.static voidsetTextSwitcherText(TextSwitcher view, CharSequence text) Set the text switcher text and animate only if there is a text change.static voidsetTextViewAllCaps(RemoteViews remoteViews, int viewId, boolean allCaps) Set the text view all caps for the remote views.static voidsetTextViewAllCaps(TextView textView, boolean allCaps) Set the text view all caps.static voidsetTextViewColors(RemoteViews remoteViews, int viewId, int color, int linkColor) Set the text view colors for the remote views.static voidsetTextViewLinkColor(RemoteViews remoteViews, int viewId, int color) Set the text view link color for the remote views.static voidsetTextViewMaxLines(RemoteViews remoteViews, int viewId, int lines) Set the text view max lines for the remote views.static voidsetTextViewText(RemoteViews remoteViews, int viewId, CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)and hide the view if the text is empty.static voidsetTextViewText(RemoteViews remoteViews, int viewId, CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)and hide the view if the text is empty.static voidsetTextViewTextHtml(RemoteViews remoteViews, int viewId, CharSequence text) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)and hide the view if the text is empty.static voidsetTextViewTextHtml(RemoteViews remoteViews, int viewId, CharSequence text, boolean visible) Equivalent to callingRemoteViews.setTextViewText(int, CharSequence)and hide the view if the text is empty.static voidsetTextViewTextSize(RemoteViews remoteViews, int viewId, int units, float size) Equivalent to callingTextView.setTextSize(int, float).static voidsetTextViewTextSize(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:
trueif 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-trueto hide the layout navigation.
-
isEdgeToEdge
Deprecated.Try to useWindowInsetsControllerCompatif 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:
trueif 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-trueto 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-trueto 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-trueto 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-trueto 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-trueto 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:
trueif 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-trueto apply the left window inset padding.top-trueto apply the top window inset padding.right-trueto apply the right window inset padding.bottom-trueto apply the bottom window inset padding.consume-trueto 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-trueto 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-trueto 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-trueto 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-trueto 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-trueto apply the left window inset margin.top-trueto apply the top window inset margin.right-trueto apply the right window inset margin.bottom-trueto apply the bottom window inset margin.consume-trueto 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-trueto 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-trueto 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-trueto 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-trueto 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-trueto 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-trueto 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-trueto set the all caps.- See Also:
-
setTextViewAllCaps
Set the text view all caps.- Parameters:
textView- The text view to be used.allCaps-trueto 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-trueto 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:
-
WindowInsetsControllerCompatif possible.