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

Source: Internet
Author: User

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. The Reorderapps method is called after the system is sorted, so you can also sort by the installation time under other conditions, adding the appropriate Reorderapps method before it is called
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 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.