-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Accessibility | ||
Accessible apps allow more users to use your app; however, it is usually an afterthought for developers, and it makes your XML layout files messy whether Accessibility was a forethought or afterthought. This library allows for hassle-free accessibility additions in your application — possibly in 1 line of code! | ||
|
||
##Motivation | ||
|
||
I was finishing up a project of mine, and as an afterthought, of course, I decided to add Accessibility of navigation in custom views and Accessibility of spoken text. Since I always disliked accessibility additions "uglifying" my XML Layout Resource files, I decided to do it programmatically; however, that typically would only "uglifying" my Java code, and if there is anything I dislike the more, it is ugly Java code. | ||
|
||
So for kicks and giggles, I went the Java code path and object-orientified it and was able to produce this libary. | ||
|
||
##Usage | ||
|
||
###Custom View | ||
|
||
public class ContributionView extends RelativeLayout implements Mappable<Resume.Contribution> { | ||
|
||
// Called from Constructors | ||
private void init(AttributeSet attrs, int defStyle) { | ||
|
||
root = (ViewGroup) LayoutInflater.from(getContext()).inflate( | ||
R.layout.internal_contribution_view, this, true); | ||
|
||
... | ||
|
||
// Declare Navigation Accessibility | ||
Accessibility.with(root) | ||
// Disable certain views in the ViewGroup from ever gaining focus | ||
.disableFocusableNavigationOn( | ||
R.id.contribution_textview_creator, | ||
R.id.contribution_textview_year) | ||
|
||
// For all focusable views in the ViewGroup, set the D-pad Navigation | ||
.setFocusableNavigationOn(txtProjectName) | ||
.down(R.id.contribution_textview_description).complete() | ||
.setFocusableNavigationOn(txtContributionDescription) | ||
.up(R.id.contribution_textview_name) | ||
.down(R.id.contribution_textview_link).complete() | ||
.setFocusableNavigationOn(txtProjectLink) | ||
.up(R.id.project_textview_description).complete() | ||
|
||
// Set which view in the ViewGroup will have be first to be focused | ||
.requestFocusOn(R.id.contribution_textview_name); | ||
|
||
invalidateView(); | ||
|
||
} | ||
private void invalidateView() { | ||
|
||
... | ||
|
||
// Declare Content Description Accessibility | ||
Accessibility.with(root) | ||
|
||
// Set the content descriptions for each focusable view in the ViewGroup | ||
|
||
// Set the content description for the Contribution Name | ||
.setAccessibilityTextOn(txtProjectName) | ||
.setModifiableContentDescription(getProjectName()) | ||
.prepend("Contribution occurred on the Project called ") | ||
.append(String.format(" by %s in %s", | ||
getProjectCreator(), | ||
getContributionYear())).complete() | ||
|
||
// Set the content description for the Contribution Description | ||
.setAccessibilityTextOn(txtContributionDescription) | ||
.setModifiableContentDescription(getContributionDescription()) | ||
.prepend("Description: ").complete() | ||
|
||
// Set the content description for the Contribution URL | ||
.setAccessibilityTextOn(txtProjectLink) | ||
.setModifiableContentDescription(getProjectLink()) | ||
.prepend("URL is ").complete(); | ||
|
||
} | ||
|
||
... | ||
|
||
} |