Android launcher3 开发初始篇

版本:1.0
日期:2014.8.26 2014.8.27  2014.11.10
版权:© 2014 kince 转载注明出处
    
   好久没有写博客,也是因为工作比较忙的关系。当然这不是理由,主要是很多bug要改,而自己的效率又不是很高,所以把很多时间都浪费在修复bug上面了。闲话不多说,切入正题。
    Launcher3是最新的google官方Launcher,相比Launcher2,它具有更加小巧、流畅、清新等特点,所以选择它作为研究的对象。第一步当然是去下载其源码,git网址是:https://android.googlesource.com/platform/packages/apps/Launcher3/。如果没有git工具,可以点击master。
刚好最近lollipop的Launcher源码也更新了。和之前的Launcher3会有一些区别,不过不大,倒入过程大同小异。

git下载:

压缩包下载:

下载完后解压,目录如下:


  接着导入eclipse,因为Launcher3的某些新特性,需要将build target设置为API level 19(不是必须,为了方便研究起见,Launcher3的源码最低可以兼容大API16)。然后导入项目所依赖的类库,这个地方分为三种情况,一是导入v4包,手动添加一个libs目录,将v4包加进去;二是需要protocol buffers,到https://android.googlesource.com/platform/external/protobuf.git下载,最好打成jar包,然后放在libs目录下。三是添加BackupProtos.java这个类。可以从上一步中获取。英文好的朋友可以看一下下面的步骤:

Do it yourself

  1. Use Git to pull down the latest Launcher 3 source:

    git clone https://android.googlesource.com/platform/packages/apps/Launcher3

  2. Import existing code into Eclipse (Android Project from Existing Code)
  3. Change the project build target to API level 19
  4. Add Android support libraries
  5. Build protocol buffers JAR from AOSP source. You will actually need to build the protoc binary as well. You need to know how to use ‘make’ have gcc available for the protoc binary, and Maven for the JAR: https://android.googlesource.com/pla…l/protobuf.git
  6. Use protoc binary built from step above to generate the BackupProtos.java file:

    protoc –javanano_out=src/ -I protos protos/backup.proto

  7. Rename the Android package (Android Tools->Rename Application Package) to one of your choice
  8. Add min SDK in a new ‘uses-sdk’ element in AndroidManifest.xml (works down to API level 17 without too many complaints in Lint, obviously stick to 19 to play it safe).
  9. Clean and run. BIND APP WIDGETS error can be ignored

Fabio Lo Brutto:
https://plus.google.com/+FabioLoBrutto/posts/KJeyKMBHVT7

 导完后的目录结构如下:
  如果想做一个自己的Launcher,那么需要把包名改一下,研究的话就没有必要了。最后运行,截图如下:


  关于Launcher最复杂的东西不在于如何显示应用程序、Widget、文件夹等功能,而是自定义View方面,因为基本上Launcher的View都是自定义的,而且代码都很多,理解起来不是那么简单。所以说,如果把Launcher里面的自定义的View掌握了,那么对Launcher也就基本掌握了。因此,学习重点应该集中在自定义View上。
  今后会持续更新关于Launcher3开发方面的文章,在做Launcher开发的朋友可以一起交流。


  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值