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

前面已经分析了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









  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值