原始碼剖析】Launcher 8.0 原始碼 (12) --- Launcher 啟動流程 第五步之計算桌面各佈局細節引數
第四步主要講解了桌面佈局的建立與繫結,這篇主要是講各佈局的細節引數的計算。
我們來看一下這一步的具體程式碼。
mDeviceProfile.layout(this, false /* notifyListeners */); loadExtractedColorsAndColorItems(); mPopupDataProvider = new PopupDataProvider(this); ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)) .addAccessibilityStateChangeListener(this); restoreState(savedInstanceState); // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground int currentScreen = PagedView.INVALID_RESTORE_PAGE; if (savedInstanceState != null) { currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen); }
1.mDeviceProfile.layout(this, false /* notifyListeners */);
在該方法中有一些具體的註釋,主要是桌面具體控制元件佈局的位置放置,包括searchbar,allapps,workspace,hotseat,indicators,等等。
// Layout the search bar space
//Layout the all apps
// Layout the workspace
// Layout the hotseat
// Layout the page indicators
//layout the arrow tips
//// Layout the flat menu page indicators
// Layout the Overview Mode
// Layout the snack tips
// Layout the AllAppsRecyclerView
2.loadExtractedColorsAndColorItems();
此方法中是設定控制元件的顏色
private void loadExtractedColorsAndColorItems() { // TODO: do this in pre-N as well, once the extraction part is complete. if (Utilities.ATLEAST_NOUGAT) { mExtractedColors.load(this); mHotseat.updateColor(mExtractedColors, !mPaused); mWorkspace.getPageIndicator().updateColor(mExtractedColors); } }
會根據桌布的顏色,來調節Hotseat,pageIndicator的顏色。workspace圖示文字的顏色。
3.mPopupDataProvider = new PopupDataProvider(this);
當你長按桌面圖片,或者allapps裡面的圖示的時候會彈出來一個視窗,窗口裡面有幾個選項可供選擇。
4.((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
.addAccessibilityStateChangeListener(this);
監聽桌面的變化,進行事件分發,AccessibilityManager是系統級別的服務,用來管理AccessibilityService服務,比如分發事件,查詢系統中服務的狀態等等。
5.對介面,以及資料進行恢復
restoreState(savedInstanceState); if (LauncherAppState.PROFILE_STARTUP) { Trace.endSection(); } // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground int currentScreen = PagedView.INVALID_RESTORE_PAGE; if (savedInstanceState != null) { currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen); }
這裡進行資料的儲存與恢復。這裡運用了安卓的資料儲存恢復機制,對儲存在savedInstanceState裡面的資料進行恢復。
到這裡整個Launcher 啟動流程 第五步之計算桌面各佈局細節引數,就分析完了。接下來繼續講解。