[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
@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
相关文章推荐
- [RK3288][Android7.1.2] Launcher3 源码阅读之step3:详解Launcher的OnCreate方法的B部分
- [RK3288][Android7.1.2] Launcher3 源码阅读之step2:详解Launcher的OnCreate方法的A部分
- [RK3288][Android7.1.2] Launcher3 源码阅读之step5:查看主要的xml布局文件
- [RK3288][Android7.1.2] Launcher3 源码阅读之step1:查看项目的目录并找到入口
- [RK3288][Android7.1.2] Launcher3 源码阅读之step6:根据布局文件找到对应的自定义View
- 图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)
- Android源码下载方法详解
- Android源码下载方法详解
- Android中源码Launcher主屏幕程序排列详解【安卓Launcher进化一】
- Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)
- Android中源码Launcher主屏幕程序排列详解【安卓Launcher进化一】
- Ubuntu下android-4.0.3_r1源码下载,阅读工具安装配置,源码编译详解
- Android中源码Launcher主屏幕程序排列详解【安卓Launcher进化一】
- Windows下获取Android 源码方法的详解
- Android源码下载方法详解
- Android中源码Launcher主屏幕程序排列详解【安卓Launcher进化一】
- Android源码下载方法详解
- Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)
- Android Launcher研究(一)-----------图文详解手把手教你在Windows环境下下载Android源码(Launcher为例) (转)
- Android源码下载方法详解