Android 深入研究拖放功能Launcher(一)
来源:互联网 发布:ubuntu怎么安装到u盘 编辑:程序博客网 时间:2024/06/10 17:04
Luancher有一个相对比较复杂的功能就是拖放功能,要深入了解launcher,深入理解拖放功能是有必要的,这篇blog,我将对launcher的拖放功能做深入的了解
1.首先直观感受什么时候开始拖放?我们长按桌面一个应用图标或者控件的时候拖放就开始了,包括在all app view中长按应用图标,下面就是我截取的拖放开始的代码调用堆栈
java代码:
复制代码
桌面应用图标由Launcher.onLongClick负责监听处理,插入断点debug进入onLongclick函数
java代码:复制代码
我上面只写出关键代码,首先是获取被拖动的对象v.getTag(),Tag什么时候被设置进去的了
java代码:
复制代码
1.首先直观感受什么时候开始拖放?我们长按桌面一个应用图标或者控件的时候拖放就开始了,包括在all app view中长按应用图标,下面就是我截取的拖放开始的代码调用堆栈
java代码:
- at com.android.launcher2.DragController.startDrag
- at com.android.launcher2.Workspace.startDrag
- at com.android.launcher2.Launcher.onLongClick
- at android.view.View.performLongClick
- at android.widget.TextView.performLongClick
- at android.view.View$CheckForLongPress.run
- at android.os.Handler.handleCallback
- at android.os.Handler.dispatchMessage
- at android.os.Looper.loop
桌面应用图标由Launcher.onLongClick负责监听处理,插入断点debug进入onLongclick函数
java代码:
- if (!(v instanceof CellLayout)) {
- v = (View) v.getParent();
- }
- //获取桌面CellLayout上一个被拖动的对象
- CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
- if (mWorkspace.allowLongPress()) {
- if (cellInfo.cell == null) {
- } else {
- if (!(cellInfo.cell instanceof Folder)) {
- //调用Workspace.startDrag处理拖动
- mWorkspace.startDrag(cellInfo);
- }
- }
- }
我上面只写出关键代码,首先是获取被拖动的对象v.getTag(),Tag什么时候被设置进去的了
java代码:
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- if (action == MotionEvent.ACTION_DOWN) {
- boolean found = false;
- for (int i = count - 1; i >= 0; i--) {
- final View child = getChildAt(i);
- if ((child.getVisibility()) == VISIBLE || child.getAnimation() != null) {
- child.getHitRect(frame);
- //判断区域是否在这个子控件的区间,如果有把child信息赋给mCellInfo
- if (frame.contains(x, y)) {
- final LayoutParams lp = (LayoutParams) child.getLayoutParams();
- cellInfo.cell = child;
- cellInfo.cellX = lp.cellX;
- cellInfo.cellY = lp.cellY;
- cellInfo.spanX = lp.cellHSpan;
- cellInfo.spanY = lp.cellVSpan;
- cellInfo.valid = true;
- found = true;
- mDirtyTag = false;
- break;
- }
- }
- }
- mLastDownOnOccupiedCell = found;
- if (!found) {
- //没有child view 说明没有点击桌面图标项
- cellInfo.cell = null;
- }
- setTag(cellInfo);
- }
- Android 深入研究拖放功能Launcher(一)
- Android Launcher 拖放功能深入研究
- Android 深入研究拖放功能Launcher(二)
- android Launcher——拖放功能深入研究
- android Launcher——拖放功能深入研究
- android Launcher——拖放功能深入研究
- android Launcher——拖放功能深入研究
- android Launcher——拖放功能深入研究
- Launcher——拖放功能深入研究 (转)
- android Launcher研究(一)
- 【转】Android Launcher研究 (一)
- android launcher3拖放功能深入剖析
- Android launcher - Launcher(一)
- Launcher数据库研究(一)
- Android Launcher研究一(编译Android4.0 launcher 源码 上)
- Android Launcher源码研究(一) 基本结构
- Android 深入研究adb(一)
- Android Download 下载功能深入研究(一) : android下载功能的初探与实现
- windows系统上安装配置使用Android NDK r5
- new & delete
- Freemarker语法基础
- DisplayObject显示对象之间的关系
- 使用GDI绘制矩形
- Android 深入研究拖放功能Launcher(一)
- 职场饭桌:请上司吃饭的学问
- 惠普xp网卡驱动
- DWZ框架中修改默认主页
- flex组件生命周期
- Hibernate Sql优化方案及索引使用
- com.mysql.jdbc.CommunicationsException: Communications link failure
- Cocos2d宏的数学解释
- 调用《构造SqlDataAdapter InsertCommand和UpdateCommand 帮助类解决并发冲突》方法