Android Launcher源码研究(一) 基本结构

Launcher 是 Android手机开启后第一个运行的 应用程序,也叫Home,或者叫做手机桌面。
本文介绍的是4.1源码的launcher2 app. Android41\packages\apps\Launcher2




首先找到主Activity,打开AndroidManifest.xml  入口是  com.android.launcher2.Launcher 这个类
Launcher 主界面包含 wallpaper墙纸,work_screen屏幕, 最底部的hotseat, 以及all apps.

onCreate方法里面 主要初始化一些对象,包括拖拽对象,hotSeat,  墙纸大小设置,
打开主布局文件launcher.xml
外层是一个Framelayout叠层 com.android.launcher2.DragLayer
com.android.launcher2.Workspace.java 为主要Home Screen
手机里面包含了多个屏的滑动,一共有5个
    <com.android.launcher2.Workspace
        android:id="@+id/workspace"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingLeft="@dimen/workspace_left_padding"
        android:paddingRight="@dimen/workspace_right_padding"
        android:paddingTop="@dimen/workspace_top_padding"
        android:paddingBottom="@dimen/workspace_bottom_padding"
        launcher:defaultScreen="2"
        launcher:cellCountX="@integer/cell_count_x"
        launcher:cellCountY="@integer/cell_count_y"
        launcher:pageSpacing="@dimen/workspace_page_spacing"
        launcher:scrollIndicatorPaddingLeft="@dimen/qsb_bar_height"
        launcher:scrollIndicatorPaddingRight="@dimen/button_bar_height">

        <include android:id="@+id/cell1" layout="@layout/workspace_screen" />
        <include android:id="@+id/cell2" layout="@layout/workspace_screen" />
        <include android:id="@+id/cell3" layout="@layout/workspace_screen" />
        <include android:id="@+id/cell4" layout="@layout/workspace_screen" />
        <include android:id="@+id/cell5" layout="@layout/workspace_screen" />
    </com.android.launcher2.Workspace>


每一个屏叫做 com.android.launcher2.CellLayout.java
<com.android.launcher2.CellLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/cell_layout_left_padding"
    android:paddingRight="@dimen/cell_layout_right_padding"
    android:paddingTop="@dimen/cell_layout_top_padding"
    android:paddingBottom="@dimen/cell_layout_bottom_padding"
    android:hapticFeedbackEnabled="false"

    launcher:cellWidth="@dimen/workspace_cell_width"
    launcher:cellHeight="@dimen/workspace_cell_height"
    launcher:widthGap="@dimen/workspace_width_gap"
    launcher:heightGap="@dimen/workspace_height_gap"
    launcher:maxGap="@dimen/workspace_max_gap" />


Workspace.java 是继承ViewGroup
CellLayout 也是继承ViewGroup

Workspace.java 对象在Launcher里面做了一些初始化。
首先在setupViews方法里面 获取了对象引用。还包含了shortcut添加与删除操作。

在Workspace.java中onTouchEvent方法中,监听了屏幕的滑动操作,比如长按,拖动app图标。
拖动用DragController.java类,处理拖动计算坐标。




暂时说到这,如有问题,请指出谢谢。

Launcher默认界面配置(default workspace) 2 1 界面默认配置文件 2 2 LauncherProvider java的loadFavorites分析 3 二 Icon修改 界面布局调整 壁纸设置 5 1 图标大小和标题大小 5 2 Launcher 图标加入默认背景 6 3 更换Launcher默认壁纸 7 4 壁纸设置过程: 8 三 Launcher启动和初始化 9 1 Launcher进程启动过程 9 2 Launcher初始化――LauncherApplication 10 3 Launcher java初始化 12 1 Callbacks接口 15 2 数据加载流程 16 4 LoaderTask的run 方法 17 5 workspace加载数据 18 6 workspace绑定数据 20 7 ALL APP数据加载绑定 22 五 HotSeat分析 24 1 Hotseat配置文件 24 2 Hotseat构造函数 26 3 Hotseat加载数据 27 4 Hotseat绑定数据 27 5 Hotseat类 28 6 总结 30 六 页面滑动 PagedView 30 七 AllApp全部应用列表 AppsCustomizeTabHost 38 1 AllApp列表配置文件 38 2 AppsCustomizeTabHost分析 40 3 Tab变化时执行onTabChanged 41 八 AllApp界面拖拽元素 42 1 触摸拦截 43 2 handleTouchEvent方法 43 4 拖曳按钮 44 九 Launcher启动APP流程 45 1 WorkSpace触摸 45 2 CellLayout的onInterceptTouchEvent 方法 46 3 WorkSpace的onTouch 事件 47 4 BubbleTextView 48 5 onClick 方法 49 6 总结 50 1 常用类介绍 50 2 Launcher的数据库 51">一 Launcher默认界面配置(default workspace) 2 1 界面默认配置文件 2 2 LauncherProvider java的loadFavorites分析 3 二 Icon修改 界面布局调整 壁纸设置 5 1 图标大小和标题大小 5 2 Launcher 图标加入默认背景 6 3 更换Launcher默认壁纸 7 [更多]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值