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:
- 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 );
- // Set the tag of favorite (a desktop shortcut icon)
- Favorite. settag (Info );
- Favorite. setonclicklistener (this );
- Return favorite;
- }
Copy code
Continue to explain the dragcontroller. startdrag Function
Java code:
- Public void startdrag (view V, dragsource source, object draginfo, int dragaction ){
- // Set the drag-and-drop source view
- Moriginator = V;
- // Obtain the bitmap of the View
- Bitmap B = getviewbitmap (v );
- If (B = NULL ){
- // Out of memory?
- Return;
- }
- // Obtain the coordinates of the Source view on the entire Screen
- Int [] loc = mcoordinatestemp;
- V. getlocationonscreen (LOC );
- Int screenx = loc [0];
- Int screeny = loc [1];
- // Continue to read this function.
- Startdrag (B, screenx, screeny, 0, 0, B. getwidth (), B. getheight (),
- Source, draginfo, dragaction );
- B. Recycle ();
- // Set the original view to invisible
- If (dragaction = drag_action_move ){
- V. setvisibility (view. Gone );
- }
- }
Copy code
Java code:
- Public void startdrag (Bitmap B, int screenx, int screeny, int textureleft, int texturetop, int texturewidth, int textureheight, dragsource source, object draginfo, int dragaction ){
- // Hide the keyboard
- If (minputmethodmanager = NULL ){
- Minputmethodmanager = (inputmethodmanager)
- Mcontext. getsystemservice (context. input_method_service );
- }
- Minputmethodmanager. hidesoftinputfromwindow (mwindowtoken, 0 );
- // Mlistener = deletezone. This function is described in the blog laucher UI framework, mainly in deletezone.
- If (mlistener! = NULL ){
- Mlistener. ondragstart (source, draginfo, dragaction );
- }
- // Remember the offset between the click position of the finger and the position in the upper left corner of the screen
- Int registrationx = (INT) mmotiondownx)-screenx;
- Int registrationy = (INT) mmotiondowny)-screeny;
- Mtouchoffsetx = mmotiondownx-screenx;