您的位置:首页 > 移动开发 > Android开发

[RK3288][Android7.1.2] Launcher3 源码阅读之step4:详解Launcher的OnCreate方法的C部分

2017-08-16 14:09 507 查看
前面已经分析了A部分和B部分,现在我们来分析C部分。

@Override

protected void onCreate(Bundle savedInstanceState) {

// ================================= A 部分

  super.onCreate(savedInstanceState);

 // ================================= B 部分

  setContentView(R.layout.launcher);

// ================================= C 部分

}

因为在 setContentView 之后也就是已经设定好了布局。C部分如下:

setupViews();//設置視圖

mDeviceProfile.layout(this, false /* notifyListeners */);

mExtractedColors = new ExtractedColors();//提取顏色

loadExtractedColorsAndColorItems();//加載提取的顏色和顏色item

// 獲取系統服務 AccessibilityManager 狀態改變的監聽

((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE)).addAccessibilityStateChangeListener(this);

lockAllApps();//鎖定所有的app

mSavedState = savedInstanceState;//狀態的保存

restoreState(mSavedState);//恢復狀態

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

if (!mModel.startLoader(mWorkspace.getRestorePage())) {

    // If we are not binding synchronously, show a fade in animation when the first page bind completes.

    mDragLayer.setAlpha(0);

} else {

    setWorkspaceLoading(true);

}

// For handling default keys

mDefaultKeySsb = new SpannableStringBuilder();

Selection.setSelection(mDefaultKeySsb, 0);//設置選擇的默認的key

// 注冊UI 廣播接收器

IntentFilter filter = new IntentFilter(ACTION_APPWIDGET_HOST_RESET);

registerReceiver(mUiBroadcastReceiver, filter);

mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);

// In case we are on a device with locked rotation, we should look at preferences to check

// if the user has specifically allowed rotation.

if (!mRotationEnabled) {//設備的某個的方向被鎖上,是否允許旋轉

    mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());

    mRotationPrefChangeHandler = new RotationPrefChangeHandler(); 

    // 注冊共享參數改變的監聽

    mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);

}

// On large interfaces, or on devices that a user has specifically enabled screen rotation,

// we want the screen to auto-rotate based on the current orientation

setOrientation();//設置方向 ,在當前的基礎方向上選擇自動旋轉

if (mLauncherCallbacks != null) {

    mLauncherCallbacks.onCreate(savedInstanceState);

}

第一部分:设置视图

setupViews();

这个方法里面初始化一系列控件。

例如 findViewById 和 mDragLayer.findViewById
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android7.1.2 rk3288
相关文章推荐