List of usage examples for android.support.v4.util Preconditions checkArgumentNonnegative
public static long checkArgumentNonnegative(final long value, final String errorMessage)
From source file:android.support.text.emoji.widget.EmojiEditTextHelper.java
/** * Set the maximum number of EmojiSpans to be added to a CharSequence. The number of spans in a * CharSequence affects the performance of the EditText insert/delete operations. Insert/delete * operations slow down as the number of spans increases. * <p/>//from w w w .ja v a 2 s .c o m * * @param maxEmojiCount maximum number of EmojiSpans to be added to a single CharSequence, * should be equal or greater than 0 * * @see EmojiCompat#process(CharSequence, int, int, int) */ public void setMaxEmojiCount(@IntRange(from = 0) int maxEmojiCount) { Preconditions.checkArgumentNonnegative(maxEmojiCount, "maxEmojiCount should be greater than 0"); mMaxEmojiCount = maxEmojiCount; mHelper.setMaxEmojiCount(maxEmojiCount); }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. * <p>//ww w . java 2 s .c om * <ul> * <li>If no emojis are found, {@code charSequence} given as the input is returned without * any changes. i.e. charSequence is a String, and no emojis are found, the same String is * returned.</li> * <li>If the given input is not a Spannable (such as String), and at least one emoji is found * a new {@link android.text.Spannable} instance is returned. </li> * <li>If the given input is a Spannable, the same instance is returned. </li> * </ul> * When used on devices running API 18 or below, returns the given {@code charSequence} without * processing it. * * @param charSequence CharSequence to add the EmojiSpans, cannot be {@code null} * @param start start index in the charSequence to look for emojis, should be greater than or * equal to {@code 0}, also less than {@code charSequence.length()} * @param end end index in the charSequence to look for emojis, should be greater than or * equal to {@code start} parameter, also less than {@code charSequence.length()} * @param maxEmojiCount maximum number of emojis in the {@code charSequence}, should be greater * than or equal to {@code 0} * @param replaceStrategy whether to replace all emoji with {@link EmojiSpan}s, should be one of * {@link #REPLACE_STRATEGY_DEFAULT}, * {@link #REPLACE_STRATEGY_NON_EXISTENT}, * {@link #REPLACE_STRATEGY_ALL} * * @throws IllegalStateException if not initialized yet * @throws IllegalArgumentException in the following cases: * {@code start < 0}, {@code end < 0}, {@code end < start}, * {@code start > charSequence.length()}, * {@code end > charSequence.length()} * {@code maxEmojiCount < 0} */ @CheckResult public CharSequence process(@NonNull final CharSequence charSequence, @IntRange(from = 0) final int start, @IntRange(from = 0) final int end, @IntRange(from = 0) final int maxEmojiCount, @ReplaceStrategy int replaceStrategy) { Preconditions.checkState(isInitialized(), "Not initialized yet"); Preconditions.checkArgumentNonnegative(start, "start cannot be negative"); Preconditions.checkArgumentNonnegative(end, "end cannot be negative"); Preconditions.checkArgumentNonnegative(maxEmojiCount, "maxEmojiCount cannot be negative"); Preconditions.checkArgument(start <= end, "start should be <= than end"); // early return since there is nothing to do //noinspection ConstantConditions if (charSequence == null) { return charSequence; } Preconditions.checkArgument(start <= charSequence.length(), "start should be < than charSequence length"); Preconditions.checkArgument(end <= charSequence.length(), "end should be < than charSequence length"); // early return since there is nothing to do if (charSequence.length() == 0 || start == end) { return charSequence; } final boolean replaceAll; switch (replaceStrategy) { case REPLACE_STRATEGY_ALL: replaceAll = true; break; case REPLACE_STRATEGY_NON_EXISTENT: replaceAll = false; break; case REPLACE_STRATEGY_DEFAULT: default: replaceAll = mReplaceAll; break; } return mHelper.process(charSequence, start, end, maxEmojiCount, replaceAll); }