Class DynamicWindowUtils
- java.lang.Object
-
- com.pranavpandey.android.dynamic.util.DynamicWindowUtils
-
public class DynamicWindowUtils extends java.lang.Object
Helper class to perform window operations and to detect system configurations at runtime.- See Also:
WindowManager
-
-
Field Summary
Fields Modifier and Type Field Description static int
GESTURE_NAVIGATION_BAR_HEIGHT
Maximum height for the gesture navigation in DP.
-
Constructor Summary
Constructors Constructor Description DynamicWindowUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Point
getAppUsableScreenSize(Context context)
Get the app usable screen size.static WindowMetrics
getCurrentWindowMetrics(Context context)
Returns the current window metrics for the supplied context.static Display
getDisplay(Context context)
Returns the correct display according to the different API levels.static float
getDisplayDensity(Context context)
Returns the display used by the supplied context.static DisplayMetrics
getDisplayMetrics(Context context)
Returns the display metrics for the supplied context.static Point
getNavigationBarSize(Context context)
Get the on-screen navigation bar size.static int
getOverlayFlag(boolean alert)
Get the overlay flag according to the Android version.static int
getOverlayFlag(boolean alert, boolean accessibility)
Get the overlay flag according to the Android version.static Point
getRealScreenSize(Context context)
Get the real screen size.static int
getScreenOrientation(Context context)
Get the current device orientation.static int
getStatusBarSize(Context context)
Get the status bar size.static boolean
isGestureNavigation(Context context)
Detects support for gesture navigation.static boolean
isNavigationBarPresent(Context context)
Detects if on-screen navigation bar is present or not.static boolean
isNavigationBarThemeSupported(Context context)
Detects support for navigation bar theme.static void
setEdgeToEdge(Window window, boolean edgeToEdge)
Set the hide navigation flag for edge-to-edge content on API 23 and above.static void
setShowWallpaper(Window window, boolean showWallpaper)
Set the show wallpaper flag for the supplied window.
-
-
-
Field Detail
-
GESTURE_NAVIGATION_BAR_HEIGHT
public static final int GESTURE_NAVIGATION_BAR_HEIGHT
Maximum height for the gesture navigation in DP.- See Also:
- Constant Field Values
-
-
Method Detail
-
getDisplay
@Nullable public static Display getDisplay(@Nullable 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 DisplayMetrics getDisplayMetrics(@Nullable 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 WindowMetrics getCurrentWindowMetrics(@Nullable 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 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 Point getAppUsableScreenSize(@Nullable 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 Point getRealScreenSize(@Nullable 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 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 Point getNavigationBarSize(@NonNull 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 Context context)
Detects if on-screen navigation bar is present or not.- Parameters:
context
- The context to be used.- Returns:
true
if on-screen navigation bar is present.
-
isNavigationBarThemeSupported
public static boolean isNavigationBarThemeSupported(@NonNull Context context)
Detects support for navigation bar theme.- Parameters:
context
- The context to be used.- Returns:
true
if navigation bar theme is supported.
-
isGestureNavigation
public static boolean isGestureNavigation(@NonNull Context context)
Detects support for gesture navigation.- Parameters:
context
- The context to be used.- Returns:
true
if gesture navigation is supported.
-
setShowWallpaper
public static void setShowWallpaper(@Nullable 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
-true
to show the wallpaper.- See Also:
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
-
setEdgeToEdge
public static void setEdgeToEdge(@Nullable 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
-true
to hide the layout navigation.
-
getScreenOrientation
public static int getScreenOrientation(@Nullable 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
-true
to return alert flag on API 25 and below.accessibility
-true
to return the accessibility overlay.- Returns:
- The
WindowManager
overlay 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
-true
to return alert flag on API 25 and below.- Returns:
- The
WindowManager
overlay 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
-
-