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