parent
2ae19260fb
commit
d00eeb882d
@ -1,5 +1,8 @@
|
||||
package de.mm20.launcher2.ui.gestures
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.staticCompositionLocalOf
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
|
||||
@ -9,6 +12,12 @@ class GestureDetector {
|
||||
|
||||
var gestureListener: OnGestureListener? = null
|
||||
|
||||
var shouldDetectDoubleTaps by mutableStateOf(false)
|
||||
|
||||
fun dispatchTap(position: Offset) {
|
||||
gestureListener?.onTap(position)
|
||||
}
|
||||
|
||||
fun dispatchDoubleTap(position: Offset) {
|
||||
gestureListener?.onDoubleTap(position)
|
||||
}
|
||||
@ -33,6 +42,7 @@ class GestureDetector {
|
||||
|
||||
|
||||
interface OnGestureListener {
|
||||
fun onTap(position: Offset) {}
|
||||
fun onDoubleTap(position: Offset) {}
|
||||
fun onLongPress(position: Offset) {}
|
||||
|
||||
|
||||
@ -7,12 +7,17 @@ import androidx.compose.ui.geometry.Offset
|
||||
@Composable
|
||||
fun GestureHandler(
|
||||
detector: GestureDetector,
|
||||
onTap: (Offset) -> Unit = {},
|
||||
onLongPress: (Offset) -> Unit = {},
|
||||
onDoubleTap: (Offset) -> Unit = {},
|
||||
onDrag: (Offset) -> Boolean = { false },
|
||||
) {
|
||||
DisposableEffect(detector) {
|
||||
detector.gestureListener = object : GestureDetector.OnGestureListener {
|
||||
override fun onTap(position: Offset) {
|
||||
onTap(position)
|
||||
}
|
||||
|
||||
override fun onLongPress(position: Offset) {
|
||||
onLongPress(position)
|
||||
}
|
||||
|
||||
@ -111,6 +111,7 @@ class LauncherScaffoldVM : ViewModel(), KoinComponent {
|
||||
val searchBarStyle = dataStore.data.map { it.searchBar.searchBarStyle }.asLiveData()
|
||||
|
||||
|
||||
val shouldDetectDoubleTapGesture = dataStore.data.map { it.gestures.doubleTap != GestureAction.None }.asLiveData()
|
||||
var failedGestureState by mutableStateOf<FailedGesture?>(null)
|
||||
fun handleGesture(gesture: Gesture): Boolean {
|
||||
val action = when (gesture) {
|
||||
|
||||
@ -348,14 +348,17 @@ fun PagerScaffold(
|
||||
modifier = Modifier
|
||||
.requiredWidth(width)
|
||||
.fillMaxHeight()
|
||||
.pointerInput(Unit) {
|
||||
.pointerInput(gestureManager.shouldDetectDoubleTaps) {
|
||||
detectTapGestures(
|
||||
onDoubleTap = {
|
||||
onDoubleTap = if (gestureManager.shouldDetectDoubleTaps) {{
|
||||
if (!isWidgetEditMode) gestureManager.dispatchDoubleTap(it)
|
||||
},
|
||||
}} else null,
|
||||
onLongPress = {
|
||||
if (!isWidgetEditMode) gestureManager.dispatchLongPress(it)
|
||||
}
|
||||
},
|
||||
onTap = {
|
||||
if (!isWidgetEditMode) gestureManager.dispatchTap(it)
|
||||
},
|
||||
)
|
||||
}
|
||||
.verticalScroll(widgetsScrollState)
|
||||
|
||||
@ -387,18 +387,24 @@ fun PullDownScaffold(
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.graphicsLayer {
|
||||
val progress = pagerState.currentPage + pagerState.currentPageOffsetFraction
|
||||
val progress =
|
||||
pagerState.currentPage + pagerState.currentPageOffsetFraction
|
||||
transformOrigin = TransformOrigin.Center
|
||||
alpha = 1 - progress
|
||||
}
|
||||
.pointerInput(Unit) {
|
||||
.pointerInput(gestureManager.shouldDetectDoubleTaps) {
|
||||
detectTapGestures(
|
||||
onDoubleTap = {
|
||||
onDoubleTap = if (gestureManager.shouldDetectDoubleTaps) {{
|
||||
if (!isWidgetEditMode) gestureManager.dispatchDoubleTap(it)
|
||||
},
|
||||
}} else null,
|
||||
onLongPress = {
|
||||
if (!isWidgetEditMode) gestureManager.dispatchLongPress(it)
|
||||
}
|
||||
if (!isWidgetEditMode) gestureManager.dispatchLongPress(
|
||||
it
|
||||
)
|
||||
},
|
||||
onTap = {
|
||||
if (!isWidgetEditMode) gestureManager.dispatchTap(it)
|
||||
},
|
||||
)
|
||||
}
|
||||
.fillMaxSize()
|
||||
@ -442,7 +448,8 @@ fun PullDownScaffold(
|
||||
SearchColumn(
|
||||
modifier = Modifier
|
||||
.graphicsLayer {
|
||||
val progress = pagerState.currentPage + pagerState.currentPageOffsetFraction
|
||||
val progress =
|
||||
pagerState.currentPage + pagerState.currentPageOffsetFraction
|
||||
transformOrigin = TransformOrigin.Center
|
||||
alpha = progress
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import android.app.WallpaperManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.foundation.background
|
||||
@ -94,6 +95,10 @@ abstract class SharedLauncherActivity(
|
||||
val bottomSheetManager = LauncherBottomSheetManager()
|
||||
val gestureDetector = GestureDetector()
|
||||
|
||||
viewModel.shouldDetectDoubleTapGesture.observe(this) {
|
||||
gestureDetector.shouldDetectDoubleTaps = it
|
||||
}
|
||||
|
||||
setContent {
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val wallpaperColors by wallpaperColorsAsState()
|
||||
@ -158,18 +163,6 @@ abstract class SharedLauncherActivity(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.pointerInput(null) {
|
||||
detectTapGestures {
|
||||
wallpaperManager?.sendWallpaperCommand(
|
||||
window.decorView.applicationWindowToken,
|
||||
WallpaperManager.COMMAND_TAP,
|
||||
it.x.toInt(),
|
||||
it.y.toInt(),
|
||||
0,
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
.background(if (dimBackground) Color.Black.copy(alpha = 0.30f) else Color.Transparent),
|
||||
contentAlignment = Alignment.BottomCenter
|
||||
) {
|
||||
@ -291,6 +284,16 @@ abstract class SharedLauncherActivity(
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
},
|
||||
onTap = {
|
||||
wallpaperManager.sendWallpaperCommand(g
|
||||
window.decorView.windowToken,
|
||||
WallpaperManager.COMMAND_TAP,
|
||||
it.x.toInt(),
|
||||
it.y.toInt(),
|
||||
0,
|
||||
null
|
||||
)
|
||||
}
|
||||
)
|
||||
if (viewModel.failedGestureState != null) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user