从这里可以下载源码
launcher,启动器,是我们安卓系统运行的第一个程序。我们可以通过学习源码,对launcher进行了解,从而定制我们的桌面程序。
清单文件
通过源码我们可以看出,launcher中声明 了一些 自定义的权限。
<activity
android:name="com.android.launcher3.Launcher"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:stateNotNeeded="true"
android:theme="@style/Theme"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="nosensor"
android:resumeWhilePausing="true"
android:taskAffinity=""
android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MONKEY"/>
</intent-filter>
</activity>
laucher类是我们开发中最终的的一个类,也就是我么所看到的桌面类。从他的launchmode可以看出他是一个,单任务模式。
从android:name=”android.intent.category.HOME” ,可以看出他就是桌面。
从名字可以看出,他是对外提供设置壁纸的功能
<activity
android:name="com.android.launcher3.WallpaperPickerActivity"
android:theme="@style/Theme.WallpaperPicker"
android:label="@string/pick_wallpaper"
android:icon="@mipmap/ic_launcher_wallpaper"
android:finishOnCloseSystemDialogs="true"
android:process=":wallpaper_chooser">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
通过第三方设置壁纸的接口
<activity
android:name="com.android.launcher3.WallpaperCropActivity"
android:theme="@style/Theme.WallpaperCropper"
android:label="@string/crop_wallpaper"
android:icon="@mipmap/ic_launcher_wallpaper"
android:finishOnCloseSystemDialogs="true"
android:process=":wallpaper_chooser">
<intent-filter>
<action android:name="android.service.wallpaper.CROP_AND_SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
既然提供了改变壁纸的接口,那么同样提供壁纸改变的广播接收器
<receiver
android:name="com.android.launcher3.WallpaperChangedReceiver">
<intent-filter>
<action android:name="android.intent.action.WALLPAPER_CHANGED" />
</intent-filter>
</receiver>
既然launcher是我们系统的启动程序,那么他肯定监听系统启动完成的广播
:StartupReceiver
launcher3数据库组件: LauncherProvider,可以看得出继承一个内容提供者
Lau ncher初始化
在launcher类的oncreate方法里面,LauncherAppState.setApplicationContext(getApplicationContext());
LauncherAppState app = LauncherAppState.getInstance();
这是对LauncherAppState进行初始化,他保存这laucher运行时所需要的公共信息。
当我们的laucher因为某些原因种植的时候,可以调用其onTerminate()方法。
在这个方法里面里,laucher会对其运行环境进行清理