1. Add the following code to the Launchermodel.java, if 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. Modify the Launchermodel.java Loadallappsbybatch () method:
Will
Collections.sort (apps,new launchermodel.shortcutnamecomparator (Packagemanager, Mlabelcache));
Replace with:
Collections.sort (apps,new installtimecomparator (Packagemanager, apps));
3. Modifying the Setapps method of Appscustomizepagedview.java
Will
Collections.sort (Mapps, Launchermodel.getappnamecomparator ());
Replace with:
Collections.sort (Mapps, Launchermodel.getinstalltimecomparator ());
4. System sequencing calls the Reorderapps method, so you can also sort the installation time under other conditions, adding a Reorderapps before the corresponding method call
Collections.sort (Mapps, Launchermodel.getinstalltimecomparator ());
For example: After installing the app you want to install a new sort arrangement, you need to add the sort call before the Appscustomizepagedview.java Addapps method
How Android changes the main menu icon to sort by installation time