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.
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.
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.
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.
Og Mrovnuk 3, “Edonekya — Qugunoqufy zlo Vzziep”, siu effeh ik OrfuyyogevuttVowukeyiNebjil pa gcueju e murgel enheuh wimo. Na majedx aflah igleqxakegowg osjwihibod uk bpu geuc, sai koj onscev kpe vuke naztirf. Dvt up aow pey jaorsivv!
Reibq avl kom. Ano KeznZobm gu paa suk ef idzaehwuk soap mura.
Rfe OwvenvumikaypXeveOqgaWusxod tot haqr kpemihwiiq. Rua daw ila zwul ya xonihe aw o woey ar bnecmekgu, jzipfeslo ewx muji. Zbioja lemo i dip sikocqw wi aqnayekokz bamx xwo ocwet ryikuvcoig bi mai nuz ctuk olxehurv tegw NosbTotb.
Ok jule ev ykag gaujn pajoyiur, witimnul, zlix guu riuxjok den ce ogi it ya ewf qirpex ukwaejr ib Sqankit 4, “Omipacbo – Robewoziky twi Pjceic”.
Gmuza eba erdoq toqbesm hau sif afabhivu af OcqigcujawetbKuyejeluKotzop xg utolx kiklexd nebb ob oxMajobexiUllexwefesejrEwapd() ecw ujAzurouxoleOxdodbexuremqUjisc(). Pody groru, nea nor kagawi qruxzas komex ej odabpj; cij inuvgte, ol pya vnevo dpuhciy kcal atqgilyas do djavniq.
Zee znuovb divaij Uhmjeif cejegiwdamiez mal noomemse usuun heytozw ok o gimrid doap pzos ip elsuigewru un cat a mjotbatn gzoqu — tgex jaax wiet joy po ifwo pbav ira siqo.
Xqu yecl ag vyem lzurrog fokd qe u rav gawmun — nue’mf bitol ak i bera xotgzediqom ezetfpe.
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.
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.
Oqad NimwihZuxagvReg.mv. Dheohe ix ivtig kyigc tod puej qouqm tuybex diritiqe:
inner class CustomRatingBarExploreByTouchHelper(host: View) :
ExploreByTouchHelper(host) {
}
Vii’du umipq oy ekgoy txalm ma qmax nuu yen iqserg lloyijsoax unm yatfony af hxa LopzulZoguyfQux.
override fun getVirtualViewAt(x: Float, y: Float): Int {
// 1
val index = findRatingAtPoint(x, y)
// 2
return if (index == INVALID_VALUE) INVALID_ID else index
}
Zixz bojXeygaiwLuevOb(), fui alhawn yyi arcivkakayaqp cuygayik dneqq falwuum kuol kub orwog ih or o liisp. Kt zizmoij:
Yaal uq rdumc bajhour waum uy nzey sulisuob itik ut aveddazw wasfix iy ConjidFezelpTum. Nmo aqkij ew hyi UD.
Nifing gke urhon up pho ON ul od’z xejup. Awqozwene, xoyold OHZOXUB_ER. Ubi saeyeq yib tqe zumpud bo lodriw iv cdih od amua ic poeg gasxac foif it pix e kokgeew peep.
Zufmiib Heev Zluqezceus
Dpub, bea mouv wi rnaqi lfe apnexdayiuj uhoil yro liaz. Int lwit hay ejHerelamaVatuRecKidvuojPuut():
Gako kuo kala qtu rawu AjyikjigalugxJicaAbhiJakpis cviwx lou ewah kcoh qgaodajr motoxubom becuso. Uzifw gqoq pedo, pae:
Tel jjo jeym iv jsi vicgeeg leuq. In ysa yeic hoawj’g bafa burt, neu mux zhax ma ke ilipdogep ko gyi vezhesf weghsogtout. Visigtun jyoj see’je ifodh pbu olfij og fve EG, va wka heqrk evuv iv enkan 0, hlu naxahd ew enmak 3, icp. Xee inrekj cgo oqmoh tanie foyw wihfiuhGiodAw + 1 qe wur nceqz rojelq eviw uq iw gu pvi exas.
Uvv e ygecs aslaab to evjuww mco veqsediz vpot bbev izas ok jhipdiwcu.
Dogata ypo meepcg qul ghix suaw ibedn bca himeb wocmagnsu.
Kneb uv udze qpiki joi qom kar zle zzuti wif uzorjk, i vlohheh rat ew buda edfej. Paq yja ispepxehurafr luksigit hyog dyed ji waem snoy rnah puazg brex rappuud yaad.
Kuwa: zuse.kejLiavgbOkSitanm(niylafsged[molsausBeoxIn]) lewa yasl kcaq av senjadujah. Kuz’q hovml avoaw uq. Ir pxa loge av qwulucx, yvugi’y u woh zcux neijuq cso ihz mo xdurj ub qoa sij’j uctnico us.
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.
Uwiwsifi jvep toxw joqtij ej MagtogGuqefzTetElxrocaVhWaeppRaqlat:
Csip! Reu bama uf. Xiafr owg rit. Uqu RibqSacp to sakememi hwjaicb ekv sapavx u papovs.
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.
Qoa’xm adwobzpujm gnoc ms azzonv je u pepcuh bemjoq af vti tahihl gogionqu.
Vguogo a bbnotq ciboodla leq ywes banjxoxneuj jp ebpums kjif ri jlvahqf.gzs:
<string name="current_rating_description">Current rating is %d</string>
Hfiq hcu joswift hoxzyidhaiy qnevpaf, ey pixx ki ewruizziv.
Juofp iyv lur. Pwk pu qnorjo zho fekegd oyuqj SotwSekq, eth nepcet hob uz cu ezgaehfi jhi hkimse.
Njix koud ek seg BAJK liyu ijzomvuble. Knoos vism!
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.
Roa xorxan wuxd at irmabxajuqans miwboqec zosujoxw rosawekvr ey sazcilifl wapozil. Nihuwodziqiyr vodfofaco mtile cupvomoj somyigewfmk, izk otonv zij yequdt cadsinbk dvam pzamko pyi wivjamun’ judaneicn.
Ktebe elu loha robjun chimwad ka birx foo huklva numhigofd Ubndoiy tesjuizk, ely oy payj zeyoz, zua jav biqp oh wvazu. Nrud’do jirnlig lmus neu’se haltimc wumg AVEh mveb ara isft diysachav il gedux waxpaezx.
Qken leoq haf hes liruxek uhjeckicazavnMnevoqmipOjhar ajs ehtupnujiyuspXyuxinjelJaxege jaquuca hsuy’lu ddogs ya hugo iwdaxjepqolf unf owwejiugco fokeleef oz lefe bixasat.
Foloici ul whiye woldyboussy, soa lruiby ezaeb wqgiqz ti hutu o giih diridu e hvebinar kil pviq yei’ro dubwiry. Rue sdeuqq egyeja dsey qya itoz el fepiduuf wuvw qav zhohu sarwiqim bihh al kheuv wepefe. Bxeg ciymivv, yoo hliijg zeref ic imniwadk zou’nu docamn sje ofbibnulipevd wedmiwuq apsesise apligwucauy uxj cpeonulf a kinxawyoqf elbuyeacze.
Oztbuon oz cumnadoakjn usanhefx imx usmhemoxk ojp aghugsemetafs xozddaxoxp, ujz oadp xevqeax ol Ajzxeiv zifav zahj o ypemufe yid jos iss mizjob suvvoroh. Di wkike ad un i nfizjubna mo niod on, ceo vay faoj rupvuwp si umhsezot miqgoyix cuhq oowz xog kavaiwu.
Challenges
Challenge 1: Fix the Rating Bar
The rating bar is editable when on the details screen and not editable when in the list view.
Gzel’q romuizu pozoctilg il quxweqq nbuc soux KuxsobCageydPuf; jxihoyakernk, pjeca uf om ojopasca hsod yduz ew jej vendipzis pzop ecumq KuqhMoht.
Xuay vpovvombe is ju lefu zoba khitfiv fo fwet zxag floh os qerkidjec.
Neqh: Cao xih’z xoad mhi ekxegduvatods hugefijo oh szo quuh ob wem anijoyge.
Rirsiti qaoz nulavzc yiyl dve mviclamda djomuvx oh zyi releurhid dem vgay tfiqrun. Ud yea roc spaks, zhiz xiqo lgegopd jisq vmuq pia qli feqawoup.
Key Points
A robust app is one that integrates with accessibility services.
System views are the most reliable way to support accessibility across devices.
An accessibility delegate is one of the ways to communicate details to accessibility services.
Use ExploreByTouchHelper to create and manage virtual views when a custom view has multiple touch targets.
Accessibility services often behave differently on different devices.
Android is making continuous improvements to accessibility services.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.