ADD week 5
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.method.KeyListener;
|
||||
import android.text.method.NumberKeyListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.widget.EditText;
|
||||
import androidx.core.util.Preconditions;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class EmojiEditTextHelper {
|
||||
private int mEmojiReplaceStrategy;
|
||||
private final HelperInternal mHelper;
|
||||
private int mMaxEmojiCount;
|
||||
|
||||
public int getEmojiReplaceStrategy() {
|
||||
return this.mEmojiReplaceStrategy;
|
||||
}
|
||||
|
||||
public int getMaxEmojiCount() {
|
||||
return this.mMaxEmojiCount;
|
||||
}
|
||||
|
||||
public EmojiEditTextHelper(EditText editText) {
|
||||
this(editText, true);
|
||||
}
|
||||
|
||||
public EmojiEditTextHelper(EditText editText, boolean z) {
|
||||
this.mMaxEmojiCount = Integer.MAX_VALUE;
|
||||
this.mEmojiReplaceStrategy = 0;
|
||||
Preconditions.checkNotNull(editText, "editText cannot be null");
|
||||
this.mHelper = new HelperInternal19(editText, z);
|
||||
}
|
||||
|
||||
public void setMaxEmojiCount(int i) {
|
||||
Preconditions.checkArgumentNonnegative(i, "maxEmojiCount should be greater than 0");
|
||||
this.mMaxEmojiCount = i;
|
||||
this.mHelper.setMaxEmojiCount(i);
|
||||
}
|
||||
|
||||
public KeyListener getKeyListener(KeyListener keyListener) {
|
||||
return this.mHelper.getKeyListener(keyListener);
|
||||
}
|
||||
|
||||
public InputConnection onCreateInputConnection(InputConnection inputConnection, EditorInfo editorInfo) {
|
||||
if (inputConnection == null) {
|
||||
return null;
|
||||
}
|
||||
return this.mHelper.onCreateInputConnection(inputConnection, editorInfo);
|
||||
}
|
||||
|
||||
public void setEmojiReplaceStrategy(int i) {
|
||||
this.mEmojiReplaceStrategy = i;
|
||||
this.mHelper.setEmojiReplaceStrategy(i);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.mHelper.isEnabled();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean z) {
|
||||
this.mHelper.setEnabled(z);
|
||||
}
|
||||
|
||||
static class HelperInternal {
|
||||
KeyListener getKeyListener(KeyListener keyListener) {
|
||||
return keyListener;
|
||||
}
|
||||
|
||||
boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
InputConnection onCreateInputConnection(InputConnection inputConnection, EditorInfo editorInfo) {
|
||||
return inputConnection;
|
||||
}
|
||||
|
||||
void setEmojiReplaceStrategy(int i) {
|
||||
}
|
||||
|
||||
void setEnabled(boolean z) {
|
||||
}
|
||||
|
||||
void setMaxEmojiCount(int i) {
|
||||
}
|
||||
|
||||
HelperInternal() {
|
||||
}
|
||||
}
|
||||
|
||||
private static class HelperInternal19 extends HelperInternal {
|
||||
private final EditText mEditText;
|
||||
private final EmojiTextWatcher mTextWatcher;
|
||||
|
||||
HelperInternal19(EditText editText, boolean z) {
|
||||
this.mEditText = editText;
|
||||
EmojiTextWatcher emojiTextWatcher = new EmojiTextWatcher(editText, z);
|
||||
this.mTextWatcher = emojiTextWatcher;
|
||||
editText.addTextChangedListener(emojiTextWatcher);
|
||||
editText.setEditableFactory(EmojiEditableFactory.getInstance());
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
void setMaxEmojiCount(int i) {
|
||||
this.mTextWatcher.setMaxEmojiCount(i);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
void setEmojiReplaceStrategy(int i) {
|
||||
this.mTextWatcher.setEmojiReplaceStrategy(i);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
KeyListener getKeyListener(KeyListener keyListener) {
|
||||
if (keyListener instanceof EmojiKeyListener) {
|
||||
return keyListener;
|
||||
}
|
||||
if (keyListener == null) {
|
||||
return null;
|
||||
}
|
||||
return keyListener instanceof NumberKeyListener ? keyListener : new EmojiKeyListener(keyListener);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
InputConnection onCreateInputConnection(InputConnection inputConnection, EditorInfo editorInfo) {
|
||||
return inputConnection instanceof EmojiInputConnection ? inputConnection : new EmojiInputConnection(this.mEditText, inputConnection, editorInfo);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
void setEnabled(boolean z) {
|
||||
this.mTextWatcher.setEnabled(z);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiEditTextHelper.HelperInternal
|
||||
boolean isEnabled() {
|
||||
return this.mTextWatcher.isEnabled();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.Editable;
|
||||
import androidx.emoji2.text.SpannableBuilder;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class EmojiEditableFactory extends Editable.Factory {
|
||||
private static final Object INSTANCE_LOCK = new Object();
|
||||
private static volatile Editable.Factory sInstance;
|
||||
private static Class<?> sWatcherClass;
|
||||
|
||||
private EmojiEditableFactory() {
|
||||
try {
|
||||
sWatcherClass = Class.forName("android.text.DynamicLayout$ChangeWatcher", false, getClass().getClassLoader());
|
||||
} catch (Throwable unused) {
|
||||
}
|
||||
}
|
||||
|
||||
public static Editable.Factory getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (INSTANCE_LOCK) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new EmojiEditableFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
@Override // android.text.Editable.Factory
|
||||
public Editable newEditable(CharSequence charSequence) {
|
||||
Class<?> cls = sWatcherClass;
|
||||
if (cls != null) {
|
||||
return SpannableBuilder.create(cls, charSequence);
|
||||
}
|
||||
return super.newEditable(charSequence);
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputConnectionWrapper;
|
||||
import android.widget.TextView;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class EmojiInputConnection extends InputConnectionWrapper {
|
||||
private final EmojiCompatDeleteHelper mEmojiCompatDeleteHelper;
|
||||
private final TextView mTextView;
|
||||
|
||||
EmojiInputConnection(TextView textView, InputConnection inputConnection, EditorInfo editorInfo) {
|
||||
this(textView, inputConnection, editorInfo, new EmojiCompatDeleteHelper());
|
||||
}
|
||||
|
||||
EmojiInputConnection(TextView textView, InputConnection inputConnection, EditorInfo editorInfo, EmojiCompatDeleteHelper emojiCompatDeleteHelper) {
|
||||
super(inputConnection, false);
|
||||
this.mTextView = textView;
|
||||
this.mEmojiCompatDeleteHelper = emojiCompatDeleteHelper;
|
||||
emojiCompatDeleteHelper.updateEditorInfoAttrs(editorInfo);
|
||||
}
|
||||
|
||||
@Override // android.view.inputmethod.InputConnectionWrapper, android.view.inputmethod.InputConnection
|
||||
public boolean deleteSurroundingText(int i, int i2) {
|
||||
return this.mEmojiCompatDeleteHelper.handleDeleteSurroundingText(this, getEditable(), i, i2, false) || super.deleteSurroundingText(i, i2);
|
||||
}
|
||||
|
||||
@Override // android.view.inputmethod.InputConnectionWrapper, android.view.inputmethod.InputConnection
|
||||
public boolean deleteSurroundingTextInCodePoints(int i, int i2) {
|
||||
return this.mEmojiCompatDeleteHelper.handleDeleteSurroundingText(this, getEditable(), i, i2, true) || super.deleteSurroundingTextInCodePoints(i, i2);
|
||||
}
|
||||
|
||||
private Editable getEditable() {
|
||||
return this.mTextView.getEditableText();
|
||||
}
|
||||
|
||||
public static class EmojiCompatDeleteHelper {
|
||||
public boolean handleDeleteSurroundingText(InputConnection inputConnection, Editable editable, int i, int i2, boolean z) {
|
||||
return EmojiCompat.handleDeleteSurroundingText(inputConnection, editable, i, i2, z);
|
||||
}
|
||||
|
||||
public void updateEditorInfoAttrs(EditorInfo editorInfo) {
|
||||
if (EmojiCompat.isConfigured()) {
|
||||
EmojiCompat.get().updateEditorInfo(editorInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.InputFilter;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.Spanned;
|
||||
import android.widget.TextView;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class EmojiInputFilter implements InputFilter {
|
||||
private EmojiCompat.InitCallback mInitCallback;
|
||||
private final TextView mTextView;
|
||||
|
||||
EmojiInputFilter(TextView textView) {
|
||||
this.mTextView = textView;
|
||||
}
|
||||
|
||||
@Override // android.text.InputFilter
|
||||
public CharSequence filter(CharSequence charSequence, int i, int i2, Spanned spanned, int i3, int i4) {
|
||||
if (this.mTextView.isInEditMode()) {
|
||||
return charSequence;
|
||||
}
|
||||
int loadState = EmojiCompat.get().getLoadState();
|
||||
if (loadState != 0) {
|
||||
if (loadState == 1) {
|
||||
if ((i4 == 0 && i3 == 0 && spanned.length() == 0 && charSequence == this.mTextView.getText()) || charSequence == null) {
|
||||
return charSequence;
|
||||
}
|
||||
if (i != 0 || i2 != charSequence.length()) {
|
||||
charSequence = charSequence.subSequence(i, i2);
|
||||
}
|
||||
return EmojiCompat.get().process(charSequence, 0, charSequence.length());
|
||||
}
|
||||
if (loadState != 3) {
|
||||
return charSequence;
|
||||
}
|
||||
}
|
||||
EmojiCompat.get().registerInitCallback(getInitCallback());
|
||||
return charSequence;
|
||||
}
|
||||
|
||||
private EmojiCompat.InitCallback getInitCallback() {
|
||||
if (this.mInitCallback == null) {
|
||||
this.mInitCallback = new InitCallbackImpl(this.mTextView, this);
|
||||
}
|
||||
return this.mInitCallback;
|
||||
}
|
||||
|
||||
private static class InitCallbackImpl extends EmojiCompat.InitCallback {
|
||||
private final Reference<EmojiInputFilter> mEmojiInputFilterReference;
|
||||
private final Reference<TextView> mViewRef;
|
||||
|
||||
InitCallbackImpl(TextView textView, EmojiInputFilter emojiInputFilter) {
|
||||
this.mViewRef = new WeakReference(textView);
|
||||
this.mEmojiInputFilterReference = new WeakReference(emojiInputFilter);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.text.EmojiCompat.InitCallback
|
||||
public void onInitialized() {
|
||||
CharSequence text;
|
||||
CharSequence process;
|
||||
super.onInitialized();
|
||||
TextView textView = this.mViewRef.get();
|
||||
if (isInputFilterCurrentlyRegisteredOnTextView(textView, this.mEmojiInputFilterReference.get()) && textView.isAttachedToWindow() && text != (process = EmojiCompat.get().process((text = textView.getText())))) {
|
||||
int selectionStart = Selection.getSelectionStart(process);
|
||||
int selectionEnd = Selection.getSelectionEnd(process);
|
||||
textView.setText(process);
|
||||
if (process instanceof Spannable) {
|
||||
EmojiInputFilter.updateSelection((Spannable) process, selectionStart, selectionEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInputFilterCurrentlyRegisteredOnTextView(TextView textView, InputFilter inputFilter) {
|
||||
InputFilter[] filters;
|
||||
if (inputFilter == null || textView == null || (filters = textView.getFilters()) == null) {
|
||||
return false;
|
||||
}
|
||||
for (InputFilter inputFilter2 : filters) {
|
||||
if (inputFilter2 == inputFilter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void updateSelection(Spannable spannable, int i, int i2) {
|
||||
if (i >= 0 && i2 >= 0) {
|
||||
Selection.setSelection(spannable, i, i2);
|
||||
} else if (i >= 0) {
|
||||
Selection.setSelection(spannable, i);
|
||||
} else if (i2 >= 0) {
|
||||
Selection.setSelection(spannable, i2);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,53 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.method.KeyListener;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class EmojiKeyListener implements KeyListener {
|
||||
private final EmojiCompatHandleKeyDownHelper mEmojiCompatHandleKeyDownHelper;
|
||||
private final KeyListener mKeyListener;
|
||||
|
||||
EmojiKeyListener(KeyListener keyListener) {
|
||||
this(keyListener, new EmojiCompatHandleKeyDownHelper());
|
||||
}
|
||||
|
||||
EmojiKeyListener(KeyListener keyListener, EmojiCompatHandleKeyDownHelper emojiCompatHandleKeyDownHelper) {
|
||||
this.mKeyListener = keyListener;
|
||||
this.mEmojiCompatHandleKeyDownHelper = emojiCompatHandleKeyDownHelper;
|
||||
}
|
||||
|
||||
@Override // android.text.method.KeyListener
|
||||
public int getInputType() {
|
||||
return this.mKeyListener.getInputType();
|
||||
}
|
||||
|
||||
@Override // android.text.method.KeyListener
|
||||
public boolean onKeyDown(View view, Editable editable, int i, KeyEvent keyEvent) {
|
||||
return this.mEmojiCompatHandleKeyDownHelper.handleKeyDown(editable, i, keyEvent) || this.mKeyListener.onKeyDown(view, editable, i, keyEvent);
|
||||
}
|
||||
|
||||
@Override // android.text.method.KeyListener
|
||||
public boolean onKeyUp(View view, Editable editable, int i, KeyEvent keyEvent) {
|
||||
return this.mKeyListener.onKeyUp(view, editable, i, keyEvent);
|
||||
}
|
||||
|
||||
@Override // android.text.method.KeyListener
|
||||
public boolean onKeyOther(View view, Editable editable, KeyEvent keyEvent) {
|
||||
return this.mKeyListener.onKeyOther(view, editable, keyEvent);
|
||||
}
|
||||
|
||||
@Override // android.text.method.KeyListener
|
||||
public void clearMetaKeyState(View view, Editable editable, int i) {
|
||||
this.mKeyListener.clearMetaKeyState(view, editable, i);
|
||||
}
|
||||
|
||||
public static class EmojiCompatHandleKeyDownHelper {
|
||||
public boolean handleKeyDown(Editable editable, int i, KeyEvent keyEvent) {
|
||||
return EmojiCompat.handleOnKeyDown(editable, i, keyEvent);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,237 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.InputFilter;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.util.SparseArray;
|
||||
import android.widget.TextView;
|
||||
import androidx.core.util.Preconditions;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class EmojiTextViewHelper {
|
||||
private final HelperInternal mHelper;
|
||||
|
||||
public EmojiTextViewHelper(TextView textView) {
|
||||
this(textView, true);
|
||||
}
|
||||
|
||||
public EmojiTextViewHelper(TextView textView, boolean z) {
|
||||
Preconditions.checkNotNull(textView, "textView cannot be null");
|
||||
if (!z) {
|
||||
this.mHelper = new SkippingHelper19(textView);
|
||||
} else {
|
||||
this.mHelper = new HelperInternal19(textView);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateTransformationMethod() {
|
||||
this.mHelper.updateTransformationMethod();
|
||||
}
|
||||
|
||||
public InputFilter[] getFilters(InputFilter[] inputFilterArr) {
|
||||
return this.mHelper.getFilters(inputFilterArr);
|
||||
}
|
||||
|
||||
public TransformationMethod wrapTransformationMethod(TransformationMethod transformationMethod) {
|
||||
return this.mHelper.wrapTransformationMethod(transformationMethod);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean z) {
|
||||
this.mHelper.setEnabled(z);
|
||||
}
|
||||
|
||||
public void setAllCaps(boolean z) {
|
||||
this.mHelper.setAllCaps(z);
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.mHelper.isEnabled();
|
||||
}
|
||||
|
||||
static class HelperInternal {
|
||||
InputFilter[] getFilters(InputFilter[] inputFilterArr) {
|
||||
return inputFilterArr;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void setAllCaps(boolean z) {
|
||||
}
|
||||
|
||||
void setEnabled(boolean z) {
|
||||
}
|
||||
|
||||
void updateTransformationMethod() {
|
||||
}
|
||||
|
||||
TransformationMethod wrapTransformationMethod(TransformationMethod transformationMethod) {
|
||||
return transformationMethod;
|
||||
}
|
||||
|
||||
HelperInternal() {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SkippingHelper19 extends HelperInternal {
|
||||
private final HelperInternal19 mHelperDelegate;
|
||||
|
||||
SkippingHelper19(TextView textView) {
|
||||
this.mHelperDelegate = new HelperInternal19(textView);
|
||||
}
|
||||
|
||||
private boolean skipBecauseEmojiCompatNotInitialized() {
|
||||
return !EmojiCompat.isConfigured();
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void updateTransformationMethod() {
|
||||
if (skipBecauseEmojiCompatNotInitialized()) {
|
||||
return;
|
||||
}
|
||||
this.mHelperDelegate.updateTransformationMethod();
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
InputFilter[] getFilters(InputFilter[] inputFilterArr) {
|
||||
return skipBecauseEmojiCompatNotInitialized() ? inputFilterArr : this.mHelperDelegate.getFilters(inputFilterArr);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
TransformationMethod wrapTransformationMethod(TransformationMethod transformationMethod) {
|
||||
return skipBecauseEmojiCompatNotInitialized() ? transformationMethod : this.mHelperDelegate.wrapTransformationMethod(transformationMethod);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void setAllCaps(boolean z) {
|
||||
if (skipBecauseEmojiCompatNotInitialized()) {
|
||||
return;
|
||||
}
|
||||
this.mHelperDelegate.setAllCaps(z);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void setEnabled(boolean z) {
|
||||
if (skipBecauseEmojiCompatNotInitialized()) {
|
||||
this.mHelperDelegate.setEnabledUnsafe(z);
|
||||
} else {
|
||||
this.mHelperDelegate.setEnabled(z);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
public boolean isEnabled() {
|
||||
return this.mHelperDelegate.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
private static class HelperInternal19 extends HelperInternal {
|
||||
private final EmojiInputFilter mEmojiInputFilter;
|
||||
private boolean mEnabled = true;
|
||||
private final TextView mTextView;
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
public boolean isEnabled() {
|
||||
return this.mEnabled;
|
||||
}
|
||||
|
||||
void setEnabledUnsafe(boolean z) {
|
||||
this.mEnabled = z;
|
||||
}
|
||||
|
||||
HelperInternal19(TextView textView) {
|
||||
this.mTextView = textView;
|
||||
this.mEmojiInputFilter = new EmojiInputFilter(textView);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void updateTransformationMethod() {
|
||||
this.mTextView.setTransformationMethod(wrapTransformationMethod(this.mTextView.getTransformationMethod()));
|
||||
}
|
||||
|
||||
private void updateFilters() {
|
||||
this.mTextView.setFilters(getFilters(this.mTextView.getFilters()));
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
InputFilter[] getFilters(InputFilter[] inputFilterArr) {
|
||||
if (!this.mEnabled) {
|
||||
return removeEmojiInputFilterIfPresent(inputFilterArr);
|
||||
}
|
||||
return addEmojiInputFilterIfMissing(inputFilterArr);
|
||||
}
|
||||
|
||||
private InputFilter[] addEmojiInputFilterIfMissing(InputFilter[] inputFilterArr) {
|
||||
int length = inputFilterArr.length;
|
||||
for (InputFilter inputFilter : inputFilterArr) {
|
||||
if (inputFilter == this.mEmojiInputFilter) {
|
||||
return inputFilterArr;
|
||||
}
|
||||
}
|
||||
InputFilter[] inputFilterArr2 = new InputFilter[inputFilterArr.length + 1];
|
||||
System.arraycopy(inputFilterArr, 0, inputFilterArr2, 0, length);
|
||||
inputFilterArr2[length] = this.mEmojiInputFilter;
|
||||
return inputFilterArr2;
|
||||
}
|
||||
|
||||
private InputFilter[] removeEmojiInputFilterIfPresent(InputFilter[] inputFilterArr) {
|
||||
SparseArray<InputFilter> emojiInputFilterPositionArray = getEmojiInputFilterPositionArray(inputFilterArr);
|
||||
if (emojiInputFilterPositionArray.size() == 0) {
|
||||
return inputFilterArr;
|
||||
}
|
||||
int length = inputFilterArr.length;
|
||||
InputFilter[] inputFilterArr2 = new InputFilter[inputFilterArr.length - emojiInputFilterPositionArray.size()];
|
||||
int i = 0;
|
||||
for (int i2 = 0; i2 < length; i2++) {
|
||||
if (emojiInputFilterPositionArray.indexOfKey(i2) < 0) {
|
||||
inputFilterArr2[i] = inputFilterArr[i2];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return inputFilterArr2;
|
||||
}
|
||||
|
||||
private SparseArray<InputFilter> getEmojiInputFilterPositionArray(InputFilter[] inputFilterArr) {
|
||||
SparseArray<InputFilter> sparseArray = new SparseArray<>(1);
|
||||
for (int i = 0; i < inputFilterArr.length; i++) {
|
||||
InputFilter inputFilter = inputFilterArr[i];
|
||||
if (inputFilter instanceof EmojiInputFilter) {
|
||||
sparseArray.put(i, inputFilter);
|
||||
}
|
||||
}
|
||||
return sparseArray;
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
TransformationMethod wrapTransformationMethod(TransformationMethod transformationMethod) {
|
||||
if (this.mEnabled) {
|
||||
return wrapForEnabled(transformationMethod);
|
||||
}
|
||||
return unwrapForDisabled(transformationMethod);
|
||||
}
|
||||
|
||||
private TransformationMethod unwrapForDisabled(TransformationMethod transformationMethod) {
|
||||
return transformationMethod instanceof EmojiTransformationMethod ? ((EmojiTransformationMethod) transformationMethod).getOriginalTransformationMethod() : transformationMethod;
|
||||
}
|
||||
|
||||
private TransformationMethod wrapForEnabled(TransformationMethod transformationMethod) {
|
||||
return ((transformationMethod instanceof EmojiTransformationMethod) || (transformationMethod instanceof PasswordTransformationMethod)) ? transformationMethod : new EmojiTransformationMethod(transformationMethod);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void setAllCaps(boolean z) {
|
||||
if (z) {
|
||||
updateTransformationMethod();
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.viewsintegration.EmojiTextViewHelper.HelperInternal
|
||||
void setEnabled(boolean z) {
|
||||
this.mEnabled = z;
|
||||
updateTransformationMethod();
|
||||
updateFilters();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.TextWatcher;
|
||||
import android.widget.EditText;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
final class EmojiTextWatcher implements TextWatcher {
|
||||
private final EditText mEditText;
|
||||
private final boolean mExpectInitializedEmojiCompat;
|
||||
private EmojiCompat.InitCallback mInitCallback;
|
||||
private int mMaxEmojiCount = Integer.MAX_VALUE;
|
||||
private int mEmojiReplaceStrategy = 0;
|
||||
private boolean mEnabled = true;
|
||||
|
||||
@Override // android.text.TextWatcher
|
||||
public void afterTextChanged(Editable editable) {
|
||||
}
|
||||
|
||||
@Override // android.text.TextWatcher
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
}
|
||||
|
||||
int getEmojiReplaceStrategy() {
|
||||
return this.mEmojiReplaceStrategy;
|
||||
}
|
||||
|
||||
int getMaxEmojiCount() {
|
||||
return this.mMaxEmojiCount;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.mEnabled;
|
||||
}
|
||||
|
||||
void setEmojiReplaceStrategy(int i) {
|
||||
this.mEmojiReplaceStrategy = i;
|
||||
}
|
||||
|
||||
void setMaxEmojiCount(int i) {
|
||||
this.mMaxEmojiCount = i;
|
||||
}
|
||||
|
||||
EmojiTextWatcher(EditText editText, boolean z) {
|
||||
this.mEditText = editText;
|
||||
this.mExpectInitializedEmojiCompat = z;
|
||||
}
|
||||
|
||||
@Override // android.text.TextWatcher
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
|
||||
if (this.mEditText.isInEditMode() || shouldSkipForDisabledOrNotConfigured() || i2 > i3 || !(charSequence instanceof Spannable)) {
|
||||
return;
|
||||
}
|
||||
int loadState = EmojiCompat.get().getLoadState();
|
||||
if (loadState != 0) {
|
||||
if (loadState == 1) {
|
||||
EmojiCompat.get().process((Spannable) charSequence, i, i + i3, this.mMaxEmojiCount, this.mEmojiReplaceStrategy);
|
||||
return;
|
||||
} else if (loadState != 3) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
EmojiCompat.get().registerInitCallback(getInitCallback());
|
||||
}
|
||||
|
||||
private boolean shouldSkipForDisabledOrNotConfigured() {
|
||||
return (this.mEnabled && (this.mExpectInitializedEmojiCompat || EmojiCompat.isConfigured())) ? false : true;
|
||||
}
|
||||
|
||||
private EmojiCompat.InitCallback getInitCallback() {
|
||||
if (this.mInitCallback == null) {
|
||||
this.mInitCallback = new InitCallbackImpl(this.mEditText);
|
||||
}
|
||||
return this.mInitCallback;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean z) {
|
||||
if (this.mEnabled != z) {
|
||||
if (this.mInitCallback != null) {
|
||||
EmojiCompat.get().unregisterInitCallback(this.mInitCallback);
|
||||
}
|
||||
this.mEnabled = z;
|
||||
if (z) {
|
||||
processTextOnEnablingEvent(this.mEditText, EmojiCompat.get().getLoadState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class InitCallbackImpl extends EmojiCompat.InitCallback {
|
||||
private final Reference<EditText> mViewRef;
|
||||
|
||||
InitCallbackImpl(EditText editText) {
|
||||
this.mViewRef = new WeakReference(editText);
|
||||
}
|
||||
|
||||
@Override // androidx.emoji2.text.EmojiCompat.InitCallback
|
||||
public void onInitialized() {
|
||||
super.onInitialized();
|
||||
EmojiTextWatcher.processTextOnEnablingEvent(this.mViewRef.get(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void processTextOnEnablingEvent(EditText editText, int i) {
|
||||
if (i == 1 && editText != null && editText.isAttachedToWindow()) {
|
||||
Editable editableText = editText.getEditableText();
|
||||
int selectionStart = Selection.getSelectionStart(editableText);
|
||||
int selectionEnd = Selection.getSelectionEnd(editableText);
|
||||
EmojiCompat.get().process(editableText);
|
||||
EmojiInputFilter.updateSelection(editableText, selectionStart, selectionEnd);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.text.method.TransformationMethod;
|
||||
import android.view.View;
|
||||
import androidx.emoji2.text.EmojiCompat;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class EmojiTransformationMethod implements TransformationMethod {
|
||||
private final TransformationMethod mTransformationMethod;
|
||||
|
||||
public TransformationMethod getOriginalTransformationMethod() {
|
||||
return this.mTransformationMethod;
|
||||
}
|
||||
|
||||
EmojiTransformationMethod(TransformationMethod transformationMethod) {
|
||||
this.mTransformationMethod = transformationMethod;
|
||||
}
|
||||
|
||||
@Override // android.text.method.TransformationMethod
|
||||
public CharSequence getTransformation(CharSequence charSequence, View view) {
|
||||
if (view.isInEditMode()) {
|
||||
return charSequence;
|
||||
}
|
||||
TransformationMethod transformationMethod = this.mTransformationMethod;
|
||||
if (transformationMethod != null) {
|
||||
charSequence = transformationMethod.getTransformation(charSequence, view);
|
||||
}
|
||||
return (charSequence == null || EmojiCompat.get().getLoadState() != 1) ? charSequence : EmojiCompat.get().process(charSequence);
|
||||
}
|
||||
|
||||
@Override // android.text.method.TransformationMethod
|
||||
public void onFocusChanged(View view, CharSequence charSequence, boolean z, int i, Rect rect) {
|
||||
TransformationMethod transformationMethod = this.mTransformationMethod;
|
||||
if (transformationMethod != null) {
|
||||
transformationMethod.onFocusChanged(view, charSequence, z, i, rect);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package androidx.emoji2.viewsintegration;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class R {
|
||||
private R() {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user