Android 深入研究拖放功能Launcher(二)

來源:互聯網
上載者:User

  看了上面代碼知道,當開始點擊案頭時,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代碼:

  1. View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) {
  2. TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
  3. favorite.setCompoundDrawablesWithIntrinsicBounds(null,new FastBitmapDrawable(info.getIcon(mIconCache)),null, null);
  4. favorite.setText(info.title);
  5. //設定favorite(一個案頭Shortcut類型的表徵圖)的tag
  6. favorite.setTag(info);
  7. favorite.setOnClickListener(this);
  8. return favorite;
  9. }

複製代碼

       繼續深入解讀DragController.startDrag函數

java代碼:

  1. public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
  2. //設定拖放源view
  3. mOriginator = v;
  4. //擷取view的bitmap
  5. Bitmap b = getViewBitmap(v);
  6. if (b == null) {
  7. // out of memory?
  8. return;
  9. }
  10. //擷取源view在整個螢幕的座標
  11. int[] loc = mCoordinatesTemp;
  12. v.getLocationOnScreen(loc);
  13. int screenX = loc[0];
  14. int screenY = loc[1];
  15. //該函數功能解讀請繼續往下看
  16. startDrag(b, screenX, screenY, 0, 0, b.getWidth(), b.getHeight(),
  17. source, dragInfo, dragAction);
  18. b.recycle();
  19. //設定原來view不可見
  20. if (dragAction == DRAG_ACTION_MOVE) {
  21. v.setVisibility(View.GONE);
  22. }
  23. }

複製代碼

java代碼:

  1. public void startDrag(Bitmap b, int screenX, int screenY,int textureLeft, int textureTop, int textureWidth, int textureHeight,DragSource source, Object dragInfo, int dragAction) {
  2. //隱藏軟鍵盤
  3. if (mInputMethodManager == null) {
  4. mInputMethodManager = (InputMethodManager)
  5. mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
  6. }
  7. mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
  8. //mListener = deletezone,在blog laucher ui架構中有說明該函數,主要就是現實deletezone
  9. if (mListener != null) {
  10. mListener.onDragStart(source, dragInfo, dragAction);
  11. }
  12. //記住手指點擊位置與螢幕左上方位置偏差
  13. int registrationX = ((int)mMotionDownX) - screenX;
  14. int registrationY = ((int)mMotionDownY) - screenY;
  15. mTouchOffsetX = mMotionDownX - screenX;

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.