diff --git a/app/build.gradle b/app/build.gradle index 0b3a63596b..3bc1316d71 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -450,7 +450,7 @@ dependencies { def annotation_version_experimental = "1.3.1" def core_version = "1.10.1" // 1.12.0-rc01 def appcompat_version = "1.6.1" // 1.7.0-alpha03 - def emoji_version = "1.3.0" // Version 1.4.0-rc01 + def emoji_version = "1.4.0" def flatbuffers_version = "2.0.0" def activity_version = "1.7.2" // 1.8.0-alpha06 def fragment_version = "1.6.1" // 1.7.0-alpha02 diff --git a/app/src/main/java/androidx/emoji2/text/DefaultEmojiCompatConfig.java b/app/src/main/java/androidx/emoji2/text/DefaultEmojiCompatConfig.java index c874512c27..f9ca1031a0 100644 --- a/app/src/main/java/androidx/emoji2/text/DefaultEmojiCompatConfig.java +++ b/app/src/main/java/androidx/emoji2/text/DefaultEmojiCompatConfig.java @@ -102,7 +102,6 @@ public final class DefaultEmojiCompatConfig { * Actual factory for generating default emoji configs, does service locator lookup internally. * * @see DefaultEmojiCompatConfig#create - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public static class DefaultEmojiCompatConfigFactory { @@ -113,7 +112,6 @@ public final class DefaultEmojiCompatConfig { private final DefaultEmojiCompatConfigHelper mHelper; /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public DefaultEmojiCompatConfigFactory(@Nullable DefaultEmojiCompatConfigHelper helper) { @@ -122,7 +120,6 @@ public final class DefaultEmojiCompatConfig { /** * @see DefaultEmojiCompatConfig#create - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @Nullable @@ -150,7 +147,6 @@ public final class DefaultEmojiCompatConfig { * Find the installed font provider and return a FontInfo that describes it. * @param context context for getting package manager * @return valid FontRequest, or null if no provider could be found - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @Nullable @@ -256,7 +252,6 @@ public final class DefaultEmojiCompatConfig { /** * Helper to lookup signatures in package manager. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public static class DefaultEmojiCompatConfigHelper { @@ -295,7 +290,6 @@ public final class DefaultEmojiCompatConfig { /** * Actually do lookups > API 19 * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @RequiresApi(19) @@ -318,7 +312,6 @@ public final class DefaultEmojiCompatConfig { /** * Helper to lookup signatures in package manager > API 28 - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @RequiresApi(28) diff --git a/app/src/main/java/androidx/emoji2/text/DefaultGlyphChecker.java b/app/src/main/java/androidx/emoji2/text/DefaultGlyphChecker.java index 644c026655..345dbef202 100644 --- a/app/src/main/java/androidx/emoji2/text/DefaultGlyphChecker.java +++ b/app/src/main/java/androidx/emoji2/text/DefaultGlyphChecker.java @@ -29,7 +29,6 @@ import androidx.core.graphics.PaintCompat; /** * Utility class that checks if the system can render a given glyph. * - * @hide */ @AnyThread @RestrictTo(LIBRARY) diff --git a/app/src/main/java/androidx/emoji2/text/EmojiCompat.java b/app/src/main/java/androidx/emoji2/text/EmojiCompat.java index 960479608f..af41c890e3 100644 --- a/app/src/main/java/androidx/emoji2/text/EmojiCompat.java +++ b/app/src/main/java/androidx/emoji2/text/EmojiCompat.java @@ -17,7 +17,6 @@ package androidx.emoji2.text; import static androidx.annotation.RestrictTo.Scope.LIBRARY; import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static androidx.annotation.RestrictTo.Scope.TESTS; import android.app.Application; import android.content.Context; @@ -43,6 +42,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; +import androidx.annotation.VisibleForTesting; import androidx.collection.ArraySet; import androidx.core.util.Preconditions; @@ -160,7 +160,6 @@ public class EmojiCompat { public static final int LOAD_STATE_FAILED = 2; /** - * @hide */ @RestrictTo(LIBRARY) @IntDef({LOAD_STATE_DEFAULT, LOAD_STATE_LOADING, LOAD_STATE_SUCCEEDED, LOAD_STATE_FAILED}) @@ -188,7 +187,6 @@ public class EmojiCompat { public static final int REPLACE_STRATEGY_NON_EXISTENT = 2; /** - * @hide */ @RestrictTo(LIBRARY) @IntDef({REPLACE_STRATEGY_DEFAULT, REPLACE_STRATEGY_NON_EXISTENT, REPLACE_STRATEGY_ALL}) @@ -212,7 +210,6 @@ public class EmojiCompat { public static final int LOAD_STRATEGY_MANUAL = 1; /** - * @hide */ @RestrictTo(LIBRARY) @IntDef({LOAD_STRATEGY_DEFAULT, LOAD_STRATEGY_MANUAL}) @@ -221,7 +218,6 @@ public class EmojiCompat { } /** - * @hide */ @RestrictTo(LIBRARY) @IntDef({EMOJI_UNSUPPORTED, EMOJI_SUPPORTED, @@ -341,7 +337,6 @@ public class EmojiCompat { public static final int EMOJI_FALLBACK = 2; /** - * @hide */ @RestrictTo(LIBRARY) static final int EMOJI_COUNT_UNLIMITED = Integer.MAX_VALUE; @@ -502,7 +497,6 @@ public class EmojiCompat { } /** - * @hide */ @RestrictTo(LIBRARY) @Nullable @@ -602,8 +596,8 @@ public class EmojiCompat { * Used by the tests to reset EmojiCompat with a new configuration. Every time it is called a * new instance is created with the new configuration. * - * @hide */ + @RestrictTo(LIBRARY) @NonNull public static EmojiCompat reset(@NonNull final Config config) { synchronized (INSTANCE_LOCK) { @@ -616,9 +610,9 @@ public class EmojiCompat { /** * Used by the tests to reset EmojiCompat with a new singleton instance. * - * @hide */ - @RestrictTo(TESTS) + @RestrictTo(LIBRARY) + @VisibleForTesting @Nullable public static EmojiCompat reset(@Nullable final EmojiCompat emojiCompat) { synchronized (INSTANCE_LOCK) { @@ -630,9 +624,9 @@ public class EmojiCompat { /** * Reset default configuration lookup flag, for tests. * - * @hide */ - @RestrictTo(TESTS) + @RestrictTo(LIBRARY) + @VisibleForTesting public static void skipDefaultConfigurationLookup(boolean shouldSkip) { synchronized (CONFIG_LOCK) { sHasDoneDefaultConfigLookup = shouldSkip; @@ -801,7 +795,6 @@ public class EmojiCompat { /** * @return whether a background should be drawn for the emoji for debugging - * @hide */ @RestrictTo(LIBRARY_GROUP) public boolean isEmojiSpanIndicatorEnabled() { @@ -810,7 +803,6 @@ public class EmojiCompat { /** * @return color of background drawn if {@link EmojiCompat#isEmojiSpanIndicatorEnabled} is true - * @hide */ @RestrictTo(LIBRARY_GROUP) public @ColorInt int getEmojiSpanIndicatorColor() { @@ -830,6 +822,8 @@ public class EmojiCompat { */ public int getEmojiStart(@NonNull final CharSequence charSequence, @IntRange(from = 0) int offset) { + Preconditions.checkState(isInitialized(), "Not initialized yet"); + Preconditions.checkNotNull(charSequence, "charSequence cannot be null"); return mHelper.getEmojiStart(charSequence, offset); } @@ -838,6 +832,8 @@ public class EmojiCompat { */ public int getEmojiEnd(@NonNull final CharSequence charSequence, @IntRange(from = 0) int offset) { + Preconditions.checkState(isInitialized(), "Not initialized yet"); + Preconditions.checkNotNull(charSequence, "charSequence cannot be null"); return mHelper.getEmojiEnd(charSequence, offset); } @@ -1201,7 +1197,6 @@ public class EmojiCompat { /** - * @hide */ @RestrictTo(LIBRARY) public static class DefaultSpanFactory implements SpanFactory { diff --git a/app/src/main/java/androidx/emoji2/text/EmojiDefaults.java b/app/src/main/java/androidx/emoji2/text/EmojiDefaults.java index 9818af1d8e..13dcb49399 100644 --- a/app/src/main/java/androidx/emoji2/text/EmojiDefaults.java +++ b/app/src/main/java/androidx/emoji2/text/EmojiDefaults.java @@ -21,7 +21,6 @@ import androidx.annotation.RestrictTo; /** * Defaults for emojicompat * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public class EmojiDefaults { diff --git a/app/src/main/java/androidx/emoji2/text/EmojiProcessor.java b/app/src/main/java/androidx/emoji2/text/EmojiProcessor.java index 6efcd7a99b..7b388fb528 100644 --- a/app/src/main/java/androidx/emoji2/text/EmojiProcessor.java +++ b/app/src/main/java/androidx/emoji2/text/EmojiProcessor.java @@ -45,7 +45,6 @@ import java.util.Set; /** * Processes the CharSequence and adds the emojis. * - * @hide */ @AnyThread @RestrictTo(LIBRARY) diff --git a/app/src/main/java/androidx/emoji2/text/EmojiSpan.java b/app/src/main/java/androidx/emoji2/text/EmojiSpan.java index 7c334c6057..d106a87d9f 100644 --- a/app/src/main/java/androidx/emoji2/text/EmojiSpan.java +++ b/app/src/main/java/androidx/emoji2/text/EmojiSpan.java @@ -16,7 +16,6 @@ package androidx.emoji2.text; import static androidx.annotation.RestrictTo.Scope.LIBRARY; -import static androidx.annotation.RestrictTo.Scope.TESTS; import android.annotation.SuppressLint; import android.graphics.Paint; @@ -26,6 +25,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; +import androidx.annotation.VisibleForTesting; import androidx.core.util.Preconditions; /** @@ -68,7 +68,6 @@ public abstract class EmojiSpan extends ReplacementSpan { * * @param rasterizer information about the emoji, cannot be {@code null} * - * @hide */ @RestrictTo(LIBRARY) EmojiSpan(@NonNull final TypefaceEmojiRasterizer rasterizer) { @@ -113,7 +112,6 @@ public abstract class EmojiSpan extends ReplacementSpan { /** * @return width of the span * - * @hide */ @RestrictTo(LIBRARY) final int getWidth() { @@ -123,15 +121,14 @@ public abstract class EmojiSpan extends ReplacementSpan { /** * @return height of the span * - * @hide */ - @RestrictTo(TESTS) + @RestrictTo(LIBRARY) + @VisibleForTesting public final int getHeight() { return mHeight; } /** - * @hide */ @RestrictTo(LIBRARY) final float getRatio() { @@ -141,9 +138,9 @@ public abstract class EmojiSpan extends ReplacementSpan { /** * @return unique id for the emoji that this EmojiSpan is used for * - * @hide */ - @RestrictTo(TESTS) + @RestrictTo(LIBRARY) + @VisibleForTesting public final int getId() { return getTypefaceRasterizer().getId(); } diff --git a/app/src/main/java/androidx/emoji2/text/FontRequestEmojiCompatConfig.java b/app/src/main/java/androidx/emoji2/text/FontRequestEmojiCompatConfig.java index 143c06f1b0..62a55d075c 100644 --- a/app/src/main/java/androidx/emoji2/text/FontRequestEmojiCompatConfig.java +++ b/app/src/main/java/androidx/emoji2/text/FontRequestEmojiCompatConfig.java @@ -123,7 +123,6 @@ public class FontRequestEmojiCompatConfig extends EmojiCompat.Config { } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public FontRequestEmojiCompatConfig(@NonNull Context context, @NonNull FontRequest request, @@ -406,7 +405,6 @@ public class FontRequestEmojiCompatConfig extends EmojiCompat.Config { /** * Delegate class for mocking FontsContractCompat.fetchFonts. - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public static class FontProviderHelper { diff --git a/app/src/main/java/androidx/emoji2/text/MetadataListReader.java b/app/src/main/java/androidx/emoji2/text/MetadataListReader.java index 2ed42e0700..f9fde4bb9a 100644 --- a/app/src/main/java/androidx/emoji2/text/MetadataListReader.java +++ b/app/src/main/java/androidx/emoji2/text/MetadataListReader.java @@ -32,7 +32,6 @@ import java.nio.ByteOrder; /** * Reads the emoji metadata from a given InputStream or ByteBuffer. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @AnyThread diff --git a/app/src/main/java/androidx/emoji2/text/MetadataRepo.java b/app/src/main/java/androidx/emoji2/text/MetadataRepo.java index f08ae06653..5835cb348c 100644 --- a/app/src/main/java/androidx/emoji2/text/MetadataRepo.java +++ b/app/src/main/java/androidx/emoji2/text/MetadataRepo.java @@ -15,6 +15,8 @@ */ package androidx.emoji2.text; +import static androidx.annotation.RestrictTo.Scope.LIBRARY; + import android.content.res.AssetManager; import android.graphics.Typeface; import android.util.SparseArray; @@ -85,10 +87,10 @@ public final class MetadataRepo { * Construct MetadataRepo with empty metadata. * * This should only be used from tests. - * @hide */ + @RestrictTo(LIBRARY) @NonNull - @RestrictTo(RestrictTo.Scope.TESTS) + @VisibleForTesting public static MetadataRepo create(@NonNull final Typeface typeface) { try { TraceCompat.beginSection(S_TRACE_CREATE_REPO); @@ -170,7 +172,6 @@ public final class MetadataRepo { } /** - * @hide */ @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY) @@ -179,7 +180,6 @@ public final class MetadataRepo { } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) int getMetadataVersion() { @@ -187,7 +187,6 @@ public final class MetadataRepo { } /** - * @hide */ @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY) @@ -196,7 +195,6 @@ public final class MetadataRepo { } /** - * @hide */ @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY) @@ -205,7 +203,6 @@ public final class MetadataRepo { } /** - * @hide */ @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY) @@ -216,7 +213,6 @@ public final class MetadataRepo { /** * Add a TypefaceEmojiRasterizer to the index. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) @VisibleForTesting @@ -233,7 +229,6 @@ public final class MetadataRepo { * * A single codepoint emoji is represented by a child of the root node. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) static class Node { diff --git a/app/src/main/java/androidx/emoji2/text/SpannableBuilder.java b/app/src/main/java/androidx/emoji2/text/SpannableBuilder.java index 9d46c2f31f..e6fef5cddb 100644 --- a/app/src/main/java/androidx/emoji2/text/SpannableBuilder.java +++ b/app/src/main/java/androidx/emoji2/text/SpannableBuilder.java @@ -44,7 +44,6 @@ import java.util.concurrent.atomic.AtomicInteger; * applied only for EmojiSpans. Therefore any other span change operation works the same way as in * the framework. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) public final class SpannableBuilder extends eu.faircode.email.SpannableStringBuilderEx { @@ -59,7 +58,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui private final @NonNull List mWatchers = new ArrayList<>(); /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) SpannableBuilder(@NonNull Class watcherClass) { @@ -68,7 +66,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) SpannableBuilder(@NonNull Class watcherClass, @NonNull CharSequence text) { @@ -78,7 +75,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) SpannableBuilder(@NonNull Class watcherClass, @NonNull CharSequence text, int start, @@ -89,7 +85,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui } /** - * @hide */ @NonNull @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @@ -137,7 +132,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui mWatchers.add(span); what = span; } - super.setSpan(what, start, end, flags); } @@ -255,7 +249,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public void beginBatchEdit() { @@ -263,7 +256,6 @@ public final class SpannableBuilder extends eu.faircode.email.SpannableStringBui } /** - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY) public void endBatchEdit() { diff --git a/app/src/main/java/androidx/emoji2/text/TypefaceEmojiRasterizer.java b/app/src/main/java/androidx/emoji2/text/TypefaceEmojiRasterizer.java index f120b3cb23..cd45cd2d1d 100644 --- a/app/src/main/java/androidx/emoji2/text/TypefaceEmojiRasterizer.java +++ b/app/src/main/java/androidx/emoji2/text/TypefaceEmojiRasterizer.java @@ -17,7 +17,6 @@ package androidx.emoji2.text; import static androidx.annotation.RestrictTo.Scope.LIBRARY; import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static androidx.annotation.RestrictTo.Scope.TESTS; import android.annotation.SuppressLint; import android.graphics.Canvas; @@ -30,6 +29,7 @@ import androidx.annotation.IntRange; import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; +import androidx.annotation.VisibleForTesting; import androidx.emoji2.text.flatbuffer.MetadataItem; import androidx.emoji2.text.flatbuffer.MetadataList; @@ -54,7 +54,6 @@ import java.lang.annotation.RetentionPolicy; public class TypefaceEmojiRasterizer { /** * Defines whether the system can render the emoji. - * @hide */ @IntDef({HAS_GLYPH_UNKNOWN, HAS_GLYPH_ABSENT, HAS_GLYPH_EXISTS}) @Retention(RetentionPolicy.SOURCE) @@ -64,21 +63,18 @@ public class TypefaceEmojiRasterizer { /** * Not calculated on device yet. - * @hide */ @RestrictTo(LIBRARY) static final int HAS_GLYPH_UNKNOWN = 0; /** * Device cannot render the emoji. - * @hide */ @RestrictTo(LIBRARY) static final int HAS_GLYPH_ABSENT = 1; /** * Device can render the emoji. - * @hide */ @RestrictTo(LIBRARY) static final int HAS_GLYPH_EXISTS = 2; @@ -108,7 +104,6 @@ public class TypefaceEmojiRasterizer { private volatile int mCache = 0; /** - * @hide */ @RestrictTo(LIBRARY) TypefaceEmojiRasterizer(@NonNull final MetadataRepo metadataRepo, @@ -172,7 +167,6 @@ public class TypefaceEmojiRasterizer { * Unique id for the emoji, as loaded from the font file. * * @return unique id for the emoji - * @hide */ @RestrictTo(LIBRARY) public int getId() { @@ -195,7 +189,6 @@ public class TypefaceEmojiRasterizer { /** * @return in which metadata version the emoji was added - * @hide */ @RestrictTo(LIBRARY) public short getCompatAdded() { @@ -204,7 +197,6 @@ public class TypefaceEmojiRasterizer { /** * @return first SDK that the support for this emoji was added - * @hide */ @RestrictTo(LIBRARY) public short getSdkAdded() { @@ -219,7 +211,6 @@ public class TypefaceEmojiRasterizer { * * @see TypefaceEmojiRasterizer#setHasGlyph * @return the set value of hasGlyph for this metadata item - * @hide */ @HasGlyph @SuppressLint("KotlinPropertyAccess") @@ -233,9 +224,9 @@ public class TypefaceEmojiRasterizer { * * This is only useful for testing, and will make the next display of this emoji slower. * - * @hide */ - @RestrictTo(TESTS) + @RestrictTo(LIBRARY) + @VisibleForTesting public void resetHasGlyphCache() { boolean willExclude = isPreferredSystemRender(); if (willExclude) { @@ -250,7 +241,6 @@ public class TypefaceEmojiRasterizer { * * @see PaintCompat#hasGlyph * @param hasGlyph {@code true} if system can render the emoji - * @hide */ @SuppressLint("KotlinPropertyAccess") @RestrictTo(LIBRARY) @@ -268,7 +258,6 @@ public class TypefaceEmojiRasterizer { * If this emoji is excluded due to CodepointExclusions.getExcludedCodpoints() * * @param exclude if the emoji should never be rendered by emojicompat - * @hide */ @RestrictTo(LIBRARY) public void setExclusion(boolean exclude) { diff --git a/app/src/main/java/androidx/emoji2/text/TypefaceEmojiSpan.java b/app/src/main/java/androidx/emoji2/text/TypefaceEmojiSpan.java index 3b23474cc9..7595fd53b3 100644 --- a/app/src/main/java/androidx/emoji2/text/TypefaceEmojiSpan.java +++ b/app/src/main/java/androidx/emoji2/text/TypefaceEmojiSpan.java @@ -21,6 +21,7 @@ import android.graphics.Paint; import android.text.Spanned; import android.text.TextPaint; import android.text.style.CharacterStyle; +import android.text.style.MetricAffectingSpan; import androidx.annotation.IntRange; import androidx.annotation.NonNull; @@ -31,7 +32,6 @@ import androidx.annotation.RestrictTo; /** * EmojiSpan subclass used to render emojis using Typeface. * - * @hide */ @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @RequiresApi(19) @@ -122,7 +122,10 @@ public final class TypefaceEmojiSpan extends EmojiSpan { wp.set(paint); //noinspection ForLoopReplaceableByForEach for (int pos = 0; pos < spans.length; pos++) { - spans[pos].updateDrawState(wp); + if (!(spans[pos] instanceof MetricAffectingSpan)) { + // we're in draw, so at this point we can't do anything to metrics don't try + spans[pos].updateDrawState(wp); + } } return wp; } else {