Skip to content

Commit

Permalink
Always use cursor when using keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenMcGirr committed Mar 6, 2024
1 parent af1d493 commit 59a60e4
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ package com.enaboapps.switchify.service.utils
import android.graphics.Rect
import android.util.Log
import android.view.accessibility.AccessibilityWindowInfo
import com.enaboapps.switchify.service.scanning.ScanReceiver

object KeyboardInfo {
var isKeyboardVisible = false
var keyboardHeight = 0

// Track scan receiver state to go back to when keyboard is hidden
private var previousScanReceiverState = ScanReceiver.state

fun updateKeyboardState(windows: List<AccessibilityWindowInfo>) {
val keyboardWindow = windows.firstOrNull { window ->
window.type == AccessibilityWindowInfo.TYPE_INPUT_METHOD
Expand All @@ -17,9 +21,16 @@ object KeyboardInfo {
val rect = Rect()
keyboardWindow.getBoundsInScreen(rect)
keyboardHeight = rect.height()

// Go to cursor as keyboard keys don't report AccessibilityNodeInfo
previousScanReceiverState = ScanReceiver.state
ScanReceiver.state = ScanReceiver.ReceiverState.CURSOR
} else {
isKeyboardVisible = false
keyboardHeight = 0

// Go back to previous state
ScanReceiver.state = previousScanReceiverState
}
Log.d("KeyboardInfo", "isKeyboardVisible: $isKeyboardVisible window count: ${windows.size}")
}
Expand Down

0 comments on commit 59a60e4

Please sign in to comment.