Android_Q_Launcher调整为横向滑动
以下内容为原创,其中有参考部分同行的blog。
需求说明:
1.Android Q Launcher去掉抽屉功能,屏蔽从下往上的滑动功能;
2.将系统中apk及新安装的apk全部显示在workspace中;
3.workspace中,不可卸载的应用长按滑动后,只能有cancel功能,可卸载应用,长按滑动后,有卸载功能;
4.Launcher横屏显示时,屏蔽从下往上的滑动功能;
需求分解:备注:以下相关代码注释请搜索“by lj”
1.将 AllAppsContainerView 中的图标加载到 Workspace,需要在LoaderTask中,将所有APP都Load并且通过addAndBindAddedWorkspaceItems,添加显示到workspace。packages\apps\Launcher3\src\com\android\launcher3\model\LoaderTask.java文件中,在run()方法中,
// second step
TraceHelper.partitionSection(TAG, "step 2.1: loading all apps");
List<LauncherActivityInfo> allActivityList = loadAllApps();
/*add start by lj on 20200530*/
verifyApplications();
/*add end by lj on 20200530*/
需要添加的方法如下:
/*add start by lj on 20200530*/
private void verifyApplications() {
final Context context = mApp.getContext();
ArrayList<Pair<ItemInfo, Object>> installQueue = new ArrayList<>();
final List<UserHandle> profiles = mUserManager.getUserProfiles();
for (UserHandle user : profiles) {
final List<LauncherActivityInfo> apps = mLauncherApps.getActivityList(null, user);
ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo> added =
new ArrayList<InstallShortcutReceiver.PendingInstallShortcutInfo>();
synchronized (this) {
for (LauncherActivityInfo app : apps) {
InstallShortcutReceiver.PendingInstallShortcutInfo pendingInstallShortcutInfo =
new InstallShortcutReceiver.PendingInstallShortcutInfo(app, context);
added.add(pendingInstallShortcutInfo);
installQueue.add(pendingInstallShortcutInfo.getItemInfo());
}
}
if (!added.isEmpty()) {