mirror of
https://github.com/jrpie/Launcher.git
synced 2025-04-12 15:24:31 +02:00
Compare commits
2 commits
c1511cd475
...
72f9c0595f
Author | SHA1 | Date | |
---|---|---|---|
72f9c0595f | |||
75b22400c5 |
4 changed files with 28 additions and 8 deletions
|
@ -87,24 +87,40 @@ class TouchGestureDetector(
|
||||||
}
|
}
|
||||||
|
|
||||||
private var paths = HashMap<Int, PointerPath>()
|
private var paths = HashMap<Int, PointerPath>()
|
||||||
private var gestureIsLongClick = false
|
|
||||||
|
/* Set when
|
||||||
|
* - the longPressHandler has detected this gesture as a long press
|
||||||
|
* - the gesture was cancelled by MotionEvent.ACTION_CANCEL
|
||||||
|
* In any case, the current gesture should be ignored by further detection logic.
|
||||||
|
*/
|
||||||
|
private var cancelled = false
|
||||||
|
|
||||||
private var lastTappedTime = 0L
|
private var lastTappedTime = 0L
|
||||||
private var lastTappedLocation: Vector? = null
|
private var lastTappedLocation: Vector? = null
|
||||||
|
|
||||||
fun onTouchEvent(event: MotionEvent) {
|
fun onTouchEvent(event: MotionEvent) {
|
||||||
|
|
||||||
|
if (event.actionMasked == MotionEvent.ACTION_CANCEL) {
|
||||||
|
synchronized(this@TouchGestureDetector) {
|
||||||
|
cancelled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val pointerIdToIndex =
|
val pointerIdToIndex =
|
||||||
(0..<event.pointerCount).associateBy { event.getPointerId(it) }
|
(0..<event.pointerCount).associateBy { event.getPointerId(it) }
|
||||||
|
|
||||||
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
if (event.actionMasked == MotionEvent.ACTION_DOWN) {
|
||||||
synchronized(this@TouchGestureDetector) {
|
synchronized(this@TouchGestureDetector) {
|
||||||
paths = HashMap()
|
paths = HashMap()
|
||||||
gestureIsLongClick = false
|
cancelled = false
|
||||||
}
|
}
|
||||||
longPressHandler.postDelayed({
|
longPressHandler.postDelayed({
|
||||||
synchronized(this@TouchGestureDetector) {
|
synchronized(this@TouchGestureDetector) {
|
||||||
|
if (cancelled) {
|
||||||
|
return@postDelayed
|
||||||
|
}
|
||||||
if (paths.entries.size == 1 && paths.entries.firstOrNull()?.value?.isTap() == true) {
|
if (paths.entries.size == 1 && paths.entries.firstOrNull()?.value?.isTap() == true) {
|
||||||
gestureIsLongClick = true
|
cancelled = true
|
||||||
Gesture.LONG_CLICK.invoke(context)
|
Gesture.LONG_CLICK.invoke(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +158,7 @@ class TouchGestureDetector(
|
||||||
// if the long press handler is still running, kill it
|
// if the long press handler is still running, kill it
|
||||||
longPressHandler.removeCallbacksAndMessages(null)
|
longPressHandler.removeCallbacksAndMessages(null)
|
||||||
// if the gesture was already detected as a long click, there is nothing to do
|
// if the gesture was already detected as a long click, there is nothing to do
|
||||||
if (gestureIsLongClick) {
|
if (cancelled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,21 @@
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:src="@mipmap/ic_launcher_round"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/list_apps_row_name"
|
android:id="@+id/list_apps_row_name"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="60sp"
|
android:layout_marginStart="20sp"
|
||||||
android:gravity="start"
|
android:gravity="start"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
|
tools:text="@string/app_name"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toEndOf="@id/list_apps_row_icon"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -15,6 +15,7 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
tools:src="@mipmap/ic_launcher_round"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -25,7 +26,7 @@
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="5dp"
|
||||||
android:text=""
|
android:text=""
|
||||||
android:textSize="11sp"
|
android:textSize="11sp"
|
||||||
tools:text="some app"
|
tools:text="@string/app_name"
|
||||||
app:layout_constraintTop_toBottomOf="@id/list_apps_row_icon"
|
app:layout_constraintTop_toBottomOf="@id/list_apps_row_icon"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
@ -32,6 +32,6 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
tools:text="some app" />
|
tools:text="@string/app_name" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Add table
Reference in a new issue