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

[fenix] For https://github.com/mozilla-mobile/fenix/issues/16477: Switch to using an extension to update a11y collection info.

This commit is contained in:
mcarare 2020-11-12 16:39:57 +02:00 committed by Mihai Adrian Carare
parent 2302a589da
commit 1ed7efce41
2 changed files with 34 additions and 22 deletions

View File

@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@file:Suppress("TooManyFunctions")
package org.mozilla.fenix.ext
import android.graphics.Rect
@ -95,6 +97,28 @@ fun View.updateAccessibilityCollectionItemInfo(
}
}
/**
* Updates the a11y collection info for a list.
*/
fun View.updateAccessibilityCollectionInfo(
rowCount: Int,
columnCount: Int
) {
this.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
info?.collectionInfo = AccessibilityNodeInfo.CollectionInfo.obtain(
rowCount,
columnCount,
false
)
}
}
}
/**
* Fills a [Rect] with data about a view's location in the screen.
*
@ -103,10 +127,12 @@ fun View.updateAccessibilityCollectionItemInfo(
*/
fun View.getRectWithScreenLocation(): Rect {
val locationOnScreen = IntArray(2).apply { getLocationOnScreen(this) }
return Rect(locationOnScreen[0],
return Rect(
locationOnScreen[0],
locationOnScreen[1],
locationOnScreen[0] + width,
locationOnScreen[1] + height)
locationOnScreen[1] + height
)
}
/**

View File

@ -9,8 +9,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo
import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo
import androidx.annotation.IdRes
import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
@ -52,6 +50,7 @@ import org.mozilla.fenix.components.toolbar.TabCounter.Companion.MAX_VISIBLE_TAB
import org.mozilla.fenix.components.toolbar.TabCounter.Companion.SO_MANY_TABS_OPEN
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.updateAccessibilityCollectionInfo
import org.mozilla.fenix.tabtray.SaveToCollectionsButtonAdapter.MultiselectModeChange
import org.mozilla.fenix.tabtray.TabTrayDialogFragmentState.Mode
import java.text.NumberFormat
@ -673,24 +672,11 @@ class TabTrayView(
String.format(view.context.getString(R.string.open_tab_tray_plural), count.toString())
}
view.tabsTray.accessibilityDelegate = object : View.AccessibilityDelegate() {
override fun onInitializeAccessibilityNodeInfo(
host: View?,
info: AccessibilityNodeInfo?
) {
super.onInitializeAccessibilityNodeInfo(host, info)
val isListTabView = view.context.settings().listTabView
val columnCount = if (isListTabView) 1 else getNumberOfGridColumns(view.context)
val rowCount = count.toDouble().div(columnCount).roundToInt()
info?.collectionInfo = CollectionInfo.obtain(
rowCount,
columnCount,
false
)
}
}
view.tabsTray.updateAccessibilityCollectionInfo(rowCount, columnCount)
}
private fun updateTabCounter(count: Int): String {