1. Add the following code to launchermodel. java. If it is KK launcher3 applicationinfo, replace it with 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 loadall1_bybatch () method of launchermodel. Java:
Set
Collections. Sort (apps, new launchermodel. shortcutnamecomparator (packagemanager, mlabelcache ));
Replace:
Collections. Sort (apps, new installtimecomparator (packagemanager, Apps ));
3. Modify the setapps method of appscustomizepagedview. java.
Set
Collections. Sort (mapps, launchermodel. getappnamecomparator ());
Replace:
Collections. Sort (mapps, launchermodel. getinstalltimecomparator ());
4. The reorderapps method is called after system sorting. Therefore, you must sort the reorderapps method by installation time under other conditions. Please add the reorderapps method before it is called.
Collections. Sort (mapps, launchermodel. getinstalltimecomparator ());
For example, if you want to install a new sorting method after installing an application, you need to add the sort call before the addapps method of appscustomizepagedview. java.
How to change the main menu icon to sort by installation time