Class DynamicWindowUtils
- java.lang.Object
-
- com.pranavpandey.android.dynamic.util.DynamicWindowUtils
-
public class DynamicWindowUtils extends java.lang.ObjectHelper class to perform window operations and to detect system configurations at runtime.- See Also:
WindowManager
-
-
Constructor Summary
Constructors Constructor Description DynamicWindowUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static android.graphics.PointgetAppUsableScreenSize(android.content.Context context)Get the app usable screen size.static android.view.WindowMetricsgetCurrentWindowMetrics(android.content.Context context)Returns the current window metrics for the supplied context.static android.view.DisplaygetDisplay(android.content.Context context)Returns the correct display according to the different API levels.static floatgetDisplayDensity(android.content.Context context)Returns the display used by the supplied context.static android.util.DisplayMetricsgetDisplayMetrics(android.content.Context context)Returns the display metrics for the supplied context.static android.graphics.PointgetNavigationBarSize(android.content.Context context)Get the on-screen navigation bar size.static intgetOverlayFlag(boolean alert)Get the overlay flag according to the Android version.static intgetOverlayFlag(boolean alert, boolean accessibility)Get the overlay flag according to the Android version.static android.graphics.PointgetRealScreenSize(android.content.Context context)Get the real screen size.static intgetScreenOrientation(android.content.Context context)Get the current device orientation.static intgetStatusBarSize(android.content.Context context)Get the status bar size.static booleanisGestureNavigation(android.content.Context context)Detects support for gesture navigation.static booleanisNavigationBarPresent(android.content.Context context)Detects if on-screen navigation bar is present or not.static booleanisNavigationBarThemeSupported(android.content.Context context)Detects support for navigation bar theme.static voidsetEdgeToEdge(android.view.Window window, boolean edgeToEdge)Set the hide navigation flag for edge-to-edge content on API 23 and above.static voidsetShowWallpaper(android.view.Window window, boolean showWallpaper)Set the show wallpaper flag for the supplied window.
-
-
-
Method Detail
-
getDisplay
@Nullable public static android.view.Display getDisplay(@Nullable android.content.Context context)Returns the correct display according to the different API levels.- Parameters:
context- The context to be used.- Returns:
- The display according to the API level.
- See Also:
Context.getDisplay(),WindowManager.getDefaultDisplay()
-
getDisplayMetrics
@Nullable public static android.util.DisplayMetrics getDisplayMetrics(@Nullable android.content.Context context)Returns the display metrics for the supplied context.- Parameters:
context- The context to be used.- Returns:
- The display metrics for the supplied context.
- See Also:
Context.getResources(),Resources.getDisplayMetrics()
-
getCurrentWindowMetrics
@Nullable public static android.view.WindowMetrics getCurrentWindowMetrics(@Nullable android.content.Context context)Returns the current window metrics for the supplied context.- Parameters:
context- The context to be used.- Returns:
- The current window metrics for the supplied context.
- See Also:
WindowManager.getCurrentWindowMetrics()
-
getDisplayDensity
public static float getDisplayDensity(@Nullable android.content.Context context)Returns the display used by the supplied context.- Parameters:
context- The context to be used.- Returns:
- The display density used by the supplied context.
- See Also:
Context.getResources(),Resources.getDisplayMetrics(),DisplayMetrics.density
-
getAppUsableScreenSize
@NonNull public static android.graphics.Point getAppUsableScreenSize(@Nullable android.content.Context context)Get the app usable screen size.- Parameters:
context- The context to be used.- Returns:
- The app usable screen size in point.
- See Also:
Context.WINDOW_SERVICE,Point
-
getRealScreenSize
@NonNull public static android.graphics.Point getRealScreenSize(@Nullable android.content.Context context)Get the real screen size.- Parameters:
context- The context to be used.- Returns:
- The real screen size in point.
- See Also:
Context.WINDOW_SERVICE,Point
-
getStatusBarSize
public static int getStatusBarSize(@NonNull android.content.Context context)Get the status bar size.- Parameters:
context- The context to get the resources.- Returns:
- The status bar size in pixels.
-
getNavigationBarSize
@NonNull public static android.graphics.Point getNavigationBarSize(@NonNull android.content.Context context)Get the on-screen navigation bar size.- Parameters:
context- The context to be used.- Returns:
- The on-screen navigation bar size in point.
- See Also:
Context.WINDOW_SERVICE,Point
-
isNavigationBarPresent
public static boolean isNavigationBarPresent(@NonNull android.content.Context context)Detects if on-screen navigation bar is present or not.- Parameters:
context- The context to retrieve the resources.- Returns:
trueif on-screen navigation bar is present.
-
isNavigationBarThemeSupported
public static boolean isNavigationBarThemeSupported(@NonNull android.content.Context context)Detects support for navigation bar theme.- Parameters:
context- The context to retrieve the resources.- Returns:
trueif navigation bar theme is supported.
-
isGestureNavigation
public static boolean isGestureNavigation(@NonNull android.content.Context context)Detects support for gesture navigation.- Parameters:
context- The context to retrieve the resources.- Returns:
trueif gesture navigation is supported.
-
setShowWallpaper
public static void setShowWallpaper(@Nullable android.view.Window window, boolean showWallpaper)Set the show wallpaper flag for the supplied window.This method must be called before window is created.
- Parameters:
window- The window to be used.showWallpaper-trueto show the wallpaper.- See Also:
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
-
setEdgeToEdge
public static void setEdgeToEdge(@Nullable android.view.Window window, boolean edgeToEdge)Set the hide navigation flag for edge-to-edge content on API 23 and above.- Parameters:
window- The window to be used.edgeToEdge-trueto hide the layout navigation.
-
getScreenOrientation
public static int getScreenOrientation(@Nullable android.content.Context context)Get the current device orientation.- Parameters:
context- The context to be used.- Returns:
- The current activity orientation info.
- See Also:
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
-
getOverlayFlag
public static int getOverlayFlag(boolean alert, boolean accessibility)Get the overlay flag according to the Android version.- Parameters:
alert-trueto return alert flag on API 25 and below.accessibility-trueto return the accessibility overlay.- Returns:
- The
WindowManageroverlay flag according to the Android version. - See Also:
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY
-
getOverlayFlag
public static int getOverlayFlag(boolean alert)
Get the overlay flag according to the Android version.- Parameters:
alert-trueto return alert flag on API 25 and below.- Returns:
- The
WindowManageroverlay flag according to the Android version. - See Also:
getOverlayFlag(boolean, boolean),WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
-
-