@@ -3,9 +3,7 @@ package com.tool.tree
33import android.app.Activity
44import android.app.WallpaperManager
55import android.graphics.Color
6- import android.graphics.drawable.BitmapDrawable
76import android.graphics.drawable.Drawable
8- import android.os.Build
97import android.view.View
108import android.view.WindowManager
119import androidx.appcompat.app.AppCompatDelegate
@@ -24,11 +22,30 @@ object ThemeModeState {
2422 @JvmStatic
2523 fun isDarkMode (): Boolean = themeMode.isDarkMode
2624
25+ /* *
26+ * Kiểm tra file cấu hình tắt blur dựa trên đường dẫn tương đối
27+ * Đường dẫn đầy đủ sẽ là: /data/user/0/com.tool.tree/files/home/log/dissblur
28+ */
29+ private fun isBlurDisabled (activity : Activity ): Boolean {
30+ val file = File (activity.filesDir, " home/log/dissblur" )
31+ return try {
32+ if (file.exists()) {
33+ file.readText().trim() == " 1"
34+ } else {
35+ false
36+ }
37+ } catch (e: Exception ) {
38+ false
39+ }
40+ }
41+
2742 fun switchTheme (activity : Activity , themeLevel : Int? = null): ThemeMode {
2843 val level = themeLevel ? : ThemeConfig (activity).getThemeMode()
2944
30- // Cập nhật logic xác định Night Mode hệ thống nhanh hơn
31- val isSystemNight = (activity.resources.configuration.uiMode and android.content.res.Configuration .UI_MODE_NIGHT_MASK ) == android.content.res.Configuration .UI_MODE_NIGHT_YES
45+ // Xác định chế độ tối của hệ thống
46+ val isSystemNight = (activity.resources.configuration.uiMode and
47+ android.content.res.Configuration .UI_MODE_NIGHT_MASK ) ==
48+ android.content.res.Configuration .UI_MODE_NIGHT_YES
3249
3350 when (level.coerceIn(0 , 5 )) {
3451 0 -> {
@@ -63,10 +80,9 @@ object ThemeModeState {
6380 }
6481 }
6582
66- // BlurEngine logic
67- if (level >= 3 ) {
83+ // Logic xử lý Blur: Chỉ bật khi level >= 3 VÀ file dissblur không phải là 1
84+ if (level >= 3 && ! isBlurDisabled(activity) ) {
6885 BlurEngine .isPaused = false
69- // Đảm bảo View đã layout xong trước khi capture
7086 activity.window.decorView.post {
7187 BlurEngine .controller.captureAndBlur(activity)
7288 }
@@ -86,15 +102,14 @@ object ThemeModeState {
86102
87103 try {
88104 if (customWallpaperFile.exists()) {
89- // Sử dụng createFromPath để tiết kiệm bộ nhớ hơn decode trực tiếp
90105 val drawable = Drawable .createFromPath(customWallpaperFile.absolutePath)
91106 activity.window.setBackgroundDrawable(drawable)
92107 } else if (wallpaper.wallpaperInfo != null ) {
93- // Nếu là Live Wallpaper, dùng flag SHOW_WALLPAPER
108+ // Live Wallpaper
94109 activity.window.addFlags(WindowManager .LayoutParams .FLAG_SHOW_WALLPAPER )
95110 activity.window.setBackgroundDrawable(null )
96111 } else {
97- // Hình nền tĩnh hệ thống
112+ // Hệ thống Wallpaper tĩnh
98113 activity.window.setBackgroundDrawable(wallpaper.drawable)
99114 }
100115 } catch (e: Exception ) {
@@ -104,26 +119,23 @@ object ThemeModeState {
104119
105120 private fun applyWindowFlags (activity : Activity ) {
106121 val window = activity.window
107- // Thiết lập Edge-to-Edge chuẩn SDK 23+
108122 WindowCompat .setDecorFitsSystemWindows(window, false )
109123 window.statusBarColor = Color .TRANSPARENT
110124 window.navigationBarColor = Color .TRANSPARENT
111125
112126 val rootView = window.decorView
113- ViewCompat .setOnApplyWindowInsetsListener(rootView) { view , insets ->
127+ ViewCompat .setOnApplyWindowInsetsListener(rootView) { _ , insets ->
114128 val systemBars = insets.getInsets(WindowInsetsCompat .Type .systemBars())
115129
116- // Cập nhật padding cho các container nếu tồn tại
117130 activity.findViewById<View >(R .id.blur_top_container)?.setPadding(0 , systemBars.top, 0 , 0 )
118131 activity.findViewById<View >(R .id.file_selector_list)?.setPadding(0 , systemBars.top, 0 , 0 )
119132 activity.findViewById<View >(R .id.main_list)?.setPadding(0 , systemBars.top, 0 , 0 )
120133 activity.findViewById<View >(R .id.blur_bottom_container)?.setPadding(0 , 0 , 0 , systemBars.bottom)
121134 activity.findViewById<View >(R .id.kr_online_webview)?.setPadding(0 , systemBars.top, 0 , 0 )
122135
123- insets // Trả về insets để các view khác vẫn nhận được
136+ insets
124137 }
125138
126- // Điều khiển màu icon trên thanh trạng thái
127139 val controller = WindowInsetsControllerCompat (window, rootView)
128140 val useLightIcons = ! themeMode.isDarkMode
129141 controller.isAppearanceLightStatusBars = useLightIcons
0 commit comments