Skip to content

Commit e7635a8

Browse files
committed
Update
1 parent 0ed7fbe commit e7635a8

5 files changed

Lines changed: 74 additions & 84 deletions

File tree

app/src/main/java/com/omarea/common/ui/BlurEngine.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ public Bitmap getUpdatedBlurBitmap() {
7272
cachedCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
7373

7474
if (!blurBitmap.isRecycled()) {
75-
int dstLeft = x < 0 ? -x : 0;
76-
int dstTop = y < 0 ? -y : 0;
77-
Rect dstRect = new Rect(dstLeft, dstTop, dstLeft + srcRect.width(), dstTop + srcRect.height());
78-
79-
cachedCanvas.drawBitmap(blurBitmap, srcRect, dstRect, null);
75+
cachedCanvas.drawBitmap(blurBitmap, srcRect, new Rect(0, 0, w, h), null);
8076
cachedCanvas.drawColor(getBlurTintColor());
8177
return cachedBitmap;
8278
}

app/src/main/java/com/omarea/common/ui/FastBlurUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class FastBlurUtility {
1313

1414
// Tỉ lệ thu nhỏ ảnh để xử lý nhanh (1/10 giúp giảm 100 lần số pixel cần tính toán)
1515
private static final float SCALE_FACTOR = 0.10f;
16-
private static final int BLUR_RADIUS = 10;
16+
private static final int BLUR_RADIUS = 8;
1717

1818
/**
1919
* Chụp màn hình và làm mờ (Dùng làm phương án dự phòng khi không lấy được Wallpaper)

app/src/main/java/com/tool/tree/CrashHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ public void uncaughtException(Thread thread, Throwable ex) {
2525

2626
Intent intent = new Intent(context, CrashLogActivity.class);
2727
intent.putExtra("crash_log", stackTrace);
28-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
29-
| Intent.FLAG_ACTIVITY_CLEAR_TASK
30-
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
28+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
29+
| Intent.FLAG_ACTIVITY_CLEAR_TASK);
3130

3231
context.startActivity(intent);
3332

app/src/main/java/com/tool/tree/SplashActivity.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import java.io.BufferedReader
2929
import java.io.DataOutputStream
3030
import java.io.File
3131
import java.util.Locale
32+
import com.tool.tree.databinding.ActivityMainBinding
3233

3334
class SplashActivity : AppCompatActivity() {
3435

@@ -66,8 +67,11 @@ class SplashActivity : AppCompatActivity() {
6667
}
6768
}
6869

69-
binding.startLogoXml.startAnimation(AnimationUtils.loadAnimation(this, R.anim.ic_settings_rotate))
70-
// applyTheme()
70+
binding.startLogoXml.postDelayed({
71+
val animation = AnimationUtils.loadAnimation(this, R.anim.ic_settings_rotate)
72+
binding.startLogoXml.startAnimation(animation)
73+
}, 2000)
74+
7175
}
7276

7377
// =================== LOGIC XỬ LÝ QUYỀN ===================
@@ -83,7 +87,7 @@ class SplashActivity : AppCompatActivity() {
8387
// Sau đó mới đi xin quyền hệ thống
8488
requestRequiredPermissions()
8589
},
86-
Runnable { finishAffinity() }
90+
Runnable { finish() }
8791
).setCancelable(false)
8892
}
8993

@@ -135,14 +139,12 @@ class SplashActivity : AppCompatActivity() {
135139
}
136140

137141
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
138-
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
139142
if (requestCode == REQUEST_CODE_PERMISSIONS) {
140-
if (grantResults.isNotEmpty() && grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
143+
if (grantResults.all { it == PackageManager.PERMISSION_GRANTED }) {
141144
checkPermissionsNextStep()
142-
} else {
143-
finishAffinity()
144-
}
145+
} else finish()
145146
}
147+
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
146148
}
147149

148150
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
@@ -204,12 +206,11 @@ class SplashActivity : AppCompatActivity() {
204206
}
205207

206208
private fun gotoHome() {
207-
val intentToStart = if (intent?.getBooleanExtra("JumpActionPage", false) == true) {
208-
Intent(this, ActionPage::class.java).apply { putExtras(intent!!) }
209-
} else {
210-
Intent(this, MainActivity::class.java)
211-
}
212-
startActivity(intentToStart)
209+
startActivity(
210+
if (intent?.getBooleanExtra("JumpActionPage", false) == true)
211+
Intent(this, ActionPage::class.java).apply { putExtras(intent!!) }
212+
else Intent(this, MainActivity::class.java)
213+
)
213214
finish()
214215
}
215216

app/src/main/java/com/tool/tree/ThemeModeState.kt

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ package com.tool.tree
22

33
import android.app.Activity
44
import android.app.WallpaperManager
5-
import android.graphics.BitmapFactory
5+
import android.graphics.Color
6+
import android.graphics.drawable.BitmapDrawable
7+
import android.graphics.drawable.Drawable
68
import android.os.Build
79
import android.view.View
810
import android.view.WindowManager
911
import androidx.appcompat.app.AppCompatDelegate
12+
import androidx.core.view.ViewCompat
13+
import androidx.core.view.WindowCompat
14+
import androidx.core.view.WindowInsetsCompat
15+
import androidx.core.view.WindowInsetsControllerCompat
1016
import com.omarea.common.ui.ThemeMode
11-
import java.io.File
1217
import com.omarea.common.ui.BlurEngine
18+
import java.io.File
1319

14-
@Suppress("DEPRECATION")
1520
object ThemeModeState {
1621

1722
private var themeMode: ThemeMode = ThemeMode()
@@ -21,19 +26,15 @@ object ThemeModeState {
2126

2227
fun switchTheme(activity: Activity, themeLevel: Int? = null): ThemeMode {
2328
val level = themeLevel ?: ThemeConfig(activity).getThemeMode()
24-
val wallpaper = WallpaperManager.getInstance(activity)
25-
val wallpaperInfo = wallpaper.wallpaperInfo
26-
27-
val customWallpaperFile = File(activity.filesDir, "home/etc/wallpaper.jpg")
28-
val useCustomWallpaper = customWallpaperFile.exists()
29+
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
2932

3033
when (level.coerceIn(0, 5)) {
3134
0 -> {
32-
val nightModeFlags = activity.resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK
33-
val isNight = nightModeFlags == android.content.res.Configuration.UI_MODE_NIGHT_YES
34-
themeMode.isDarkMode = isNight
35+
themeMode.isDarkMode = isSystemNight
3536
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
36-
activity.setTheme(if (isNight) R.style.AppThemeDark else R.style.AppTheme)
37+
activity.setTheme(if (isSystemNight) R.style.AppThemeDark else R.style.AppTheme)
3738
}
3839
1 -> {
3940
themeMode.isDarkMode = true
@@ -46,29 +47,29 @@ object ThemeModeState {
4647
activity.setTheme(R.style.AppTheme)
4748
}
4849
3 -> {
49-
val nightModeFlags = activity.resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK
50-
val isNight = nightModeFlags == android.content.res.Configuration.UI_MODE_NIGHT_YES
51-
themeMode.isDarkMode = isNight
50+
themeMode.isDarkMode = isSystemNight
5251
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
53-
applyWallpaperMode(activity, wallpaper, wallpaperInfo, useCustomWallpaper)
52+
applyWallpaperMode(activity, isSystemNight)
5453
}
5554
4 -> {
5655
themeMode.isDarkMode = true
5756
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
58-
applyWallpaperMode(activity, wallpaper, wallpaperInfo, useCustomWallpaper, true)
57+
applyWallpaperMode(activity, true)
5958
}
6059
5 -> {
6160
themeMode.isDarkMode = false
6261
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
63-
applyWallpaperMode(activity, wallpaper, wallpaperInfo, useCustomWallpaper, false)
62+
applyWallpaperMode(activity, false)
6463
}
6564
}
6665

67-
// CẬP NHẬT: Luôn gọi captureAndBlur khi ở chế độ Wallpaper (level >= 3)
68-
// Không sử dụng check null ở đây vì BlurController đã có logic so sánh File Size bên trong
66+
// BlurEngine logic
6967
if (level >= 3) {
7068
BlurEngine.isPaused = false
71-
BlurEngine.controller.captureAndBlur(activity)
69+
// Đảm bảo View đã layout xong trước khi capture
70+
activity.window.decorView.post {
71+
BlurEngine.controller.captureAndBlur(activity)
72+
}
7273
} else {
7374
BlurEngine.isPaused = true
7475
}
@@ -77,29 +78,23 @@ object ThemeModeState {
7778
return themeMode
7879
}
7980

80-
private fun applyWallpaperMode(
81-
activity: Activity,
82-
wallpaper: WallpaperManager,
83-
wallpaperInfo: android.app.WallpaperInfo?,
84-
useCustomWallpaper: Boolean,
85-
forceDark: Boolean? = null
86-
) {
87-
val night = forceDark ?: (activity.resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK == android.content.res.Configuration.UI_MODE_NIGHT_YES)
88-
themeMode.isDarkMode = night
89-
activity.setTheme(if (night) R.style.AppThemeWallpaper else R.style.AppThemeWallpaperLight)
81+
private fun applyWallpaperMode(activity: Activity, isNight: Boolean) {
82+
activity.setTheme(if (isNight) R.style.AppThemeWallpaper else R.style.AppThemeWallpaperLight)
9083

84+
val wallpaper = WallpaperManager.getInstance(activity)
85+
val customWallpaperFile = File(activity.filesDir, "home/etc/wallpaper.jpg")
86+
9187
try {
92-
if (useCustomWallpaper) {
93-
val customWallpaperFile = File(activity.filesDir, "home/etc/wallpaper.jpg")
94-
if (customWallpaperFile.exists()) {
95-
val bitmap = BitmapFactory.decodeFile(customWallpaperFile.absolutePath)
96-
activity.window.setBackgroundDrawable(android.graphics.drawable.BitmapDrawable(activity.resources, bitmap))
97-
}
98-
} else if (wallpaperInfo != null && wallpaperInfo.packageName != null) {
88+
if (customWallpaperFile.exists()) {
89+
// Sử dụng createFromPath để tiết kiệm bộ nhớ hơn decode trực tiếp
90+
val drawable = Drawable.createFromPath(customWallpaperFile.absolutePath)
91+
activity.window.setBackgroundDrawable(drawable)
92+
} else if (wallpaper.wallpaperInfo != null) {
93+
// Nếu là Live Wallpaper, dùng flag SHOW_WALLPAPER
9994
activity.window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER)
95+
activity.window.setBackgroundDrawable(null)
10096
} else {
101-
// CẬP NHẬT: Xóa cache của WallpaperManager trước khi lấy Drawable hệ thống
102-
wallpaper.forgetLoadedWallpaper()
97+
// Hình nền tĩnh hệ thống
10398
activity.window.setBackgroundDrawable(wallpaper.drawable)
10499
}
105100
} catch (e: Exception) {
@@ -109,30 +104,29 @@ object ThemeModeState {
109104

110105
private fun applyWindowFlags(activity: Activity) {
111106
val window = activity.window
112-
androidx.core.view.WindowCompat.setDecorFitsSystemWindows(window, false)
113-
window.statusBarColor = android.graphics.Color.TRANSPARENT
114-
window.navigationBarColor = android.graphics.Color.TRANSPARENT
107+
// Thiết lập Edge-to-Edge chuẩn SDK 23+
108+
WindowCompat.setDecorFitsSystemWindows(window, false)
109+
window.statusBarColor = Color.TRANSPARENT
110+
window.navigationBarColor = Color.TRANSPARENT
115111

116-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
117-
val rootView = window.decorView.rootView
118-
androidx.core.view.ViewCompat.setOnApplyWindowInsetsListener(rootView) { _, insets ->
119-
val systemBars = insets.getInsets(androidx.core.view.WindowInsetsCompat.Type.systemBars())
120-
activity.findViewById<View>(R.id.blur_top_container)?.setPadding(0, systemBars.top, 0, 0)
121-
activity.findViewById<View>(R.id.file_selector_list)?.setPadding(0, systemBars.top, 0, 0)
122-
activity.findViewById<View>(R.id.main_list)?.setPadding(0, systemBars.top, 0, 0)
123-
activity.findViewById<View>(R.id.blur_bottom_container)?.setPadding(0, 0, 0, systemBars.bottom)
124-
insets
125-
}
112+
val rootView = window.decorView
113+
ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
114+
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
115+
116+
// Cập nhật padding cho các container nếu tồn tại
117+
activity.findViewById<View>(R.id.blur_top_container)?.setPadding(0, systemBars.top, 0, 0)
118+
activity.findViewById<View>(R.id.file_selector_list)?.setPadding(0, systemBars.top, 0, 0)
119+
activity.findViewById<View>(R.id.main_list)?.setPadding(0, systemBars.top, 0, 0)
120+
activity.findViewById<View>(R.id.blur_bottom_container)?.setPadding(0, 0, 0, systemBars.bottom)
121+
122+
insets // Trả về insets để các view khác vẫn nhận được
126123
}
127124

128-
val controller = androidx.core.view.WindowInsetsControllerCompat(window, window.decorView)
129-
if (!themeMode.isDarkMode) {
130-
controller.isAppearanceLightStatusBars = true
131-
controller.isAppearanceLightNavigationBars = true
132-
} else {
133-
controller.isAppearanceLightStatusBars = false
134-
controller.isAppearanceLightNavigationBars = false
135-
}
125+
// Điều khiển màu icon trên thanh trạng thái
126+
val controller = WindowInsetsControllerCompat(window, rootView)
127+
val useLightIcons = !themeMode.isDarkMode
128+
controller.isAppearanceLightStatusBars = useLightIcons
129+
controller.isAppearanceLightNavigationBars = useLightIcons
136130
}
137131

138132
fun getThemeMode(): ThemeMode = themeMode

0 commit comments

Comments
 (0)