launcher ics 添加排序功能

在4.0中的抽屉界面,是在AppsCustomizePagedView内。

首先了解程序加载图标流程:

通过LauncherModel的内部线程类LoaderTask中

 onlyLoadAllApps()和onlyBindAllApps()加载;

onlyLoadAllApps其实就是读取每个包填充进mAllAppsList

onlyBindAllApps是把mAllAppsList做为参数回调给Launcher 类中的bindAllApplications方法,

bindAllApplications将mAllAppsList加载到 AppsCustomizePagedView:mAppsCustomizeContent.setApps(apps);

setApps其填充AppsCustomizePagedView类的mApps列表。

而抽屉的界面刷新,会调用syncAppsPageItems 将依据mApps列表加载页上图标。

好了,我们添加图标排序功能。

在整个流程中,我们最核心的就是AppsCustomizePagedView类的mApps列表,

更改mApps列表的顺序,再刷新页,就是我们达到的顺序了。

在AppsCustomizePagedView类中添加以下函数()实现三种排序方式

//主菜单 排序 Add by LaiHuan Date:2013-1-4,下午2:31:18
    public void setsort(int sortType){
    	switch (sortType) {
		case 0:
			 Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR);
			break;
		case 1:
			 Collections.sort(mApps, LauncherModel.APP_INSRALL_RECENT_TIME);
			break;
		case 2:
			 Collections.sort(mApps, LauncherModel.APP_INSTALL_TIME_COMPARATOR);
			break;
		default:
			break;
		}
    	Log.d("save","saveAllAppSequence setsort");
         updatePageCounts();
         requestLayout();
         invalidatePageData(-1, false);//刷新页面
    }


 

在LauncherModel中,有以下排序方式

public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
            = new Comparator<ApplicationInfo>() {
        public final int compare(ApplicationInfo a, ApplicationInfo b) {
            int result = sCollator.compare(a.title.toString(), b.title.toString());
            if (result == 0) {
                result = a.componentName.compareTo(b.componentName);
            }
            return result;
        }
    };
    public static final Comparator<ApplicationInfo> APP_INSTALL_TIME_COMPARATOR
            = new Comparator<ApplicationInfo>() {
        public final int compare(ApplicationInfo a, ApplicationInfo b) {
            if (a.firstInstallTime < b.firstInstallTime) return 1;
            if (a.firstInstallTime > b.firstInstallTime) return -1;
            return 0;
        }
    };
    public static final Comparator<ApplicationInfo> APP_INSRALL_RECENT_TIME
    	= new Comparator<ApplicationInfo>() {
    	public final int compare(ApplicationInfo a, ApplicationInfo b) {
    		if (a.firstInstallTime < b.firstInstallTime) return -1;
    		if (a.firstInstallTime > b.firstInstallTime) return 1;
    		return 0;
    	}
    };
    public static final Comparator<AppWidgetProviderInfo> WIDGET_NAME_COMPARATOR
            = new Comparator<AppWidgetProviderInfo>() {
        public final int compare(AppWidgetProviderInfo a, AppWidgetProviderInfo b) {
            return sCollator.compare(a.label.toString(), b.label.toString());
        }
    };




 

 

你可能感兴趣的:(launcher ics 添加排序功能)