Android8.1 Launcher3 去掉抽屉(一)
Android8.1 Launcher3 去掉抽屉(一)
目前的需求是把8.1的launcher修改为国内常见的,将所有app显示在workspace中,但是网上查了一下,没有找到这方面资料,只能自己慢慢看了,这篇博客记录一下。
1:
Launcher3\src\com\android\launcher3\LauncherAppState.java:
添加一个方法:
public static boolean isDisableAllApps() { return true; }
2:
Launcher3\src\com\android\launcher3\InvariantDeviceProfile.java –>isAllAppsButtonRank():
在6.0中,这个方法是在HotSeat.java中
public boolean isAllAppsButtonRank(int rank) { if (LauncherAppState.isDisableAllApps()) { return false; } return rank == getAllAppsButtonRank(); }
3:
在HotSeat里面去掉Allapp键的加载
Launcher3\src\com\android\launcher3\HotSeat.java –>resetLayout():
void resetLayout() { mContent.removeAllViewsInLayout(); //添加判断 if (LauncherAppState.isDisableAllApps()) { return; } if (!FeatureFlags.NO_ALL_APPS_ICON) { // Add the Apps button Context context = getContext(); DeviceProfile grid = mLauncher.getDeviceProfile(); int allAppsButtonRank = grid.inv.getAllAppsButtonRank(); ......}
4:
将所有应用放在第一层
Launcher3\src\com\android\launcher3\model\LoaderTask.java –> run();
...... // second step if (DEBUG_LOADERS) Log.d(TAG, "step 2.1: loading all apps"); loadAllApps(); //添加查找APP if (LauncherAppState.isDisableAllApps()) { verifyApplications(); } if (DEBUG_LOADERS) Log.d(TAG, "step 2.2: Binding all apps"); verifyNotStopped(); mResults.bindAllApps();......
添加verifyApplications():
private void verifyApplications() { final Context context = mApp.getContext(); ArrayList.PendingInstallShortcutInfo> items = new ArrayList<>(); synchronized (this) { for (AppInfo app : mBgAllAppsList.data) { Intent data = app.getIntent(); data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, data); data.putExtra(Intent.EXTRA_SHORTCUT_ICON, app.iconBitmap); data.putExtra(Intent.EXTRA_SHORTCUT_NAME, app.title); InstallShortcutReceiver.PendingInstallShortcutInfo info = new InstallShortcutReceiver.PendingInstallShortcutInfo( data, app.user, context); items.add(info); } } if (!items.isEmpty()) { mApp.getModel().addAndBindAddedWorkspaceItems( new InstallShortcutReceiver.LazyShortcutsProvider(context.getApplicationContext(), items)); } }
需要把InstallShortcutReceiver.PendingInstallShortcutInfo和InstallShortcutReceiver.LazyShortcutsProvider改为public。到这里就初步可以了。但是运行之后发现还是不行。于是打印log查找问题;发现AddWorkspaceItemsTask.java中的execute()方法没有执行,原因是BaseModelUpdateTask.java中run()中的判断问题,导致没有执行,于是偷个懒,先把return注释;
@Override public final void run() { if (!mModel.isModelLoaded()) { if (DEBUG_TASKS) { Log.d(TAG, "Ignoring model task since loader is pending=" + this); } // Loader has not yet run. return; } execute(mApp, mDataModel, mAllAppsList); }
终于把抽屉的app放到workspace中了,接下来就是优化还有把抽屉隐藏,因为8.1上滑也是可以调出抽屉的,这个还在研究。接下里的任务仍然不轻松,还需要 有新应用添加时更新Workspace,去掉长按时的删除选项,禁止抽屉出现。
本文参考了这篇博客:Android 7.0 Launcher3 去掉应用抽屉
但是这篇博客是基于7.0,跟8.1还是有些不同的,尤其是加载应用的地方(LoaderTask.java).
更多相关文章
- cocos2d-x添加广告条(IOS and Android)
- Android(安卓)自定义TextView实现宫格布局,Drawable添加图片并控
- android ListView添加事件并获取选中项的值
- Android(安卓)7.0、8.1 导航栏上添加图标 及 相应功能
- Android(安卓)UI设计:GridView
- 【Android】使用persist属性来调用脚本文件
- Android(安卓)Studio 在默认build.gradle 中加入自定义源(新建项
- debug安装包无效的解决办法
- android 界面添加返回一栏