当前位置:网站首页>Drag and drop frame

Drag and drop frame

2022-06-23 05:18:00 xhBruce

Drag and drop Drag and drop frame

android11-release
Application and use Drag and drop Drag and drop


Drag and drop Drag and drop launch

APP Call start

Drag and drop Drag and dropstartDragAndDrop start-up
frameworks/base/core/java/android/view/View.java
 Insert picture description here
frameworks\base\services\core\java\com\android\server\wm\Session.java
 Insert picture description here

initialization DragState And register InputChannel

  • initialization DragState
  • register drag InputChannel\DragInputEventReceiver
  • Notify drag and drop to start mDragState.broadcastDragStartedLocked(touchX, touchY); Trigger DragEvent.ACTION_DRAG_STARTED

frameworks/base/services/core/java/com/android/server/wm/DragDropController.java
 Insert picture description here
frameworks/base/services/core/java/com/android/server/wm/DragState.java
frameworks/base/services/core/java/com/android/server/wm/WindowManagerInternal.java
frameworks/base/services/core/java/com/android/server/wm/DragInputEventReceiver.java
 Insert picture description here  Insert picture description here
 Insert picture description here

Last notifyLocationLocked

  • (touchedWin != mTargetWindow) && (mTargetWindow != null) Trigger when DragEvent.ACTION_DRAG_EXITED
  • touchedWin != null Trigger when DragEvent.ACTION_DRAG_LOCATION
     Insert picture description here
  • adopt ViewRootImplmpl Layer upon layer ,result = mView.dispatchDragEvent(event) notice APP And accept the return value
  • li.mOnDragListener.onDrag(this, event) Genuine notification APP
    frameworks/base/core/java/android/view/ViewRootImpl.java
    frameworks/base/core/java/android/view/View.java
     Insert picture description here  Insert picture description here  Insert picture description here  Insert picture description here

Drag and drop Drag and drop start summary :

  1. APP start-up startDragAndDrop, and View.OnDragListener monitor
  2. initialization DragState And register drag InputChannel\DragInputEventReceiver;
  3. ViewRootImpl in result = mView.dispatchDragEvent(event); Send to View, Notice the return value here result
  4. View in li.mOnDragListener.onDrag(this, event) Notice to APP monitor
  5. SurfaceControl Control display Surface, This display is similar to the general WMS Show different
    Drag and drop Drag and drop start summary

Drag and drop Drag and drop action Trigger problem

public static final int ACTION_DRAG_STARTED = 1;
public static final int ACTION_DRAG_LOCATION = 2;
public static final int ACTION_DROP = 3;
public static final int ACTION_DRAG_ENDED = 4;
public static final int ACTION_DRAG_ENTERED = 5;
public static final int ACTION_DRAG_EXITED = 6;

- ACTION_DRAG_STARTED

 When the application calls  startDragAndDrop\startDrag  And get after dragging the shadow , The drag event listener of the view object will immediately receive this event action type .

1 Trigger

You can also see initialization above registerInputChannel After completion mDragState.broadcastDragStartedLocked(touchX, touchY) Notification complete :
performDrag -> broadcastDragStartedLocked -> sendDragStartedLocked -> newWin.mClient.dispatchDragEvent(event)\dispatchDragEvent(DragEvent event) -> handleDragEvent

2 notice APP Operation before listening

frameworks/base/core/java/android/view/ViewRootImpl.java
handleDragEvent Set in mCurrentDragView = null;mDragDescription preservation event.mClipDescription
 Insert picture description here

3 result = mView.dispatchDragEvent(event) Return value

result No matter back to true or false No other treatment , All have no other effect .

- ACTION_DRAG_LOCATION

 When I received  ACTION_DRAG_ENTERED  Event and the drag shadow is still within the bounding box of the view , The drag event listener of the view object will receive this event action type .

1 Trigger

Registered here drag InputChannel\DragInputEventReceiver, received ACTION_MOVE Event call mDragDropController.handleMotionEvent(Android 12 beta4 There is no operation here ),!mMuteInput Finally call to mDragState.notifyMoveLocked.

frameworks/base/services/core/java/com/android/server/wm/DragInputEventReceiver.java
frameworks/base/services/core/java/com/android/server/wm/DragDropController.java
frameworks/base/services/core/java/com/android/server/wm/DragState.java
 Insert picture description here  Insert picture description here

stay DragState in notifyLocationLocked adopt touchedWin.mClient.dispatchDragEvent(evt) Call to ViewRootImpl in handleDragEvent

 Insert picture description here
Summary of process :drag InputChannel\DragInputEventReceiver -> handleMotionEvent -> notifyMoveLocked\notifyLocationLocked -> touchedWin.mClient.dispatchDragEvent(evt)\dispatchDragEvent(DragEvent event) -> handleDragEvent

2 notice APP Operation before listening

frameworks/base/core/java/android/view/ViewRootImpl.java
 Insert picture description here
 Insert picture description here

3 result = mView.dispatchDragEvent(event) Return value

result No matter back to true or false,!event.mEventHandlerWasCalled Judgment execution setDragFocus.
 Insert picture description here  Insert picture description here

- ACTION_DROP

 When the user releases the drag shadow onto the view object , The drag event listener of the view object will receive this event action type . Only if the listener of the view object is responding  ACTION_DRAG_STARTED  Returns a Boolean value when dragging an event  true  when , The system will send the operation type to the listener . If the user releases the drag shadow on a view that does not have a registered listener or on any view that does not belong to the current layout , The system will not send this operation type .
 If the drop operation is successfully handled , The listener should return a Boolean value  true. otherwise , It should return  false.

1 Trigger

Registered here drag InputChannel\DragInputEventReceiver, received ACTION_UP\ACTION_CANCEL Event call mDragDropController.handleMotionEvent(Android 12 beta4 There is no operation here ),!mMuteInput Finally call to mDragState.notifyDropLocked.

stay DragState in notifyLocationLocked adopt touchedWin.mClient.dispatchDragEvent(evt) Call to ViewRootImpl in handleDragEvent

 Insert picture description here
Summary of process :drag InputChannel\DragInputEventReceiver -> handleMotionEvent -> notifyMoveLocked\notifyLocationLocked -> touchedWin.mClient.dispatchDragEvent(evt)\dispatchDragEvent(DragEvent event) -> handleDragEvent

And ACTION_DRAG_LOCATION The difference is the timeout here 5s perform mDragState.endDragLocked()

 Insert picture description here  Insert picture description here

It may not trigger DragEvent.ACTION_DROP,closeLocked() End trigger DragEvent.ACTION_DRAG_ENDED

 Insert picture description here  Insert picture description here

2 notice APP Operation before listening

frameworks/base/core/java/android/view/ViewRootImpl.java
 Insert picture description here
 Insert picture description here

3 result = mView.dispatchDragEvent(event) return true situation

APP return true End drag and drop closeLocked() End trigger DragEvent.ACTION_DRAG_ENDED
 Insert picture description here  Insert picture description here
 Insert picture description here

- ACTION_DRAG_ENDED

 When the system ends the drag operation , The drag event listener of the view object will receive this event action type .
 This operation type is not necessarily in  ACTION_DROP  After the event .
 If the system has sent  ACTION_DROP, received  ACTION_DRAG_ENDED  The operation type does not mean that the drop operation is successful .
 The listener must call  getResult()  To get a response  ACTION_DROP  The value returned when .
 If not sent  ACTION_DROP  event ,getResult()  Will return  false.

1 Trigger

Read here , You can see on it closeLocked() Methods the trigger DragEvent.ACTION_DRAG_ENDED
 Insert picture description here
Log off here first drag input channel
 Insert picture description here

2 notice APP Operation before listening

 Insert picture description here

3 result = mView.dispatchDragEvent(event) Return value

result No matter back to true or false All reset
 Insert picture description here

- ACTION_DRAG_ENTERED\ACTION_DRAG_EXITED

**ACTION_DRAG_ENTERED** When you drag the shadow just into the bounding box of the view , The drag event listener of the view object will receive this event action type . This is the first event action type that the listener receives when dragging a shadow into the bounding box . If the listener wants to continue receiving drag events for this operation , Boolean values must be returned to the system  true.
**ACTION_DRAG_EXITED** When I received  ACTION_DRAG_ENTERED  And at least one  ACTION_DRAG_LOCATION  event , And when the user has moved the drag shadow outside the bounding box of the view , The drag event listener of the view object will receive this event action type .

1 Trigger

See from above setDragFocus Setting refresh will trigger
 Insert picture description here

2 Call directly callDragEventHandler

ACTION_DRAG_ENTERED Description returns true, I don't see why
 Insert picture description here

原网站

版权声明
本文为[xhBruce]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230225033562.html