How to change the main menu icon to sort by installation time

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.