This file contains hidden or 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
private var webSocket: WebSocket? = null | |
fun initWebSocket() { | |
webSocket = client.newWebSocket(request, object : WebSocketListener() { | |
override fun onOpen(webSocket: WebSocket, response: Response) { | |
super.onOpen(webSocket, response) | |
} | |
override fun onMessage(webSocket: WebSocket, text: String) { | |
super.onMessage(webSocket, text) |
This file contains hidden or 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
private fun record() | |
{ | |
val buf = ByteArray(BUFFER_SIZE_RECORDING) | |
scope.launch { | |
try { | |
do { | |
val byteRead = audioRecord?.read(buf,0, buf.size)?: break | |
if (byteRead < -1) | |
break |
This file contains hidden or 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
@Composable | |
fun FoodItemCard(foodItem: FoodItem) { | |
Card( | |
elevation = 10.dp, backgroundColor = Color.White, | |
shape = RoundedCornerShape(24.dp), | |
modifier = Modifier.padding(8.dp) | |
) { | |
Row( | |
verticalAlignment = Alignment.CenterVertically, | |
modifier = Modifier.padding(10.dp) |
This file contains hidden or 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
@Composable | |
fun PersonCard(person: Person) { | |
Column( | |
modifier = Modifier | |
.padding(6.dp) | |
.shadow(elevation = 4.dp, shape = RoundedCornerShape(16.dp)) | |
.width(width = 120.dp) | |
.fillMaxHeight(0.8f) | |
.background(Color.White, RoundedCornerShape(16.dp)), | |
verticalArrangement = Arrangement.Center, |
This file contains hidden or 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
internal class DragTargetInfo { | |
var isDragging: Boolean by mutableStateOf(false) | |
var dragPosition by mutableStateOf(Offset.Zero) | |
var dragOffset by mutableStateOf(Offset.Zero) | |
var draggableComposable by mutableStateOf<(@Composable () -> Unit)?>(null) | |
var dataToDrop by mutableStateOf<Any?>(null) | |
} |
This file contains hidden or 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
internal val LocalDragTargetInfo = compositionLocalOf { DragTargetInfo() } | |
@Composable | |
fun <T> DragTarget( | |
modifier: Modifier, | |
dataToDrop: T, | |
content: @Composable (() -> Unit) | |
) { | |
var currentPosition by remember { mutableStateOf(Offset.Zero) } | |
val currentState = LocalDragTargetInfo.current |
This file contains hidden or 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
DragTarget(modifier = Modifier, dataToDrop = foodItem) { | |
Image( | |
painter = painterResource(id = foodItem.image), | |
contentDescription = null, | |
contentScale = ContentScale.Crop, | |
modifier = Modifier | |
.size(130.dp) | |
.clip(RoundedCornerShape(16.dp)) | |
) | |
} |
This file contains hidden or 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
@Composable | |
fun LongPressDraggable( | |
modifier: Modifier = Modifier, | |
content: @Composable BoxScope.() -> Unit | |
) { | |
val state = remember { DragTargetInfo() } | |
CompositionLocalProvider( | |
LocalDragTargetInfo provides state | |
) { | |
Box( |
This file contains hidden or 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
@Composable | |
fun <T> DropTarget( | |
modifier: Modifier, | |
content: @Composable() (BoxScope.(isInBound: Boolean, data: T?) -> Unit) | |
) { | |
val dragInfo = LocalDragTargetInfo.current | |
val dragPosition = dragInfo.dragPosition | |
val dragOffset = dragInfo.dragOffset | |
var isCurrentDropTarget by remember { |
This file contains hidden or 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
@Composable | |
fun PersonCard(person: Person) { | |
val foodItems = remember { | |
mutableStateMapOf<Int, FoodItem>() | |
} | |
DropTarget<FoodItem>( | |
modifier = Modifier | |
.padding(6.dp) | |
.width(width = 120.dp) |