diff options
author | Allan Wang <me@allanwang.ca> | 2019-07-01 23:32:45 -0700 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-07-01 23:32:45 -0700 |
commit | 5ec00376fa6be5530cdd16cd5228f868f5680798 (patch) | |
tree | a023a4809fe1d95a1f2f3cdcb59372da575f54ba /app/src/main/kotlin/com/pitchedapps/frost/views | |
parent | 05bf31e1b0f2d5398e2b1cf01b2015c64636598f (diff) | |
download | frost-5ec00376fa6be5530cdd16cd5228f868f5680798.tar.gz frost-5ec00376fa6be5530cdd16cd5228f868f5680798.tar.bz2 frost-5ec00376fa6be5530cdd16cd5228f868f5680798.zip |
Add swipe to dismiss
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/views')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/views/DragFrame.kt | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/views/DragFrame.kt b/app/src/main/kotlin/com/pitchedapps/frost/views/DragFrame.kt new file mode 100644 index 00000000..db9b901b --- /dev/null +++ b/app/src/main/kotlin/com/pitchedapps/frost/views/DragFrame.kt @@ -0,0 +1,40 @@ +package com.pitchedapps.frost.views + +import android.annotation.SuppressLint +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import android.widget.FrameLayout +import androidx.core.view.ViewCompat +import androidx.customview.widget.ViewDragHelper + +class DragFrame @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : FrameLayout(context, attrs, defStyleAttr) { + var dragHelper: ViewDragHelper? = null + + override fun onInterceptTouchEvent(event: MotionEvent): Boolean { + return try { + dragHelper?.shouldInterceptTouchEvent(event) ?: false + } catch (e: Exception) { + false + } + } + + @SuppressLint("ClickableViewAccessibility") + override fun onTouchEvent(event: MotionEvent): Boolean { + try { + dragHelper?.processTouchEvent(event) ?: return false + } catch (e: Exception) { + return false + } + return true + } + + override fun computeScroll() { + super.computeScroll() + if (dragHelper?.continueSettling(true) == true) { + ViewCompat.postInvalidateOnAnimation(this) + } + } +}
\ No newline at end of file |