mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 01:22:33 -06:00
133 lines
4.5 KiB
Java
133 lines
4.5 KiB
Java
package androidx.emoji2.viewsintegration;
|
|
|
|
import android.os.Handler;
|
|
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: classes2.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;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void setEmojiReplaceStrategy(int i) {
|
|
this.mEmojiReplaceStrategy = i;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void setMaxEmojiCount(int i) {
|
|
this.mMaxEmojiCount = i;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public 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;
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public static class InitCallbackImpl extends EmojiCompat.InitCallback implements Runnable {
|
|
private final Reference<EditText> mViewRef;
|
|
|
|
InitCallbackImpl(EditText editText) {
|
|
this.mViewRef = new WeakReference(editText);
|
|
}
|
|
|
|
@Override // androidx.emoji2.text.EmojiCompat.InitCallback
|
|
public void onInitialized() {
|
|
Handler handler;
|
|
super.onInitialized();
|
|
EditText editText = this.mViewRef.get();
|
|
if (editText == null || (handler = editText.getHandler()) == null) {
|
|
return;
|
|
}
|
|
handler.post(this);
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
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);
|
|
}
|
|
}
|
|
}
|