@Test public void testSetCustomSelectionActionModeCallback_doesNotIgnoreTheGivenCallback() { Looper.prepare(); final boolean[] callbackCalled = new boolean[4]; TextViewCompat.setCustomSelectionActionModeCallback(mTextView, new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { callbackCalled[0] = true; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { callbackCalled[1] = true; return true; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { callbackCalled[2] = true; return true; } @Override public void onDestroyActionMode(ActionMode mode) { callbackCalled[3] = true; } }); final Menu menu = new MenuBuilder(mTextView.getContext()); final MenuItem item = menu.add("Option"); mTextView.getCustomSelectionActionModeCallback().onCreateActionMode(null, menu); mTextView.getCustomSelectionActionModeCallback().onPrepareActionMode(null, menu); mTextView.getCustomSelectionActionModeCallback().onActionItemClicked(null, item); mTextView.getCustomSelectionActionModeCallback().onDestroyActionMode(null); for (boolean called : callbackCalled) { assertTrue(called); } }
public static void setCustomSelectionActionModeCallback(@NonNull final TextView textView, @NonNull final ActionMode.Callback callback) { if (Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT > 27) { textView.setCustomSelectionActionModeCallback(callback); return; } textView.setCustomSelectionActionModeCallback(new OreoCallback(callback, textView)); }
TextViewCompat { public static void setCustomSelectionActionModeCallback(@NonNull final TextView textView, @NonNull final ActionMode.Callback callback) { if (Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT > 27) { textView.setCustomSelectionActionModeCallback(callback); return; } textView.setCustomSelectionActionModeCallback(new OreoCallback(callback, textView)); } }
TextViewCompat { public static void setCustomSelectionActionModeCallback(@NonNull final TextView textView, @NonNull final ActionMode.Callback callback) { if (Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT > 27) { textView.setCustomSelectionActionModeCallback(callback); return; } textView.setCustomSelectionActionModeCallback(new OreoCallback(callback, textView)); } private  TextViewCompat(); }
TextViewCompat { public static void setCustomSelectionActionModeCallback(@NonNull final TextView textView, @NonNull final ActionMode.Callback callback) { if (Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT > 27) { textView.setCustomSelectionActionModeCallback(callback); return; } textView.setCustomSelectionActionModeCallback(new OreoCallback(callback, textView)); } 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 void setCustomSelectionActionModeCallback(@NonNull final TextView textView, @NonNull final ActionMode.Callback callback) { if (Build.VERSION.SDK_INT < 26 || Build.VERSION.SDK_INT > 27) { textView.setCustomSelectionActionModeCallback(callback); return; } textView.setCustomSelectionActionModeCallback(new OreoCallback(callback, textView)); } 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; }