Skip to content

Commit 0904e1a

Browse files
committed
Update
1 parent 14191c1 commit 0904e1a

File tree

2 files changed

+168
-128
lines changed

2 files changed

+168
-128
lines changed

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

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,53 @@
1111
import java.lang.ref.WeakReference;
1212

1313
public class BlurController {
14+
15+
// Lưu trữ trạng thái file để so sánh ở lần chạy kế tiếp
16+
private static long lastFileLength = -1;
17+
private static long lastFileModified = -1;
1418

1519
/**
1620
* Chụp và làm mờ ảnh nền.
17-
* Đã lược bỏ kiểm tra quyền vì đã được xử lý ở logic bên ngoài.
1821
*/
1922
public void captureAndBlur(Activity activity) {
2023
final WeakReference<Activity> activityRef = new WeakReference<>(activity);
2124

2225
new Thread(() -> {
2326
Activity act = activityRef.get();
24-
// Kiểm tra an toàn trước khi xử lý
2527
if (act == null || act.isFinishing() || act.isDestroyed()) return;
2628

2729
Bitmap source = null;
2830
Context context = act.getApplicationContext();
2931

30-
// 1. Ưu tiên: Wallpaper tùy chỉnh từ thư mục riêng của app
32+
// 1. Kiểm tra Wallpaper tùy chỉnh trong internal storage
3133
File customWallpaperFile = new File(act.getFilesDir(), "home/etc/wallpaper.jpg");
34+
3235
if (customWallpaperFile.exists()) {
36+
long currentLength = customWallpaperFile.length();
37+
long currentModified = customWallpaperFile.lastModified();
38+
39+
// KIỂM TRA THAY ĐỔI: Nếu size và thời gian giống hệt cũ thì bỏ qua không xử lý lại
40+
if (currentLength == lastFileLength && currentModified == lastFileModified) {
41+
return;
42+
}
43+
44+
// Cập nhật dấu vết file mới
45+
lastFileLength = currentLength;
46+
lastFileModified = currentModified;
47+
3348
source = BitmapFactory.decodeFile(customWallpaperFile.getAbsolutePath());
49+
} else {
50+
// Nếu file custom không tồn tại, reset dấu vết để có thể nhận diện lại nếu file xuất hiện sau này
51+
lastFileLength = -1;
52+
lastFileModified = -1;
3453
}
3554

36-
// 2. Kế tiếp: Lấy trực tiếp Wallpaper hệ thống
55+
// 2. Kế tiếp: Lấy trực tiếp Wallpaper hệ thống nếu không có file custom
3756
if (source == null) {
3857
WallpaperManager wm = WallpaperManager.getInstance(context);
39-
// wallpaperInfo == null xác nhận đây là ảnh tĩnh (không phải Live Wallpaper)
58+
// Xóa cache cũ của WallpaperManager để đảm bảo lấy ảnh mới nhất nếu hệ thống vừa đổi
59+
wm.forgetLoadedWallpaper();
60+
4061
if (wm.getWallpaperInfo() == null) {
4162
Drawable drawable = wm.getDrawable();
4263
if (drawable instanceof BitmapDrawable) {
@@ -45,24 +66,22 @@ public void captureAndBlur(Activity activity) {
4566
}
4667
}
4768

48-
// Xử lý kết quả mờ
69+
// Xử lý làm mờ
4970
Bitmap blurredResult;
5071
if (source != null) {
51-
// Làm mờ từ nguồn ảnh wallpaper (nhanh và sạch hơn)
5272
blurredResult = FastBlurUtility.startBlurBackground(source);
5373
} else {
54-
// Cuối cùng: Chụp màn hình nếu không lấy được ảnh nền (Fallback)
74+
// Fallback: Chụp màn hình (Lưu ý: Fallback này có thể không cần check file size)
5575
blurredResult = FastBlurUtility.getBlurBackgroundDrawer(act);
5676
}
5777

58-
// Trong file BlurController.java
5978
if (blurredResult != null) {
60-
// THAY ĐỔI: Không gọi recycle() ở đây nữa để tránh xung đột với luồng UI đang vẽ
61-
// Việc gán tham chiếu mới sẽ giúp tham chiếu cũ được GC tự động dọn dẹp an toàn hơn
6279
BlurEngine.blurBitmap = blurredResult;
6380
BlurEngine.isPaused = false;
81+
82+
// Cập nhật UI
6483
act.runOnUiThread(() -> {
65-
if (act.getWindow() != null) {
84+
if (act != null && !act.isFinishing() && act.getWindow() != null) {
6685
act.getWindow().getDecorView().invalidate();
6786
}
6887
});

app/src/main/res/layout/dialog_power_operation.xml

Lines changed: 137 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
55
android:layout_height="wrap_content">
6+
67
<LinearLayout
78
android:orientation="vertical"
89
android:paddingLeft="8dp"
@@ -11,6 +12,7 @@
1112
android:paddingBottom="@dimen/activity_vertical_margin"
1213
android:layout_width="match_parent"
1314
android:layout_height="wrap_content" >
15+
1416
<TextView
1517
android:paddingLeft="10dp"
1618
android:paddingRight="10dp"
@@ -19,11 +21,13 @@
1921
android:text="@string/menu_power"
2022
android:layout_marginBottom="8dp"
2123
style="@style/textDefault" />
24+
2225
<LinearLayout
2326
android:orientation="horizontal"
2427
android:layout_width="match_parent"
2528
android:layout_height="wrap_content"
2629
android:layout_marginBottom="8dp">
30+
2731
<LinearLayout
2832
android:orientation="horizontal"
2933
android:id="@+id/power_shutdown"
@@ -55,6 +59,7 @@
5559
style="@style/textTitle" />
5660
</LinearLayout>
5761
</LinearLayout>
62+
5863
<LinearLayout
5964
android:orientation="horizontal"
6065
android:id="@+id/power_reboot"
@@ -88,139 +93,155 @@
8893
</LinearLayout>
8994
</LinearLayout>
9095
</LinearLayout>
96+
9197
<LinearLayout
9298
android:orientation="horizontal"
93-
android:id="@+id/power_recovery"
94-
android:background="@drawable/krscript_item_ripple_kin"
95-
android:layout_marginBottom="8dp"
96-
android:layout_height="65dp"
97-
android:layout_weight="1.0"
98-
style="@style/ListCardItemSmall">
99-
<ImageView
100-
android:layout_gravity="center_vertical"
101-
android:background="@drawable/action_menu_icon_bg"
102-
android:layout_width="40dp"
103-
android:layout_height="40dp"
104-
android:src="@drawable/power_recovery"
105-
android:scaleType="centerInside"
106-
android:alpha="0.8"
107-
android:layout_marginEnd="@dimen/activity_horizontal_margin"
108-
android:backgroundTint="#FF00BCD4"
109-
app:tint="#FFFFFFFF" />
99+
android:layout_width="match_parent"
100+
android:layout_height="wrap_content"
101+
android:layout_marginBottom="8dp">
102+
110103
<LinearLayout
111-
android:layout_gravity="center_vertical"
112-
android:orientation="vertical"
113-
android:layout_width="0dp"
114-
android:layout_height="wrap_content"
115-
android:layout_weight="1.0">
116-
<TextView
117-
android:layout_width="match_parent"
104+
android:orientation="horizontal"
105+
android:id="@+id/power_fastboot"
106+
android:background="@drawable/krscript_item_ripple_kin"
107+
android:layout_height="65dp"
108+
android:layout_weight="1.0"
109+
style="@style/ListCardItemSmall">
110+
<ImageView
111+
android:layout_gravity="center_vertical"
112+
android:background="@drawable/action_menu_icon_bg"
113+
android:padding="10dp"
114+
android:layout_width="40dp"
115+
android:layout_height="40dp"
116+
android:src="@drawable/power_fastboot"
117+
android:scaleType="centerInside"
118+
android:alpha="0.8"
119+
android:layout_marginEnd="@dimen/activity_horizontal_margin"
120+
android:backgroundTint="#FFEA3F00"
121+
app:tint="#FFFFFFFF" />
122+
<LinearLayout
123+
android:layout_gravity="center_vertical"
124+
android:orientation="vertical"
125+
android:layout_width="0dp"
118126
android:layout_height="wrap_content"
119-
android:layout_marginBottom="4dp"
120-
android:text="@string/text_power_recovery"
121-
style="@style/textTitle" />
127+
android:layout_weight="1.0">
128+
<TextView
129+
android:layout_width="match_parent"
130+
android:layout_height="wrap_content"
131+
android:layout_marginBottom="4dp"
132+
android:text="@string/text_power_fastboot"
133+
style="@style/textTitle" />
134+
</LinearLayout>
122135
</LinearLayout>
123-
</LinearLayout>
124-
<LinearLayout
125-
android:orientation="horizontal"
126-
android:id="@+id/power_fastboot"
127-
android:background="@drawable/krscript_item_ripple_kin"
128-
android:layout_marginBottom="8dp"
129-
android:layout_height="65dp"
130-
android:layout_weight="1.0"
131-
style="@style/ListCardItemSmall">
132-
<ImageView
133-
android:layout_gravity="center_vertical"
134-
android:background="@drawable/action_menu_icon_bg"
135-
android:padding="10dp"
136-
android:layout_width="40dp"
137-
android:layout_height="40dp"
138-
android:src="@drawable/power_fastboot"
139-
android:scaleType="centerInside"
140-
android:alpha="0.8"
141-
android:layout_marginEnd="@dimen/activity_horizontal_margin"
142-
android:backgroundTint="#FFEA3F00"
143-
app:tint="#FFFFFFFF" />
136+
144137
<LinearLayout
145-
android:layout_gravity="center_vertical"
146-
android:orientation="vertical"
147-
android:layout_width="0dp"
148-
android:layout_height="wrap_content"
149-
android:layout_weight="1.0">
150-
<TextView
151-
android:layout_width="match_parent"
138+
android:orientation="horizontal"
139+
android:id="@+id/power_recovery"
140+
android:background="@drawable/krscript_item_ripple_kin"
141+
android:layout_height="65dp"
142+
android:layout_weight="1.0"
143+
style="@style/ListCardItemSmall">
144+
<ImageView
145+
android:layout_gravity="center_vertical"
146+
android:background="@drawable/action_menu_icon_bg"
147+
android:layout_width="40dp"
148+
android:layout_height="40dp"
149+
android:src="@drawable/power_recovery"
150+
android:scaleType="centerInside"
151+
android:alpha="0.8"
152+
android:layout_marginEnd="@dimen/activity_horizontal_margin"
153+
android:backgroundTint="#FF00BCD4"
154+
app:tint="#FFFFFFFF" />
155+
<LinearLayout
156+
android:layout_gravity="center_vertical"
157+
android:orientation="vertical"
158+
android:layout_width="0dp"
152159
android:layout_height="wrap_content"
153-
android:layout_marginBottom="4dp"
154-
android:text="@string/text_power_fastboot"
155-
style="@style/textTitle" />
160+
android:layout_weight="1.0">
161+
<TextView
162+
android:layout_width="match_parent"
163+
android:layout_height="wrap_content"
164+
android:layout_marginBottom="4dp"
165+
android:text="@string/text_power_recovery"
166+
style="@style/textTitle" />
167+
</LinearLayout>
156168
</LinearLayout>
157169
</LinearLayout>
170+
158171
<LinearLayout
159172
android:orientation="horizontal"
160-
android:id="@+id/power_hot_reboot"
161-
android:background="@drawable/krscript_item_ripple_kin"
162-
android:layout_marginBottom="8dp"
163-
android:layout_height="65dp"
164-
android:layout_weight="1.0"
165-
style="@style/ListCardItemSmall">
166-
<ImageView
167-
android:layout_gravity="center_vertical"
168-
android:background="@drawable/action_menu_icon_bg"
169-
android:layout_width="40dp"
170-
android:layout_height="40dp"
171-
android:src="@drawable/power_hot_reboot"
172-
android:scaleType="centerInside"
173-
android:alpha="0.8"
174-
android:layout_marginEnd="@dimen/activity_horizontal_margin"
175-
android:backgroundTint="#C8787878"
176-
app:tint="#FFFFFFFF" />
173+
android:layout_width="match_parent"
174+
android:layout_height="wrap_content"
175+
android:layout_marginBottom="8dp">
176+
177177
<LinearLayout
178-
android:layout_gravity="center_vertical"
179-
android:orientation="vertical"
180-
android:layout_width="0dp"
181-
android:layout_height="wrap_content"
182-
android:layout_weight="1.0">
183-
<TextView
184-
android:layout_width="match_parent"
178+
android:orientation="horizontal"
179+
android:id="@+id/power_hot_reboot"
180+
android:background="@drawable/krscript_item_ripple_kin"
181+
android:layout_height="65dp"
182+
android:layout_weight="1.0"
183+
style="@style/ListCardItemSmall">
184+
<ImageView
185+
android:layout_gravity="center_vertical"
186+
android:background="@drawable/action_menu_icon_bg"
187+
android:layout_width="40dp"
188+
android:layout_height="40dp"
189+
android:src="@drawable/power_hot_reboot"
190+
android:scaleType="centerInside"
191+
android:alpha="0.8"
192+
android:layout_marginEnd="@dimen/activity_horizontal_margin"
193+
android:backgroundTint="#C8787878"
194+
app:tint="#FFFFFFFF" />
195+
<LinearLayout
196+
android:layout_gravity="center_vertical"
197+
android:orientation="vertical"
198+
android:layout_width="0dp"
185199
android:layout_height="wrap_content"
186-
android:layout_marginBottom="4dp"
187-
android:text="@string/text_power_dowload"
188-
style="@style/textTitle" />
200+
android:layout_weight="1.0">
201+
<TextView
202+
android:layout_width="match_parent"
203+
android:layout_height="wrap_content"
204+
android:layout_marginBottom="4dp"
205+
android:text="@string/text_power_dowload"
206+
style="@style/textTitle" />
207+
</LinearLayout>
189208
</LinearLayout>
190-
</LinearLayout>
191-
<LinearLayout
192-
android:orientation="horizontal"
193-
android:id="@+id/power_emergency"
194-
android:background="@drawable/krscript_item_ripple_kin"
195-
android:layout_marginBottom="8dp"
196-
android:layout_height="65dp"
197-
android:layout_weight="1.0"
198-
style="@style/ListCardItemSmall">
199-
<ImageView
200-
android:layout_gravity="center_vertical"
201-
android:background="@drawable/action_menu_icon_bg"
202-
android:padding="11dp"
203-
android:layout_width="40dp"
204-
android:layout_height="40dp"
205-
android:src="@drawable/power_emergency"
206-
android:scaleType="centerInside"
207-
android:alpha="0.8"
208-
android:layout_marginEnd="@dimen/activity_horizontal_margin"
209-
android:backgroundTint="#C8787878"
210-
app:tint="#FFFFFFFF" />
209+
211210
<LinearLayout
212-
android:layout_gravity="center_vertical"
213-
android:orientation="vertical"
214-
android:layout_width="0dp"
215-
android:layout_height="wrap_content"
216-
android:layout_weight="1.0">
217-
<TextView
218-
android:layout_width="match_parent"
211+
android:orientation="horizontal"
212+
android:id="@+id/power_emergency"
213+
android:background="@drawable/krscript_item_ripple_kin"
214+
android:layout_height="65dp"
215+
android:layout_weight="1.0"
216+
style="@style/ListCardItemSmall">
217+
<ImageView
218+
android:layout_gravity="center_vertical"
219+
android:background="@drawable/action_menu_icon_bg"
220+
android:padding="11dp"
221+
android:layout_width="40dp"
222+
android:layout_height="40dp"
223+
android:src="@drawable/power_emergency"
224+
android:scaleType="centerInside"
225+
android:alpha="0.8"
226+
android:layout_marginEnd="@dimen/activity_horizontal_margin"
227+
android:backgroundTint="#C8787878"
228+
app:tint="#FFFFFFFF" />
229+
<LinearLayout
230+
android:layout_gravity="center_vertical"
231+
android:orientation="vertical"
232+
android:layout_width="0dp"
219233
android:layout_height="wrap_content"
220-
android:layout_marginBottom="4dp"
221-
android:text="@string/text_power_edl"
222-
style="@style/textTitle" />
234+
android:layout_weight="1.0">
235+
<TextView
236+
android:layout_width="match_parent"
237+
android:layout_height="wrap_content"
238+
android:layout_marginBottom="4dp"
239+
android:text="@string/text_power_edl"
240+
style="@style/textTitle" />
241+
</LinearLayout>
223242
</LinearLayout>
243+
224244
</LinearLayout>
245+
225246
</LinearLayout>
226247
</com.omarea.common.ui.OverScrollView>

0 commit comments

Comments
 (0)