Skip to content

Commit 700cb53

Browse files
update to godot 4.5
1 parent e5c5d25 commit 700cb53

File tree

8 files changed

+37
-121
lines changed

8 files changed

+37
-121
lines changed

SystemBarColorChanger/SystemBarColorChanger.gd

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,24 @@
2424
extends Node
2525

2626
const _plugin_name: String = "SystemBarColorChanger"
27-
var is_light_status_bar: bool = false
28-
var is_light_navigation_bar: bool = false
2927

3028
var android_runtime: Object
3129

3230
func _ready() -> void:
3331
if Engine.has_singleton("AndroidRuntime"):
3432
android_runtime = Engine.get_singleton("AndroidRuntime")
35-
var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams")
36-
var window = android_runtime.getActivity().getWindow()
37-
window.addFlags(layout_params.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
3833
else:
39-
printerr("AndroidRuntime singleton not found! Try it on an Android device.")
34+
print_verbose("%s plugin not initialized. It is only available on Android devices." % _plugin_name)
4035

4136

42-
func set_status_bar_color(color: Color) -> void:
37+
func set_system_bar_color(color: Color) -> void:
4338
if not android_runtime:
44-
printerr("%s plugin not initialized!" % _plugin_name)
45-
return
46-
47-
var activity = android_runtime.getActivity()
48-
var callable = func ():
49-
var window = activity.getWindow()
50-
window.setStatusBarColor(color.to_argb32())
51-
if is_light_status_bar != (color.get_luminance() > 0.6):
52-
is_light_status_bar = color.get_luminance() > 0.6
53-
var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController")
54-
var insets_controller = window.getInsetsController()
55-
insets_controller.setSystemBarsAppearance(
56-
wic.APPEARANCE_LIGHT_STATUS_BARS if is_light_status_bar else 0,
57-
wic.APPEARANCE_LIGHT_STATUS_BARS)
58-
59-
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
60-
61-
62-
func set_navigation_bar_color(color: Color) -> void:
63-
if not android_runtime:
64-
printerr("%s plugin not initialized!" % _plugin_name)
6539
return
6640

6741
var activity = android_runtime.getActivity()
6842
var callable = func ():
69-
var window = activity.getWindow()
70-
window.setNavigationBarColor(color.to_argb32())
71-
if is_light_navigation_bar != (color.get_luminance() > 0.6):
72-
is_light_navigation_bar = color.get_luminance() > 0.6
73-
var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController")
74-
var insets_controller = window.getInsetsController()
75-
insets_controller.setSystemBarsAppearance(
76-
wic.APPEARANCE_LIGHT_NAVIGATION_BARS if is_light_navigation_bar else 0,
77-
wic.APPEARANCE_LIGHT_NAVIGATION_BARS)
43+
activity.getWindow().getDecorView().setBackgroundColor(color.to_argb32())
44+
activity.getGodot().setSystemBarsAppearance()
7845

7946
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
8047

@@ -85,14 +52,8 @@ func set_translucent_system_bars(translucent = true) -> void:
8552
return
8653

8754
var activity = android_runtime.getActivity()
55+
var godot = activity.getGodot()
8856
var callable = func ():
89-
var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams")
90-
var window = activity.getWindow()
91-
if translucent:
92-
window.addFlags(layout_params.FLAG_TRANSLUCENT_STATUS)
93-
window.addFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION)
94-
else:
95-
window.clearFlags(layout_params.FLAG_TRANSLUCENT_STATUS)
96-
window.clearFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION)
57+
godot.enableEdgeToEdge(translucent)
9758

9859
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))

SystemBarColorChanger/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="SystemBarColorChanger"
44
description="Plugin to change System Bar (status and navigation bar) color dynamically and enable translucent system bars on Android."
55
author="Anish"
6-
version="2.0"
6+
version="3.0"
77
script="plugin.gd"

demo/addons/SystemBarColorChanger/SystemBarColorChanger.gd

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,24 @@
2424
extends Node
2525

2626
const _plugin_name: String = "SystemBarColorChanger"
27-
var is_light_status_bar: bool = false
28-
var is_light_navigation_bar: bool = false
2927

3028
var android_runtime: Object
3129

3230
func _ready() -> void:
3331
if Engine.has_singleton("AndroidRuntime"):
3432
android_runtime = Engine.get_singleton("AndroidRuntime")
35-
var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams")
36-
var window = android_runtime.getActivity().getWindow()
37-
window.addFlags(layout_params.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
3833
else:
39-
printerr("AndroidRuntime singleton not found! Try it on an Android device.")
34+
print_verbose("%s plugin not initialized. It is only available on Android devices." % _plugin_name)
4035

4136

42-
func set_status_bar_color(color: Color) -> void:
37+
func set_system_bar_color(color: Color) -> void:
4338
if not android_runtime:
44-
printerr("%s plugin not initialized!" % _plugin_name)
45-
return
46-
47-
var activity = android_runtime.getActivity()
48-
var callable = func ():
49-
var window = activity.getWindow()
50-
window.setStatusBarColor(color.to_argb32())
51-
if is_light_status_bar != (color.get_luminance() > 0.6):
52-
is_light_status_bar = color.get_luminance() > 0.6
53-
var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController")
54-
var insets_controller = window.getInsetsController()
55-
insets_controller.setSystemBarsAppearance(
56-
wic.APPEARANCE_LIGHT_STATUS_BARS if is_light_status_bar else 0,
57-
wic.APPEARANCE_LIGHT_STATUS_BARS)
58-
59-
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
60-
61-
62-
func set_navigation_bar_color(color: Color) -> void:
63-
if not android_runtime:
64-
printerr("%s plugin not initialized!" % _plugin_name)
6539
return
6640

6741
var activity = android_runtime.getActivity()
6842
var callable = func ():
69-
var window = activity.getWindow()
70-
window.setNavigationBarColor(color.to_argb32())
71-
if is_light_navigation_bar != (color.get_luminance() > 0.6):
72-
is_light_navigation_bar = color.get_luminance() > 0.6
73-
var wic = JavaClassWrapper.wrap("android.view.WindowInsetsController")
74-
var insets_controller = window.getInsetsController()
75-
insets_controller.setSystemBarsAppearance(
76-
wic.APPEARANCE_LIGHT_NAVIGATION_BARS if is_light_navigation_bar else 0,
77-
wic.APPEARANCE_LIGHT_NAVIGATION_BARS)
43+
activity.getWindow().getDecorView().setBackgroundColor(color.to_argb32())
44+
activity.getGodot().setSystemBarsAppearance()
7845

7946
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
8047

@@ -85,14 +52,8 @@ func set_translucent_system_bars(translucent = true) -> void:
8552
return
8653

8754
var activity = android_runtime.getActivity()
55+
var godot = activity.getGodot()
8856
var callable = func ():
89-
var layout_params = JavaClassWrapper.wrap("android.view.WindowManager$LayoutParams")
90-
var window = activity.getWindow()
91-
if translucent:
92-
window.addFlags(layout_params.FLAG_TRANSLUCENT_STATUS)
93-
window.addFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION)
94-
else:
95-
window.clearFlags(layout_params.FLAG_TRANSLUCENT_STATUS)
96-
window.clearFlags(layout_params.FLAG_TRANSLUCENT_NAVIGATION)
57+
godot.enableEdgeToEdge(translucent)
9758

9859
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))

demo/addons/SystemBarColorChanger/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="SystemBarColorChanger"
44
description="Plugin to change System Bar (status and navigation bar) color dynamically and enable translucent system bars on Android."
55
author="Anish"
6-
version="2.0"
6+
version="3.0"
77
script="plugin.gd"

demo/export_presets.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ gradle_build/compress_native_libraries=false
2929
gradle_build/export_format=0
3030
gradle_build/min_sdk=""
3131
gradle_build/target_sdk=""
32+
gradle_build/custom_theme_attributes={}
3233
architectures/armeabi-v7a=false
3334
architectures/arm64-v8a=true
3435
architectures/x86=false
3536
architectures/x86_64=false
3637
version/code=1
37-
version/name="1.1"
38+
version/name="3.0"
3839
package/unique_name="org.godotengine.android.plugin.demo"
3940
package/name=""
4041
package/signed=true
@@ -49,13 +50,16 @@ launcher_icons/adaptive_foreground_432x432=""
4950
launcher_icons/adaptive_background_432x432=""
5051
launcher_icons/adaptive_monochrome_432x432=""
5152
graphics/opengl_debug=false
53+
shader_baker/enabled=false
5254
xr_features/xr_mode=0
5355
gesture/swipe_to_dismiss=false
5456
screen/immersive_mode=false
57+
screen/edge_to_edge=false
5558
screen/support_small=true
5659
screen/support_normal=true
5760
screen/support_large=true
5861
screen/support_xlarge=true
62+
screen/background_color=Color(0, 0, 0, 1)
5963
user_data_backup/allow=false
6064
command_line/extra_args=""
6165
apk_expansion/enable=false

demo/main.gd

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ extends Control
33

44
func _on_color_picker_button_color_changed(color: Color) -> void:
55
$ColorRect.color = color
6-
SystemBarColorChanger.set_status_bar_color(color)
7-
SystemBarColorChanger.set_navigation_bar_color(color)
6+
SystemBarColorChanger.set_system_bar_color(color)
87

98
func _on_translucent_system_bars_toggled(toggled_on: bool) -> void:
109
SystemBarColorChanger.set_translucent_system_bars(toggled_on)
1110

12-
func _on_set_status_color_pressed() -> void:
13-
SystemBarColorChanger.set_status_bar_color("004748")
14-
15-
func _on_set_nav_color_pressed() -> void:
16-
SystemBarColorChanger.set_navigation_bar_color("004748")
11+
func _on_set_system_color_pressed() -> void:
12+
SystemBarColorChanger.set_system_bar_color("004748")

demo/main.tscn

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
[gd_scene load_steps=8 format=3 uid="uid://dtl3cy3awyva1"]
22

33
[ext_resource type="Script" uid="uid://oiyx056majqr" path="res://main.gd" id="1_5g8lr"]
4-
[ext_resource type="Texture2D" uid="uid://bgs0m1punaqv3" path="res://addons/SystemBarColorChanger/icon.png" id="2_xiny2"]
4+
[ext_resource type="Texture2D" uid="uid://5yy5r3beaoiq" path="res://addons/SystemBarColorChanger/icon.png" id="2_xiny2"]
55

6-
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_qoqou"]
7-
8-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_o2o5j"]
6+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1pedh"]
97
content_margin_left = 20.0
108
bg_color = Color(0.0588235, 0.172549, 0.172549, 1)
119

12-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6mb2y"]
10+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h1amm"]
1311
content_margin_left = 20.0
1412
bg_color = Color(0.0588235, 0.172549, 0.172549, 1)
1513

16-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h1amm"]
14+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_6mb2y"]
1715
content_margin_left = 20.0
1816
bg_color = Color(0.0588235, 0.172549, 0.172549, 1)
1917

20-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1pedh"]
18+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_o2o5j"]
2119
content_margin_left = 20.0
2220
bg_color = Color(0.0588235, 0.172549, 0.172549, 1)
2321

22+
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_qoqou"]
23+
2424
[node name="demo" type="Control"]
2525
layout_mode = 3
2626
anchors_preset = 15
@@ -74,27 +74,21 @@ text = "Click to change color dynamically"
7474
horizontal_alignment = 1
7575
vertical_alignment = 1
7676

77-
[node name="set_status_color" type="Button" parent="VBoxContainer"]
77+
[node name="set_system_color" type="Button" parent="VBoxContainer"]
7878
custom_minimum_size = Vector2(0, 80)
7979
layout_mode = 2
80-
text = "Set Status Bar Color"
81-
82-
[node name="set_nav_color" type="Button" parent="VBoxContainer"]
83-
custom_minimum_size = Vector2(0, 80)
84-
layout_mode = 2
85-
text = "Set Navigation Bar Color"
80+
text = "Set System Bar Color"
8681

8782
[node name="translucent_system_bars" type="CheckButton" parent="VBoxContainer"]
8883
custom_minimum_size = Vector2(0, 80)
8984
layout_mode = 2
90-
theme_override_styles/focus = SubResource("StyleBoxEmpty_qoqou")
91-
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_o2o5j")
92-
theme_override_styles/hover = SubResource("StyleBoxFlat_6mb2y")
93-
theme_override_styles/pressed = SubResource("StyleBoxFlat_h1amm")
9485
theme_override_styles/normal = SubResource("StyleBoxFlat_1pedh")
86+
theme_override_styles/pressed = SubResource("StyleBoxFlat_h1amm")
87+
theme_override_styles/hover = SubResource("StyleBoxFlat_6mb2y")
88+
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_o2o5j")
89+
theme_override_styles/focus = SubResource("StyleBoxEmpty_qoqou")
9590
text = "Translucent System Bars"
9691

9792
[connection signal="color_changed" from="VBoxContainer/ColorPickerButton" to="." method="_on_color_picker_button_color_changed"]
98-
[connection signal="pressed" from="VBoxContainer/set_status_color" to="." method="_on_set_status_color_pressed"]
99-
[connection signal="pressed" from="VBoxContainer/set_nav_color" to="." method="_on_set_nav_color_pressed"]
93+
[connection signal="pressed" from="VBoxContainer/set_system_color" to="." method="_on_set_system_color_pressed"]
10094
[connection signal="toggled" from="VBoxContainer/translucent_system_bars" to="." method="_on_translucent_system_bars_toggled"]

demo/project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="SystemBarColorChanger"
1414
run/main_scene="res://main.tscn"
15-
config/features=PackedStringArray("4.4", "GL Compatibility")
15+
config/features=PackedStringArray("4.5", "GL Compatibility")
1616
config/icon="res://addons/SystemBarColorChanger/icon.png"
1717

1818
[autoload]

0 commit comments

Comments
 (0)