Class DynamicViewUtils

java.lang.Object
com.pranavpandey.android.dynamic.util.DynamicViewUtils

public class DynamicViewUtils extends Object
Helper class to perform View operations.
  • Constructor Details

    • DynamicViewUtils

      public DynamicViewUtils()
  • Method Details

    • isRootLayout

      public static <T extends View> boolean isRootLayout(@Nullable T view)
      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

      public static void setEdgeToEdge(@Nullable View view, boolean edgeToEdge)
      Deprecated.
      Use DynamicWindowUtils.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

      public static boolean isEdgeToEdge(@NonNull View view)
      Deprecated.
      Try to use WindowInsetsControllerCompat 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

      public static void setLightStatusBar(@Nullable Window window, @Nullable View view, boolean light)
      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

      public static void setLightStatusBar(@Nullable View view, boolean light)
      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

      public static void setLightStatusBarLegacy(@Nullable View view, boolean light)
      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.
    • setLightNavigationBar

      public static void setLightNavigationBar(@Nullable Window window, @Nullable View view, boolean light)
      Set light navigation bar on API 26 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 navigation bar.
      See Also:
    • setLightNavigationBar

      public static void setLightNavigationBar(@Nullable View view, boolean light)
      Set light navigation bar on API 26 and above.
      Parameters:
      view - The view to get the system ui flags.
      light - true to set the light navigation bar.
      See Also:
    • setLightNavigationBarLegacy

      public static void setLightNavigationBarLegacy(@Nullable View view, boolean light)
      Set light navigation bar on API 26 and above.
      Parameters:
      view - The view to get the system ui flags.
      light - true to set the light navigation 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

      public static boolean isLayoutRtl(@Nullable View view)
      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

      public static void applyWindowInsetsHorizontal(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsHorizontal(@Nullable View view)
      Apply horizontal window insets padding for the supplied view.
      Parameters:
      view - The view to set the insets padding.
      See Also:
    • applyWindowInsetsVertical

      public static void applyWindowInsetsVertical(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsVertical(@Nullable View view)
      Apply vertical window insets padding for the supplied view.
      Parameters:
      view - The view to set the insets padding.
      See Also:
    • applyWindowInsetsBottom

      public static void applyWindowInsetsBottom(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsBottom(@Nullable View view)
      Apply bottom window insets padding for the supplied view.
      Parameters:
      view - The view to set the insets padding.
      See Also:
    • applyWindowInsetsHorizontalBottom

      public static void applyWindowInsetsHorizontalBottom(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsHorizontalBottom(@Nullable View view)
      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

      public static void applyWindowInsetsMarginHorizontal(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsMarginHorizontal(@Nullable View view)
      Apply horizontal window insets margin for the supplied view.
      Parameters:
      view - The view to set the insets margin.
      See Also:
    • applyWindowInsetsMarginVertical

      public static void applyWindowInsetsMarginVertical(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsMarginVertical(@Nullable View view)
      Apply vertical window insets margin for the supplied view.
      Parameters:
      view - The view to set the insets margin.
      See Also:
    • applyWindowInsetsMarginBottom

      public static void applyWindowInsetsMarginBottom(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsMarginBottom(@Nullable View view)
      Apply bottom window insets margin for the supplied view.
      Parameters:
      view - The view to set the insets margin.
      See Also:
    • applyWindowInsetsMarginHorizontalBottom

      public static void applyWindowInsetsMarginHorizontalBottom(@Nullable View view, boolean consume)
      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

      public static void applyWindowInsetsMarginHorizontalBottom(@Nullable View view)
      Apply horizontal and bottom window insets margin for the supplied view.
      Parameters:
      view - The view to set the insets margin.
      See Also:
    • requestApplyWindowInsets

      public static void requestApplyWindowInsets(@Nullable View view)
      Request to apply window insets for a view
      Parameters:
      view - The view to request the window insets.
    • setTextSwitcherText

      public static void setTextSwitcherText(@Nullable TextSwitcher view, @Nullable CharSequence text)
      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

      public static void setTextViewTextSize(@Nullable RemoteViews remoteViews, @IdRes int viewId, int units, float size)
      Equivalent to calling TextView.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 calling RemoteViews.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 calling RemoteViews.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 calling RemoteViews.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 calling RemoteViews.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

      public static void setTextViewAllCaps(@Nullable TextView textView, boolean allCaps)
      Set the text view all caps.
      Parameters:
      textView - The text view to be used.
      allCaps - true to set the all caps.
      See Also:
    • setAlpha

      public static void setAlpha(@Nullable View view, @FloatRange(from=0.0,to=1.0) float alpha)
      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: