public class

BundledEmojiCompatConfig

extends EmojiCompat.Config

 java.lang.Object

androidx.emoji.text.EmojiCompat.Config

↳androidx.emoji.bundled.BundledEmojiCompatConfig

Gradle dependencies

compile group: 'androidx.emoji', name: 'emoji-bundled', version: '1.2.0-alpha03'

  • groupId: androidx.emoji
  • artifactId: emoji-bundled
  • version: 1.2.0-alpha03

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

Androidx artifact mapping:

androidx.emoji:emoji-bundled com.android.support:support-emoji-bundled

Androidx class mapping:

androidx.emoji.bundled.BundledEmojiCompatConfig android.support.text.emoji.bundled.BundledEmojiCompatConfig

Overview

implementation that loads the metadata using AssetManager and bundled resources.

EmojiCompat.init(new BundledEmojiCompatConfig(context));

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.emoji.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.emoji.text.EmojiCompat;
import androidx.emoji.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>
 *
 * @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);
            }
        }
    }
}