green-code-initiative / ecoCode-challenge

Emboard in the hackhatons serie for improving ecoCode
3 stars 4 forks source link

[Hackathon 2024][Niobium][Android] Usage of contentDescription should be required #111

Open tdeffains opened 1 month ago

tdeffains commented 1 month ago

Rule title

Accessibility: Provide contentDescription attribute for each UI element

Language and platform

XML - Android

Rule description

For accessibility purpose each UI element should be described for visual disabled user who will navigate through the application using Google TalkBack. See Google documentation. This description is provided by adding contentDescription attribute to the UI element.

Bad code:

<ImageView
        android:id="@+id/image_id"
        android:src="@drawable/ic_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

Good code:

<ImageView
        android:id="@+id/image_id"
        android:src="@drawable/ic_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:content_description="@string/image_description"
        />

Rule short description

contentDescription should be provided for each UI element.

Rule justification

Accessibility has become a major concern regarding mobile application development and it is part of WCAG requirements (WCAG 2.2).

Severity / Remediation Cost

Severity: Critical - regarding the accessibility category this flaw should be considered critical because users who need vocal assistance to navigate through the application will not be able to if this rule is not respected.

Remediation cost: Easy - add the contentDescription attribute. If the element should be not be considered by TalkBack the value can be set to null.

Implementation principle