Android Launcher研究.docx

上传人:b****0 文档编号:17079187 上传时间:2023-07-21 格式:DOCX 页数:20 大小:1.09MB
下载 相关 举报
Android Launcher研究.docx_第1页
第1页 / 共20页
Android Launcher研究.docx_第2页
第2页 / 共20页
Android Launcher研究.docx_第3页
第3页 / 共20页
Android Launcher研究.docx_第4页
第4页 / 共20页
Android Launcher研究.docx_第5页
第5页 / 共20页
Android Launcher研究.docx_第6页
第6页 / 共20页
Android Launcher研究.docx_第7页
第7页 / 共20页
Android Launcher研究.docx_第8页
第8页 / 共20页
Android Launcher研究.docx_第9页
第9页 / 共20页
Android Launcher研究.docx_第10页
第10页 / 共20页
Android Launcher研究.docx_第11页
第11页 / 共20页
Android Launcher研究.docx_第12页
第12页 / 共20页
Android Launcher研究.docx_第13页
第13页 / 共20页
Android Launcher研究.docx_第14页
第14页 / 共20页
Android Launcher研究.docx_第15页
第15页 / 共20页
Android Launcher研究.docx_第16页
第16页 / 共20页
Android Launcher研究.docx_第17页
第17页 / 共20页
Android Launcher研究.docx_第18页
第18页 / 共20页
Android Launcher研究.docx_第19页
第19页 / 共20页
Android Launcher研究.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Android Launcher研究.docx

《Android Launcher研究.docx》由会员分享,可在线阅读,更多相关《Android Launcher研究.docx(20页珍藏版)》请在冰点文库上搜索。

Android Launcher研究.docx

AndroidLauncher研究

AndroidLauncher研究

一、图文详解手把手教你在Windows环境下下载Android源码(Launcher为例)

大家好,这篇文章我将教大家如何在Windows环境下下载Android源码,Android自2007年11月5号发布以来,发展速度如此之快,和它走开源的路是分不开的。

我们在开发中有什么不明白不清楚的,直接把Android源码下下来研究就可以了,看源代码将会让你提升很快!

在这之前大家先熟悉俩个代码版本管理工具SVN,以及Git。

SVN(Windows环境下最常用的):

svn(subversion)是近年来崛起的版本管理工具,是cvs的接班人。

目前,绝大多数开源软件都使用svn作为代码版本管理软件。

Git:

Git是用于Linux内核开发的版本控制工具。

与常用的版本控制工具CVS,Subversion等不同,它采用了分布式版本库的方式,不必服务器端软件支持,使源代码的发布和交流极其方便。

Git的速度很快,这对于诸如Linuxkernel这样的大项目来说自然很重要。

Git最为出色的是它的合并跟踪(mergetracing)能力。

而GoogleAndroid的项目是基于Git进行版本管理的,所以经常在Linux环境下开发的人,就不用我多说了,而大都数在Windows环境开发的人,就比较陌生了。

那下面我就手把手教你如何在Windows环境下GitAndroid源码。

第一步:

Msysgit工具的下载(这个是Google为Windows环境下开发的Git客户端程序):

下载地址如图:

第二步:

安装Msysgit软件(一直默认到底),如下图:

第三步:

建立一个文件夹用来存放Git下来的Android源码(我这里以G:

/AndroidSrc)为例,如下图:

第四步:

右击AndroidSrc文件夹选择GitBash出现如下图所示:

第五步:

查找我们要下载源代码的地址。

Android的源代码是放在下面地址下:

http:

//android.git.kernel.org/

这里以Launcher为例,我们Ctrl+F查找:

输入Launcher如下图所示:

点击链接进入另一个页面:

第六步在GitBash端输入如下命令,命令格式(如上图图示)

gitclonegit:

//android.git.kernel.org/platform/packages/apps/Launcher.git

在ReceivingObjects:

100%时候,我们在G:

/AndroidSrc/文件夹下多一个工程Launcher,这正是我们所要的,如下图所示:

Ok通过以上的步骤我们就把AndroidLauncher的源代码拿到手了,下面就剩下你研究了!

二、Launcher为何物,究竟是干什么的?

在上一节,我讲了如何下载Launcher的教程,今天这一节,我将重点讲一下什么Launcher,究竟它是什么神秘东东?

Launcher俗称HomeScreen,也就是我们启动Android手机,第一眼看到的应用程序,而这个应用程序是比较特殊而且任务艰巨的。

它负责了我们除了应用本身操作以外的所有操作,它负责了我们有几个桌面,点击应用图标启动应用程序,长时间按桌面出现上下文菜单,

长时间按桌面的图标出现垃圾箱,拖动应用图标重新定位等等,一系列的操作。

我将截些图让大家更容易理解!

图1:

开机画面,Laucher的主界面图2:

打开抽屉,列出所有我们的所安装应用

图三:

长按图标,抽屉变成垃圾箱了图四:

手指向左滑动进入另一个桌面

我就先截这几个图让大家感受感受,图2中我们列出的所有应用并不包括诸如:

Launcher,Widget等应用,是因为我们我们列出的应用仅仅是在AndroidManifest.xml配置文件有这样标记的应用(如下代码:

viewplaincopytoclipboardprint?

1

name=".HomeStyle"

2android:

theme="@android:

style/Theme.NoTitleBar"

3android:

label="@string/app_name">

4

5

name="android.intent.action.MAIN"/>

6

name="android.intent.category.LAUNCHER"/>

7

8

其中第5,6行是关键,有了这两句,你的应用程序才会被列出,而Launcher特殊就是这个应用中唯一一个Activity是这样申明的,如下代码:

viewplaincopytoclipboardprint?

9

10android:

name="Launcher"

11android:

launchMode="singleTask"

12android:

clearTaskOnLaunch="true"

13android:

stateNotNeeded="true"

14android:

theme="@android:

style/Theme.Wallpaper.NoTitleBar"

15android:

screenOrientation="nosensor"

16android:

windowSoftInputMode="stateUnspecified|adjustPan">

17

18

name="android.intent.action.MAIN"/>

19

name="android.intent.category.HOME"/>

20

name="android.intent.category.DEFAULT"/>

21

name="android.intent.category.MONKEY"/>

22

23

这里第11行起了作用了,大家看出来Launcher与普通应用程序的区别了吗,变成Home的时候,当我们重新安装一个Launcher的时候,我们按一下手机的HOME键会出现Launcher列表如下图:

图5:

Launcher列表图6:

传说中的Launcher2

Ok,今天就先说到这里,大家有什么不明白的请留言!

我一定尽量准时答复.谢谢~

三、列出所安装的应用,点击进入相应的应用!

大家好,我今天给大家简单讲一下Launcher里如何列出所有安装的应用的,我们点击Launcher的抽屉(SlidingDrawer)就会出现所有安装的应用列表(当然Widget,Launcher本身除外).并且点击应用图标进入相关应用。

我这里就先简单的用一个GridView来显示应用。

老样子我还会写一个简单的Demo让大家理解。

大家跟着我的步骤来。

第一步:

新建一个Android工程命名为:

Launcher.

第二步:

修改main.xml布局文件,代码如下(只有一个GridView这里):

viewplaincopytoclipboardprint?

1

xmlversion="1.0"encoding="utf-8"?

>

2

android="

3android:

orientation="vertical"

4android:

layout_width="fill_parent"

5android:

layout_height="fill_parent"

6>

7

8android:

id="@+id/allapps"

9android:

layout_width="fill_parent"

10android:

layout_height="wrap_content"

11/>

12

第三步:

新建一个application_layout.xml布局文件,用来定义应用的图标和标题,代码如下:

viewplaincopytoclipboardprint?

13

xmlversion="1.0"encoding="utf-8"?

>

14

android="

15android:

orientation="vertical"

16android:

layout_width="fill_parent"

17android:

layout_height="fill_parent"

18>

19

20android:

id="@+id/app_icon"

21android:

layout_width="wrap_content"

22android:

layout_height="wrap_content"

23/>

24

25android:

id="@+id/app_title"

26android:

layout_width="wrap_content"

27android:

layout_height="wrap_content"

28/>

29

第四步:

也就是核心了,修改Launcher.java代码如下:

viewplaincopytoclipboardprint?

30packagecom.tutor.launcher;

31importjava.util.Collections;

32importjava.util.List;

33importandroid.app.Activity;

34importandroid.content.ComponentName;

35importandroid.content.Context;

36importandroid.content.Intent;

37importandroid.content.pm.PackageManager;

38importandroid.content.pm.ResolveInfo;

39importandroid.os.Bundle;

40importandroid.view.LayoutInflater;

41importandroid.view.View;

42importandroid.view.ViewGroup;

43importandroid.widget.AdapterView;

44importandroid.widget.BaseAdapter;

45importandroid.widget.GridView;

46importandroid.widget.ImageView;

47importandroid.widget.TextView;

48importandroid.widget.AdapterView.OnItemClickListener;

49publicclassLauncherextendsActivityimplementsOnItemClickListener{

50

51privateGridViewmGridView;

52privateContextmContext;

53privatePackageManagermPackageManager;

54privateListmAllApps;

55

56publicvoidonCreate(BundlesavedInstanceState){

57super.onCreate(savedInstanceState);

58setContentView(R.layout.main);

59

60setupViews();

61

62}

63

64publicvoidsetupViews(){

65mContext=Launcher.this;

66mPackageManager=getPackageManager();

67mGridView=(GridView)findViewById(R.id.allapps);

68bindAllApps();

69

70mGridView.setAdapter(newGridItemAdapter(mContext,mAllApps));

71mGridView.setNumColumns(4);

72mGridView.setOnItemClickListener(this);

73}

74

75publicvoidbindAllApps(){

76//这里是关键哦,我们平时写的应用总有一个activity申明成这两个属性

77//也就是应用的入口

78IntentmainIntent=newIntent(Intent.ACTION_MAIN,null);

79mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

80//符合上面条件的全部查出来,并且排序

81mAllApps=mPackageManager.queryIntentActivities(mainIntent,0);

82Collections.sort(mAllApps,newResolveInfo.DisplayNameComparator(mPackageManager));

83}

84

85

86

87//gridview点击事件,点击进入相关应用

88@Override

89publicvoidonItemClick(AdapterView

>parent,Viewview,intposition,longid){

90//TODOAuto-generatedmethodstub

91ResolveInfores=mAllApps.get(position);

92//该应用的包名和主Activity

93Stringpkg=res.activityInfo.packageName;

94Stringcls=res.activityInfo.name;

95

96ComponentNamecomponet=newComponentName(pkg,cls);

97

98Intenti=newIntent();

99i.setComponent(componet);

100startActivity(i);

101}

102

103//不明白BaseAdapter的用法我高手进阶里有

104privateclassGridItemAdapterextendsBaseAdapter{

105privateContextcontext;

106privateListresInfo;

107

108//构造函数

109publicGridItemAdapter(Contextc,Listres){

110context=c;

111resInfo=res;

112}

113@Override

114publicintgetCount(){

115//TODOAuto-generatedmethodstub

116returnresInfo.size();

117}

118@Override

119publicObjectgetItem(intposition){

120//TODOAuto-generatedmethodstub

121returnnull;

122}

123@Override

124publiclonggetItemId(intposition){

125//TODOAuto-generatedmethodstub

126return0;

127}

128@Override

129publicViewgetView(intposition,ViewconvertView,ViewGroupparent){

130

131//不明白LayoutInflater的我android高手进阶里有

132convertView=LayoutInflater.from(context)

133.inflate(R.layout.application_layout,null);

134

135ImageViewapp_icon=(ImageView)convertView.findViewById(R.id.app_icon);

136TextViewapp_tilte=(TextView)convertView.findViewById(R.id.app_title);

137

138ResolveInfores=resInfo.get(position);

139app_icon.setImageDrawable(res.loadIcon(mPackageManager));

140app_tilte.setText(res.loadLabel(mPackageManager).toString());

141returnconvertView;

142}

143

144}

145}

第五步:

运行以上工程,得到的效果图如下:

图1.列出所有安装的应用.

图2.点击aQQ应用进入到相应的应用里。

OK,今天就写到这里,大家有什么不明白的地方可以留言。

thx~

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 简洁抽象

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2