# DragStartHelper

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#nestedclasses)\|[Ctors](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#)  

# DragStartHelper

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
DragStartHelper
`  
`

extends Object


``


`

|---|------------------------------------------|
| java.lang.Object                            ||
| ↳ | android.support.v13.view.DragStartHelper |

<br />

*** ** * ** ***

DragStartHelper is a utility class for implementing drag and drop support.

It detects gestures commonly used to start drag (long click for any input source, click and drag for mouse).

It also keeps track of the screen location where the drag started, and helps determining the hot spot position for a drag shadow.

Implement[DragStartHelper.OnDragStartListener](https://developer.android.com/reference/android/support/v13/view/DragStartHelper.OnDragStartListener)to start the drag operation:  

```
 DragStartHelper.OnDragStartListener listener = new DragStartHelper.OnDragStartListener {
     protected void onDragStart(View view, DragStartHelper helper) {
         View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view) {
             public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) {
                 super.onProvideShadowMetrics(shadowSize, shadowTouchPoint);
                 helper.getTouchPosition(shadowTouchPoint);
             }
         };
         view.startDrag(mClipData, shadowBuilder, mLocalState, mDragFlags);
     }
 };
 mDragStartHelper = new DragStartHelper(mDraggableView, listener);
 
```
Once created, DragStartHelper can be attached to a view (this will replace existing long click and touch listeners):  

```
 mDragStartHelper.attach();
 
```
It may also be used in combination with existing listeners:  

```
 public boolean onTouch(View view, MotionEvent event) {
     if (mDragStartHelper.onTouch(view, event)) {
         return true;
     }
     return handleTouchEvent(view, event);
 }
 public boolean onLongClick(View view) {
     if (mDragStartHelper.onLongClick(view)) {
         return true;
     }
     return handleLongClickEvent(view);
 }
 
```

<br />

## Summary

|                                                                                                                 ### Nested classes                                                                                                                 ||
|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [DragStartHelper.OnDragStartListener](https://developer.android.com/reference/android/support/v13/view/DragStartHelper.OnDragStartListener) Interface definition for a callback to be invoked when a drag start gesture is detected. |

|                                                                                                                                                                                                                                              ### Public constructors                                                                                                                                                                                                                                              ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[DragStartHelper](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#DragStartHelper(android.view.View, android.support.v13.view.DragStartHelper.OnDragStartListener))`(`[View](https://developer.android.com/reference/android/view/View.html)` view, `[DragStartHelper.OnDragStartListener](https://developer.android.com/reference/android/support/v13/view/DragStartHelper.OnDragStartListener)` listener) ` Create a DragStartHelper associated with the specified view. |

|                                                                                                                                                                         ### Public methods                                                                                                                                                                         ||
|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`    | ` `[attach](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#attach())`() ` Attach the helper to the view.                                                                                                                                                                                                             |
| ` void`    | ` `[detach](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#detach())`() ` Detach the helper from the view.                                                                                                                                                                                                           |
| ` void`    | ` `[getTouchPosition](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#getTouchPosition(android.graphics.Point))`(`[Point](https://developer.android.com/reference/android/graphics/Point.html)` point) ` Compute the position of the touch event that started the drag operation.                                     |
| ` boolean` | ` `[onLongClick](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#onLongClick(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View.html)` v) ` Handle a long click event.                                                                                                            |
| ` boolean` | ` `[onTouch](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#onTouch(android.view.View, android.view.MotionEvent))`(`[View](https://developer.android.com/reference/android/view/View.html)` v, `[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent.html)` event) ` Handle a touch event. |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public constructors

### DragStartHelper

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DragStartHelper (View view, 
                DragStartHelper.OnDragStartListener listener)
```

Create a DragStartHelper associated with the specified view. The newly created helper is not initially attached to the view,[attach()](https://developer.android.com/reference/android/support/v13/view/DragStartHelper#attach())must be called explicitly.

<br />

|                        Parameters                        ||
|------------|----------------------------------------------|
| `view`     | `View`: A View <br />                        |
| `listener` | `DragStartHelper.OnDragStartListener` <br /> |

## Public methods

### attach

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void attach ()
```

Attach the helper to the view.

This will replace previously existing touch and long click listeners.

<br />

### detach

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void detach ()
```

Detach the helper from the view.

This will reset touch and long click listeners to`null`.

<br />

### getTouchPosition

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void getTouchPosition (Point point)
```

Compute the position of the touch event that started the drag operation.

<br />

|                                        Parameters                                         ||
|---------|----------------------------------------------------------------------------------|
| `point` | `Point`: The position of the touch event that started the drag operation. <br /> |

### onLongClick

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean onLongClick (View v)
```

Handle a long click event.

<br />

|                       Parameters                        ||
|-----|----------------------------------------------------|
| `v` | `View`: The view that was clicked and held. <br /> |

|                                     Returns                                      ||
|-----------|-----------------------------------------------------------------------|
| `boolean` | true if the callback consumed the long click, false otherwise. <br /> |

### onTouch

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean onTouch (View v, 
                MotionEvent event)
```

Handle a touch event.

<br />

|                                             Parameters                                             ||
|---------|-------------------------------------------------------------------------------------------|
| `v`     | `View`: The view the touch event has been dispatched to. <br />                           |
| `event` | `MotionEvent`: The MotionEvent object containing full information about the event. <br /> |

|                                     Returns                                     ||
|-----------|----------------------------------------------------------------------|
| `boolean` | True if the listener has consumed the event, false otherwise. <br /> |

-

  ## Interfaces

  - [DragStartHelper.OnDragStartListener](https://developer.android.com/reference/android/support/v13/view/DragStartHelper.OnDragStartListener)
-

  ## Classes

  - [DragAndDropPermissionsCompat](https://developer.android.com/reference/android/support/v13/view/DragAndDropPermissionsCompat)
  - [DragStartHelper](https://developer.android.com/reference/android/support/v13/view/DragStartHelper)
  - [ViewCompat](https://developer.android.com/reference/android/support/v13/view/ViewCompat)