EmojiTextView.java revision f8ec169d022fbed42fd82091d24c45f3767cdfe7
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 */ 16package android.support.text.emoji.widget; 17 18import android.content.Context; 19import android.os.Build; 20import android.support.annotation.RequiresApi; 21import android.text.InputFilter; 22import android.util.AttributeSet; 23import android.widget.TextView; 24 25/** 26 * TextView widget enhanced with emoji capability by using {@link EmojiTextViewHelper}. 27 */ 28public class EmojiTextView extends TextView { 29 private EmojiTextViewHelper mEmojiTextViewHelper; 30 private boolean mInitialized; 31 32 public EmojiTextView(Context context) { 33 super(context); 34 init(); 35 } 36 37 public EmojiTextView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 init(); 40 } 41 42 public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr) { 43 super(context, attrs, defStyleAttr); 44 init(); 45 } 46 47 @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 48 public EmojiTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 49 super(context, attrs, defStyleAttr, defStyleRes); 50 init(); 51 } 52 53 private void init() { 54 if (!mInitialized) { 55 mInitialized = true; 56 getEmojiTextViewHelper().updateTransformationMethod(); 57 } 58 } 59 60 @Override 61 public void setFilters(InputFilter[] filters) { 62 super.setFilters(getEmojiTextViewHelper().getFilters(filters)); 63 } 64 65 @Override 66 public void setAllCaps(boolean allCaps) { 67 super.setAllCaps(allCaps); 68 getEmojiTextViewHelper().setAllCaps(allCaps); 69 } 70 71 private EmojiTextViewHelper getEmojiTextViewHelper() { 72 if (mEmojiTextViewHelper == null) { 73 mEmojiTextViewHelper = new EmojiTextViewHelper(this); 74 } 75 return mEmojiTextViewHelper; 76 } 77} 78