-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : initial implementation icon gesture support (#5266)
- Loading branch information
Showing
10 changed files
with
296 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
lawnchair/src/app/lawnchair/gestures/IconGestureListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package app.lawnchair.gestures | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.lifecycle.lifecycleScope | ||
import app.lawnchair.gestures.config.GestureHandlerConfig | ||
import app.lawnchair.gestures.type.GestureType | ||
import app.lawnchair.launcher | ||
import app.lawnchair.preferences2.PreferenceManager2 | ||
import com.android.launcher3.model.data.ItemInfo | ||
import com.android.launcher3.util.VibratorWrapper | ||
import kotlinx.coroutines.flow.firstOrNull | ||
import kotlinx.coroutines.launch | ||
|
||
class IconGestureListener( | ||
private val context: Context, | ||
private val prefs: PreferenceManager2, | ||
private val cmp: ItemInfo?, | ||
) : DirectionalGestureListener(context) { | ||
|
||
override fun onSwipeRight() = handleGesture(GestureType.SWIPE_RIGHT) | ||
override fun onSwipeLeft() = handleGesture(GestureType.SWIPE_LEFT) | ||
override fun onSwipeTop() = handleGesture(GestureType.SWIPE_UP) | ||
override fun onSwipeDown() = handleGesture(GestureType.SWIPE_DOWN) | ||
|
||
private fun handleGesture(gestureType: GestureType) { | ||
Log.d("GESTURE_HANDLER", "Handling gesture: ${gestureType.name}") | ||
|
||
cmp?.componentKey?.let { | ||
context.launcher.lifecycleScope.launch { | ||
val gesture = prefs.getGestureForApp(it, gestureType).firstOrNull() | ||
if (gesture !is GestureHandlerConfig.NoOp) { | ||
Log.d("GESTURE_HANDLER", "Triggering gesture: ${gestureType.name}") | ||
VibratorWrapper.INSTANCE.get(context.launcher).vibrate(VibratorWrapper.OVERVIEW_HAPTIC) | ||
gesture?.createHandler(context)?.onTrigger(context.launcher) | ||
} else { | ||
Log.d("GESTURE_HANDLER", "NoOp gesture, ignoring") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.lawnchair.gestures.type | ||
|
||
import android.annotation.StringRes | ||
import android.content.Context | ||
import com.android.launcher3.R | ||
|
||
enum class GestureType(@StringRes val keyResId: Int, @StringRes val labelResId: Int) { | ||
SWIPE_UP(R.string.pref_key_swipe_up, R.string.gesture_swipe_up), | ||
SWIPE_DOWN(R.string.pref_key_swipe_down, R.string.gesture_swipe_down), | ||
SWIPE_LEFT(R.string.pref_key_swipe_left, R.string.gesture_swipe_left), | ||
SWIPE_RIGHT(R.string.pref_key_swipe_right, R.string.gesture_swipe_right), | ||
; | ||
|
||
companion object { | ||
fun fromKey(key: String, context: Context): GestureType? { | ||
return entries.find { context.getString(it.keyResId) == key } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.