Giter Club home page Giter Club logo

drag-and-drop's Introduction

Drag-and-drop

Drag and Drop any object from one view to another.

Steps

  1. Implement Long Click Listeners

    imageView.setOnLongClickListener( v -> { ... })

  2. Create ClipItem and ClipData object

Old Way
val clipItem = ClipData.Item(textMessage)
val mimeType = arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN)
val clipData2 = ClipData(label, mimeType, clipItem)
New/Simple Way
val clipData = ClipData.newPlainText(label, textMessage)

Instantiate the drag shadow builder.

View.DragShadowBuilder(binding.sivSrc)

Call startDragAndDrop() to start dragging.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
    view.startDragAndDrop(clipData, shadowBuilder, null, 0)
else
    view.startDrag(clipData, shadowBuilder, null, 0)

Drag Listeners

Implements drag listener to handle results
view.setOnDragListener { v, event -> 
    true
}

Working Algorithm

When user make a UI gesture, app recognizes as a signal to start dragging. Thus, 
system invoke drag listeners for us and provide a drag shadow. If dragging is released onto a 
receiving view that accepts the data (a drop target), the system will send data to target.

Building Blocks

-> Drag Class
-> Drag Listeners

Drag Shadow Builder

Its constructor is of two types:

  1. DragShadowBuilder(View) -> Pass the view to generate the shadow

  2. DragShadowBuilder() -> With empty Constuctor either extend View.DragShadowBuilder and override its method or you will get an invisible dragging.

Drag and Drop Process

There are four basic steps for drag and drop:
1) Started
2) Continuing 
3) Dropped
4) Ended    

drag-and-drop's People

Contributors

epegasus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.