Android launcher3 -- launcher3源码4

Android launcher3 – launcher3源码4

默认布局怎样加载到桌面显示,有兴趣可阅读【墨香带你学Launcher之(三)-绑定屏幕、图标、文件夹和Widget】,其中流程图不错。

图标加载开始

Launcher.java 调用startLoader,启动LoaderTask

public void startLoader(int synchronousBindPage) {
    startLoader(synchronousBindPage, LOADER_FLAG_NONE);
}

public void startLoader(int synchronousBindPage, int loadFlags) {
    // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
    InstallShortcutReceiver.enableInstallQueue();
    synchronized (mLock) {
        // Clear any deferred bind-runnables from the synchronized load process
        // We must do this before any loading/binding is scheduled below.
        synchronized (mDeferredBindRunnables) {
            mDeferredBindRunnables.clear();
        }

        // Don't bother to start the thread if we know it's not going to do anything
        if (mCallbacks != null && mCallbacks.get() != null) {
            // If there is already one running, tell it to stop.
            stopLoaderLocked();
            mLoaderTask = new LoaderTask(mApp.getContext(), loadFlags);
            if (synchronousBindPage != PagedView.INVALID_RESTORE_PAGE
                    && mAllAppsLoaded && mWorkspaceLoaded && !mIsLoaderTaskRunning) {
                mLoaderTask.runBindSynchronousPage(synchronousBindPage);
            } else {
                sWorkerThread.setPriority(Thread.NORM_PRIORITY);
                sWorker.post(mLoaderTask);
            }
        }
    }
}

LauncherModel.java:异步线程LoaderTask加载图标

public void run() {
	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();
	}

	// 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 = true;
	}
}

//step 1: loading workspace
loadAndBindWorkspace();
//step 2: loading all apps
loadAndBindAllApps();

绑定workspace

private void loadAndBindWorkspace() {
    ......
    // Load the workspace

    if (!mWorkspaceLoaded) {
        loadWorkspace();
        ......
    }

    // Bind the workspace
    bindWorkspace(-1);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xhBruce

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值