-
-
Save pavan5208/718e3d92c5611fbbc020f4b90a410803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun addOnTouchListener(params: WindowManager.LayoutParams) { | |
//Add touch listerner to floating controls view to move/close/expand the controls | |
floatingControlView?.setOnTouchListener(object : View.OnTouchListener { | |
private var initialTouchX = 0f | |
private var initialTouchY = 0f | |
private var initialX = 0 | |
private var initialY = 0 | |
override fun onTouch(view: View?, motionevent: MotionEvent): Boolean { | |
val flag3: Boolean | |
flag3 = true | |
var flag = false | |
when (motionevent.action) { | |
MotionEvent.ACTION_DOWN -> { | |
params.alpha = 1.0f | |
initialX = params.x | |
initialY = params.y | |
initialTouchX = motionevent.rawX | |
initialTouchY = motionevent.rawY | |
Log.d( | |
"OnTouchListener", | |
java.lang.StringBuilder("POS: x = ") | |
.append(initialX).append(" y = ") | |
.append(initialY).append(" tx = ") | |
.append(initialTouchX) | |
.append(" ty = ") | |
.append(initialTouchY).toString() | |
) | |
return true | |
} | |
MotionEvent.ACTION_UP -> { | |
flag = flag3 | |
if (Math.abs(initialTouchX - motionevent.rawX) >= 25f) { | |
return flag | |
} else { | |
flag = flag3 | |
if (Math.abs( | |
initialTouchY | |
- motionevent.rawY | |
) >= 25f | |
) { | |
return flag | |
} else { | |
return true | |
} | |
} | |
} | |
MotionEvent.ACTION_MOVE -> { | |
initialX = params.x | |
initialY = params.y | |
if ((motionevent.rawX < (initialX - iconWidth / 2).toFloat()) || (motionevent.rawY < (initialY - iconHeight / 2).toFloat()) || (motionevent.rawX | |
.toDouble() > initialX.toDouble() + iconWidth.toDouble() * 1.2) | |
) { | |
} | |
params.x = (motionevent.rawX - (iconWidth / 2).toFloat()).toInt() | |
params.y = (motionevent.rawY - iconHeight.toFloat()).toInt() | |
try { | |
windowManager?.updateViewLayout(floatingControlView, params) | |
} // Misplaced declaration of an exception | |
// variable | |
catch (e: java.lang.Exception) { | |
e.printStackTrace() | |
// ExceptionHandling(e) | |
return true | |
} | |
return true | |
} | |
else -> { | |
} | |
} | |
return flag | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment