package com.dofu.hidebars.hidebars; import android.app.Activity; import android.graphics.Color; import android.os.Build; import android.view.View; import android.view.Window; import android.view.WindowManager; import androidx.core.view.WindowCompat; import androidx.core.view.WindowInsetsCompat; import androidx.core.view.WindowInsetsControllerCompat; import com.google.appinventor.components.annotations.DesignerComponent; import com.google.appinventor.components.annotations.SimpleFunction; import com.google.appinventor.components.annotations.SimpleObject; import com.google.appinventor.components.common.ComponentCategory; import com.google.appinventor.components.runtime.AndroidNonvisibleComponent; import com.google.appinventor.components.runtime.ComponentContainer; @DesignerComponent( version = 18, // Version Funcional [Limpia] description = "Extensión para ocultar barras del sistema con modo inmersivo y compatibilidad Android 5.1 a 15.", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAACxAAAAsQHGLUmNAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAoRJREFUSIm11l2IjmkYB/Df+zHyOWVtafPdyhFLas+ElNZmy2xqKbLJnlBkWzFsG1Jr94T2YJz4is1HhvYAJ+REaYtNkbBYu+tgTIxWYciaGQfX/c48PZ4ZFP96up/3vu7nf133df3v634r2I/f0jgYw3Ebh3EejWjDYqxBPabiomJMwa9YgrFVDE2GoRiQnvF4hAoGoT8G4hC24eNeyKEzBQj/VdCAEibiJh5jAfagBStQh3tp/jq6cK0XB8/xP27hSgVnMTlF1oJ/cR+/4xn+TAEcxB004YO0rggfYQY+REcfO303KOEHTH9P/GffE28PSiL6dehXYL+A70WRt2PCW3A/x09wUui/CE1CXXOw/i3IYQhOVIVun2ApjmCD0P9RIc0B4hzcLyApY7SQdlvO9ghdVfwsdH0a7WhODm69JsIl+BpXhTTb8S0eZBdVMQ7nsEikZF1ysKMP8nn4FLNFBoj2sRtfpoC7cTyNdWmsF22jgo2JqAHfZL45LFKXxxbMynKX00tJNLXBot8cwcw+drAQTwvmL4k+1o1yIu9K3h9jrtj6mYwtj4Oi8HlMwl/ZiSquYKdccRL5NNGjRuZsx/AjvssE8Imow+a8g0aM0lODLDYpTsUxUadTuIwRydEyPUXvdiAZa1oek6J/HXZhn8j5Q9wtWlTFVnFY/sABrBW1IU7x57lv6vCZYhURN113HaqiMF9kFizPvG/yav/5Bf/g7wLyCvbiK7TWHNSKNDND1inu1S6vpmuYkPGdAgdlIZb6rIMaWjO/O/GigABWY5W41fLoEH8ebtQmqnryfT09WdSaYWfG+V1v1llLKJewEvPFRV0UUYNovc29rOkNdWh+CZzdjrDsaBf8AAAAAElFTkSuQmCC") @SimpleObject(external = true) public class HideBars extends AndroidNonvisibleComponent { private final Activity activity; private int currentStatusBarColor; private int currentNavBarColor; private final int defaultStatusBarColor; private final int defaultNavBarColor; public HideBars(ComponentContainer container) { super(container.$form()); this.activity = container.$context(); Window window = activity.getWindow(); this.defaultStatusBarColor = window.getStatusBarColor(); this.defaultNavBarColor = window.getNavigationBarColor(); this.currentStatusBarColor = this.defaultStatusBarColor; this.currentNavBarColor = this.defaultNavBarColor; } @SimpleFunction(description = "Establece un color personalizado para la barra de estado y la barra de navegación.") public void SetBarColor(int statusColor, int navColor) { currentStatusBarColor = statusColor; currentNavBarColor = navColor; applyColors(); } @SimpleFunction(description = "Restaura los colores de las barras a los definidos por el tema de la aplicación.") public void ResetBarColors() { currentStatusBarColor = defaultStatusBarColor; currentNavBarColor = defaultNavBarColor; applyColors(); } private void applyColors() { Window window = activity.getWindow(); if (window != null) { window.setStatusBarColor(currentStatusBarColor); window.setNavigationBarColor(currentNavBarColor); } } @SimpleFunction(description = "Activa el modo inmersivo, ocultando las barras del sistema y usando toda la pantalla (edge-to-edge).") public void HideSystemUI() { Window window = activity.getWindow(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { WindowCompat.setDecorFitsSystemWindows(window, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; } window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, window.getDecorView()); controller.hide(WindowInsetsCompat.Type.systemBars()); controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); window.setStatusBarColor(Color.TRANSPARENT); window.setNavigationBarColor(Color.TRANSPARENT); } else { // Metodo legacy para versiones antiguas View decorView = window.getDecorView(); int flags = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; decorView.setSystemUiVisibility(flags); } } @SimpleFunction(description = "Muestra las barras del sistema y sale del modo inmersivo.") public void ShowSystemUI() { Window window = activity.getWindow(); WindowCompat.setDecorFitsSystemWindows(window, true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { window.getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; } window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(window, window.getDecorView()); controller.show(WindowInsetsCompat.Type.systemBars()); applyColors(); }