Resizable Apps & Multi-Window Support in Android

Mar 30 2021 · Kotlin 1.4, Android 11, Android Studio 4

Part 1: Resizable Apps & Multi-Window Support in Android

07. Enable Drag & Drop Support: Part 1

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 06. Launch Activities In Multi-Window Mode Next episode: 08. Enable Drag & Drop Support: Part 2

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The last feature you’ll learn about that works well with multi-window support is the drag & drop feature.

 private val dragListener by lazy { buildDragListener() }
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    enableDragListener() // here
  }
  private fun enableDragListener() {
    binding.notes.setOnDragListener(dragListener)
    binding.notes.setOnLongClickListener(buildLongClickListener())
  }
private fun buildLongClickListener() = View.OnLongClickListener {


  true
}
  val data = ClipData.Item(binding.notes.text.toString())
  val dragData = ClipData("Notes Data", arrayOf(ClipDescription.MIMETYPE_TEXT_PLAIN), data)
  it.startDragAndDrop(
    dragData,
    View.DragShadowBuilder(binding.notes),
    null,
    View.DRAG_FLAG_GLOBAL
  )
private fun buildDragListener(): View.OnDragListener = View.OnDragListener { _, event ->

  
  true
}
  when (event.action) {
    DragEvent.ACTION_DRAG_STARTED -> {
      binding.notes.setTextColor(getColor(R.color.purple_200))
    }
  }
    DragEvent.ACTION_DRAG_ENDED -> {
      binding.notes.setTextColor(getColor(R.color.teal_700))
    }