diff --git a/app/src/main/java/de/codevoid/andremote2/KeyInjectionService.kt b/app/src/main/java/de/codevoid/andremote2/KeyInjectionService.kt index e40d967..c889d55 100644 --- a/app/src/main/java/de/codevoid/andremote2/KeyInjectionService.kt +++ b/app/src/main/java/de/codevoid/andremote2/KeyInjectionService.kt @@ -111,7 +111,7 @@ class KeyInjectionService : Service() { downTime, now, action, keyCode, repeatCount, 0, -1, 0, flags, - InputDevice.SOURCE_KEYBOARD + InputDevice.SOURCE_GAMEPAD ) val injectMethod = manager.javaClass.getMethod( "injectInputEvent", diff --git a/app/src/main/java/de/codevoid/andremote2/views/JoystickView.kt b/app/src/main/java/de/codevoid/andremote2/views/JoystickView.kt index a5c32b7..3a52f74 100644 --- a/app/src/main/java/de/codevoid/andremote2/views/JoystickView.kt +++ b/app/src/main/java/de/codevoid/andremote2/views/JoystickView.kt @@ -4,6 +4,8 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path +import android.os.Handler +import android.os.Looper import android.os.SystemClock import android.util.AttributeSet import android.view.MotionEvent @@ -52,6 +54,14 @@ class JoystickView @JvmOverloads constructor( private var currentKeyCode = -1 private var pressDownTime = 0L + private val longPressHandler = Handler(Looper.getMainLooper()) + private val longPressRunnable = Runnable { + if (currentKeyCode != -1) { + KeyInjectionService.instance?.injectKeyLongPress(currentKeyCode, pressDownTime) + ?: Log.w("JoystickView", "KeyInjectionService not available for long press") + } + } + override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { centerX = w / 2f centerY = h / 2f @@ -138,9 +148,12 @@ class JoystickView @JvmOverloads constructor( pressDownTime = SystemClock.uptimeMillis() KeyInjectionService.instance?.injectKeyDown(keyCode, pressDownTime) ?: Log.w("JoystickView", "KeyInjectionService not available") + longPressHandler.removeCallbacks(longPressRunnable) + longPressHandler.postDelayed(longPressRunnable, 500) } private fun sendKeyUp(keyCode: Int) { + longPressHandler.removeCallbacks(longPressRunnable) KeyInjectionService.instance?.injectKeyUp(keyCode, pressDownTime) ?: Log.w("JoystickView", "KeyInjectionService not available") } diff --git a/app/src/main/java/de/codevoid/andremote2/views/LeverView.kt b/app/src/main/java/de/codevoid/andremote2/views/LeverView.kt index 49e45f1..c3fa1c2 100644 --- a/app/src/main/java/de/codevoid/andremote2/views/LeverView.kt +++ b/app/src/main/java/de/codevoid/andremote2/views/LeverView.kt @@ -4,6 +4,8 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path +import android.os.Handler +import android.os.Looper import android.os.SystemClock import android.util.AttributeSet import android.view.MotionEvent @@ -26,6 +28,14 @@ class LeverView @JvmOverloads constructor( private var startY = 0f private var leverY = 0f + private val longPressHandler = Handler(Looper.getMainLooper()) + private val longPressRunnable = Runnable { + if (currentKeyCode != -1) { + KeyInjectionService.instance?.injectKeyLongPress(currentKeyCode, pressDownTime) + ?: Log.w("LeverView", "KeyInjectionService not available for long press") + } + } + private val paintTrack = Paint(Paint.ANTI_ALIAS_FLAG).apply { color = ContextCompat.getColor(context, R.color.control_track) style = Paint.Style.FILL @@ -132,9 +142,12 @@ class LeverView @JvmOverloads constructor( pressDownTime = SystemClock.uptimeMillis() KeyInjectionService.instance?.injectKeyDown(keyCode, pressDownTime) ?: Log.w("LeverView", "KeyInjectionService not available") + longPressHandler.removeCallbacks(longPressRunnable) + longPressHandler.postDelayed(longPressRunnable, 500) } private fun sendKeyUp(keyCode: Int) { + longPressHandler.removeCallbacks(longPressRunnable) KeyInjectionService.instance?.injectKeyUp(keyCode, pressDownTime) ?: Log.w("LeverView", "KeyInjectionService not available") }