add touch events handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.omixlab.mosis
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
@@ -7,6 +8,7 @@ import android.content.res.AssetManager
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import android.util.Log
|
||||
import android.view.MotionEvent
|
||||
import android.view.Surface
|
||||
import android.view.SurfaceView
|
||||
import android.view.SurfaceHolder
|
||||
@@ -36,7 +38,6 @@ class MainActivity : ComponentActivity() {
|
||||
Log.d("MosisTest", "Service Connected")
|
||||
statusText.value = "Service Connected"
|
||||
remote_service = IMosisService.Stub.asInterface(service)
|
||||
Log.d("MosisTest", "Number: ${remote_service?.number}")
|
||||
serviceConnected(service)
|
||||
}
|
||||
|
||||
@@ -94,11 +95,13 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
Text(statusText.value)
|
||||
NativeViewport(
|
||||
modifier = Modifier.fillMaxSize(0.8f)
|
||||
modifier = Modifier
|
||||
.fillMaxSize(0.8f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Composable
|
||||
fun NativeViewport(modifier: Modifier = Modifier) {
|
||||
AndroidView(
|
||||
@@ -106,6 +109,26 @@ class MainActivity : ComponentActivity() {
|
||||
factory = { context ->
|
||||
SurfaceView(context).apply {
|
||||
holder.addCallback(viewport)
|
||||
setOnTouchListener { v, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
Log.d("ServiceTester", "ACTION_DOWN ${event.x} - ${event.y}")
|
||||
remote_service?.onTouchDown(event.x /v.width, event.y / v.height)
|
||||
true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
Log.d("ServiceTester", "ACTION_MOVE ${event.x} - ${event.y}")
|
||||
remote_service?.onTouchMove(event.x /v.width, event.y / v.height)
|
||||
true
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
Log.d("ServiceTester", "ACTION_ ${event.x} - ${event.y}")
|
||||
remote_service?.onTouchUp(event.x /v.width, event.y / v.height)
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user