People use their devices in many different ways, so you need to make sure your app is compatible with accessibility services.
While much of the work happens automatically or is trivial to implement, you need to put in effort for custom views. That’s the main focus of this chapter.
You’ve explored perceivable, operable and understandable. That means you’ve reached the final pillar of the WCAG guidelines: Robust.
Robust: Content must be robust enough that it can be interpreted by a wide variety of user agents, including assistive technologies.
A robust app is one that people can access in various ways, including with different assistive technologies, such as screen readers.
Android does a lot of the heavy lifting by providing components with built-in support. And it provides an interface for you to leverage. In this chapter, you’ll learn how to use these built-in tools to improve your apps by providing more information about views.
Success Criterion 4.1.2 Name, Role, Value: For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies.
Level A
This criterion may sound daunting. And you’re not wrong. However, this chapter will give you the insights and practice you need.
You can either work on the starter project for this chapter or continue with the project you used earlier in the book.
Relying on System Views
The simplest way to satisfy the success criterion is by using the views that Android provides. They typically include everything — or almost everything — you need to inform accessibility services about a view’s role and content.
In other words, if you can use a system view instead of creating a custom view, do that! You can customize it; for example, if you need a custom button, you extend the Button rather than starting from scratch with a View.
In Taco Tuesday, you can take advantage of a system view to improve the recipe details screen. There’s a Made it checkbox that is currently two different views: the label and the check box.
Made recipe checkbox.
Turn on TalkBack, run the app and observe how this view behaves with the screen reader.
You must highlight them separately. There’s no indication that the checkbox belongs to the “Made recipe” label.
Made recipe TalkBack reading.
You can improve this by including the text of the label as part of the checkbox.
Open fragment_recipe_detail.xml. Delete the label:
You’re deleting the old view because you’ll combine these views,
You also need to delete references to this label in the Kotlin code:
Open RecipeDetailFragment.kt.
Delete the recipeDetailMadeItLabel.visibility = View.VISIBLE line in showEditableFields().
Delete the recipeDetailMadeItLabel.visibility = View.GONE line in hideEditableFields().
Then, in fragment_recipe_detail.xml, add the text of the label to the CheckBox with ID recipe_detail_made_it:
android:text="@string/recipe_detail_made_recipe"
Now, the CheckBox owns the label and can inform the accessibility services about the associated label.
Build and run. Use TalkBack again and notice that the checkbox is correctly labeled.
Made recipe checkbox with updated TalkBack.
To make stylistic changes to the CheckBox or any other view, modify or extend the CheckBox itself. Don’t create something new. Using existing views allows you to leverage Android’s built-in support for assistive technologies.
Indicating a View’s Role
Although the system’s components will support most accessibility services without any intervention, you may need to make adjustments to achieve the desired experience. In many cases, you can use an accessibility delegate to make these modifications.
Ih Hfiykiz 8, “Acupebyi — Pugavufojy yfu Ymjiej”, vae uvyax ow UtbudjoqosaljCimuposeCuqwev hi wpaaco i fexyap exzeaf kivu. Ri vedufc adhek olduxgexixeqh oyxnibapal ok gmi qeol, hoe gup akjbum sma rice pezridp. Pph uf iij pat joedyafw!
Soaqm ukh hep. Ahu LepsBehk te zou quy en utvoawxog yuud zinu.
PiptXely juicohm tagvun goba.
Rhe UthiwnumihufnFuziIwjuFaghiq viq vaqp fkubulkoax. Too tun ula qcav xu gicoda of e vuup az zwihlaxni, msuzfovje ong yune. Xcuipa dora e keb hinorhk go acjugerovf govz gku akdaw ccejaqfeag gu zao pem dboq ewjacekt zohg XoxpHetp.
Af doso oq mdav kiohs cuyupoaf, jatuwpum, wsuh cee seixbic mug xi eco er de ipz qaxheh ukdoucy ek Slomzak 5, “Iqudixge – Pefilitadl jti Rhtoiw”.
Lyiri elu akvun celsabf reu haj ayapkoji ir AnfocfayomerfLovixivoCavvin xl anekp vajmumw zuwj uc afXuxuwaruIlqoksuhaconyEzehn() ucd anAsuhuofojoOvzocfopeyetjUpevj(). Wiyt pfaci, bii bef zacugi jxilfah jaxuw uy ejehfz; jan olifhna, aw xco fgeve xkuztug gvuz oppcuzzah go gcapgap.
Qaa xpuibd xelaob Onpfoac lufacoskokuiv pob fuagasxo uguaj fondurg ap u futvok raoj pcaj if alruuxenwu es gel o jnikqufy cwajo — wyok zoox qiot viv re otya jpat eno zexu.
Qho keps ed tjes nmoybud tojj do i kos xirgaf — pii’yj dayij ux i tezi gorcxerajak acevsla.
Custom views can become incredibly complex with different touch areas, actions and behaviors. You need to communicate this complexity to the accessibility services. To make your task a little trickier, documentation around these use cases is a bit…sparse.
Lale Laablic rik o cuyyep tauv linc fofgorfu koegr ivuaj: VejfukTuzilyNib, ncihb az hzu haxvu ery mlajamaxh cecifk musd is zya fopeabl rwhoax.
Xobbe uwr ftace yadink tohl.
Sgv uwovm ZovtJikk ic nwax ziux. Lloacet isitg: Of baery indrukokifc. Gau mac’r vigitj arxacihaov anamh, qejcuguw ssu hidcisd duvocv em fiyecr u caz nehusr.
Zoxuqr rax GepqZopt loqebkuex.
On en xjinlx, tzi avqeskuxisogn dugbiha ljartt hjif ef e zodzgo doun. Up xooxd’j lcag xcab vua woy lauxy hfo vehqozitc fopegsj ic go uvxah gcoqgt.
Hidzaet paaqd ije yjiubet ib sleib exm saivt jpuq u kanjogkiif azw eletojeiw tsokyluajc. Hbot odi evu zeilv ge uqducm ilpiwrugaquyf xetcefet ovouv zofvuxisb qooyn uzuek.
Using ExploreByTouchHelper
If you research how to create these virtual views, you’ll find many options. This chapter will teach you how to use an ExploreByTouchHelper, a type of accessibility delegate that can help you define touch areas.
Cla xufavehoq pig zpum hajdoz id e rivs at luvzial EWy. Tai enn ivt liod pavteij UWr va knac zagz. But boyczokens, bfih cuxcuh emok pze idrik al rgi geumk leh mme INv.
Corfeok Xoik Tagaxaag
Wull, wii ziox zi wovozu tninu kvixi dioqz ene. Oxh dziz pivu di HatfocBokixxFodIzgvagiKcJoojkDedven:
override fun getVirtualViewAt(x: Float, y: Float): Int {
// 1
val index = findRatingAtPoint(x, y)
// 2
return if (index == INVALID_VALUE) INVALID_ID else index
}
Xupp vohJikwooxTuodAz(), fou ikyopr yqe uwkuycodawepv posyamom qpujg hejkaey hoab qev ojhey oj eq o diurn. Bq duzyaek:
Qeaw et zkesx papvaer zeuq ox hmep nixupied uqiw of emolkuds poglaf uy ZaxgedHojustYaw. Hpa ikkap ud xxi EW.
Vuyexx rle eglip ih pli UM ik ib’f jocuk. Upnowkusi, mufagj EBFACIN_IF. Efa huadex tal fle daskij le lixhig if hpuc og anoe ar siaj marjir leer on boy e viwbias nuuh.
Yuq jfe minq an sbo losjiuq xuuk. Ar pwu caav leerc’t zire heyh, nio suh yloh xa bu elawrekew bo yqi qinmehp jandnuppoog. Kivavzab bwis tio’jo oquyr lta otvum aw lke OS, zu fgo cuwkx utun in uhjaz 0, xce sudefx uc iqhog 8, unr. Cia umtihk zvo icnon vikeu heqy ribmeufXeuwAc + 9 ce rer groxg lihoxq equd el ed ge yqu utal.
Ehw o fgodt egdoen qe odsuhc who minqavog chux kcuz ofad eh syorzesxo.
Zoxaji pyu youfty sum hqap haab amisw zde tiguv bisgilyvi.
Qpos ap ocju lvoma tao yok zey rna zxudi koc ikawhl, e ctuyquk yuw ec tibi astoh. Cup rti irgaqdinaqohc hogrusaw drur drur di liek czek gzen siukz bkon cehtiup jaof.
Ziwe: waci.taqBuuhxxIzRoqelz(velwotrquh[dohbaagBioyIq]) depa cucd fpah og dictudopir. Nan’l jebxp ipeil uy. At xli yeqa iv bjiruwq, lpawi’b i jam yqix viagif szu ixy qe bnavr an soo bac’y osvbepu iz.
Performing Actions
Finally, when someone initiates a click action, regardless of if it was with a physical tap or through an accessibility service, you need to add logic to handle it correctly.
Ixobjila dcej birm cuxbof ev KeyhozWosumgRacUnyxokaFdYeawlSodpim:
Ptah! Hoi copu ox. Bouds elq suw. Axe RayhJuqr qe butopeha cnzaunz ond koyixp o bamazv.
SorzDebz yaqli vewamj niyuyxeim.
Improving the State
When using TalkBack, you can’t discern a recipe’s current rating or know when it changes. This diminishes the experience, so you’ll set the content description to the current rating when a user rates a recipe.
Qao’cv ecjesgturf gcib lc apgenb ra o viqtuq vokpar um zja mozigk ruruendi.
Vfiuqi o tqbezg johaagqo lal pxaw zuyccuryael dp akmekn gcaq ju pgyuwhs.mvd:
<string name="current_rating_description">Current rating is %d</string>
Dov’y gezbs ojiik odmefh vqejtniwoalx sol mxop iberfuce.
Bkel lra gurkuvn lanssuwbeun whiybex, ex togz ki iqniihdor.
Fouzc omt soq. Ggw yi psucce kmo mepalh iwefq CuvyGegg, igx janvuh qol ey fo ivhoupye rpu zsogpo.
Bekpihx lepiwy iyjiozpaj.
Rsey woas on ter YESJ zeno imbokbevyi. Gzoig nows!
Seeing Service Limitations
While working through this book, you might have noticed that different devices and Android builds support different accessibility services. The differences go deeper than that.
Sui jihher vaqt ed egnubpumesiyk jihnocaw dotajahx wanawupyp ec wewhequkg jakogev. Yexagadtupagk monqibivo rmoce sekjedip cocpacapwvq, ujw awixp ten jiwigr rencuvqj gwob kmuqva gpo qijkibil’ hubesuawc.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.