Launcher3源码地址:Launcher3-master
[This tutorial was written by Ticoo]
Google Launcher3默认是抽屉型的桌面,到Android 8.0依然是没有这样的功能。这样的功能是手机厂商提供给我们的,不得不说,横向排列的桌面
更适合国人的使用习惯,可能是使用iphone的习惯吧。
好,那我们如何实现这样功能呢?其实并不会太难的。
在Launcher加载流程里,我们知道桌面的数据是在LauncherModel的 LoaderTask完成加载的
我们在loadAndBindAllApps()方法调用之后添加一个verifyApplications()方法调用,为什么在这里调用呢?
因为只用当应用数据加载完全后,我们才能讲所有的应用进行横向绑定到Workspace的操作
@Override
public void run() {
AppTypeHelper.configSystemAppIcon(mContext);
synchronized (mLock) {
if (mStopped) {
return;
}
mIsLoaderTaskRunning = true;
}
// Optimize for end-user experience: if the Launcher is up and // running with the
// All Apps interface in the foreground, load All Apps first. Otherwise, load the
// workspace first (default).
keep_running:
{
if (DEBUG_LOADERS) {
Log.d(TAG, "step 1: loading workspace");
}
loadAndBindWorkspace();
if (mStopped) {
break keep_running;
}
waitForIdle();
// second step
if (DEBUG_LOADERS) {
Log.d(TAG, "step 2: loading all apps");
}
loadAndBindAllApps();
}
if (LauncherAppState.getInstance().getInvariantDeviceProfile()
.isDisableAllApps) {
verifyApplications();
}
// Clear out this reference, otherwise we end up holding it until all of the
// callback runnables are done.
mContext = null;
synchronized (mLock) {
// If we are still the last one to be scheduled, remove ourselves.
if (mLoaderTask == this) {
mLoaderTask = null;
}
mIsLoaderTaskRunning = false;
mHasLoaderCompletedOnce = tru