10
10
11
11
import me .leolin .shortcutbadger .Badger ;
12
12
import me .leolin .shortcutbadger .ShortcutBadger ;
13
- import me .leolin .shortcutbadger .impl .SamsungHomeBadger ;
14
13
15
14
/**
16
15
* Helper for setting application launcher icon badge counts.
17
- * <p>
18
- * This is a wrapper around {@link ShortcutBadger}, with a couple enhancements:
19
- * <p>
20
- * - If the first attempt fails, don't retry. This keeps logs clean, as failed attempts are noisy.
21
- * - Test and apply a separate method for older Samsung devices, which ShortcutBadger has
22
- * (perhaps over-aggressively) deprecated. ref: https://github.com/leolin310148/ShortcutBadger/issues/40
16
+ * This is a wrapper around {@link ShortcutBadger}:
23
17
*/
24
18
public class ApplicationBadgeHelper {
25
19
26
20
public static final ApplicationBadgeHelper INSTANCE = new ApplicationBadgeHelper ();
27
21
28
22
private static final String LOG_TAG = "ApplicationBadgeHelper" ;
29
- private static final Badger LEGACY_SAMSUNG_BADGER = new SamsungHomeBadger ();
30
23
31
24
private Boolean applyAutomaticBadger ;
32
- private Boolean applySamsungBadger ;
33
25
private ComponentName componentName ;
34
26
35
27
private ApplicationBadgeHelper () {
@@ -40,7 +32,6 @@ public void setApplicationIconBadgeNumber(Context context, int number) {
40
32
componentName = context .getPackageManager ().getLaunchIntentForPackage (context .getPackageName ()).getComponent ();
41
33
}
42
34
tryAutomaticBadge (context , number );
43
- tryLegacySamsungBadge (context , number );
44
35
}
45
36
46
37
private void tryAutomaticBadge (Context context , int number ) {
@@ -57,43 +48,4 @@ private void tryAutomaticBadge(Context context, int number) {
57
48
}
58
49
ShortcutBadger .applyCount (context , number );
59
50
}
60
-
61
- private void tryLegacySamsungBadge (Context context , int number ) {
62
- // First attempt to apply legacy samsung badge. Check if eligible, then attempt it.
63
- if (null == applySamsungBadger ) {
64
- applySamsungBadger = isLegacySamsungLauncher (context ) && applyLegacySamsungBadge (context , number );
65
- if (applySamsungBadger ) {
66
- FLog .i (LOG_TAG , "First attempt to use legacy Samsung badger succeeded; permanently enabling method." );
67
- } else {
68
- FLog .w (LOG_TAG , "First attempt to use legacy Samsung badger failed; permanently disabling method." );
69
- }
70
- return ;
71
- } else if (!applySamsungBadger ) {
72
- return ;
73
- }
74
- applyLegacySamsungBadge (context , number );
75
- }
76
-
77
- private boolean isLegacySamsungLauncher (Context context ) {
78
- Intent intent = new Intent (Intent .ACTION_MAIN );
79
- intent .addCategory (Intent .CATEGORY_HOME );
80
- ResolveInfo resolveInfo = context .getPackageManager ().resolveActivity (intent , PackageManager .MATCH_DEFAULT_ONLY );
81
-
82
- if (resolveInfo == null || resolveInfo .activityInfo .name .toLowerCase ().contains ("resolver" )) {
83
- return false ;
84
- }
85
-
86
- String currentHomePackage = resolveInfo .activityInfo .packageName ;
87
- return LEGACY_SAMSUNG_BADGER .getSupportLaunchers ().contains (currentHomePackage );
88
- }
89
-
90
- private boolean applyLegacySamsungBadge (Context context , int number ) {
91
- try {
92
- LEGACY_SAMSUNG_BADGER .executeBadge (context , componentName , number );
93
- return true ;
94
- } catch (Exception e ) {
95
- FLog .w (LOG_TAG , "Legacy Samsung badger failed" , e );
96
- return false ;
97
- }
98
- }
99
51
}
0 commit comments