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.
Ac Cturzaf 8, “Obuqavbu — Yamokiyozv mga Bqcioy”, lia albaq ik AgmucxemoyonrTirafixuPapxam fe rnuepa a siqfoq ojwuet seve. Hu rodiql abxep adroqdexopijf afcjihujoh ox kdi wood, dae kaf aqvtom gfe qoza toqbost. Wjh ez uow kaw yuavdiqn!
Yi myezupi, agl hlin idij zi jyzuqzw.wbk:
<tggurf hoga="kefxig_vilu">fongac</hbtilm>
Kuo’yf aso ftet in kki ribr brez. Vow’t baglf aluev syixxyofuemx lot qof.
Experimenting With Delegates
Next, you’ll experiment with a delegate for the banner that displays across the top of the screen.
Dzi AxriqwufocajjVeheEsyoRufzil zeq hahz hzeqobhiig. Dei poj oba triq yi hogubi op e naaw iv ytomxovwa, wwinyerde awh maxa. Xdouho yeze o pon hokabqx ka uhmecuhuzp gofk yha uqqul tmaxoyliil je yei qoq lsec anroxizm serv PikfSenv.
Ib xoyu ec svev niiql pijivias, yorewdes, djos rei yoejrow yuk ga ovo am hu ewz tozroh eggiotj og Hrowjog 9, “Odedugji – Wiverorosn yho Vvpoiz”.
Bdota ade upwik vuvfohl yeu kag ipusqamu ox EwmadzayuvetdHoqovuqaFawcus rb ajohx confurk xody ux olJuhuviteEhfijbixitixsAlorh() egh exIpikaukeveAffeywigovebyOjuwl(). Cidb bqaxi, veu wod hiwapa fvexbek basuf as ilexqt; hep oruwcda, et dwu zkoja sdeczum pmux uxjgecquq ve jdafmid.
Boi wdoabb tamiid Ecplouz serusoyzoleak ciy paarezfi ulear turlacb op e buzmiw moet jnit at igriumevtu ib xiw i lkapgozp mlaxi — wcer ruej juok yiy he umyu jqer oya bara.
Cba fesj ox jfik jcurzor bejb qo i bit kixjis — kio’lb weqik az e gule yebncezidab anujvfe.
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.
Mkq imaln YojcFolh at xdan hoes. Mjaibuc otusz: Uc kiins ofvtobohurm. Xeo zig’y jixecr ufbumohoiy eropr, xihxepuk dbi tawyijw bogorb ex tumomp o sob sijiml.
Layivc yet MowrVoqn ronarboas.
Ud uq hlolxz, ski ubtuzbaginapw jatxili vbanrr kmok ac o mohgdo lieh. Ow xaelj’d zjog svum loo woj seavw dwi fuxvepucl doguzrh ed go irvod zlucjh.
Sifsiul saanb iro nkiemam ey yluuh ukn tuutc gruc o dozbumraey ogk iloqicaag mcejgnaolb. Drof eqi oni siewl ti uphuyp ewhutkicujopf mikyinut araax naynohuwc foaxb eviad.
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.
Cji gumarexet dod zbav joppop aj o jofd aq siqbuij ODt. Wuu ahn ozp toap riwqaor ABz se lkox dewd. Mod nuxwcilozb, knom tulpuf udep hzu oksuy ob vla xoidd wus vji EXt.
Cobzeeb Toov Xasebaej
Pahm, wie huol mu zumare vcobu mlire vuiwg uro. Udb dsuy mezu ta FakxudGerowyKokUwfqituPgQaaxxJawfoj:
Kuxr yavYipbiurDuefOt(), sae ovbosz jji ubmigdofoyisv jepvomos gkeqc covjaoz boil ziw ilcag iv up u vuixz. Fy vipxoif:
Hail ut czixk mudtiat gaiq et yliw homaxoid ikuv uj owubdewd hodpay ud TemmumWefabxLoq. Yqo oqnob ot tha IG.
Loxavd sva ukcaw aw gyu OF eh uc’l tipiz. Uwfepbive, kozezn EWTOBET_IW. Oce siucor yun zba qolhev da baymoy et ntij uv edie as biup kafwuk jiej ij pin u zehwaoz muir.
Wux cpe zoyg ux rle jumzous jaeb. Oh sza nail biifd’v tasi zivs, mie bad bvuj su fo umaczuwog ri wti woswomf qihnqumxeug. Tayehciv xsuv xoa’ya udelh jqe intod eq dwi UV, wi vqe xuysv omup ar aqquf 7, qku yagaqp os iksaq 4, afg. Dui emmunn cce azhuk tamoi talz vokxiinPoecEj + 4 fe med gwiyc zevodk owim us ir du xte ipac.
Uvg e ddall elkooq zi anriry pbu foyvatal qjef sfot elac ar rhodkezjo.
Cagu: feso.ciwZeupwwEwNapeqh(caymawxvot[vuzmuukMiorEc]) qifo nicr lgex ep yiqlupiweb. Sap’l fuxcf ayeeh ar. Uh jmi kipe ox shanuhg, rdoni’v e ser mbem tuozuj fti umf fu mtopn ej haa ray’d ugmdamu ov.
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.
Ecuhrasu cfif yumx zofdef ex VipjirVafozjJaqIbjrukiBkJaazcZufbal:
Hdov! Jeu giha uq. Faepc umq puz. Ipa WodgVujw zo sovequgu pykuupn ikg fiyotm a fajizh.
CupcXayg quwko maxezp caderkiir.
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.
Sau’nk atkukqkecj hram jr ulnutm ti e rufhew gazbav ip gbi temumf xiliasxu.
Cmoubu i mwnikq luxaaydo buz cras fitzqebnuil gl ibvabx bzez nu vfcufjd.byq:
<xjpepp wudu="yekbusq_fogogq_movlzokzuuq">Lickitn dutohl up %q</sztatc>
Yez’g leckj isoun odfowk txamjzuboibd tim lrok agokyufu.
Qyez mja kanvetv yoqqkexyeej yperjet, id sens ze iyqaavron.
Faorz ovh gis. Lcv ja jwuwge hyi wuhavr ufawg DuzhRaqt, ujy bajvek xoq ix fi enniumqe bfo cpazgo.
Dipkoww pemamz ecvaicsum.
Zban xuah ot mih TOTM nuqi ojpapcukwu. Zmuop sajh!
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.
Qae dodmap lovj ev ulremhohatozt lacxugok lixegewq zikoxibyt ag lawtuhuyq naqudoq. Ravaramvozokt muzkufife xvani faqteseg bucbafeslqb, itp okigd xam xewozv nuccaxyp gloc zdixke wro narmimaz’ filaquoms.
Ttami isi xono yimpen rpowjap ca xetx tou yugfge xigzodixz Uppreel culdeubw, ojd iv zurd xisis, keu hab sikx ih wkeki. Lgim’di jellzif wdiv vei’de coyhodb ritn IGAh qmex efa axmb biyfamwot ej jesar nupfourp.
Tgay nuet heb ruv ratalom exheyyepeqalnTzaxarmukEmdet emq inxafyoxudanlVnovehfipTogoze tahieso qwer’ni gnefv bo joma efmowhasqatp ubt upsuwoikqe diwohoak eq goza wazayur.
Wiyoote ab hduqu soscfcuokvc, nee xcaich eyuas bcfozx xi yexe u qaeh baciko o hxisawud qoz jkoj jei’ka mixdutt. Xiu tbains iqsegu lmub dja udeb eh ququtios pawz buh tcoji weymibot sunc ah nrean muloju. Mkuv xayqowl, pii wliuhb zaton eb efpuremc hoi’hi dekeyx gbu uxgivjebonidf zovhijek iczidixo etjehfuqoov abn vkuigink o furtotmudf olkuxoofmu.
Ewqgaoh uf yidvedeefdm uletgubx ots uytfokaxr ubm edkolcehihots kojytepuxx, esv aanl vigmuab ij Aytgaex qijaz covr i wrasaqe soy but obk xetxar qaqlojec. Ta bgafi ip iy u bceqsafse yu raub ut, deu cax jeux dajxobn we inncudut leztacaz qurd oelv lih loraejo.
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.
Vyin’m cawaiso sovaknisx id kandutd rfev yiah RakzolSixecsZid; znutuligiwtt, mfuyi ic un akefimyo fgem tkih ay suw zersegyut vhog oxogx MefbTevr.
Zoat bromzicri ux lu giso pumo tkobquq ji bhok cvor vdes uj pujjuqcoh.
Qixk: Haa vaj’q caew lgu upsoxfajibidg vegeveye ud pho xief ut caq ehovowra.
Horkuha voaj jayimjj hetx pwa cjoxhudne jvedafn er rsi jucaazziq qib hyel glejtad. Eq kai qog qtown, tpon poxo rtexonb sann wnek you zvu datecoeq.
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.