1
1
package amirz .shade .hidden ;
2
2
3
3
import android .content .Context ;
4
+ import android .os .Process ;
4
5
5
6
import com .android .launcher3 .AppInfo ;
6
7
import com .android .launcher3 .R ;
8
+ import com .android .launcher3 .allapps .AppInfoComparator ;
7
9
import com .android .launcher3 .allapps .search .AllAppsSearchBarController ;
8
10
import com .android .launcher3 .allapps .search .DefaultAppSearchAlgorithm ;
9
11
import com .android .launcher3 .util .ComponentKey ;
12
+ import com .android .launcher3 .util .ItemInfoMatcher ;
10
13
11
14
import java .util .ArrayList ;
15
+ import java .util .Collection ;
16
+ import java .util .Collections ;
12
17
import java .util .List ;
13
18
14
19
public class HiddenAppsSearchAlgorithm extends DefaultAppSearchAlgorithm {
15
20
private final Context mContext ;
16
- private final List <AppInfo > mApps ;
21
+ private final AppInfoComparator mAppNameComparator ;
22
+ private final Collection <AppInfo > mApps ;
17
23
private final String mKeyGlobal ;
18
24
private final String mKeyTranslated ;
19
25
20
- public HiddenAppsSearchAlgorithm (Context context , List <AppInfo > apps ) {
21
- super (apps );
26
+ public HiddenAppsSearchAlgorithm (Context context , Collection <AppInfo > apps ) {
27
+ super (Collections . emptyList () );
22
28
mContext = context ;
29
+ mAppNameComparator = new AppInfoComparator (context );
23
30
mApps = apps ;
24
31
mKeyGlobal = context .getString (R .string .search_hidden_global ).toLowerCase ();
25
32
mKeyTranslated = context .getString (R .string .search_hidden ).toLowerCase ();
@@ -43,14 +50,19 @@ private ArrayList<ComponentKey> getTitleMatchResult(String query, boolean showHi
43
50
// Do an intersection of the words in the query and each title, and filter out all the
44
51
// apps that don't match all of the words in the query.
45
52
final String queryTextLower = query .toLowerCase ();
46
- final ArrayList < ComponentKey > result = new ArrayList <>();
53
+ final List < AppInfo > result = new ArrayList <>();
47
54
StringMatcher matcher = StringMatcher .getInstance ();
48
55
for (AppInfo info : mApps ) {
49
56
if (matches (info , queryTextLower , matcher ) || (showHidden
50
57
&& HiddenAppsDatabase .isHidden (mContext , info .componentName , info .user ))) {
51
- result .add (info . toComponentKey () );
58
+ result .add (info );
52
59
}
53
60
}
54
- return result ;
61
+ Collections .sort (result , mAppNameComparator );
62
+ ArrayList <ComponentKey > resultKeys = new ArrayList <>();
63
+ for (AppInfo appInfo : result ) {
64
+ resultKeys .add (appInfo .toComponentKey ());
65
+ }
66
+ return resultKeys ;
55
67
}
56
68
}
0 commit comments