Merge "Speak auto-corrections for accessibility"

This commit is contained in:
Alan Viverette 2013-09-30 18:14:12 +00:00 committed by Android (Google) Code Review
commit 458fb52b98
4 changed files with 73 additions and 2 deletions

View file

@ -174,6 +174,11 @@
<!-- Spoken description when there is no text entered -->
<string name="spoken_no_text_entered">No text entered</string>
<!-- Spoken description to let the user know what auto-correction will be performed when a key is pressed. -->
<string name="spoken_auto_correct"><xliff:g id="key" example="Space">%1$s</xliff:g> corrects <xliff:g id="original">%2$s</xliff:g> to <xliff:g id="corrected">%3$s</xliff:g></string>
<!-- 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" example="Space">%1$s</xliff:g> has auto-correction</string>
<!-- Spoken description for unknown keyboard keys. -->
<string name="spoken_description_unknown">Key code %d</string>
<!-- Spoken description for the "Shift" keyboard key when "Shift" is off. -->

View file

@ -35,6 +35,8 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardView;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.CollectionUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
@ -285,9 +287,15 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider
private String getKeyDescription(final Key key) {
final EditorInfo editorInfo = mInputMethodService.getCurrentInputEditorInfo();
final boolean shouldObscure = mAccessibilityUtils.shouldObscureInput(editorInfo);
final String keyDescription = mKeyCodeDescriptionMapper.getDescriptionForKey(
final SettingsValues currentSettings = Settings.getInstance().getCurrent();
final String keyCodeDescription = mKeyCodeDescriptionMapper.getDescriptionForKey(
mKeyboardView.getContext(), mKeyboardView.getKeyboard(), key, shouldObscure);
return keyDescription;
if (currentSettings.isWordSeparator(key.getCode())) {
return mAccessibilityUtils.getAutoCorrectionDescription(
keyCodeDescription, shouldObscure);
} else {
return keyCodeDescription;
}
}
/**

View file

@ -23,6 +23,7 @@ import android.os.Build;
import android.os.SystemClock;
import android.provider.Settings;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@ -34,6 +35,7 @@ import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.SettingsSecureCompatUtils;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.utils.InputTypeUtils;
public final class AccessibilityUtils {
@ -48,6 +50,12 @@ public final class AccessibilityUtils {
private AccessibilityManager mAccessibilityManager;
private AudioManager mAudioManager;
/** The most recent auto-correction. */
private String mAutoCorrectionWord;
/** The most recent typed word for auto-correction. */
private String mTypedWord;
/*
* Setting this constant to {@code false} will disable all keyboard
* accessibility code, regardless of whether Accessibility is turned on in
@ -141,6 +149,51 @@ public final class AccessibilityUtils {
return InputTypeUtils.isPasswordInputType(editorInfo.inputType);
}
/**
* Sets the current auto-correction word and typed word. These may be used
* to provide the user with a spoken description of what auto-correction
* will occur when a key is typed.
*
* @param suggestedWords the list of suggested auto-correction words
* @param typedWord the currently typed word
*/
public void setAutoCorrection(final SuggestedWords suggestedWords, final String typedWord) {
if (suggestedWords != null && suggestedWords.mWillAutoCorrect) {
mAutoCorrectionWord = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
mTypedWord = typedWord;
} else {
mAutoCorrectionWord = null;
mTypedWord = null;
}
}
/**
* Obtains a description for an auto-correction key, taking into account the
* currently typed word and auto-correction.
*
* @param keyCodeDescription spoken description of the key that will insert
* an auto-correction
* @param shouldObscure whether the key should be obscured
* @return a description including a description of the auto-correction, if
* needed
*/
public String getAutoCorrectionDescription(
final String keyCodeDescription, final boolean shouldObscure) {
if (!TextUtils.isEmpty(mAutoCorrectionWord)) {
if (!TextUtils.equals(mAutoCorrectionWord, mTypedWord)) {
if (shouldObscure) {
// This should never happen, but just in case...
return mContext.getString(R.string.spoken_auto_correct_obscured,
keyCodeDescription);
}
return mContext.getString(R.string.spoken_auto_correct, keyCodeDescription,
mTypedWord, mAutoCorrectionWord);
}
}
return keyCodeDescription;
}
/**
* Sends the specified text to the {@link AccessibilityManager} to be
* spoken.

View file

@ -2557,6 +2557,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
final String typedWord) {
if (suggestedWords.isEmpty()) {
// No auto-correction is available, clear the cached values.
AccessibilityUtils.getInstance().setAutoCorrection(null, null);
clearSuggestionStrip();
return;
}
@ -2565,6 +2567,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
setSuggestedWords(suggestedWords, isAutoCorrection);
setAutoCorrectionIndicator(isAutoCorrection);
setSuggestionStripShown(isSuggestionsStripVisible());
// An auto-correction is available, cache it in accessibility code so
// we can be speak it if the user touches a key that will insert it.
AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
}
private void showSuggestionStrip(final SuggestedWords suggestedWords) {