public class

BundledEmojiCompatConfig

extends EmojiCompat.Config

 java.lang.Object

androidx.emoji2.text.EmojiCompat.Config

↳androidx.emoji2.bundled.BundledEmojiCompatConfig

Gradle dependencies

compile group: 'androidx.emoji2', name: 'emoji2-bundled', version: '1.2.0-alpha04'

  • groupId: androidx.emoji2
  • artifactId: emoji2-bundled
  • version: 1.2.0-alpha04

Artifact androidx.emoji2:emoji2-bundled:1.2.0-alpha04 it located at Google repository (https://maven.google.com/)

Overview

implementation that loads the metadata using AssetManager and bundled resources.

EmojiCompat.init(new BundledEmojiCompatConfig(context));
Including the emoji2-bundled artifact disables the EmojiCompatInitializer. You must manually call EmojiCompat.init when using the bundled configuration.

Summary

Constructors
publicBundledEmojiCompatConfig(Context context)

Default constructor.

Methods
from EmojiCompat.ConfiggetMetadataRepoLoader, registerInitCallback, setEmojiSpanIndicatorColor, setEmojiSpanIndicatorEnabled, setGlyphChecker, setMetadataLoadStrategy, setReplaceAll, setUseEmojiAsDefaultStyle, setUseEmojiAsDefaultStyle, unregisterInitCallback
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public BundledEmojiCompatConfig(Context context)

Default constructor.

Parameters:

context: Context instance

Source

/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.emoji2.bundled;

import android.content.Context;
import android.content.res.AssetManager;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.util.Preconditions;
import androidx.emoji2.text.EmojiCompat;
import androidx.emoji2.text.MetadataRepo;

/**
 * {@link EmojiCompat.Config} implementation that loads the metadata using AssetManager and
 * bundled resources.
 * <p/>
 * <pre><code>EmojiCompat.init(new BundledEmojiCompatConfig(context));</code></pre>
 *
 * Including the emoji2-bundled artifact disables the
 * {@link androidx.emoji2.text.EmojiCompatInitializer}. You must manually call EmojiCompat.init
 * when using the bundled configuration.
 *
 * @see EmojiCompat
 */
public class BundledEmojiCompatConfig extends EmojiCompat.Config {

    /**
     * Default constructor.
     *
     * @param context Context instance
     */
    public BundledEmojiCompatConfig(@NonNull Context context) {
        super(new BundledMetadataLoader(context));
    }

    private static class BundledMetadataLoader implements EmojiCompat.MetadataRepoLoader {
        private final Context mContext;

        BundledMetadataLoader(@NonNull Context context) {
            mContext = context.getApplicationContext();
        }

        @Override
        @RequiresApi(19)
        public void load(@NonNull EmojiCompat.MetadataRepoLoaderCallback loaderCallback) {
            Preconditions.checkNotNull(loaderCallback, "loaderCallback cannot be null");
            final InitRunnable runnable = new InitRunnable(mContext, loaderCallback);
            final Thread thread = new Thread(runnable);
            thread.setDaemon(false);
            thread.start();
        }
    }

    @RequiresApi(19)
    private static class InitRunnable implements Runnable {
        private static final String FONT_NAME = "NotoColorEmojiCompat.ttf";
        private final EmojiCompat.MetadataRepoLoaderCallback mLoaderCallback;
        private final Context mContext;

        InitRunnable(Context context, EmojiCompat.MetadataRepoLoaderCallback loaderCallback) {
            mContext = context;
            mLoaderCallback = loaderCallback;
        }

        @Override
        public void run() {
            try {
                final AssetManager assetManager = mContext.getAssets();
                final MetadataRepo resourceIndex = MetadataRepo.create(assetManager, FONT_NAME);
                mLoaderCallback.onLoaded(resourceIndex);
            } catch (Throwable t) {
                mLoaderCallback.onFailed(t);
            }
        }
    }
}