-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature - Add accessibility support for android date picker (#314)
* Implemented accessibility support for android date picker. * Created new function to return accessible text. Changed access modifier of few functions to public. * removed duplicate contentDescription for accessibility to work correct. * Added finnish and swedish localizations for accessible items in datepicker. * Added localisation english texts. * Implemented localisations for accessible selections made inside android datepicker. * Added getLocaleStringResource function for getting localised string resource. * Added required imports for getLocaleStringResource function. * Content description set based on localised strings from resources initially. * Implemented meaningful content description for dateTime picker. Added new keys for time prefix. Content description set when screen reader is focused on picker wheels. * Updated correct finnish and swedish translations. * refactor: move accessibility to its own class Co-authored-by: Jencir CJ <[email protected]> Co-authored-by: Henning Hall <[email protected]>
- Loading branch information
1 parent
1c4063d
commit 5038b6b
Showing
12 changed files
with
260 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
android/src/main/java/com/henninghall/date_picker/ui/Accessibility.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.henninghall.date_picker.ui; | ||
|
||
import android.view.View; | ||
import android.view.accessibility.AccessibilityEvent; | ||
|
||
import com.henninghall.date_picker.State; | ||
import com.henninghall.date_picker.Utils; | ||
import com.henninghall.date_picker.wheelFunctions.WheelFunction; | ||
import com.henninghall.date_picker.wheels.Wheel; | ||
|
||
import java.util.Locale; | ||
|
||
public class Accessibility { | ||
|
||
public static class SetAccessibilityDelegate implements WheelFunction { | ||
|
||
private final Locale locale; | ||
|
||
public SetAccessibilityDelegate(Locale locale) { | ||
this.locale = locale; | ||
} | ||
|
||
@Override | ||
public void apply(Wheel wheel) { | ||
final View view = wheel.picker.getView(); | ||
view.setAccessibilityDelegate( | ||
new View.AccessibilityDelegate(){ | ||
@Override | ||
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) { | ||
super.onPopulateAccessibilityEvent(host, event); | ||
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED) { | ||
String resourceKey = view.getTag().toString()+"_description"; | ||
String localeTag = Utils.getLocalisedStringFromResources(locale, resourceKey); | ||
// Screen reader reads the content description when focused on each picker wheel | ||
view.setContentDescription(localeTag); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
private final State state; | ||
private final Wheels wheels; | ||
|
||
public Accessibility(State state, Wheels wheels){ | ||
this.state = state; | ||
this.wheels = wheels; | ||
} | ||
|
||
public void update(Wheel picker){ | ||
String tagName = picker.picker.getView().getTag().toString(); | ||
String selectedDateString = getAccessibleTextForSelectedDate(); | ||
String descriptionPrefix = Utils.getLocalisedStringFromResources(state.getLocale(), "selected_"+tagName+"_description"); | ||
String descriptionPostFix = Utils.getLocalisedStringFromResources(state.getLocale(), "selected_value_description"); | ||
|
||
picker.picker.getView().setContentDescription(descriptionPrefix + ", "+ descriptionPostFix + " "+ selectedDateString); | ||
} | ||
|
||
private String getAccessibleTextForSelectedDate() { | ||
String accessibleText; | ||
switch(state.getMode()) { | ||
case date: | ||
accessibleText = wheels.getDateString(); | ||
break; | ||
case time: | ||
accessibleText = wheels.getTimeString(); | ||
break; | ||
default: | ||
// default is dateTime | ||
String timePrefix = Utils.getLocalisedStringFromResources(state.getLocale(), "time_tag"); | ||
String hourPrefix = Utils.getLocalisedStringFromResources(state.getLocale(), "hour_tag"); | ||
String minutesPrefix = Utils.getLocalisedStringFromResources(state.getLocale(), "minutes_tag"); | ||
accessibleText = wheels.getAccessibleDateTimeString(timePrefix, hourPrefix, minutesPrefix); | ||
break; | ||
} | ||
return accessibleText; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.