package metricrat.co.uk.hidebars; import android.app.*; import android.content.*; import android.view.*; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; public class HideBars extends AndroidNonvisibleComponent { private ComponentContainer container; private static Context context; private final Activity activity; public HideBars(ComponentContainer container) { super(container.$form()); this.container = container; context = container.$context(); this.activity = container.$context(); } @SimpleFunction(description = "hides system bars - you can swipe them open, and makes app fullscreen") public void HideSystemUI() { Window scrn = this.activity.getWindow(); scrn.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; scrn.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); scrn.getInsetsController().hide(WindowInsets.Type.systemBars()); scrn.getInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); scrn.setDecorFitsSystemWindows(false); } @SimpleFunction(description = "shows system bars and clears full screen settings") public void ShowSystemUI() { Window scrn = this.activity.getWindow(); scrn.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; scrn.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); scrn.getInsetsController().show(WindowInsets.Type.systemBars()); scrn.getInsetsController().setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT); scrn.setDecorFitsSystemWindows(true); } @SimpleProperty(description = "sets the background cololur of the Navigation Bar") public void SetNavBarColour(int colour) { Window scrn = this.activity.getWindow(); scrn.setNavigationBarColor(colour); } @SimpleProperty(description = "sets the background colour of the Status Bar") public void SetStatusBarColour(int colour) { Window scrn = this.activity.getWindow(); scrn.setStatusBarColor(colour); } @SimpleFunction(description = "sets system bars text/icon colours to light mode") public void SetLightMode() { Window scrn = this.activity.getWindow(); scrn.getInsetsController().setSystemBarsAppearance(WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS); } @SimpleFunction(description = "sets system bars text/icon colours to dark mode") public void SetDarkMode() { Window scrn = this.activity.getWindow(); scrn.getInsetsController().setSystemBarsAppearance(0, WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS); } }