Skip to content

Commit

Permalink
Merge pull request #23 from Irineu333/release/v0.1.1
Browse files Browse the repository at this point in the history
[Release/v0.1.1] Prototype - Patch 1
  • Loading branch information
Irineu333 authored Mar 18, 2023
2 parents a5d446a + d1b4256 commit c5fd972
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.neo.speaktouch"
minSdk 22
targetSdk 33
versionCode 1
versionName "0.1.0"
versionCode 2
versionName "0.1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ class FocusInterceptor : Interceptor {
private fun getFocusableNode(node: NodeInfo): NodeInfo? {

if (node.isRequiredFocus) {
// Priority 1
return node
}

// Priority 2
val nearestAncestor = node.getNearestAncestor {
it.isRequiredFocus
}

return nearestAncestor ?: when {
node.isReadable -> node
node.isReadable -> node // Priority 3
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SpeechInterceptor(

fun speak(text: CharSequence) {

Timber.i("speak: $text")
Timber.i("speak:\"$text\"")

textToSpeech.speak(
text,
Expand Down Expand Up @@ -82,7 +82,7 @@ class SpeechInterceptor(
private fun getContent(
node: NodeInfo
) = with(node) {
Timber.d("getContent\n${node.getLog()}")
Timber.d("getContent:\n${node.getLog()}")

val content = contentDescription.ifEmptyOrNull {
text.ifEmptyOrNull {
Expand All @@ -94,9 +94,7 @@ class SpeechInterceptor(

listOf(
content,
getType(node),
hintText?.takeIf { it != content },
error
getType(node)
).filterNotNullOrEmpty()
.joinToString(", ")
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/neo/speaktouch/model/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ enum class Type {
if (className instanceOf ImageButton::class.java) return BUTTON

// View->ImageView
if (className instanceOf ImageView::class.java) return IMAGE
if (className instanceOf ImageView::class.java) {
return if (node.isClickable) BUTTON else IMAGE
}

/* TextView */

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

/* Additional */
/* Independent of inheritance */

if (node.isCheckable) return CHECKABLE

if (node.isEditable) return EDITABLE

if (node.collectionInfo != null) return LIST

if (node.isHeading) return TITLE
if (node.isHeading) return TITLE

if (node.isClickable) return BUTTON

return NONE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,19 @@ typealias NodeAction = AccessibilityNodeInfoCompat.AccessibilityActionCompat
val NodeInfo.hasAnyClick: Boolean
get() = isClickable || isLongClickable

val NodeInfo.isActionable: Boolean
get() = hasAnyClick || isFocusable

val NodeInfo.isReadable: Boolean
get() = !isIgnore && (hasText || hasStateDescription)
get() = !isIgnore && hasText

val NodeInfo.hasText: Boolean
get() = !contentDescription.isNullOrEmpty() ||
!text.isNullOrEmpty() ||
!hintText.isNullOrEmpty()

val NodeInfo.hasStateDescription: Boolean
get() = !stateDescription.isNullOrEmpty() || isCheckable

val NodeInfo.isButtonType: Boolean
get() = listOf(
"android.widget.Button",
"android.widget.ImageButton",
).contains(className)

val NodeInfo.isImageType: Boolean
get() = listOf(
"android.widget.ImageView"
).contains(className)

val NodeInfo.isAvailableForAccessibility: Boolean
get() = !isIgnore && (isRequiredFocus || isReadable)

val NodeInfo.isRequiredFocus
get() = !isIgnore && (isActionable || isScreenReaderFocusable)
get() = !isIgnore && (hasAnyClick || isScreenReaderFocusable)

val NodeInfo.isIgnore
get() = !isImportantForAccessibility || !isVisibleToUser
Expand Down Expand Up @@ -92,7 +75,6 @@ fun NodeInfo.getLog() = buildList {
add("\nACTION")
add("isCheckable: $isCheckable")
add("isEditable: $isEditable")
add("isActionable: $isActionable")
add("isClickable: $isClickable")
add("isLongClickable: $isLongClickable")
add("actions: ${actionList.joinToString(", ") { it.name }}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.neo.speaktouch.utils.extensions

import timber.log.Timber

fun <T : CharSequence> T?.ifEmptyOrNull(
fallback : () -> T
) : T {
fallback: () -> T
): T {
return if (this.isNullOrEmpty()) {
fallback()
} else {
Expand All @@ -15,7 +17,11 @@ fun <T : List<CharSequence?>> T.filterNotNullOrEmpty() = filterNot { it.isNullOr
infix fun CharSequence.instanceOf(childClass: Class<*>): Boolean {
if (equals(childClass.name)) return true

val superClazz = Class.forName(toString())

return childClass.isAssignableFrom(superClazz)
return runCatching {
childClass.isAssignableFrom(Class.forName(toString()))
}.onFailure {
Timber.e(it)
}.getOrElse {
false
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "ScreenReader"
rootProject.name = "SpeakTouch"

include ':app'
include ':test'

0 comments on commit c5fd972

Please sign in to comment.