List of usage examples for android.support.v4.util Preconditions checkState
public static void checkState(final boolean expression, String message)
From source file:android.support.text.emoji.EmojiCompat.java
/** * Return singleton EmojiCompat instance. Should be called after * {@link #init(EmojiCompat.Config)} is called to initialize the singleton instance. * * @return EmojiCompat instance//from w w w . j a va2 s. com * * @throws IllegalStateException if called before {@link #init(EmojiCompat.Config)} */ public static EmojiCompat get() { synchronized (sInstanceLock) { Preconditions.checkState(sInstance != null, "EmojiCompat is not initialized. Please call EmojiCompat.init() first"); return sInstance; } }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Returns {@code true} if EmojiCompat is capable of rendering an emoji. When used on devices * running API 18 or below, always returns {@code false}. * * @param sequence CharSequence representing the emoji * * @return {@code true} if EmojiCompat can render given emoji, cannot be {@code null} * * @throws IllegalStateException if not initialized yet *//*w ww . j av a 2 s. co m*/ public boolean hasEmojiGlyph(@NonNull final CharSequence sequence) { Preconditions.checkState(isInitialized(), "Not initialized yet"); Preconditions.checkNotNull(sequence, "sequence cannot be null"); return mHelper.hasEmojiGlyph(sequence); }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Returns {@code true} if EmojiCompat is capable of rendering an emoji at the given metadata * version. When used on devices running API 18 or below, always returns {@code false}. * * @param sequence CharSequence representing the emoji * @param metadataVersion the metadata version to check against, should be greater than or * equal to {@code 0}, * * @return {@code true} if EmojiCompat can render given emoji, cannot be {@code null} * * @throws IllegalStateException if not initialized yet *//*www . jav a 2 s. com*/ public boolean hasEmojiGlyph(@NonNull final CharSequence sequence, @IntRange(from = 0) final int metadataVersion) { Preconditions.checkState(isInitialized(), "Not initialized yet"); Preconditions.checkNotNull(sequence, "sequence cannot be null"); return mHelper.hasEmojiGlyph(sequence, metadataVersion); }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Checks a given CharSequence for emojis, and adds EmojiSpans if any emojis are found. * <p>//from w ww . ja va2 s . c o m * <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); }
From source file:android.support.text.emoji.EmojiCompat.java
/** * Returns signature for the currently loaded emoji assets. The signature is a SHA that is * constructed using emoji assets. Can be used to detect if currently loaded asset is different * then previous executions. When used on devices running API 18 or below, returns empty string. * * @throws IllegalStateException if not initialized yet *///from w ww .j a v a 2 s. co m @NonNull public String getAssetSignature() { Preconditions.checkState(isInitialized(), "Not initialized yet"); return mHelper.getAssetSignature(); }