DroidFS/app/src/main/java/sushi/hardcore/droidfs/widgets/TakePhotoButton.kt

28 lines
894 B
Kotlin
Raw Normal View History

2020-08-05 14:06:54 +02:00
package sushi.hardcore.droidfs.widgets
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatImageView
class TakePhotoButton: AppCompatImageView {
constructor(context: Context) : super(context) { init() }
constructor(context: Context, attrs: AttributeSet): super(context, attrs) { init() }
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int): super(context, attrs, defStyleAttr) { init() }
2021-06-07 16:34:50 +02:00
lateinit var onClick: () -> Unit
2020-08-05 14:06:54 +02:00
2021-06-07 16:34:50 +02:00
private fun init() {
setOnTouchListener{ view, event ->
view.performClick()
2020-08-05 14:06:54 +02:00
when (event.action) {
MotionEvent.ACTION_DOWN -> onClick()
MotionEvent.ACTION_UP -> isPressed = true
}
true
}
}
fun onPhotoTaken(){
isPressed = false
}
}