Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #135

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: gradle
- name: Build with Gradle
run: ./gradlew build --no-daemon

- name: Upload results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: SpeakTouch-APKs
path: app/build/outputs/apk/**/*.apk
4 changes: 2 additions & 2 deletions .github/workflows/validate-gradle-wrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.iml
.gradle
.kotlin
/local.properties
/.idea/caches
/.idea/libraries
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 11 additions & 16 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* App build configurations.
*
* Copyright (C) 2023-2025 Patryk Mis.
* Copyright (C) 2023 Irineu A. Silva.
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -23,32 +24,34 @@ plugins {
alias(libs.plugins.dagger)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.ksp)
id("com.neo.speaktouch.custom_plugin")
}

val keystorePropertiesFile = rootProject.file("keystore.properties")

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
languageVersion.set(JavaLanguageVersion.of(21))
vendor.set(JvmVendorSpec.ADOPTIUM)
}
}

appVersion(VersionConfig.Type.DEV) {
versionConfig {
major = 1
minor = 0
patch = 0
type = VersionConfig.Type.DEV
}

android {
namespace = "com.neo.speaktouch"
compileSdk = 34
buildToolsVersion = "34.0.0"
compileSdk = 35
buildToolsVersion = "35.0.1"

if (keystorePropertiesFile.canRead()) {
signingConfigs {
create("release") {
properties(keystorePropertiesFile) { properties ->
loadPropertiesFromFile(keystorePropertiesFile) { properties ->
storeFile = rootProject.file(properties.getProperty("storeFile"))
storePassword = properties.getProperty("storePassword")
keyAlias = properties.getProperty("keyAlias")
Expand All @@ -64,15 +67,7 @@ android {
configure<BasePluginExtension> { archivesName.set(rootProject.name) }

minSdk = 22
targetSdk = 34

resourceConfigurations.addAll(
listOf(
"en",
"pl",
"pt"
)
)
targetSdk = 35
}

buildTypes {
Expand All @@ -98,8 +93,8 @@ android {
buildConfig = true
}

compileOptions {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
androidResources {
localeFilters += listOf("en", "pl", "pt")
}

testOptions {
Expand Down
33 changes: 27 additions & 6 deletions app/src/main/java/com/neo/speaktouch/controller/FocusController.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Focus controller.
*
* Copyright (C) 2023-2025 Patryk Mis.
* Copyright (C) 2023 Irineu A. Silva.
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -55,12 +56,12 @@ class FocusController @Inject constructor(
recursive()

if (nodeFilter.filter(current)) {
current.performFocus()
current.performFocus(this)
}
}

if (nodeFilter.filter(current)) {
current.performFocus()
current.performFocus(this)
}

if (current.performAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD)) {
Expand All @@ -73,7 +74,7 @@ class FocusController @Inject constructor(
}
)

stop()
this.stop()
}
}
}
Expand All @@ -88,7 +89,7 @@ class FocusController @Inject constructor(
target.descendants(Direction.Right()) {

if (nodeFilter.filter(current)) {
current.performFocus()
current.performFocus(this)
}

recursive()
Expand All @@ -103,7 +104,7 @@ class FocusController @Inject constructor(
) {

if (nodeFilter.filter(current)) {
current.performFocus()
current.performFocus(this)
}

recursive()
Expand All @@ -119,9 +120,29 @@ class FocusController @Inject constructor(
}
)

stop()
this.stop()
}
}
}
}

fun moveFocusToFirst() {
val root = getTarget() ?: return

val currentFocus = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)

if (currentFocus == null) {
nodeScan {
root.descendants(Direction.Right()) {
if (NodeFilter.Focusable.filter(current)) {
current.performFocus(this)
}
recursive()
}
}
return
}

currentFocus.performAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ package com.neo.speaktouch.di.module

import android.content.Context
import android.media.AudioAttributes
import android.os.Build
import android.os.Vibrator
import android.os.VibratorManager
import android.speech.tts.TextToSpeech
import com.neo.speaktouch.R
import com.neo.speaktouch.controller.Controllers
Expand All @@ -44,7 +46,14 @@ object ControllerModule {
context: Context
) : VibratorController {

val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val vibratorManager =
context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
vibratorManager.defaultVibrator
} else {
@Suppress("DEPRECATION")
context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
}

return VibratorController(vibrator)
}
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/com/neo/speaktouch/service/SpeakTouchService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ import android.accessibilityservice.AccessibilityServiceInfo
import android.os.Build
import android.view.accessibility.AccessibilityEvent
import com.neo.speaktouch.controller.Controllers
import com.neo.speaktouch.controller.FocusController
import com.neo.speaktouch.intercepter.Interceptors
import com.neo.speaktouch.intercepter.event.contract.EventInterceptor
import com.neo.speaktouch.utils.extension.addFlags
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import timber.log.Timber

@AndroidEntryPoint
class SpeakTouchService : AccessibilityService() {
class SpeakTouchService : AccessibilityService () {

@Inject
lateinit var interceptors: Interceptors

@Inject
lateinit var focusController: FocusController

override fun onCreate() {
super.onCreate()

Controllers.install()
Controllers.install(this)
}

override fun onServiceConnected() {
Expand All @@ -51,6 +56,14 @@ class SpeakTouchService : AccessibilityService() {
}

override fun onAccessibilityEvent(event: AccessibilityEvent) {
when (event.eventType) {
AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED -> {
val windowTitle = event.text.joinToString(" ").ifEmpty { "Unknown window" }
Timber.d("New window detected: $windowTitle")
focusController.moveFocusToFirst()
}
}

interceptors.event.forEach {
it.handle(event)
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/neo/speaktouch/utils/Installable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ abstract class Installable<T : Any> {
protected var instance = WeakReference<T>(null)
private set

context (T)
fun install() {
instance = WeakReference(this@T)
fun install(context: T) {
instance = WeakReference(context)
}

fun uninstall() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Extensions for NodeInfo (AccessibilityNodeInfoCompat).
*
* Copyright (C) 2023-2025 Patryk Mis.
* Copyright (C) 2023 Irineu A. Silva.
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -49,17 +50,16 @@ operator fun AccessibilityNodeInfoCompat.iterator() =
}

override fun next(): AccessibilityNodeInfoCompat {
return getChild(++index)
return getChild(++index) ?: throw NoSuchElementException("No more child nodes available")
}

}

context(NodeScanScope)
fun AccessibilityNodeInfo.performFocus(mustStop: Boolean = true) {
fun AccessibilityNodeInfo.performFocus(scope: NodeScanScope, mustStop: Boolean = true) {

performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS)

if (mustStop) stop(result = this)
if (mustStop) scope.stop(result = this)
}

fun AccessibilityNodeInfo.getFocusedOrNull(): AccessibilityNodeInfo? {
Expand Down
2 changes: 2 additions & 0 deletions build-logic/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Gradle properties are not passed to included builds https://github.com/gradle/gradle/issues/2534
org.gradle.parallel=true
1 change: 1 addition & 0 deletions build-logic/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading