Label empty suggestions.

When talkback is enabled, empty strings will have a content description.

Bug 19479836.

Change-Id: I25679a2bdeff238a5330ba406d5bc7e6e2868ba1
main
Dan Zivkovic 2015-02-27 12:38:18 -08:00
parent 69c04cadc7
commit 24c275ccb9
3 changed files with 17 additions and 7 deletions

View File

@ -31,6 +31,9 @@
<!-- Spoken description used during obscured (e.g. password) entry to let the user know that auto-correction will be performed when a key is pressed. --> <!-- Spoken description used during obscured (e.g. password) entry to let the user know that auto-correction will be performed when a key is pressed. -->
<string name="spoken_auto_correct_obscured"><xliff:g id="KEY_NAME" example="Space">%1$s</xliff:g> performs auto-correction</string> <string name="spoken_auto_correct_obscured"><xliff:g id="KEY_NAME" example="Space">%1$s</xliff:g> performs auto-correction</string>
<!-- Spoken description of a suggestion when nothing is specified and the field is blank. -->
<string name="spoken_empty_suggestion">No suggestion</string>
<!-- Spoken description for unknown keyboard keys. --> <!-- Spoken description for unknown keyboard keys. -->
<string name="spoken_description_unknown">Unknown character</string> <string name="spoken_description_unknown">Unknown character</string>
<!-- Spoken description for the "Shift" keyboard key when "Shift" is off. --> <!-- Spoken description for the "Shift" keyboard key when "Shift" is off. -->

View File

@ -342,8 +342,11 @@ final class SuggestionStripLayoutHelper {
* @param placerView the view where the debug info will be placed. * @param placerView the view where the debug info will be placed.
* @return the start index of more suggestions. * @return the start index of more suggestions.
*/ */
public int layoutAndReturnStartIndexOfMoreSuggestions(final SuggestedWords suggestedWords, public int layoutAndReturnStartIndexOfMoreSuggestions(
final ViewGroup stripView, final ViewGroup placerView) { final Context context,
final SuggestedWords suggestedWords,
final ViewGroup stripView,
final ViewGroup placerView) {
if (suggestedWords.isPunctuationSuggestions()) { if (suggestedWords.isPunctuationSuggestions()) {
return layoutPunctuationsAndReturnStartIndexOfMoreSuggestions( return layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
(PunctuationSuggestions)suggestedWords, stripView); (PunctuationSuggestions)suggestedWords, stripView);
@ -362,7 +365,7 @@ final class SuggestionStripLayoutHelper {
// by consolidating all slots in the strip. // by consolidating all slots in the strip.
final int countInStrip = 1; final int countInStrip = 1;
mMoreSuggestionsAvailable = (wordCountToShow > countInStrip); mMoreSuggestionsAvailable = (wordCountToShow > countInStrip);
layoutWord(mCenterPositionInStrip, stripWidth - mPadding); layoutWord(context, mCenterPositionInStrip, stripWidth - mPadding);
stripView.addView(centerWordView); stripView.addView(centerWordView);
setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT); setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT);
if (SuggestionStripView.DBG) { if (SuggestionStripView.DBG) {
@ -385,7 +388,7 @@ final class SuggestionStripLayoutHelper {
} }
final int width = getSuggestionWidth(positionInStrip, stripWidth); final int width = getSuggestionWidth(positionInStrip, stripWidth);
final TextView wordView = layoutWord(positionInStrip, width); final TextView wordView = layoutWord(context, positionInStrip, width);
stripView.addView(wordView); stripView.addView(wordView);
setLayoutWeight(wordView, getSuggestionWeight(positionInStrip), setLayoutWeight(wordView, getSuggestionWeight(positionInStrip),
ViewGroup.LayoutParams.MATCH_PARENT); ViewGroup.LayoutParams.MATCH_PARENT);
@ -414,7 +417,7 @@ final class SuggestionStripLayoutHelper {
* @param width the maximum width for layout in pixels. * @param width the maximum width for layout in pixels.
* @return the {@link TextView} containing the suggested word appropriately formatted. * @return the {@link TextView} containing the suggested word appropriately formatted.
*/ */
private TextView layoutWord(final int positionInStrip, final int width) { private TextView layoutWord(final Context context, final int positionInStrip, final int width) {
final TextView wordView = mWordViews.get(positionInStrip); final TextView wordView = mWordViews.get(positionInStrip);
final CharSequence word = wordView.getText(); final CharSequence word = wordView.getText();
if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) { if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
@ -428,7 +431,10 @@ final class SuggestionStripLayoutHelper {
} }
// {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack. // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
// Use a simple {@link String} to avoid the issue. // Use a simple {@link String} to avoid the issue.
wordView.setContentDescription(TextUtils.isEmpty(word) ? null : word.toString()); wordView.setContentDescription(
TextUtils.isEmpty(word)
? context.getResources().getString(R.string.spoken_empty_suggestion)
: word.toString());
final CharSequence text = getEllipsizedTextWithSettingScaleX( final CharSequence text = getEllipsizedTextWithSettingScaleX(
word, width, wordView.getPaint()); word, width, wordView.getPaint());
final float scaleX = wordView.getTextScaleX(); final float scaleX = wordView.getTextScaleX();

View File

@ -146,6 +146,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
word.setOnClickListener(this); word.setOnClickListener(this);
word.setOnLongClickListener(this); word.setOnLongClickListener(this);
mWordViews.add(word); mWordViews.add(word);
@ -200,7 +201,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
mSuggestedWords = suggestedWords; mSuggestedWords = suggestedWords;
mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions( mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions(
mSuggestedWords, mSuggestionsStrip, this); getContext(), mSuggestedWords, mSuggestionsStrip, this);
mStripVisibilityGroup.showSuggestionsStrip(); mStripVisibilityGroup.showSuggestionsStrip();
} }