forked from upstream-mirrors/quik
Merge pull request #212 from gavine99/select_copy_text_part
[ FEAT REQ ] Select and copy a text part #178
This commit is contained in:
+45
-19
@@ -21,15 +21,17 @@ package dev.octoshrimpy.quik.common.util.extensions
|
|||||||
import android.animation.LayoutTransition
|
import android.animation.LayoutTransition
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.graphics.PorterDuff
|
import android.view.GestureDetector
|
||||||
import android.os.Build
|
import android.view.GestureDetector.SimpleOnGestureListener
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.View.OnTouchListener
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.ProgressBar
|
import android.widget.ProgressBar
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager.widget.ViewPager
|
import androidx.viewpager.widget.ViewPager
|
||||||
|
|
||||||
@@ -83,29 +85,53 @@ fun View.setVisible(visible: Boolean, invisible: Int = View.GONE) {
|
|||||||
*/
|
*/
|
||||||
fun View.forwardTouches(parent: View) {
|
fun View.forwardTouches(parent: View) {
|
||||||
var isLongClick = false
|
var isLongClick = false
|
||||||
|
var textInitiallySelectable = false
|
||||||
|
if (this@forwardTouches is TextView)
|
||||||
|
textInitiallySelectable = this@forwardTouches.isTextSelectable
|
||||||
|
|
||||||
setOnLongClickListener {
|
setOnTouchListener(object : OnTouchListener {
|
||||||
isLongClick = true
|
private val gestureDetector =
|
||||||
true
|
GestureDetector(parent.context, object : SimpleOnGestureListener() {
|
||||||
}
|
private var lastUpEvent: MotionEvent? = null
|
||||||
|
|
||||||
setOnTouchListener { v, event ->
|
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||||
parent.onTouchEvent(event)
|
parent.onTouchEvent(e)
|
||||||
|
if (lastUpEvent !== null) {
|
||||||
|
parent.onTouchEvent(lastUpEvent)
|
||||||
|
lastUpEvent = null
|
||||||
|
}
|
||||||
|
|
||||||
when {
|
return true
|
||||||
event.action == MotionEvent.ACTION_UP && isLongClick -> {
|
}
|
||||||
isLongClick = true
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
event.action == MotionEvent.ACTION_DOWN -> {
|
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||||
isLongClick = false
|
onTouchEvent(e)
|
||||||
v.onTouchEvent(event)
|
lastUpEvent = e
|
||||||
}
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
else -> v.onTouchEvent(event)
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
|
isLongClick = false
|
||||||
|
onTouchEvent(e)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLongPress(e: MotionEvent) {
|
||||||
|
parent.onTouchEvent(e)
|
||||||
|
isLongClick = true
|
||||||
|
// this is kinda odd but we have to 'bounce' the text selectable value so it doesn't
|
||||||
|
// start selecting text on a long press, but will start selecting it on the next double-tap
|
||||||
|
if (this@forwardTouches is TextView) {
|
||||||
|
(this@forwardTouches as TextView).setTextIsSelectable(false)
|
||||||
|
(this@forwardTouches as TextView).setTextIsSelectable(textInitiallySelectable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
override fun onTouch(v: View, e: MotionEvent): Boolean {
|
||||||
|
return gestureDetector.onTouchEvent(e)
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ViewPager.addOnPageChangeListener(listener: (Int) -> Unit) {
|
fun ViewPager.addOnPageChangeListener(listener: (Int) -> Unit) {
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
android:background="@drawable/message_only"
|
android:background="@drawable/message_only"
|
||||||
android:gravity="start|center_vertical"
|
android:gravity="start|center_vertical"
|
||||||
android:minHeight="36dp"
|
android:minHeight="36dp"
|
||||||
|
android:textIsSelectable="true"
|
||||||
app:layout_constrainedWidth="true"
|
app:layout_constrainedWidth="true"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="0"
|
app:layout_constraintHorizontal_bias="0"
|
||||||
|
|||||||
@@ -92,6 +92,7 @@
|
|||||||
android:backgroundTint="?attr/bubbleColor"
|
android:backgroundTint="?attr/bubbleColor"
|
||||||
android:gravity="start|center_vertical"
|
android:gravity="start|center_vertical"
|
||||||
android:minHeight="36dp"
|
android:minHeight="36dp"
|
||||||
|
android:textIsSelectable="true"
|
||||||
app:layout_constrainedWidth="true"
|
app:layout_constrainedWidth="true"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintHorizontal_bias="1"
|
app:layout_constraintHorizontal_bias="1"
|
||||||
|
|||||||
Reference in New Issue
Block a user