1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.text.emoji.widget;
18
19import android.content.Context;
20import android.support.v7.widget.AppCompatTextView;
21import android.text.InputFilter;
22import android.util.AttributeSet;
23
24/**
25 * AppCompatTextView widget enhanced with emoji capability by using {@link EmojiTextViewHelper}.
26 * When used on devices running API 18 or below, this widget acts as a regular
27 * {@link AppCompatTextView}.
28 */
29public class EmojiAppCompatTextView extends AppCompatTextView {
30    private EmojiTextViewHelper mEmojiTextViewHelper;
31    private boolean mInitialized;
32
33    public EmojiAppCompatTextView(Context context) {
34        super(context);
35        init();
36    }
37
38    public EmojiAppCompatTextView(Context context, AttributeSet attrs) {
39        super(context, attrs);
40        init();
41    }
42
43    public EmojiAppCompatTextView(Context context, AttributeSet attrs, int defStyleAttr) {
44        super(context, attrs, defStyleAttr);
45        init();
46    }
47
48    private void init() {
49        if (!mInitialized) {
50            mInitialized = true;
51            getEmojiTextViewHelper().updateTransformationMethod();
52        }
53    }
54
55    @Override
56    public void setFilters(InputFilter[] filters) {
57        super.setFilters(getEmojiTextViewHelper().getFilters(filters));
58    }
59
60    @Override
61    public void setAllCaps(boolean allCaps) {
62        super.setAllCaps(allCaps);
63        getEmojiTextViewHelper().setAllCaps(allCaps);
64    }
65
66    private EmojiTextViewHelper getEmojiTextViewHelper() {
67        if (mEmojiTextViewHelper == null) {
68            mEmojiTextViewHelper = new EmojiTextViewHelper(this);
69        }
70        return mEmojiTextViewHelper;
71    }
72}
73