Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/de/codevoid/andremote2/views/JoystickView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/de/codevoid/andremote2/views/LeverView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down
Loading