An Android library that enables keyboard developers to add Switchify scanning support to their keyboards. This library helps make keyboards accessible to users who rely on adaptive switches through the Switchify app.
Switchify is an Android app that enables users with motor impairments to control their devices using adaptive switches. This library allows keyboard developers to make their keyboards compatible with Switchify's scanning functionality.
Add JitPack repository to your root settings.gradle.kts
:
dependencyResolutionManagement {
repositories {
// ... other repositories
maven { url = uri("https://jitpack.io") }
}
}
Add the dependency to your module's build.gradle.kts
:
dependencies {
implementation("com.github.enaboapps:SwitchifyKeyboardScanLib:1.1.0")
}
The library provides two main components:
Implement this interface in your keyboard key view class to make it scannable:
class YourKeyView : View(), KeyboardSwitchifyNode {
override fun getSwitchifyKeyboardNodeInfo(): KeyboardNodeInfo {
return KeyboardNodeInfo(
x = x,
y = y,
width = width.toFloat(),
height = height.toFloat(),
contentDescription = contentDescription?.toString() ?: "Key"
)
}
}
Use this class to broadcast your keyboard's layout and visibility to Switchify:
class YourKeyboard : ViewGroup {
private lateinit var switchifyLink: KeyboardSwitchifyLink
private fun initSwitchify() {
switchifyLink = KeyboardSwitchifyLink(context)
}
// When keyboard becomes visible:
fun onKeyboardShow() {
switchifyLink.showKeyboard(this)
}
// When keyboard is hidden:
fun onKeyboardHide() {
switchifyLink.hideKeyboard()
}
// When keyboard layout changes (e.g., switching between QWERTY and numbers):
fun onLayoutChanged() {
if (isVisible) {
switchifyLink.captureAndBroadcastLayoutInfo(this)
}
}
}
The library will automatically:
- Scan the ViewGroup hierarchy for views implementing
KeyboardSwitchifyNode
- Collect the positions, dimensions, and content descriptions of all keyboard keys
- Broadcast this information to the Switchify app using LocalBroadcastManager
Interface that keyboard key views must implement to participate in Switchify scanning.
getSwitchifyKeyboardNodeInfo(): KeyboardNodeInfo
- Returns information about the node's position, dimensions, and content description
Data class containing information about a keyboard key.
x: Float
- X coordinate of the key in pixelsy: Float
- Y coordinate of the key in pixelswidth: Float
- Width of the key in pixelsheight: Float
- Height of the key in pixelscontentDescription: String
- Content description for accessibility (required, non-null)
Main class for capturing and broadcasting keyboard information.
KeyboardSwitchifyLink(context: Context)
- Creates a new instance with the given context
showKeyboard(keyboardView: ViewGroup)
- Call when keyboard becomes visiblehideKeyboard()
- Call when keyboard is hiddencaptureAndBroadcastLayoutInfo(keyboardView: ViewGroup)
- Call when layout changes
The library uses the following broadcast actions:
com.enaboapps.ACTION_KEYBOARD_LAYOUT_INFO
- Sent when keyboard layout changescom.enaboapps.ACTION_KEYBOARD_SHOW
- Sent when keyboard becomes visible, includes layout infocom.enaboapps.ACTION_KEYBOARD_HIDE
- Sent when keyboard is hidden
keyboardLayoutInfo
- JSON string containing the keyboard layout information in the following format:
{
"keys": [
{
"x": 0.0,
"y": 0.0,
"width": 100.0,
"height": 50.0,
"contentDescription": "Letter A"
},
// ... more keys
]
}
- Always provide meaningful content descriptions for your keyboard keys
- Use descriptive text that clearly identifies the key's function
- For letter keys, use format like "Letter A", "Letter B", etc.
- For special keys, use clear descriptions like "Backspace", "Shift", "Space"
- Call
captureAndBroadcastLayoutInfo
whenever your keyboard layout changes- Layout switches (QWERTY to numbers)
- Orientation changes
- Any dynamic layout modifications
- Ensure proper show/hide handling
- Call
showKeyboard
when your keyboard becomes visible - Call
hideKeyboard
when your keyboard is hidden - Always update layout before showing keyboard
- Call
- Handle configuration changes
- Re-broadcast layout information after configuration changes
- Maintain proper keyboard state during transitions
MIT License
Copyright (c) 2024 EnaboApps
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.