看了上面代碼知道,當開始點擊案頭時,celllayout就會根據點擊地區去尋找在該地區是否有child存在,若有把它設定為tag.cell,沒有,tag.cell設定為null,後面在開始拖放時launcher.onlongclick中對tag進行處理,
這個理順了,再深入到workspace.startDrag函數,workspace.startDrag調用DragController.startDrag去處理拖放
mDragController.startDrag(child, this, child.getTag(), DragController.DRAG_ACTION_MOVE);
再分析一下上面調用的幾個參數
child = tag.cell
this = workspace
child.getTag()是什麼呢?在什麼時候被設定?再仔細回顧原來launcher載入過程代碼,在launcher.createShortcut中它被設定了:注意下面我代碼中的注釋
java代碼:
- View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
- TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
- favorite.setCompoundDrawablesWithIntrinsicBounds(null,new FastBitmapDrawable(info.getIcon(mIconCache)),null, null);
- favorite.setText(info.title);
- //設定favorite(一個案頭Shortcut類型的表徵圖)的tag
- favorite.setTag(info);
- favorite.setOnClickListener(this);
- return favorite;
- }
複製代碼
繼續深入解讀DragController.startDrag函數
java代碼:
- public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
- //設定拖放源view
- mOriginator = v;
- //擷取view的bitmap
- Bitmap b = getViewBitmap(v);
- if (b == null) {
- // out of memory?
- return;
- }
- //擷取源view在整個螢幕的座標
- int[] loc = mCoordinatesTemp;
- v.getLocationOnScreen(loc);
- int screenX = loc[0];
- int screenY = loc[1];
- //該函數功能解讀請繼續往下看
- startDrag(b, screenX, screenY, 0, 0, b.getWidth(), b.getHeight(),
- source, dragInfo, dragAction);
- b.recycle();
- //設定原來view不可見
- if (dragAction == DRAG_ACTION_MOVE) {
- v.setVisibility(View.GONE);
- }
- }
複製代碼
java代碼:
- public void startDrag(Bitmap b, int screenX, int screenY,int textureLeft, int textureTop, int textureWidth, int textureHeight,DragSource source, Object dragInfo, int dragAction) {
- //隱藏軟鍵盤
- if (mInputMethodManager == null) {
- mInputMethodManager = (InputMethodManager)
- mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
- }
- mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
- //mListener = deletezone,在blog laucher ui架構中有說明該函數,主要就是現實deletezone
- if (mListener != null) {
- mListener.onDragStart(source, dragInfo, dragAction);
- }
- //記住手指點擊位置與螢幕左上方位置偏差
- int registrationX = ((int)mMotionDownX) - screenX;
- int registrationY = ((int)mMotionDownY) - screenY;
- mTouchOffsetX = mMotionDownX - screenX;