@Test public void testMaxLines() throws Throwable { final int maxLinesCount = 4; onView(withId(R.id.text_view)).perform(setMaxLines(maxLinesCount)); assertEquals("Empty view: Max lines must match", TextViewCompat.getMaxLines(mTextView), maxLinesCount); onView(withId(R.id.text_view)).perform(setText(R.string.test_text_short)); assertEquals("Short text: Max lines must match", TextViewCompat.getMaxLines(mTextView), maxLinesCount); onView(withId(R.id.text_view)).perform(setText(R.string.test_text_medium)); assertEquals("Medium text: Max lines must match", TextViewCompat.getMaxLines(mTextView), maxLinesCount); onView(withId(R.id.text_view)).perform(setText(R.string.test_text_long)); assertEquals("Long text: Max lines must match", TextViewCompat.getMaxLines(mTextView), maxLinesCount); }
public static int getMaxLines(@NonNull TextView textView) { if (Build.VERSION.SDK_INT >= 16) { return textView.getMaxLines(); } if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; }
TextViewCompat { public static int getMaxLines(@NonNull TextView textView) { if (Build.VERSION.SDK_INT >= 16) { return textView.getMaxLines(); } if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; } }
TextViewCompat { public static int getMaxLines(@NonNull TextView textView) { if (Build.VERSION.SDK_INT >= 16) { return textView.getMaxLines(); } if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; } private  TextViewCompat(); }
TextViewCompat { public static int getMaxLines(@NonNull TextView textView) { if (Build.VERSION.SDK_INT >= 16) { return textView.getMaxLines(); } if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; } private  TextViewCompat(); static void setCompoundDrawablesRelative(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @DrawableRes int start, @DrawableRes int top, @DrawableRes int end,
            @DrawableRes int bottom); static int getMaxLines(@NonNull TextView textView); static int getMinLines(@NonNull TextView textView); static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId); @NonNull static Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeWithDefaults(@NonNull TextView textView,
            int autoSizeTextType); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithConfiguration(
            @NonNull TextView textView,
            int autoSizeMinTextSize,
            int autoSizeMaxTextSize,
            int autoSizeStepGranularity,
            int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull TextView textView,
            @NonNull int[] presetSizes, int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeTextType(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeStepGranularity(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMinTextSize(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMaxTextSize(@NonNull TextView textView); @NonNull @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView); static void setCustomSelectionActionModeCallback(@NonNull final TextView textView,
                @NonNull final ActionMode.Callback callback); static void setFirstBaselineToTopHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) final int firstBaselineToTopHeight); static void setLastBaselineToBottomHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) int lastBaselineToBottomHeight); static int getFirstBaselineToTopHeight(@NonNull final TextView textView); static int getLastBaselineToBottomHeight(@NonNull final TextView textView); static void setLineHeight(@NonNull final TextView textView,
                              @Px @IntRange(from = 0) int lineHeight); }
TextViewCompat { public static int getMaxLines(@NonNull TextView textView) { if (Build.VERSION.SDK_INT >= 16) { return textView.getMaxLines(); } if (!sMaxModeFieldFetched) { sMaxModeField = retrieveField("mMaxMode"); sMaxModeFieldFetched = true; } if (sMaxModeField != null && retrieveIntFromField(sMaxModeField, textView) == LINES) { if (!sMaximumFieldFetched) { sMaximumField = retrieveField("mMaximum"); sMaximumFieldFetched = true; } if (sMaximumField != null) { return retrieveIntFromField(sMaximumField, textView); } } return -1; } private  TextViewCompat(); static void setCompoundDrawablesRelative(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end,
            @Nullable Drawable bottom); static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView,
            @DrawableRes int start, @DrawableRes int top, @DrawableRes int end,
            @DrawableRes int bottom); static int getMaxLines(@NonNull TextView textView); static int getMinLines(@NonNull TextView textView); static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId); @NonNull static Drawable[] getCompoundDrawablesRelative(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeWithDefaults(@NonNull TextView textView,
            int autoSizeTextType); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithConfiguration(
            @NonNull TextView textView,
            int autoSizeMinTextSize,
            int autoSizeMaxTextSize,
            int autoSizeStepGranularity,
            int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static void setAutoSizeTextTypeUniformWithPresetSizes(@NonNull TextView textView,
            @NonNull int[] presetSizes, int unit); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeTextType(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeStepGranularity(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMinTextSize(@NonNull TextView textView); @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int getAutoSizeMaxTextSize(@NonNull TextView textView); @NonNull @SuppressWarnings("RedundantCast") // Intentionally invoking interface method. static int[] getAutoSizeTextAvailableSizes(@NonNull TextView textView); static void setCustomSelectionActionModeCallback(@NonNull final TextView textView,
                @NonNull final ActionMode.Callback callback); static void setFirstBaselineToTopHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) final int firstBaselineToTopHeight); static void setLastBaselineToBottomHeight(
            @NonNull final TextView textView,
            @Px @IntRange(from = 0) int lastBaselineToBottomHeight); static int getFirstBaselineToTopHeight(@NonNull final TextView textView); static int getLastBaselineToBottomHeight(@NonNull final TextView textView); static void setLineHeight(@NonNull final TextView textView,
                              @Px @IntRange(from = 0) int lineHeight); static final int AUTO_SIZE_TEXT_TYPE_NONE; static final int AUTO_SIZE_TEXT_TYPE_UNIFORM; }