Skip to content

Commit c5fd972

Browse files
authored
Merge pull request #23 from Irineu333/release/v0.1.1
[Release/v0.1.1] Prototype - Patch 1
2 parents a5d446a + d1b4256 commit c5fd972

File tree

7 files changed

+29
-37
lines changed

7 files changed

+29
-37
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ android {
1111
applicationId "com.neo.speaktouch"
1212
minSdk 22
1313
targetSdk 33
14-
versionCode 1
15-
versionName "0.1.0"
14+
versionCode 2
15+
versionName "0.1.1"
1616

1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
}

app/src/main/java/com/neo/speaktouch/intercepter/FocusInterceptor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ class FocusInterceptor : Interceptor {
4545
private fun getFocusableNode(node: NodeInfo): NodeInfo? {
4646

4747
if (node.isRequiredFocus) {
48+
// Priority 1
4849
return node
4950
}
5051

52+
// Priority 2
5153
val nearestAncestor = node.getNearestAncestor {
5254
it.isRequiredFocus
5355
}
5456

5557
return nearestAncestor ?: when {
56-
node.isReadable -> node
58+
node.isReadable -> node // Priority 3
5759
else -> null
5860
}
5961
}

app/src/main/java/com/neo/speaktouch/intercepter/SpeechInterceptor.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SpeechInterceptor(
2222

2323
fun speak(text: CharSequence) {
2424

25-
Timber.i("speak: $text")
25+
Timber.i("speak:\"$text\"")
2626

2727
textToSpeech.speak(
2828
text,
@@ -82,7 +82,7 @@ class SpeechInterceptor(
8282
private fun getContent(
8383
node: NodeInfo
8484
) = with(node) {
85-
Timber.d("getContent\n${node.getLog()}")
85+
Timber.d("getContent:\n${node.getLog()}")
8686

8787
val content = contentDescription.ifEmptyOrNull {
8888
text.ifEmptyOrNull {
@@ -94,9 +94,7 @@ class SpeechInterceptor(
9494

9595
listOf(
9696
content,
97-
getType(node),
98-
hintText?.takeIf { it != content },
99-
error
97+
getType(node)
10098
).filterNotNullOrEmpty()
10199
.joinToString(", ")
102100
}

app/src/main/java/com/neo/speaktouch/model/Type.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ enum class Type {
2828
if (className instanceOf ImageButton::class.java) return BUTTON
2929

3030
// View->ImageView
31-
if (className instanceOf ImageView::class.java) return IMAGE
31+
if (className instanceOf ImageView::class.java) {
32+
return if (node.isClickable) BUTTON else IMAGE
33+
}
3234

3335
/* TextView */
3436

@@ -60,15 +62,17 @@ enum class Type {
6062
// View->ViewGroup->AdapterView->AbsSpinner
6163
if (className instanceOf AbsSpinner::class.java) return OPTIONS
6264

63-
/* Additional */
65+
/* Independent of inheritance */
6466

6567
if (node.isCheckable) return CHECKABLE
6668

6769
if (node.isEditable) return EDITABLE
6870

6971
if (node.collectionInfo != null) return LIST
7072

71-
if (node.isHeading) return TITLE
73+
if (node.isHeading) return TITLE
74+
75+
if (node.isClickable) return BUTTON
7276

7377
return NONE
7478
}

app/src/main/java/com/neo/speaktouch/utils/extensions/AccessibilityNodeInfo.kt

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,19 @@ typealias NodeAction = AccessibilityNodeInfoCompat.AccessibilityActionCompat
88
val NodeInfo.hasAnyClick: Boolean
99
get() = isClickable || isLongClickable
1010

11-
val NodeInfo.isActionable: Boolean
12-
get() = hasAnyClick || isFocusable
13-
1411
val NodeInfo.isReadable: Boolean
15-
get() = !isIgnore && (hasText || hasStateDescription)
12+
get() = !isIgnore && hasText
1613

1714
val NodeInfo.hasText: Boolean
1815
get() = !contentDescription.isNullOrEmpty() ||
1916
!text.isNullOrEmpty() ||
2017
!hintText.isNullOrEmpty()
2118

22-
val NodeInfo.hasStateDescription: Boolean
23-
get() = !stateDescription.isNullOrEmpty() || isCheckable
24-
25-
val NodeInfo.isButtonType: Boolean
26-
get() = listOf(
27-
"android.widget.Button",
28-
"android.widget.ImageButton",
29-
).contains(className)
30-
31-
val NodeInfo.isImageType: Boolean
32-
get() = listOf(
33-
"android.widget.ImageView"
34-
).contains(className)
35-
3619
val NodeInfo.isAvailableForAccessibility: Boolean
3720
get() = !isIgnore && (isRequiredFocus || isReadable)
3821

3922
val NodeInfo.isRequiredFocus
40-
get() = !isIgnore && (isActionable || isScreenReaderFocusable)
23+
get() = !isIgnore && (hasAnyClick || isScreenReaderFocusable)
4124

4225
val NodeInfo.isIgnore
4326
get() = !isImportantForAccessibility || !isVisibleToUser
@@ -92,7 +75,6 @@ fun NodeInfo.getLog() = buildList {
9275
add("\nACTION")
9376
add("isCheckable: $isCheckable")
9477
add("isEditable: $isEditable")
95-
add("isActionable: $isActionable")
9678
add("isClickable: $isClickable")
9779
add("isLongClickable: $isLongClickable")
9880
add("actions: ${actionList.joinToString(", ") { it.name }}")
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.neo.speaktouch.utils.extensions
22

3+
import timber.log.Timber
4+
35
fun <T : CharSequence> T?.ifEmptyOrNull(
4-
fallback : () -> T
5-
) : T {
6+
fallback: () -> T
7+
): T {
68
return if (this.isNullOrEmpty()) {
79
fallback()
810
} else {
@@ -15,7 +17,11 @@ fun <T : List<CharSequence?>> T.filterNotNullOrEmpty() = filterNot { it.isNullOr
1517
infix fun CharSequence.instanceOf(childClass: Class<*>): Boolean {
1618
if (equals(childClass.name)) return true
1719

18-
val superClazz = Class.forName(toString())
19-
20-
return childClass.isAssignableFrom(superClazz)
20+
return runCatching {
21+
childClass.isAssignableFrom(Class.forName(toString()))
22+
}.onFailure {
23+
Timber.e(it)
24+
}.getOrElse {
25+
false
26+
}
2127
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencyResolutionManagement {
1212
mavenCentral()
1313
}
1414
}
15-
rootProject.name = "ScreenReader"
15+
rootProject.name = "SpeakTouch"
1616

1717
include ':app'
1818
include ':test'

0 commit comments

Comments
 (0)