mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-22 22:11:27 +01:00
add <,>,V,Λ gestures
This commit is contained in:
parent
0c0d90a357
commit
5669279c64
4 changed files with 120 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
package de.jrpie.android.launcher.actions
|
package de.jrpie.android.launcher.actions
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.util.Log
|
||||||
import de.jrpie.android.launcher.R
|
import de.jrpie.android.launcher.R
|
||||||
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
import de.jrpie.android.launcher.preferences.LauncherPreferences
|
||||||
|
|
||||||
|
@ -169,6 +170,54 @@ enum class Gesture(
|
||||||
R.array.default_double_right,
|
R.array.default_double_right,
|
||||||
R.anim.left_right
|
R.anim.left_right
|
||||||
),
|
),
|
||||||
|
SWIPE_LARGER(
|
||||||
|
"action.larger",
|
||||||
|
R.string.settings_gesture_swipe_larger,
|
||||||
|
R.string.settings_gesture_description_swipe_larger,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_LARGER_REVERSE(
|
||||||
|
"action.larger_reverse",
|
||||||
|
R.string.settings_gesture_swipe_larger_reverse,
|
||||||
|
R.string.settings_gesture_description_swipe_larger_reverse,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_SMALLER(
|
||||||
|
"action.smaller",
|
||||||
|
R.string.settings_gesture_swipe_smaller,
|
||||||
|
R.string.settings_gesture_description_swipe_smaller,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_SMALLER_REVERSE(
|
||||||
|
"action.smaller_reverse",
|
||||||
|
R.string.settings_gesture_swipe_smaller_reverse,
|
||||||
|
R.string.settings_gesture_description_swipe_smaller_reverse,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_LAMBDA(
|
||||||
|
"action.lambda",
|
||||||
|
R.string.settings_gesture_swipe_lambda,
|
||||||
|
R.string.settings_gesture_description_swipe_lambda,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_LAMBDA_REVERSE(
|
||||||
|
"action.lambda_reverse",
|
||||||
|
R.string.settings_gesture_swipe_lambda_reverse,
|
||||||
|
R.string.settings_gesture_description_swipe_lambda_reverse,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_V(
|
||||||
|
"action.v",
|
||||||
|
R.string.settings_gesture_swipe_v,
|
||||||
|
R.string.settings_gesture_description_swipe_v,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
|
SWIPE_V_REVERSE(
|
||||||
|
"action.v_reverse",
|
||||||
|
R.string.settings_gesture_swipe_v_reverse,
|
||||||
|
R.string.settings_gesture_description_swipe_v_reverse,
|
||||||
|
R.array.no_default
|
||||||
|
),
|
||||||
BACK(
|
BACK(
|
||||||
"action.back",
|
"action.back",
|
||||||
R.string.settings_gesture_back,
|
R.string.settings_gesture_back,
|
||||||
|
@ -267,6 +316,7 @@ enum class Gesture(
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun invoke(context: Context) {
|
operator fun invoke(context: Context) {
|
||||||
|
Log.i("Launcher", "Detected gesture: $this")
|
||||||
val action = Action.forGesture(this)
|
val action = Action.forGesture(this)
|
||||||
Action.launch(action, context, this.animationIn, this.animationOut)
|
Action.launch(action, context, this.animationIn, this.animationOut)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ class TouchGestureDetector(
|
||||||
private val TAP_TIMEOUT: Int
|
private val TAP_TIMEOUT: Int
|
||||||
private val DOUBLE_TAP_TIMEOUT: Int
|
private val DOUBLE_TAP_TIMEOUT: Int
|
||||||
|
|
||||||
|
private val MIN_TRIANGLE_HEIGHT = 250
|
||||||
|
|
||||||
|
|
||||||
data class Vector(val x: Float, val y: Float) {
|
data class Vector(val x: Float, val y: Float) {
|
||||||
fun absSquared(): Float {
|
fun absSquared(): Float {
|
||||||
|
@ -94,19 +96,24 @@ class TouchGestureDetector(
|
||||||
}
|
}
|
||||||
|
|
||||||
// add new pointers
|
// add new pointers
|
||||||
(0..<event.pointerCount).filter {
|
for(i in 0..<event.pointerCount){
|
||||||
!paths.containsKey(event.getPointerId(it))
|
if(paths.containsKey(event.getPointerId(i))) {
|
||||||
}.forEach {
|
continue
|
||||||
val index = pointerIdToIndex[it] ?: return@forEach
|
}
|
||||||
paths[it] = PointerPath(
|
val index = pointerIdToIndex[i] ?: continue
|
||||||
|
paths[i] = PointerPath(
|
||||||
paths.entries.size,
|
paths.entries.size,
|
||||||
Vector(event.getX(index), event.getY(index))
|
Vector(event.getX(index), event.getY(index))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
(0..<event.pointerCount).forEach {
|
for( i in 0..<event.pointerCount) {
|
||||||
val index = pointerIdToIndex[it] ?: return@forEach
|
val index = pointerIdToIndex[i] ?: continue
|
||||||
paths[it]?.update(Vector(event.getX(index), event.getY(index)))
|
|
||||||
|
repeat(event.historySize) {
|
||||||
|
paths[i]?.update(Vector(event.getHistoricalX(index), event.getHistoricalY(index)))
|
||||||
|
}
|
||||||
|
paths[i]?.update(Vector(event.getX(index), event.getY(index)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.actionMasked == MotionEvent.ACTION_UP) {
|
if (event.actionMasked == MotionEvent.ACTION_UP) {
|
||||||
|
@ -180,6 +187,41 @@ class TouchGestureDetector(
|
||||||
gesture = gesture?.let(Gesture::getDoubleVariant)
|
gesture = gesture?.let(Gesture::getDoubleVariant)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// detect triangles
|
||||||
|
val startEndMin = mainPointerPath.start.min(mainPointerPath.last)
|
||||||
|
val startEndMax = mainPointerPath.start.max(mainPointerPath.last)
|
||||||
|
when (gesture) {
|
||||||
|
Gesture.SWIPE_DOWN -> {
|
||||||
|
if(startEndMax.x + MIN_TRIANGLE_HEIGHT < mainPointerPath.max.x) {
|
||||||
|
gesture = Gesture.SWIPE_LARGER
|
||||||
|
} else if (startEndMin.x - MIN_TRIANGLE_HEIGHT > mainPointerPath.min.x) {
|
||||||
|
gesture = Gesture.SWIPE_SMALLER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Gesture.SWIPE_UP -> {
|
||||||
|
if(startEndMax.x + MIN_TRIANGLE_HEIGHT < mainPointerPath.max.x) {
|
||||||
|
gesture = Gesture.SWIPE_LARGER_REVERSE
|
||||||
|
} else if (startEndMin.x - MIN_TRIANGLE_HEIGHT > mainPointerPath.min.x) {
|
||||||
|
gesture = Gesture.SWIPE_SMALLER_REVERSE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Gesture.SWIPE_RIGHT -> {
|
||||||
|
if(startEndMax.y + MIN_TRIANGLE_HEIGHT < mainPointerPath.max.y) {
|
||||||
|
gesture = Gesture.SWIPE_V
|
||||||
|
} else if (startEndMin.y - MIN_TRIANGLE_HEIGHT > mainPointerPath.min.y) {
|
||||||
|
gesture = Gesture.SWIPE_LAMBDA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Gesture.SWIPE_LEFT -> {
|
||||||
|
if(startEndMax.y + MIN_TRIANGLE_HEIGHT < mainPointerPath.max.y) {
|
||||||
|
gesture = Gesture.SWIPE_V_REVERSE
|
||||||
|
} else if (startEndMin.y - MIN_TRIANGLE_HEIGHT > mainPointerPath.min.y) {
|
||||||
|
gesture = Gesture.SWIPE_LAMBDA_REVERSE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> { }
|
||||||
|
}
|
||||||
|
|
||||||
if (edgeActions) {
|
if (edgeActions) {
|
||||||
if (mainPointerPath.max.x < edgeWidth * width) {
|
if (mainPointerPath.max.x < edgeWidth * width) {
|
||||||
gesture = gesture?.getEdgeVariant(Gesture.Edge.LEFT)
|
gesture = gesture?.getEdgeVariant(Gesture.Edge.LEFT)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
<resources>
|
<resources>
|
||||||
<!-- Default Apps for different actions (button-press, swipes ...) -->
|
<!-- Default Apps for different actions (button-press, swipes ...) -->
|
||||||
|
<string-array name="no_default">
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<!-- Back - Apps list -->
|
<!-- Back - Apps list -->
|
||||||
<string-array name="default_back">
|
<string-array name="default_back">
|
||||||
|
|
|
@ -59,6 +59,24 @@
|
||||||
<string name="settings_gesture_description_down_left_edge">Swipe down at the left edge of the screen</string>
|
<string name="settings_gesture_description_down_left_edge">Swipe down at the left edge of the screen</string>
|
||||||
<string name="settings_gesture_down_right_edge">Down (Right Edge)</string>
|
<string name="settings_gesture_down_right_edge">Down (Right Edge)</string>
|
||||||
<string name="settings_gesture_description_down_right_edge">Swipe down at the right edge of the screen</string>
|
<string name="settings_gesture_description_down_right_edge">Swipe down at the right edge of the screen</string>
|
||||||
|
|
||||||
|
<string name="settings_gesture_swipe_larger"><![CDATA[>]]></string>
|
||||||
|
<string name="settings_gesture_description_swipe_larger">Top left -> mid right -> bottom left</string>
|
||||||
|
<string name="settings_gesture_swipe_larger_reverse"><![CDATA[> (reverse)]]></string>
|
||||||
|
<string name="settings_gesture_description_swipe_larger_reverse">Bottom left -> mid right -> top left</string>
|
||||||
|
<string name="settings_gesture_swipe_smaller"><![CDATA[<]]></string>
|
||||||
|
<string name="settings_gesture_description_swipe_smaller">Top right -> mid left -> bottom right</string>
|
||||||
|
<string name="settings_gesture_swipe_smaller_reverse"><![CDATA[< (reverse)]]></string>
|
||||||
|
<string name="settings_gesture_description_swipe_smaller_reverse">Bottom right -> mid left -> top right</string>
|
||||||
|
<string name="settings_gesture_swipe_v">V</string>
|
||||||
|
<string name="settings_gesture_description_swipe_v">Top left -> bottom mid -> top right</string>
|
||||||
|
<string name="settings_gesture_swipe_v_reverse">V (reverse)</string>
|
||||||
|
<string name="settings_gesture_description_swipe_v_reverse">Top right -> bottom mid -> top left</string>
|
||||||
|
<string name="settings_gesture_swipe_lambda">Λ</string>
|
||||||
|
<string name="settings_gesture_description_swipe_lambda">Bottom left -> top mid -> bottom right</string>
|
||||||
|
<string name="settings_gesture_swipe_lambda_reverse">Λ (reverse)</string>
|
||||||
|
<string name="settings_gesture_description_swipe_lambda_reverse">Bottom right -> top mid -> bottom left</string>
|
||||||
|
|
||||||
<string name="settings_gesture_vol_up">Volume Up</string>
|
<string name="settings_gesture_vol_up">Volume Up</string>
|
||||||
<string name="settings_gesture_description_vol_up">Press the volume up button</string>
|
<string name="settings_gesture_description_vol_up">Press the volume up button</string>
|
||||||
<string name="settings_gesture_vol_down">Volume Down</string>
|
<string name="settings_gesture_vol_down">Volume Down</string>
|
||||||
|
|
Loading…
Add table
Reference in a new issue