4. ITEM_WALLPAPER,墙纸。
下面,我们详细的来说一下launcher内里的详细功能:
1.DragLayer–DragLayer继续FrameLayout,并在此底子上组合了DragController实现拖放功能,DragLayer紧张监听下面两个用户变乱onInterceptTouchEvent和onTouchEvent
并交给DragController举行处理处罚,DragController根据是否在拖放中等信息控制控件拖放过程处理处罚。DragLayer 是Launcher这个activity的顶层view,其着实Launcher2这个应用只有Laucher.java这么一个activity。
2.DeleteZone–
[html] view plain copy
- <com.android.launcher2.DeleteZone
- android:id=“@+id/delete_zone”
- android:layout_width=“@dimen/delete_zone_size”
- android:layout_height=“@dimen/delete_zone_size”
- android:paddingTop=“@dimen/delete_zone_padding”
- android:layout_gravity=“bottom|center_horizontal”
- android:scaleType=“center”
- android:src=“@drawable/delete_zone_selector”
- android:visibility=“invisible”
- launcher:direction=“horizontal”
- />
在launcher.xml中,可以发现,DeleteZone默认是不表现的android:visibility=“invisible”,但是我们每次开始拖放图标的时间DeleteZone就表现了,这个功能是怎样实现的呢?在代码中可以发现DeleteZone实现了DragController.DragListener接口,
[html] view plain copy
- public class DeleteZone extends ImageView implements DropTarget, DragController.DragListener
DragListener提供两个接口方法,
onDragStart:潜伏把手,表现DeleteZone
onDragEnd:表现把手,潜伏DeleteZone
在DeleteZone中,看一下代码:
[java] view plain copy
- public void onDragStart(DragSource source, Object info, int dragAction) {
- final ItemInfo item = (ItemInfo) info;
- if (item != null) {
- mTrashMode = true;
- createAnimations();
- final int[] location = mLocation;
- getLocationOnScreen(location);
- mRegion.set(location[0], location[1], location[0] + mRight - mLeft,
- location[1] + mBottom - mTop);
- mDragController.setDeleteRegion(mRegion);
- mTransition.resetTransition();
- startAnimation(mInAnimation);
- mHandle.startAnimation(mHandleOutAnimation);
- setVisibility(VISIBLE);
- }
- }
- public void onDragEnd() {
- if (mTrashMode) {
- mTrashMode = false;
- mDragController.setDeleteRegion(null);
- startAnimation(mOutAnimation);
- mHandle.startAnimation(mHandleInAnimation);
- setVisibility(GONE);
- }
- }
分别在开始DragController开始拖放和竣事拖放的时间被调用.
别的DeleteZone实现了DropTarget接口的onDrop方法
[java] view plain copy
- public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
- DragView dragView, Object dragInfo) {
- final ItemInfo item = (ItemInfo) dragInfo;
- if (item.container == -1) return;
- if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
- if (item instanceof LauncherAppWidgetInfo) {
- mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
- }
- } else {
- if (source instanceof UserFolder) {
- final UserFolder userFolder = (UserFolder) source;
- final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo();
- // Item must be a ShortcutInfo otherwise it couldn’t have been in the folder
- // in the first place.
- userFolderInfo.remove((ShortcutInfo)item);
- }
- }
- if (item instanceof UserFolderInfo) {
- final UserFolderInfo userFolderInfo = (UserFolderInfo)item;
- LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo);
- mLauncher.removeFolder(userFolderInfo);
- } else if (item instanceof LauncherAppWidgetInfo) {
- final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
- final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
- if (appWidgetHost != null) {
- final int appWidgetId = launcherAppWidgetInfo.appWidgetId;
- // Deleting an app widget ID is a void call but writes to disk before returning
- // to the caller…
- new Thread(“deleteAppWidgetId”) {
- public void run() {
- appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
- }
- }.start();
- }
- }
- LauncherModel.deleteItemFromDatabase(mLauncher, item);
- }
当把图标拖放到DeleteZone,就会调用DeleteZone,实现的onDrop方法对应用图标举行删除处理处罚。
3.屏幕左右移动按钮,就是利用的ImageView,
[html] view plain copy
- <ImageView
- android:id=“@+id/previous_screen”
- android:layout_width=“93dip”
- android:layout_height=“@dimen/button_bar_height”
- android:layout_gravity=“bottom|left”
- android:layout_marginLeft=“6dip”
- android:scaleType=“center”
- android:src=“@drawable/home_arrows_left”
- android
nClick=“previousScreen”
- android:focusable=“true”
- android:clickable=“true” />
- <ImageView
- android:id=“@+id/next_screen”
- android:layout_width=“93dip”
- android:layout_height=“@dimen/button_bar_height”
- android:layout_gravity=“bottom|right”
- android:layout_marginRight=“6dip”
- android:scaleType=“center”
- android:src=“@drawable/home_arrows_right”
- android
nClick=“nextScreen”
- android:focusable=“true”
- android:clickable=“true” />
留意三点,
–1.桌面左右移动时Drawable的变动,变动图标列表可查察home_arrows_right.xml
,ImageView通过把drawable通报给worksapce,当桌面切换时通过调用Drawable.setLevel()方法实现差别图标表现。
–2.当点击实现左右桌面切换,查察上面的布局文件中android nClick=“previousScreen”,该属性界说了一个 onClick变乱相应函数,在Launcher.java中的788行。
[html] view plain copy
- @SuppressWarnings({“UnusedDeclaration”})
- publicvoid previousScreen(View v) {
- if(!isAllAppsVisible()) {
- mWorkspace.scrollLeft();
- }
- }
–3.在(Launcher.setupViews)中添加了长按变乱OnLongClickListener有当长按会实验launcher.onlongclick方法,方法实验表现5个桌面的预览微缩图表现。
4.RelativeLayout–android:id=“@+id/all_apps_button_cluster”,如前面截图右边灰色竖状条,它是一个相对布局对象,上面承载了三个view
中心是一个HandleView,是一个进入allappview的按钮,HandleView的左面是拨号,右面是欣赏器两个ImageView。
–HandleView
自我先容一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里不停到如今。
深知大多数Android工程师,想要提拔技能,通常是自己探索发展大概是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学结果低效又漫长,而且极易碰到天花板技能故步自封!
因此网络整理了一份《2024年Android移动开辟全套学习资料》,初志也很简朴,就是渴望可以或许资助到想自学提拔又不知道该从何学起的朋侪,同时减轻各人的负担。
既有恰当小白学习的零底子资料,也有恰当3年以上履历的小同伴深入学习提拔的进阶课程,根本涵盖了95%以上Android开辟知识点,真正体系化!
由于文件比力大,这里只是将部分目次大纲截图出来,每个节点内里都包罗大厂面经、学习条记、源码课本、实战项目、讲授视频,而且后续会一连更新
如果你以为这些内容对你有资助,可以添加V获取:vip204888 (备注Android)
末了说一下我的学习门路
实在很简朴就下面这张图,含概了Android全部须要学的知识点,一共8大板块:
- 架构师筑基必备技能
- Android框架体系架构(高级UI+FrameWork源码)
- 360°Androidapp全方位性能调优
- 筹划头脑解读开源框架
- NDK模块开辟
- 移动架构师专题项目实战环节
- 移动架构师不可不学习微信小步伐
- 肴杂开辟的flutter
Android学习的资料
我呢,把上面八大板块的分支都体系的做了一份学习体系的资料和视频,大概就下面这些,我就不全部写出来了,否则太长了影响各人的阅读。
330页PDF Android学习焦点条记(内含上面8大板块)
Android学习的体系对应视频
总结
我渴望通过我自己的学习方法来资助各人去提拔技能:
- 1、多看书、看源码和做项目,寻常多种总结
- 2、不能停顿在一些根本api的利用上,应该往更深条理的方向去研究,好比activity、view的内部运行机制,好比Android内存优化,好比aidl,好比JNI等,并不但仅停顿在会用,而要通过阅读源码,明白实在现原理
- 3、同时对架构是有肯定要求的,架构是抽象的,但是筹划模式是详细的,以是肯定要加强下筹划模式的学习
- 4、android的方向大概多,高级UI,移动架构师,数据布局与算法和音视频FFMpeg解码,如果你对此中一项比力感爱好,就大胆的进阶吧!
渴望各人多多点赞,转发,批评加关注,你们的支持就是我继续下去的动力!加油!
,好比activity、view的内部运行机制,好比Android内存优化,好比aidl,好比JNI等,并不但仅停顿在会用,而要通过阅读源码,明白实在现原理
- 3、同时对架构是有肯定要求的,架构是抽象的,但是筹划模式是详细的,以是肯定要加强下筹划模式的学习
- 4、android的方向大概多,高级UI,移动架构师,数据布局与算法和音视频FFMpeg解码,如果你对此中一项比力感爱好,就大胆的进阶吧!
渴望各人多多点赞,转发,批评加关注,你们的支持就是我继续下去的动力!加油!
[外链图片转存中…(img-z7g8XMA2-1712654290145)]
|