-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Irineu333/release/v0.1.0
[Release/v0.1.0] Prototype
- Loading branch information
Showing
50 changed files
with
1,039 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...o/screenreader/ExampleInstrumentedTest.kt → ...neo/speaktouch/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/neo/speaktouch/SpeakTouchApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.neo.speaktouch | ||
|
||
import android.app.Application | ||
import timber.log.Timber | ||
|
||
class SpeakTouchApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
if (BuildConfig.DEBUG) { | ||
Timber.plant(Timber.DebugTree()) | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/neo/speaktouch/intercepter/FocusInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.neo.speaktouch.intercepter | ||
|
||
import android.view.accessibility.AccessibilityEvent | ||
import com.neo.speaktouch.intercepter.interfece.Interceptor | ||
import com.neo.speaktouch.utils.extensions.* | ||
import timber.log.Timber | ||
|
||
class FocusInterceptor : Interceptor { | ||
|
||
override fun handler(event: AccessibilityEvent) { | ||
|
||
val node = NodeInfo.wrap(event.source ?: return) | ||
|
||
Timber.d(node.getLog()) | ||
|
||
if (node.isAccessibilityFocused) return | ||
|
||
when (event.eventType) { | ||
AccessibilityEvent.TYPE_VIEW_HOVER_ENTER -> { | ||
Timber.d("event: TYPE_VIEW_HOVER_ENTER") | ||
handlerAccessibilityNode(node) | ||
} | ||
|
||
AccessibilityEvent.TYPE_VIEW_FOCUSED -> { | ||
Timber.d("event: TYPE_VIEW_FOCUSED") | ||
handlerAccessibilityNode(node) | ||
} | ||
|
||
AccessibilityEvent.TYPE_VIEW_CLICKED -> { | ||
Timber.d("event: TYPE_VIEW_CLICKED") | ||
handlerAccessibilityNode(node) | ||
} | ||
|
||
else -> Unit | ||
} | ||
} | ||
|
||
private fun handlerAccessibilityNode(node: NodeInfo) { | ||
getFocusableNode(node)?.run { | ||
Timber.i("performAction: $className") | ||
performAction(NodeInfo.ACTION_ACCESSIBILITY_FOCUS) | ||
} | ||
} | ||
|
||
private fun getFocusableNode(node: NodeInfo): NodeInfo? { | ||
|
||
if (node.isRequiredFocus) { | ||
return node | ||
} | ||
|
||
val nearestAncestor = node.getNearestAncestor { | ||
it.isRequiredFocus | ||
} | ||
|
||
return nearestAncestor ?: when { | ||
node.isReadable -> node | ||
else -> null | ||
} | ||
} | ||
} |
127 changes: 127 additions & 0 deletions
127
app/src/main/java/com/neo/speaktouch/intercepter/SpeechInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.neo.speaktouch.intercepter | ||
|
||
import android.content.Context | ||
import android.speech.tts.TextToSpeech | ||
import android.view.accessibility.AccessibilityEvent | ||
import com.neo.speaktouch.R | ||
import com.neo.speaktouch.intercepter.interfece.Interceptor | ||
import com.neo.speaktouch.model.Type | ||
import com.neo.speaktouch.utils.extensions.* | ||
import timber.log.Timber | ||
|
||
class SpeechInterceptor( | ||
private val textToSpeech: TextToSpeech, | ||
private val context: Context | ||
) : Interceptor { | ||
|
||
override fun handler(event: AccessibilityEvent) { | ||
if (event.eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { | ||
speak(NodeInfo.wrap(event.source ?: return)) | ||
} | ||
} | ||
|
||
fun speak(text: CharSequence) { | ||
|
||
Timber.i("speak: $text") | ||
|
||
textToSpeech.speak( | ||
text, | ||
TextToSpeech.QUEUE_FLUSH, | ||
null, | ||
null | ||
) | ||
} | ||
|
||
private fun speak(node: NodeInfo) { | ||
speak(getContent(node)) | ||
} | ||
|
||
fun shutdown() { | ||
|
||
Timber.i("shutdown") | ||
|
||
textToSpeech.shutdown() | ||
} | ||
|
||
private fun getType( | ||
node: NodeInfo | ||
): String { | ||
|
||
fun getState() = context.getText(node.isChecked) | ||
|
||
return when (Type.get(node)) { | ||
Type.NONE -> "" | ||
Type.IMAGE -> context.getString(R.string.text_image_type) | ||
Type.SWITCH -> context.getString(R.string.text_switch_type, getState()) | ||
Type.TOGGLE -> context.getString(R.string.text_toggle_type, getState()) | ||
Type.RADIO -> context.getString(R.string.text_radio_type, getState()) | ||
Type.CHECKBOX -> context.getString(R.string.text_checkbox_type, getState()) | ||
Type.CHECKABLE -> context.getString(R.string.text_checkable_type, getState()) | ||
Type.BUTTON -> context.getString(R.string.text_button_type) | ||
Type.EDITABLE -> context.getString(R.string.text_editable_type) | ||
Type.OPTIONS -> context.getString(R.string.text_options_type) | ||
Type.LIST -> context.getString(R.string.text_list_type) | ||
Type.TITLE -> context.getString(R.string.text_title_type) | ||
} | ||
} | ||
|
||
private fun getChildrenContent( | ||
node: NodeInfo | ||
): String { | ||
return buildList { | ||
for (index in 0 until node.childCount) { | ||
val nodeChild = node.getChild(index) | ||
|
||
if (nodeChild.isAvailableForAccessibility) { | ||
add(getContent(nodeChild)) | ||
} | ||
} | ||
}.joinToString(", ") | ||
} | ||
|
||
private fun getContent( | ||
node: NodeInfo | ||
) = with(node) { | ||
Timber.d("getContent\n${node.getLog()}") | ||
|
||
val content = contentDescription.ifEmptyOrNull { | ||
text.ifEmptyOrNull { | ||
hintText.ifEmptyOrNull { | ||
getChildrenContent(node) | ||
} | ||
} | ||
} | ||
|
||
listOf( | ||
content, | ||
getType(node), | ||
hintText?.takeIf { it != content }, | ||
error | ||
).filterNotNullOrEmpty() | ||
.joinToString(", ") | ||
} | ||
|
||
companion object { | ||
|
||
fun getInstance(context: Context): SpeechInterceptor { | ||
|
||
var speechInterceptor: SpeechInterceptor? = null | ||
|
||
speechInterceptor = SpeechInterceptor( | ||
textToSpeech = TextToSpeech(context) { status -> | ||
if (status == TextToSpeech.SUCCESS) { | ||
speechInterceptor!!.speak( | ||
"Speak Touch ${context.getText(true)}" | ||
) | ||
} else { | ||
error(message = "TTS_INITIALIZATION_ERROR") | ||
} | ||
}, | ||
context = context | ||
) | ||
|
||
return speechInterceptor | ||
} | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/neo/speaktouch/intercepter/interfece/Interceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.neo.speaktouch.intercepter.interfece | ||
|
||
import android.view.accessibility.AccessibilityEvent | ||
|
||
interface Interceptor { | ||
fun handler(event: AccessibilityEvent) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.neo.speaktouch.model | ||
|
||
import android.widget.* | ||
import com.neo.speaktouch.utils.extensions.NodeInfo | ||
import com.neo.speaktouch.utils.extensions.instanceOf | ||
|
||
enum class Type { | ||
NONE, | ||
IMAGE, | ||
SWITCH, | ||
TOGGLE, | ||
RADIO, | ||
CHECKBOX, | ||
CHECKABLE, | ||
BUTTON, | ||
EDITABLE, | ||
OPTIONS, | ||
LIST, | ||
TITLE; | ||
|
||
companion object { | ||
fun get(node: NodeInfo): Type { | ||
val className = node.className ?: return NONE | ||
|
||
/* ImageView */ | ||
|
||
// View->ImageView->ImageButton | ||
if (className instanceOf ImageButton::class.java) return BUTTON | ||
|
||
// View->ImageView | ||
if (className instanceOf ImageView::class.java) return IMAGE | ||
|
||
/* TextView */ | ||
|
||
// View->TextView->EditText | ||
if (className instanceOf EditText::class.java) return EDITABLE | ||
|
||
/* Button */ | ||
|
||
// View->TextView->Button->CompoundButton->Switch | ||
if (className instanceOf Switch::class.java) return SWITCH | ||
|
||
// View->TextView->Button->CompoundButton->ToggleButton | ||
if (className instanceOf ToggleButton::class.java) return TOGGLE | ||
|
||
// View->TextView->Button->CompoundButton->RadioButton | ||
if (className instanceOf RadioButton::class.java) return RADIO | ||
|
||
// View->TextView->Button->CompoundButton->CheckBox | ||
if (className instanceOf CheckBox::class.java) return CHECKBOX | ||
|
||
// View->TextView->Button | ||
if (className instanceOf Button::class.java) return BUTTON | ||
|
||
/* AdapterView */ | ||
|
||
// View->ViewGroup->AdapterView->AbsListView | ||
if (className instanceOf AbsListView::class.java) return LIST | ||
|
||
// View->ViewGroup->AdapterView->AbsSpinner | ||
if (className instanceOf AbsSpinner::class.java) return OPTIONS | ||
|
||
/* Additional */ | ||
|
||
if (node.isCheckable) return CHECKABLE | ||
|
||
if (node.isEditable) return EDITABLE | ||
|
||
if (node.collectionInfo != null) return LIST | ||
|
||
if (node.isHeading) return TITLE | ||
|
||
return NONE | ||
} | ||
} | ||
} |
Oops, something went wrong.