am 862d7ec3: Merge "Refactor KeyCodeDescriptionMapper class a bit"
* commit '862d7ec32e22a32878114a799bebe2de9080c5bc': Refactor KeyCodeDescriptionMapper class a bitmain
commit
b5e2da1e6d
|
@ -27,7 +27,8 @@
|
||||||
<skip />
|
<skip />
|
||||||
<!-- no translation found for spoken_auto_correct_obscured (6276420476908833791) -->
|
<!-- no translation found for spoken_auto_correct_obscured (6276420476908833791) -->
|
||||||
<skip />
|
<skip />
|
||||||
<string name="spoken_description_unknown" msgid="3197434010402179157">"Перне коды %d"</string>
|
<!-- no translation found for spoken_description_unknown (5139930082759824442) -->
|
||||||
|
<skip />
|
||||||
<string name="spoken_description_shift" msgid="244197883292549308">"Shift"</string>
|
<string name="spoken_description_shift" msgid="244197883292549308">"Shift"</string>
|
||||||
<string name="spoken_description_shift_shifted" msgid="1681877323344195035">"Shift қосулы (өшіру үшін түрту)"</string>
|
<string name="spoken_description_shift_shifted" msgid="1681877323344195035">"Shift қосулы (өшіру үшін түрту)"</string>
|
||||||
<string name="spoken_description_caps_lock" msgid="3276478269526304432">"Caps lock қосулы (өшіру үшін түрту)"</string>
|
<string name="spoken_description_caps_lock" msgid="3276478269526304432">"Caps lock қосулы (өшіру үшін түрту)"</string>
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardId;
|
import com.android.inputmethod.keyboard.KeyboardId;
|
||||||
import com.android.inputmethod.latin.Constants;
|
import com.android.inputmethod.latin.Constants;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
import com.android.inputmethod.latin.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -79,14 +80,6 @@ final class KeyCodeDescriptionMapper {
|
||||||
/**
|
/**
|
||||||
* Returns the localized description of the action performed by a specified
|
* Returns the localized description of the action performed by a specified
|
||||||
* key based on the current keyboard state.
|
* key based on the current keyboard state.
|
||||||
* <p>
|
|
||||||
* The order of precedence for key descriptions is:
|
|
||||||
* <ol>
|
|
||||||
* <li>Manually-defined based on the key label</li>
|
|
||||||
* <li>Automatic or manually-defined based on the key code</li>
|
|
||||||
* <li>Automatically based on the key label</li>
|
|
||||||
* <li>{code null} for keys with no label or key code defined</li>
|
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @param context The package's context.
|
* @param context The package's context.
|
||||||
* @param keyboard The keyboard on which the key resides.
|
* @param keyboard The keyboard on which the key resides.
|
||||||
|
@ -121,7 +114,20 @@ final class KeyCodeDescriptionMapper {
|
||||||
|
|
||||||
// Just attempt to speak the description.
|
// Just attempt to speak the description.
|
||||||
if (code != Constants.CODE_UNSPECIFIED) {
|
if (code != Constants.CODE_UNSPECIFIED) {
|
||||||
return getDescriptionForKeyCode(context, keyboard, key, shouldObscure);
|
// If the key description should be obscured, now is the time to do it.
|
||||||
|
final boolean isDefinedNonCtrl = Character.isDefined(code)
|
||||||
|
&& !Character.isISOControl(code);
|
||||||
|
if (shouldObscure && isDefinedNonCtrl) {
|
||||||
|
return context.getString(OBSCURED_KEY_RES_ID);
|
||||||
|
}
|
||||||
|
final String description = getDescriptionForCodePoint(context, code);
|
||||||
|
if (description != null) {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(key.getLabel())) {
|
||||||
|
return key.getLabel();
|
||||||
|
}
|
||||||
|
return context.getString(R.string.spoken_description_unknown);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -247,57 +253,35 @@ final class KeyCodeDescriptionMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a localized character sequence describing what will happen when
|
* Returns a localized character sequence describing what will happen when
|
||||||
* the specified key is pressed based on its key code.
|
* the specified key is pressed based on its key code point.
|
||||||
* <p>
|
|
||||||
* The order of precedence for key code descriptions is:
|
|
||||||
* <ol>
|
|
||||||
* <li>Manually-defined shift-locked description</li>
|
|
||||||
* <li>Manually-defined shifted description</li>
|
|
||||||
* <li>Manually-defined normal description</li>
|
|
||||||
* <li>Automatic based on the character represented by the key code</li>
|
|
||||||
* <li>Fall-back for undefined or control characters</li>
|
|
||||||
* </ol>
|
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
* @param context The package's context.
|
* @param context The package's context.
|
||||||
* @param keyboard The keyboard on which the key resides.
|
* @param codePoint The code point from which to obtain a description.
|
||||||
* @param key The key from which to obtain a description.
|
* @return a character sequence describing the code point.
|
||||||
* @param shouldObscure {@true} if text (e.g. non-control) characters should be obscured.
|
|
||||||
* @return a character sequence describing the action performed by pressing the key
|
|
||||||
*/
|
*/
|
||||||
private String getDescriptionForKeyCode(final Context context, final Keyboard keyboard,
|
public String getDescriptionForCodePoint(final Context context, final int codePoint) {
|
||||||
final Key key, final boolean shouldObscure) {
|
|
||||||
final int code = key.getCode();
|
|
||||||
|
|
||||||
// If the key description should be obscured, now is the time to do it.
|
// If the key description should be obscured, now is the time to do it.
|
||||||
final boolean isDefinedNonCtrl = Character.isDefined(code) && !Character.isISOControl(code);
|
final int index = mKeyCodeMap.indexOfKey(codePoint);
|
||||||
if (shouldObscure && isDefinedNonCtrl) {
|
|
||||||
return context.getString(OBSCURED_KEY_RES_ID);
|
|
||||||
}
|
|
||||||
final int index = mKeyCodeMap.indexOfKey(code);
|
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
return context.getString(mKeyCodeMap.valueAt(index));
|
return context.getString(mKeyCodeMap.valueAt(index));
|
||||||
}
|
}
|
||||||
final String accentedLetter = getSpokenAccentedLetterDescription(context, code);
|
final String accentedLetter = getSpokenAccentedLetterDescription(context, codePoint);
|
||||||
if (accentedLetter != null) {
|
if (accentedLetter != null) {
|
||||||
return accentedLetter;
|
return accentedLetter;
|
||||||
}
|
}
|
||||||
// Here, <code>code</code> may be a base (non-accented) letter.
|
// Here, <code>code</code> may be a base (non-accented) letter.
|
||||||
final String unsupportedSymbol = getSpokenSymbolDescription(context, code);
|
final String unsupportedSymbol = getSpokenSymbolDescription(context, codePoint);
|
||||||
if (unsupportedSymbol != null) {
|
if (unsupportedSymbol != null) {
|
||||||
return unsupportedSymbol;
|
return unsupportedSymbol;
|
||||||
}
|
}
|
||||||
final String emojiDescription = getSpokenEmojiDescription(context, code);
|
final String emojiDescription = getSpokenEmojiDescription(context, codePoint);
|
||||||
if (emojiDescription != null) {
|
if (emojiDescription != null) {
|
||||||
return emojiDescription;
|
return emojiDescription;
|
||||||
}
|
}
|
||||||
if (isDefinedNonCtrl) {
|
if (Character.isDefined(codePoint) && !Character.isISOControl(codePoint)) {
|
||||||
return Character.toString((char) code);
|
return StringUtils.newSingleCodePointString(codePoint);
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(key.getLabel())) {
|
return null;
|
||||||
return key.getLabel();
|
|
||||||
}
|
|
||||||
return context.getString(R.string.spoken_description_unknown, code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove this method once TTS supports those accented letters' verbalization.
|
// TODO: Remove this method once TTS supports those accented letters' verbalization.
|
||||||
|
|
Loading…
Reference in New Issue