Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc137f35 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Simplify the wrapper for TextInfo#getCharSequence

This CL simplifies the wrapper method for
TextInfo#getCharSequence() because in the almost all cases we want
to use the result of TextInfo#getText() as the default value.

BUG: 16029304
Change-Id: I62f987aed8ca42b093255e6c0703d6120fa01299
parent ba1cd8a4
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.inputmethod.annotations.UsedForTesting;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Locale;

@UsedForTesting
public final class TextInfoCompatUtils {
@@ -50,9 +49,18 @@ public final class TextInfoCompatUtils {
                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
    public static CharSequence getCharSequence(final TextInfo textInfo,
            final CharSequence defaultValue) {
    public static CharSequence getCharSequenceOrString(final TextInfo textInfo) {
        final CharSequence defaultValue = (textInfo == null ? null : textInfo.getText());
        return (CharSequence) CompatUtils.invoke(textInfo, defaultValue,
                TEXT_INFO_GET_CHAR_SEQUENCE);
    }
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class TextInfoCompatUtilsTests extends AndroidTestCase {
        final Spanned expectedSpanned = (Spanned) text.subSequence(TEST_CHAR_SEQUENCE_START,
                TEST_CHAR_SEQUENCE_END);
        final CharSequence actualCharSequence =
                TextInfoCompatUtils.getCharSequence(textInfo, textInfo.getText());
                TextInfoCompatUtils.getCharSequenceOrString(textInfo);

        // This should be valid even if TextInfo#getCharSequence is not supported.
        assertTrue(TextUtils.equals(expectedSpanned, actualCharSequence));