Skip to content

Commit c7cc211

Browse files
Change SystemBar colors to match the app theme (#22)
1 parent fb4bab6 commit c7cc211

File tree

10 files changed

+159
-1
lines changed

10 files changed

+159
-1
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2024-present Anish Mishra (syntaxerror247)
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
23+
@tool
24+
extends Node
25+
26+
const _plugin_name: String = "SystemBarColorChanger"
27+
var is_light_status_bar: bool = false
28+
var is_light_navigation_bar: bool = false
29+
30+
var android_runtime: Object
31+
32+
func _ready() -> void:
33+
if Engine.has_singleton("AndroidRuntime"):
34+
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)
38+
else:
39+
printerr("AndroidRuntime singleton not found! Try it on an Android device.")
40+
41+
42+
func set_status_bar_color(color: Color) -> void:
43+
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)
65+
return
66+
67+
var activity = android_runtime.getActivity()
68+
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)
78+
79+
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
80+
81+
82+
func set_translucent_system_bars(translucent = true) -> void:
83+
if not android_runtime:
84+
printerr("%s plugin not initialized!" % _plugin_name)
85+
return
86+
87+
var activity = android_runtime.getActivity()
88+
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)
97+
98+
activity.runOnUiThread(android_runtime.createRunnableFromGodotCallable(callable))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://btbu7ipw8efpj
30.8 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://b21otadglrwgf"
6+
path="res://.godot/imported/icon.png-62f6d5c31a8cda23c897eeed30370292.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://addons/SystemBarColorChanger/icon.png"
14+
dest_files=["res://.godot/imported/icon.png-62f6d5c31a8cda23c897eeed30370292.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[plugin]
2+
3+
name="SystemBarColorChanger"
4+
description="Plugin to change System Bar (status and navigation bar) color dynamically and enable translucent system bars on Android."
5+
author="Anish"
6+
version="2.0"
7+
script="plugin.gd"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@tool
2+
extends EditorPlugin
3+
4+
func _enter_tree() -> void:
5+
add_autoload_singleton("SystemBarColorChanger", "res://addons/SystemBarColorChanger/SystemBarColorChanger.gd")
6+
7+
func _exit_tree() -> void:
8+
remove_autoload_singleton("SystemBarColorChanger")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://bcuens7c62isp

export_presets.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ architectures/armeabi-v7a=false
3333
architectures/arm64-v8a=true
3434
architectures/x86=false
3535
architectures/x86_64=false
36-
version/code=1
36+
version/code=2
3737
version/name="1.0-alpha2"
3838
package/unique_name="com.godsvg.mobile"
3939
package/name="GodSVG Mobile"

project.godot

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ driver/driver="Dummy"
3131
Configs="*res://src/autoload/Configs.gd"
3232
State="*res://src/autoload/State.gd"
3333
HandlerGUI="*res://src/autoload/HandlerGUI.gd"
34+
SystemBarColorChanger="*res://addons/SystemBarColorChanger/SystemBarColorChanger.gd"
3435

3536
[display]
3637

@@ -40,6 +41,10 @@ window/energy_saving/keep_screen_on=false
4041
window/handheld/orientation=1
4142
mouse_cursor/tooltip_position_offset=Vector2(0, 10)
4243

44+
[editor_plugins]
45+
46+
enabled=PackedStringArray("res://addons/SystemBarColorChanger/plugin.cfg")
47+
4348
[filesystem]
4449

4550
import/blender/enabled=false

src/ui_parts/editor_scene.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ func update_theme() -> void:
1818
stylebox.bg_color = ThemeUtils.overlay_panel_inner_color
1919
stylebox.set_content_margin_all(0)
2020
panel_container.add_theme_stylebox_override("panel", stylebox)
21+
SystemBarColorChanger.set_status_bar_color(ThemeUtils.overlay_panel_inner_color)
22+
SystemBarColorChanger.set_navigation_bar_color(ThemeUtils.overlay_panel_inner_color)
2123

2224

2325
func update_layout() -> void:
@@ -31,6 +33,7 @@ func update_layout() -> void:
3133
var main_splitter := VSplitContainer.new()
3234
main_splitter.size_flags_horizontal = Control.SIZE_FILL
3335
main_splitter.add_theme_constant_override("separation", 6)
36+
main_splitter.add_theme_constant_override("autohide", 0)
3437
main_splitter.split_offset = Configs.savedata.main_splitter_offset
3538
main_splitter.dragged.connect(_on_main_splitter_dragged)
3639
panel_container.add_child(main_splitter)
@@ -61,6 +64,7 @@ func update_layout() -> void:
6164
var top_vertical_split_container := VSplitContainer.new()
6265
top_vertical_split_container.size_flags_vertical = Control.SIZE_EXPAND_FILL
6366
top_vertical_split_container.add_theme_constant_override("separation", 10)
67+
top_vertical_split_container.add_theme_constant_override("autohide", 0)
6468
top_vertical_split_container.split_offset = Configs.savedata.top_vertical_splitter_offset
6569
top_vertical_split_container.dragged.connect(_on_top_vertical_splitter_dragged)
6670
top_vertical_split_container.add_child(create_layout_node(top_left[0]))

0 commit comments

Comments
 (0)