2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

For #15636 - Focus a11y collection on snackbar view tap (#16853)

With accessibility enabled, when adding a site to a collection and tapping "View" on the snackbar, we send a request for focus and an `AccessibilityEvent.TYPE_VIEW_FOCUSED` to the specified collection.
This commit is contained in:
Codrut Topliceanu 2020-12-11 14:32:37 +02:00 committed by GitHub
parent bb2df4c887
commit 556fea5591
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View File

@ -15,7 +15,9 @@ import android.view.Display.FLAG_SECURE
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.AccessibilityDelegate
import android.view.ViewGroup import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.widget.Button import android.widget.Button
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.PopupWindow import android.widget.PopupWindow
@ -954,6 +956,43 @@ class HomeFragment : Fragment() {
border?.animate()?.alpha(1.0F)?.setStartDelay(ANIM_ON_SCREEN_DELAY) border?.animate()?.alpha(1.0F)?.setStartDelay(ANIM_ON_SCREEN_DELAY)
?.setDuration(FADE_ANIM_DURATION) ?.setDuration(FADE_ANIM_DURATION)
?.setListener(listener)?.start() ?.setListener(listener)?.start()
}.invokeOnCompletion {
val a11yEnabled = context?.settings()?.accessibilityServicesEnabled ?: false
if (a11yEnabled) {
focusCollectionForTalkBack(indexOfCollection)
}
}
}
/**
* Will focus the collection with [indexOfCollection] for accessibility services.
* */
private fun focusCollectionForTalkBack(indexOfCollection: Int) {
viewLifecycleOwner.lifecycleScope.launch {
var focusedForAccessibility = false
view?.let { mainView ->
mainView.accessibilityDelegate = object : AccessibilityDelegate() {
override fun onRequestSendAccessibilityEvent(
host: ViewGroup,
child: View,
event: AccessibilityEvent
): Boolean {
if (!focusedForAccessibility &&
event.eventType == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
) {
sessionControlView?.view?.findViewHolderForAdapterPosition(
indexOfCollection
)?.itemView?.let { viewToFocus ->
focusedForAccessibility = true
viewToFocus.requestFocus()
viewToFocus.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
return false
}
}
return super.onRequestSendAccessibilityEvent(host, child, event)
}
}
}
} }
} }

View File

@ -72,7 +72,7 @@
android:padding="16dp" android:padding="16dp"
android:scrollbars="none" android:scrollbars="none"
android:transitionGroup="false" android:transitionGroup="false"
android:importantForAccessibility="no" android:importantForAccessibility="yes"
android:overScrollMode="never" android:overScrollMode="never"
tools:listheader="@layout/collection_header" tools:listheader="@layout/collection_header"
tools:listitem="@layout/collection_home_list_row" tools:listitem="@layout/collection_home_list_row"