<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>launcher</title>
	<atom:link href="https://www.aitaocui.cn/tag/262978/feed" rel="self" type="application/rss+xml" />
	<link>https://www.aitaocui.cn</link>
	<description>翡翠玉石爱好者聚集地</description>
	<lastBuildDate>Mon, 28 Nov 2022 16:13:06 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.1</generator>

<image>
	<url>https://www.aitaocui.cn/wp-content/uploads/2022/11/taocui.png</url>
	<title>launcher</title>
	<link>https://www.aitaocui.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>launcher(安卓系统桌面启动器)</title>
		<link>https://www.aitaocui.cn/article/375244.html</link>
					<comments>https://www.aitaocui.cn/article/375244.html#respond</comments>
		
		<dc:creator><![CDATA[索拉卡]]></dc:creator>
		<pubDate>Mon, 28 Nov 2022 16:13:06 +0000</pubDate>
				<category><![CDATA[知识]]></category>
		<category><![CDATA[launcher]]></category>
		<guid isPermaLink="false">https://www.aitaocui.cn/?p=375244</guid>

					<description><![CDATA[Launcher是安卓系统中的桌面启动器，安卓系统的桌面UI统称为Launcher。Launcher是安卓系统中的主要程序组件之一，安卓系统中如果没有Launcher就无法启动安卓...]]></description>
										<content:encoded><![CDATA[</p>
<article>
<p>Launcher是安卓系统中的桌面启动器，安卓系统的桌面UI统称为Launcher。Launcher是安卓系统中的主要程序组件之一，安卓系统中如果没有Launcher就无法启动安卓桌面，Launcher出错的时候，安卓系统会出现“进程com.android.launcher意外停止”的提示窗口。这时需要重新启动Launcher。Launcher可以让你的手机主桌面非常简洁漂亮，只显示最下面一排应用图标以及顶部三个按钮，可以左右、上滑动，其中左边是当然模式下的常用预览，右边是应用分类，上滑是打开常用联系人，可以快速打电话发短信。</p>
</article>
<p><img decoding="async" src="https://www.aitaocui.cn/wp-content/uploads/2022/08/20220828_630b663c29a54.jpg" /></p>
<article>
<h1>文件类别</h1>
<div></div>
<p>1.Launcher.java:launcher中主要的activity。</p>
<p>2.DragLayer.java:launcher layout的rootview。DragLayer实际上也是一个抽象的界面，用来处理拖动和对事件进行初步处理然后按情况分发下去，角色是一个controller。它首先用onInterceptTouchEvent(MotionEvent）来拦截所有的touch事件，如果是长按item拖动的话不把事件传下去，直接交由onTouchEvent(）处理，这样就可以实现item的移动了，如果不是拖动item的话就把事件传到目标view，交有目标view的事件处理函数做相应处理。如果有要对事件的特殊需求的话可以修改onInterceptTouchEvent(MotionEvent）来实现所需要的功能。</p>
<p>3. DragController.java:为Drag定义的一个接口。包含一个接口，两个方法和两个静态常量。接口为DragListener（包含onDragStart（），onDragEnd（）两个函数），onDragStart（）是在刚开始拖动的时候被调用，onDragEnd（）是在拖动完成时被调用。在launcher中典型的应用是DeleteZone，在长按拖动item时调用onDragStart（）显示，在拖动结束的时候onDragEnd（）隐藏。两个函数包括startDrag（）和setDragItemInfo().startDrag（）用于在拖动是传递要拖动的item的信息以及拖动的方式，setDragItemInfo（）用于传递item的参数信息（包括位置以及大小）。两个常量为DRAG_ACTION_MOVE，DRAG_ACTION_COPY来标识拖动的方式，DRAG_ACTION_MOVE为移动，表示在拖动的时候需要删除原来的item，DRAG_ACTION_COPY为复制型的拖动，表示保留被拖动的item。</p>
<p>4.LauncherModel.java:辅助的文件。里面有许多封装的对数据库的操作。包含几个线程，其中最主要的是ApplicationsLoader和DesktopItemsLoader。ApplicationsLoader在加载所有应用程序时使用，DesktopItemsLoader在加载workspace的时候使用。其他的函数就是对数据库的封装，比如在删除，替换，添加程序的时候做更新数据库和UI的工作。</p>
<p>5.Workspace.java:抽象的桌面。由N个celllayout组成，从cellLayout更高一级的层面上对事件的处理。 </p>
<p>6.LauncherProvider.java:launcher的数据库，里面存储了桌面的item的信息。在创建数据库的时候会loadFavorites(db）方法，loadFavorites（）会解析xml目录下的default_workspace.xml文件，把其中的内容读出来写到数据库中，这样就做到了桌面的预制。</p>
<p>7.CellLayout.java：组成workspace的view，继承自viewgroup，既是一个dragSource，又是一个dropTarget，可以将它里面的item拖出去，也可以容纳拖动过来的item。在workspace_screen里面定了一些它的view参数。</p>
<p>8.ItemInfo.java:对item的抽象，所有类型item的父类，item包含的属性有id（标识item的id），cellX（在横向位置上的位置，从0开始），cellY（在纵向位置上的位置，从0开始），spanX（在横向位置上所占的单位格），spanY（在纵向位置上所占的单位格），screen（在workspace的第几屏，从0开始），itemType（item的类型，有widget，search，application等），container（item所在的）。</p>
<p>9.UserFolder.java:用户创建的文件夹。可以将item拖进文件夹，单击时打开文件夹，长按文件夹上面标题处可以重命名文件夹。 </p>
<p>10.LiveFolder.java:系统自带的文件夹。从系统中创建出的如联系人的文件夹等。</p>
<p>11.DeleteZone:删除框。在平时是出于隐藏状态，在将item长按拖动的时候会显示出来，如果将item拖动到删除框位置时会删除item。DeleteZone实现了DropTarget和DragListener两个接口。 </p>
<p>12.LauncherSettings.java:字符串的定义。数据库项的字符串定义，另外在这里定义了container的类型，还有itemType的定义，除此还有一些特殊的widget（如search,clock的定义等）的类型定义。 </p>
</p>
<h1>解决方式</h1>
<div></div>
<p>1.将所有的应用都排列在桌面上</p>
<p>将所有的应用都排列在桌面是通过首先创建一个三维的boolean型全局数组来记录item的排列情况，第一维是屏数，第二维是纵向上的排列情况，第三维是横向的排列情况，如果那个位置被item所占用就标记为1，否则标记为0.在启动时把全局数组初始化为0，然后在添加的时候把相应的位置置1.凡是涉及到workspace上item的变化，比如移动、添加、删除操作时都需要维护数组，保持数组的正确性，因为在安装新程序时依据数组的状态去判断把item加到什么位置。</p>
<p>2.动态增加屏幕 </p>
<p>动态增加屏幕是通过worksapce .addchild(view）的方式实现。基本思路是：首先预先规定所允许的最大的屏幕数，然后在需要增加屏幕而且当前屏幕数没有超过最大屏幕数的时候通过（CellLayout)mInflater.inflate(R.layout.workspace_screen,null）创建一个celllayout实例出来，然后通过addchild把它加入进去。在屏幕上的item被删除时通过从最后一屏起判断屏幕上是否有item，如果有的话保留，没有的话则删除最后一屏，以此类推。 </p>
</p>
<h1>xml文件</h1>
<p>1.workspace_screen.xml</p>
</p>
<p>launcher:cellWidth=&quot;95dip&quot;cell（即item）的宽 </p>
</p>
<p>launcher:cellHeight=&quot;93dip&quot;cell（即item）的宽</p>
</p>
<p>launcher:longAxisStartPadding=&quot;25dip&quot; </p>
</p>
<p>较长（屏幕的宽和高中较大的那一方向，根据横竖屏方向有所不同）方向上距离起点的像素数 </p>
</p>
<p>launcher:longAxisEndPadding=&quot;55dip&quot; </p>
</p>
<p>较长（屏幕的宽和高中较大的那一方向，根据横竖屏方向有所不同）方向上距离终点的像素数</p>
</p>
<p>launcher:shortAxisStartPadding=&quot;20dip&quot; </p>
</p>
<p>较短（屏幕的宽和高中较大的那一方向，根据横竖屏方向有所不同）方向上距离起点的像素数</p>
</p>
<p>launcher:shortAxisEndPadding=&quot;120dip&quot; </p>
</p>
<p>较短（屏幕的宽和高中较大的那一方向，根据横竖屏方向有所不同）方向上距离起点的像素数</p>
</p>
<p>launcher:shortAxisCells=&quot;3&quot;</p>
</p>
<p>较短的方向上可以容纳的cell的数量</p>
</p>
<p>launcher:longAxisCells=&quot;5&quot;</p>
</p>
<p>较长的方向上可以容纳的cell的数量 </p>
</p>
<p>shortAxisCells和longAxisCells决定一个workspace（即CellLayout）上可以容纳的item的个数为shortAxisCells*longAxisCells. </p>
</p>
<p>2.application_boxed.xml </p>
</p>
<p>所有应用程序和系统文件夹中item的定义。 </p>
</p>
<p>3.application.xml</p>
</p>
<p>Workspace的item的layout定义。</p>
</p>
</article>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
<div class="mt-3 mb-3" style="max-width: 770px;height: auto;">
                                    </div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.aitaocui.cn/article/375244.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
