http://lostghoul.blog.163.com/blog/static/11172199920112149294214/
在Workspace.Java类实现,相关方法有:
addInCurrentScreen(): Adds the specified child in the current screen. The position and dimension尺寸 of the child are defined by x, y, spanX and spanY.
setOnLongClickListener():param l (参数l) The listener used to respond to long clicks
computeScroll():重写了父类的computeScroll();主要功能是计算拖动的位移量、更新背景、设置要显示的屏幕 (setCurrentScreen(mCurrentScreen);)。
dispatchDraw():重写了父类的dispatchDraw();主要功能是判断抽屉是否打开、绘制指定的屏幕,可以绘制当前一屏,也可以绘制 当前屏幕和下一屏幕,也可以绘制所有的屏幕,这儿的绘制指显示屏幕上的child(例如:app、folder、Wiget、shortcut)。和 computeScroll()中的setCurrentScreen(mCurrentScreen)方法配合使用可以实现屏幕的拖动多少显示多少的 功能。
onMeasure():重写了父类的onMeasure();主要功能是设置屏幕的显示大小。由每个child的measure()方法设置。
onLayout():重写了父类的onLayout();主要功能是设置屏幕的显示位置。由child的layout()方法设置。
onRequestFocusInDescendants():获得焦点。
dispatchUnhandledMove():根据滑动方向判断是否可以移动(到没到头)
addFocusables():View一般通过requestfocus获取焦点,当然前提是他们“能够”获得。通过复写addFocusables函数来为当前ViewGroup中 的所有子View添加焦点获取能力。然后当屏幕被遮盖又恢复后,ViewGroup会首先收到requestfocus消息,并在下列代码中作出相应处理.
dispatchTouchEvent():如果向下滑动时。锁屏或所有app可见,则返回false
onInterceptTouchEvent():重写了父类的onInterceptTouchEvent();主要功能是在 onTouchEvent()方法之前处理touch事件。包括:down、up、move事件。
用xy记录鼠标移动时的坐标值;
mLastMotionX和mLastMotionY记录了上次鼠标按下时的XY值,在ACTION_MOVE中赋值;
xDiff和yDiff记录xy与mLastMotionX、mLastMotionY差值的绝对值;
touchSlop为系统定义的标准值,初值为16;
当xDiff和yDiff大于touchSlop时就认为界面拖动了足够大的距离,屏幕就可以移动了;
当onInterceptTouchEvent()返回true时进入onTouchEvent()。
onTouchEvent():重写了父类的onTouchEvent();主要功能是处理onInterceptTouchEvent()返回值为 true时传递过来的touch事件。