Reputation: 1
my intention is to open the application when it is dragged out of the current window area, rather than dragging it to a specific position.
My requirement is to implement a window dock where applications on the dock can be dragged out, and when dragged out, the application should open. I'm using drag and drop to achieve this. By using ACTION_DRAG_EXITED, I can determine if I successfully dragged out, and I modify my shadow to change the view style accordingly. However, after lifting, ACTION_DRAG_ENDED is used to determine if I successfully dragged out, but there is an issue with this approach: it comes with a system animation. I can't cancel this animation, and I can't update the shadow view here in ACTION_DRAG_ENDED.
DragEvent.ACTION_DRAG_STARTED -> {
val v = event.localState as View
v.visibility = View.INVISIBLE
}
DragEvent.ACTION_DRAG_ENTERED -> {
val v = event.localState as View
dragShadow.isDragIn = false
v.updateDragShadow(dragShadow)
}
DragEvent.ACTION_DRAG_EXITED -> {
val v = event.localState as View
dragShadow.isDragIn = true
v.updateDragShadow(dragShadow)
}
DragEvent.ACTION_DRAG_ENDED ->{
(event.localState as View).visibility = View.VISIBLE
if (!event.result) {
val v = event.localState as View
dragShadow.isOutAndDrop = true
v.updateDragShadow(dragShadow)
startActivity()
dismissWindow()
}
}
"I cannot use the target control to listen to the drag listener because my intention is to open the application when it is dragged out of the current window area, rather than dragging it to a specific position."
MyDragShadow:
class MyDragShadowBuilder(view: View) : View.DragShadowBuilder(view) {
var isDragIn = false
var isOutAndDrop = false
override fun onProvideShadowMetrics(outShadowSize: Point?, outShadowTouchPoint: Point?) {
outShadowSize?.set(960, 572)
outShadowTouchPoint?.set(960 / 2, 572 / 2)
}
override fun onDrawShadow(canvas: Canvas) {
if (isOutAndDrop) {
canvas.drawColor(Color.TRANSPARENT, android.graphics.PorterDuff.Mode.CLEAR)
return
}
val backgroundPaint = Paint().apply {
color = if (isDragIn) Color.WHITE else Color.TRANSPARENT
}
canvas.drawRoundRect(
RectF(0f, 0f, 960f, 572f),
8f, 8f,
backgroundPaint
)
if (isDragIn) {
val borderPaint = Paint().apply {
color = Color.parseColor("#4D4D4D")
style = Paint.Style.STROKE
strokeWidth = 1f
}
canvas.drawRoundRect(
RectF(0f, 0f, 960f, 572f),
8f, 8f,
borderPaint
)
}
val viewBitmap = viewToBitmap(view)
val centerX = (960f - viewBitmap.width) / 2f
val centerY = (572f - viewBitmap.height) / 2f
canvas.drawBitmap(viewBitmap, centerX, centerY, null)
}
private fun viewToBitmap(view: View): Bitmap {
val bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
view.draw(canvas)
return bitmap
}
}
Upvotes: 0
Views: 40