Android deeply researches the drag-and-drop function launcher (2)

Source: Internet
Author: User

After reading the code above, we can see that when we start to click the desktop, celllayout will check whether there is a child in the selected area based on the clicked area. If so, we can set it as a tag. cell, no, Tag. cell is set to null, and launcher is later started when drag and drop. onlongclick processes tags,

This straighten out, and then go deep into the workspace. startdrag function. workspace. startdrag calls dragcontroller. startdrag to process drag and drop

Mdragcontroller. startdrag (child, this, child. gettag (), dragcontroller. drag_action_move );
Analyze the parameters called above

  Child = tag. Cell
This = Workspace

What is child. gettag? When will it be set? Review the code of the original launcher loading process. It is set in launcher. createshortcut. Note the following annotations in my code:

Java code:

  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. // Set the tag of favorite (a desktop shortcut icon)
  6. Favorite. settag (Info );
  7. Favorite. setonclicklistener (this );
  8. Return favorite;
  9. }

Copy code

Continue to explain the dragcontroller. startdrag Function

Java code:

  1. Public void startdrag (view V, dragsource source, object draginfo, int dragaction ){
  2. // Set the drag-and-drop source view
  3. Moriginator = V;
  4. // Obtain the bitmap of the View
  5. Bitmap B = getviewbitmap (v );
  6. If (B = NULL ){
  7. // Out of memory?
  8. Return;
  9. }
  10. // Obtain the coordinates of the Source view on the entire Screen
  11. Int [] loc = mcoordinatestemp;
  12. V. getlocationonscreen (LOC );
  13. Int screenx = loc [0];
  14. Int screeny = loc [1];
  15. // Continue to read this function.
  16. Startdrag (B, screenx, screeny, 0, 0, B. getwidth (), B. getheight (),
  17. Source, draginfo, dragaction );
  18. B. Recycle ();
  19. // Set the original view to invisible
  20. If (dragaction = drag_action_move ){
  21. V. setvisibility (view. Gone );
  22. }
  23. }

Copy code

Java code:

  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. // Hide the keyboard
  3. If (minputmethodmanager = NULL ){
  4. Minputmethodmanager = (inputmethodmanager)
  5. Mcontext. getsystemservice (context. input_method_service );
  6. }
  7. Minputmethodmanager. hidesoftinputfromwindow (mwindowtoken, 0 );
  8. // Mlistener = deletezone. This function is described in the blog laucher UI framework, mainly in deletezone.
  9. If (mlistener! = NULL ){
  10. Mlistener. ondragstart (source, draginfo, dragaction );
  11. }
  12. // Remember the offset between the click position of the finger and the position in the upper left corner of the screen
  13. Int registrationx = (INT) mmotiondownx)-screenx;
  14. Int registrationy = (INT) mmotiondowny)-screeny;
  15. Mtouchoffsetx = mmotiondownx-screenx;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.