1. Add the following code in Launchermodel.java, assuming the KK Launcher3 applicationinfo to be replaced with the appinfo
public static final comparator<applicationinfo> Getinstalltimecomparator () {
return new comparator<applicationinfo> () {
Public final int Compare (ApplicationInfo A, applicationinfo b) {
return a.firstinstalltime = = B.firstinstalltime?
0:a.firstinstalltime > B.firstinstalltime? 1:-1;
}
};
}
public static class Installtimecomparator implements Comparator<resolveinfo> {
Private Packagemanager Mpackagemanager;
List<resolveinfo> Mapps;
Installtimecomparator (Packagemanager pm, list<resolveinfo> Apps)
{
Mpackagemanager = PM;
Mapps = apps;
}
Public final int Compare (ResolveInfo A, ResolveInfo b) {
String Packagenamea = a.activityinfo.applicationinfo.packagename;
String packagenameb = b.activityinfo.applicationinfo.packagename;
Long Firstinstalltimea = 0, Firstinstalltimeb = 0;
try{
Firstinstalltimea = Mpackagemanager.getpackageinfo (Packagenamea, 0). Firstinstalltime;
Firstinstalltimeb = Mpackagemanager.getpackageinfo (packagenameb, 0). Firstinstalltime;
}catch (Exception e) {
E.printstacktrace ();
return 0;
}
return Firstinstalltimea = = Firstinstalltimeb?
0:firstinstalltimea > Firstinstalltimeb?
1:-1;
}
};
2. Change the Launchermodel.java Loadallappsbybatch () method:
Will
Collections.sort (apps,new launchermodel.shortcutnamecomparator (Packagemanager, Mlabelcache));
Replace with:
Collections.sort (apps,new installtimecomparator (Packagemanager, apps));
3. Setapps method for changing Appscustomizepagedview.java
Will
Collections.sort (Mapps, Launchermodel.getappnamecomparator ());
Replace with:
Collections.sort (Mapps, Launchermodel.getinstalltimecomparator ());
4. System ordering calls the Reorderapps method, so you can also sort the installation time under other conditions, add the Reorderapps before the appropriate method call
Collections.sort (Mapps, Launchermodel.getinstalltimecomparator ());
For example: After installing the application also want to install new sort arrangement, need to add the sort call before the Addapps method of Appscustomizepagedview.java
How does Android change the main menu icon to sort by installation time?