diff --git a/addons/VTAndroidCore/bin/debug/VTAndroidCore-debug.aar b/addons/VTAndroidCore/bin/debug/VTAndroidCore-debug.aar new file mode 100644 index 0000000..2e9d4ca Binary files /dev/null and b/addons/VTAndroidCore/bin/debug/VTAndroidCore-debug.aar differ diff --git a/addons/VTAndroidCore/bin/release/VTAndroidCore-release.aar b/addons/VTAndroidCore/bin/release/VTAndroidCore-release.aar new file mode 100644 index 0000000..2ca4879 Binary files /dev/null and b/addons/VTAndroidCore/bin/release/VTAndroidCore-release.aar differ diff --git a/addons/VTAndroidCore/export_plugin.gd b/addons/VTAndroidCore/export_plugin.gd new file mode 100644 index 0000000..74eabce --- /dev/null +++ b/addons/VTAndroidCore/export_plugin.gd @@ -0,0 +1,40 @@ +@tool +extends EditorPlugin + +# A class member to hold the editor export plugin during its lifecycle. +var export_plugin : BillingPluginExportPlugin + +func _enter_tree(): + # Initialization of the plugin goes here. + export_plugin = BillingPluginExportPlugin.new() + add_export_plugin(export_plugin) + + +func _exit_tree(): + # Clean-up of the plugin goes here. + remove_export_plugin(export_plugin) + export_plugin = null + + +class BillingPluginExportPlugin extends EditorExportPlugin: + var _plugin_name = "VTAndroidCore" + + func _supports_platform(platform): + if platform is EditorExportPlatformAndroid: + return true + return false + + func _get_android_libraries(platform, debug): + if debug: + return PackedStringArray([_plugin_name + "/bin/debug/" + _plugin_name + "-debug.aar"]) + else: + return PackedStringArray([_plugin_name + "/bin/release/" + _plugin_name + "-release.aar"]) + + func _get_android_dependencies(platform, debug): + if debug: + return PackedStringArray() + else: + return PackedStringArray() + + func _get_name(): + return _plugin_name diff --git a/addons/VTAndroidCore/export_plugin.gd.uid b/addons/VTAndroidCore/export_plugin.gd.uid new file mode 100644 index 0000000..cfbc88a --- /dev/null +++ b/addons/VTAndroidCore/export_plugin.gd.uid @@ -0,0 +1 @@ +uid://ddhyjofvs0log diff --git a/addons/VTAndroidCore/plugin.cfg b/addons/VTAndroidCore/plugin.cfg new file mode 100644 index 0000000..b4c6fa4 --- /dev/null +++ b/addons/VTAndroidCore/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="VTAndroidCore" +description="Mandatory plugin for VectorTouch, providing essential Android-specific methods and utilities." +author="Anish Mishra" +version="1.0" +script="export_plugin.gd" diff --git a/project.godot b/project.godot index e44c3aa..a97e045 100644 --- a/project.godot +++ b/project.godot @@ -47,6 +47,7 @@ text_editor/completion/add_type_hints=true text_editor/completion/add_node_path_literals=true text_editor/completion/add_string_name_literals=false text_editor/appearance/guidelines/line_length_guideline_hard_column=160 +enabled=PackedStringArray("res://addons/VTAndroidCore/plugin.cfg") [filesystem] diff --git a/src/autoload/HandlerGUI.gd b/src/autoload/HandlerGUI.gd index b21d692..f044eef 100644 --- a/src/autoload/HandlerGUI.gd +++ b/src/autoload/HandlerGUI.gd @@ -18,49 +18,23 @@ var popup_stack: Array[Control] var shortcut_panel: PanelContainer var tabs_panel: PanelContainer -var android_runtime: JNISingleton -var is_light_system_bars: bool = false +var VTAndroidCore: JNISingleton +var system_bar_color: Color = Color.BLACK var status_bar_visible: bool = true var minimum_content_width : float -func set_system_bar_color(color: Color, override_appearance := false) -> void: - if not android_runtime: +func set_system_bar_color(color: Color, override := false) -> void: + if (system_bar_color == color and not override) or not VTAndroidCore: return - - var activity = android_runtime.getActivity() - var callable = func (): - var window = activity.getWindow() - var decorView: JavaObject = window.getDecorView() - decorView.setBackgroundColor(color.to_argb32()) - - if (is_light_system_bars != (color.get_luminance() > 0.45)) or override_appearance: - is_light_system_bars = color.get_luminance() > 0.45 - var WindowInsetsControllerCompat = JavaClassWrapper.wrap("androidx.core.view.WindowInsetsControllerCompat") - var controller = WindowInsetsControllerCompat.call("", window, window.getDecorView()) - controller.setAppearanceLightNavigationBars(is_light_system_bars) - controller.setAppearanceLightStatusBars(is_light_system_bars) - - activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable)) + VTAndroidCore.setWindowColor(color) + system_bar_color = color func toogle_status_bar(visible: bool, override := false) -> void: - if (status_bar_visible == visible and not override) or not android_runtime: + if (status_bar_visible == visible and not override) or not VTAndroidCore: return - - var activity = android_runtime.getActivity() - var callable = func (): - var window = activity.getWindow() - var WindowInsetsControllerCompat = JavaClassWrapper.wrap("androidx.core.view.WindowInsetsControllerCompat") - var controller = WindowInsetsControllerCompat.call("", window, window.getDecorView()) - var type = JavaClassWrapper.wrap("androidx.core.view.WindowInsetsCompat$Type") - if visible: - controller.show(type.statusBars()) - else: - controller.hide(type.statusBars()) - controller.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE) - status_bar_visible = visible - - activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable)) + VTAndroidCore.toogleStatusBar(visible) + status_bar_visible = visible var shortcut_registrations: Dictionary[Node, ShortcutsRegistration] = {} @@ -94,7 +68,7 @@ func _ready() -> void: await get_tree().process_frame # Helps make things more consistent. update_ui_scale() - android_runtime = Engine.get_singleton("AndroidRuntime") + VTAndroidCore = Engine.get_singleton("VTAndroidCore") set_system_bar_color(ThemeUtils.base_color, true) toogle_status_bar(Configs.current_orientation == Configs.orientation.PORTRAIT) var version = JavaClassWrapper.wrap("android.os.Build$VERSION")