am fc137f35: Simplify the wrapper for TextInfo#getCharSequence

* commit 'fc137f35c8d7b03676475fbdeabdf82f89782419':
  Simplify the wrapper for TextInfo#getCharSequence
main
Yohei Yukawa 2014-07-09 14:59:20 +00:00 committed by Android Git Automerger
commit 757964ae46
2 changed files with 12 additions and 4 deletions

View File

@ -22,7 +22,6 @@ import com.android.inputmethod.annotations.UsedForTesting;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Locale;
@UsedForTesting @UsedForTesting
public final class TextInfoCompatUtils { public final class TextInfoCompatUtils {
@ -50,9 +49,18 @@ public final class TextInfoCompatUtils {
sequenceNumber); sequenceNumber);
} }
/**
* Returns the result of {@link TextInfo#getCharSequence()} when available. Otherwise returns
* the result of {@link TextInfo#getText()} as fall back.
* @param textInfo the instance for which {@link TextInfo#getCharSequence()} or
* {@link TextInfo#getText()} is called.
* @return the result of {@link TextInfo#getCharSequence()} when available. Otherwise returns
* the result of {@link TextInfo#getText()} as fall back. If {@code textInfo} is {@code null},
* returns {@code null}.
*/
@UsedForTesting @UsedForTesting
public static CharSequence getCharSequence(final TextInfo textInfo, public static CharSequence getCharSequenceOrString(final TextInfo textInfo) {
final CharSequence defaultValue) { final CharSequence defaultValue = (textInfo == null ? null : textInfo.getText());
return (CharSequence) CompatUtils.invoke(textInfo, defaultValue, return (CharSequence) CompatUtils.invoke(textInfo, defaultValue,
TEXT_INFO_GET_CHAR_SEQUENCE); TEXT_INFO_GET_CHAR_SEQUENCE);
} }

View File

@ -58,7 +58,7 @@ public class TextInfoCompatUtilsTests extends AndroidTestCase {
final Spanned expectedSpanned = (Spanned) text.subSequence(TEST_CHAR_SEQUENCE_START, final Spanned expectedSpanned = (Spanned) text.subSequence(TEST_CHAR_SEQUENCE_START,
TEST_CHAR_SEQUENCE_END); TEST_CHAR_SEQUENCE_END);
final CharSequence actualCharSequence = final CharSequence actualCharSequence =
TextInfoCompatUtils.getCharSequence(textInfo, textInfo.getText()); TextInfoCompatUtils.getCharSequenceOrString(textInfo);
// This should be valid even if TextInfo#getCharSequence is not supported. // This should be valid even if TextInfo#getCharSequence is not supported.
assertTrue(TextUtils.equals(expectedSpanned, actualCharSequence)); assertTrue(TextUtils.equals(expectedSpanned, actualCharSequence));