正在查看: Plus 12 v10.13.1.1 应用的 EditTextCaption.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Plus 12 v10.13.1.1 应用的 EditTextCaption.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.telegram.ui.Components;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.CharacterStyle;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import java.util.List;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.BuildConfig;
import org.telegram.messenger.CodeHighlighting;
import org.telegram.messenger.Emoji;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MediaDataController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.PlusUtils;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.utils.CopyUtilities;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.AlertDialog;
import org.telegram.ui.ActionBar.AlertDialogDecor;
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.QuoteSpan;
import org.telegram.ui.Components.TextStyleSpan;
public class EditTextCaption extends EditTextBoldCursor {
private static final int ACCESSIBILITY_ACTION_SHARE = 268435456;
public boolean adaptiveCreateLinkDialog;
private boolean allowTextEntitiesIntersection;
private String caption;
private StaticLayout captionLayout;
private boolean copyPasteShowed;
private AlertDialog creationLinkDialog;
private EditTextCaptionDelegate delegate;
private int hintColor;
private boolean isInitLineCount;
private int lineCount;
public final Theme.ResourcesProvider resourcesProvider;
private int selectionEnd;
private int selectionStart;
private int triesCount;
private int userNameLength;
private int xOffset;
private int yOffset;
public interface EditTextCaptionDelegate {
void onSpansChanged();
}
public void onContextMenuClose() {
}
public void onContextMenuOpen() {
}
public void onLineCountChanged(int oldLineCount, int newLineCount) {
}
public EditTextCaption(Context context, Theme.ResourcesProvider resourcesProvider) {
super(context);
this.triesCount = 0;
this.selectionStart = -1;
this.selectionEnd = -1;
this.resourcesProvider = resourcesProvider;
this.quoteColor = Theme.getColor(Theme.key_chat_inQuote, resourcesProvider);
addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (EditTextCaption.this.lineCount != EditTextCaption.this.getLineCount()) {
if (!EditTextCaption.this.isInitLineCount && EditTextCaption.this.getMeasuredWidth() > 0) {
EditTextCaption editTextCaption = EditTextCaption.this;
editTextCaption.onLineCountChanged(editTextCaption.lineCount, EditTextCaption.this.getLineCount());
}
EditTextCaption editTextCaption2 = EditTextCaption.this;
editTextCaption2.lineCount = editTextCaption2.getLineCount();
}
}
});
setClipToPadding(true);
}
public void setCaption(String value) {
String str = this.caption;
if ((str == null || str.length() == 0) && (value == null || value.length() == 0)) {
return;
}
String str2 = this.caption;
if (str2 == null || !str2.equals(value)) {
this.caption = value;
if (value != null) {
this.caption = value.replace('\n', ' ');
}
requestLayout();
}
}
public void setDelegate(EditTextCaptionDelegate editTextCaptionDelegate) {
this.delegate = editTextCaptionDelegate;
}
public void setAllowTextEntitiesIntersection(boolean value) {
this.allowTextEntitiesIntersection = value;
}
public void makeSelectedBold() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 1;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
}
public void makeSelectedSpoiler() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 256;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
invalidateSpoilers();
}
public void makeSelectedItalic() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 2;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
}
public void makeSelectedMono() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 4;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
}
public void makeSelectedStrike() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 8;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
}
public void makeSelectedUnderline() {
TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
textStyleRun.flags |= 16;
applyTextStyleToSelection(new TextStyleSpan(textStyleRun));
}
public void makeSelectedQuote() {
makeSelectedQuote(false);
}
public void makeSelectedQuote(boolean collapse) {
int selectionEnd;
int i = this.selectionStart;
if (i >= 0 && (selectionEnd = this.selectionEnd) >= 0) {
this.selectionEnd = -1;
this.selectionStart = -1;
} else {
i = getSelectionStart();
selectionEnd = getSelectionEnd();
}
int putQuoteToEditable = QuoteSpan.putQuoteToEditable(getText(), i, selectionEnd, collapse);
if (putQuoteToEditable >= 0) {
setSelection(putQuoteToEditable);
resetFontMetricsCache();
}
invalidateQuotes(true);
invalidateSpoilers();
}
public void makeSelectedUrl() {
AlertDialogDecor.Builder builder;
final int selectionEnd;
CharSequence charSequence;
if (this.adaptiveCreateLinkDialog) {
builder = new AlertDialogDecor.Builder(getContext(), this.resourcesProvider);
} else {
builder = new AlertDialog.Builder(getContext(), this.resourcesProvider);
}
AlertDialogDecor.Builder builder2 = builder;
builder2.setTitle(LocaleController.getString("CreateLink", R.string.CreateLink));
FrameLayout frameLayout = new FrameLayout(getContext());
final EditTextBoldCursor editTextBoldCursor = new EditTextBoldCursor(this, getContext()) {
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64.0f), 1073741824));
}
};
editTextBoldCursor.setTextSize(1, 18.0f);
editTextBoldCursor.setText("http://");
editTextBoldCursor.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
editTextBoldCursor.setHintText(LocaleController.getString("URL", R.string.URL));
editTextBoldCursor.setHeaderHintColor(getThemedColor(Theme.key_windowBackgroundWhiteBlueHeader));
editTextBoldCursor.setSingleLine(true);
editTextBoldCursor.setFocusable(true);
editTextBoldCursor.setTransformHintToHeader(true);
editTextBoldCursor.setLineColors(getThemedColor(Theme.key_windowBackgroundWhiteInputField), getThemedColor(Theme.key_windowBackgroundWhiteInputFieldActivated), getThemedColor(Theme.key_text_RedRegular));
editTextBoldCursor.setImeOptions(6);
editTextBoldCursor.setBackgroundDrawable(null);
editTextBoldCursor.requestFocus();
editTextBoldCursor.setPadding(0, 0, 0, 0);
editTextBoldCursor.setHighlightColor(getThemedColor(Theme.key_chat_inTextSelectionHighlight));
editTextBoldCursor.setHandlesColor(getThemedColor(Theme.key_chat_TextSelectionCursor));
frameLayout.addView(editTextBoldCursor, LayoutHelper.createFrame(-1, -1, R.styleable.AppCompatTheme_windowActionModeOverlay));
final TextView textView = new TextView(getContext());
textView.setTextSize(1, 12.0f);
textView.setTypeface(AndroidUtilities.bold());
textView.setText(LocaleController.getString(R.string.Paste));
textView.setPadding(AndroidUtilities.dp(10.0f), 0, AndroidUtilities.dp(10.0f), 0);
textView.setGravity(17);
int themedColor = getThemedColor(Theme.key_windowBackgroundWhiteBlueText2);
textView.setTextColor(themedColor);
textView.setBackground(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(6.0f), Theme.multAlpha(themedColor, 0.12f), Theme.multAlpha(themedColor, 0.15f)));
ScaleStateListAnimator.apply(textView, 0.1f, 1.5f);
frameLayout.addView(textView, LayoutHelper.createFrame(-2, 26.0f, 21, 0.0f, 0.0f, 24.0f, 3.0f));
final Runnable runnable = new Runnable() {
@Override
public final void run() {
EditTextCaption.this.lambda$makeSelectedUrl$0(editTextBoldCursor, textView);
}
};
textView.setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
EditTextCaption.this.lambda$makeSelectedUrl$1(editTextBoldCursor, runnable, view);
}
});
editTextBoldCursor.addTextChangedListener(new TextWatcher(this) {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
runnable.run();
}
});
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService("clipboard");
if (clipboardManager != null && clipboardManager.hasPrimaryClip()) {
try {
charSequence = clipboardManager.getPrimaryClip().getItemAt(0).coerceToText(getContext());
} catch (Exception e) {
FileLog.e(e);
charSequence = null;
}
if (charSequence != null) {
editTextBoldCursor.setText(charSequence);
editTextBoldCursor.setSelection(0, editTextBoldCursor.getText().length());
}
}
runnable.run();
builder2.setView(frameLayout);
final int i = this.selectionStart;
if (i >= 0 && (selectionEnd = this.selectionEnd) >= 0) {
this.selectionEnd = -1;
this.selectionStart = -1;
} else {
i = getSelectionStart();
selectionEnd = getSelectionEnd();
}
builder2.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public final void onClick(DialogInterface dialogInterface, int i2) {
EditTextCaption.this.lambda$makeSelectedUrl$2(i, selectionEnd, editTextBoldCursor, dialogInterface, i2);
}
});
builder2.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (DialogInterface.OnClickListener) null);
final CharSequence text = ((ClipboardManager) ApplicationLoader.applicationContext.getSystemService("clipboard")).getText();
final boolean z = text != null && text.length() > 0;
if (z) {
builder2.setNeutralButton(LocaleController.getString("Paste", android.R.string.paste), (DialogInterface.OnClickListener) null);
}
if (this.adaptiveCreateLinkDialog) {
AlertDialog create = builder2.create();
this.creationLinkDialog = create;
create.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public final void onDismiss(DialogInterface dialogInterface) {
EditTextCaption.this.lambda$makeSelectedUrl$3(dialogInterface);
}
});
this.creationLinkDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public final void onShow(DialogInterface dialogInterface) {
EditTextCaption.this.lambda$makeSelectedUrl$5(editTextBoldCursor, z, text, dialogInterface);
}
});
this.creationLinkDialog.showDelayed(250L);
} else {
builder2.show().setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public final void onShow(DialogInterface dialogInterface) {
EditTextCaption.lambda$makeSelectedUrl$6(EditTextBoldCursor.this, dialogInterface);
}
});
}
final AlertDialog create2 = builder2.create();
create2.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public final void onShow(DialogInterface dialogInterface) {
EditTextCaption.lambda$makeSelectedUrl$8(EditTextBoldCursor.this, z, create2, text, dialogInterface);
}
});
create2.showDelayed(250L);
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) editTextBoldCursor.getLayoutParams();
if (marginLayoutParams != null) {
if (marginLayoutParams instanceof FrameLayout.LayoutParams) {
((FrameLayout.LayoutParams) marginLayoutParams).gravity = 1;
}
int dp = AndroidUtilities.dp(24.0f);
marginLayoutParams.leftMargin = dp;
marginLayoutParams.rightMargin = dp;
marginLayoutParams.height = AndroidUtilities.dp(36.0f);
editTextBoldCursor.setLayoutParams(marginLayoutParams);
}
editTextBoldCursor.setSelection(0, editTextBoldCursor.getText().length());
}
public void lambda$makeSelectedUrl$0(EditTextBoldCursor editTextBoldCursor, TextView textView) {
ClipboardManager clipboardManager = (ClipboardManager) getContext().getSystemService("clipboard");
boolean z = (TextUtils.isEmpty(editTextBoldCursor.getText()) || TextUtils.equals(editTextBoldCursor.getText().toString(), "http://")) && clipboardManager != null && clipboardManager.hasPrimaryClip();
textView.animate().alpha(z ? 1.0f : 0.0f).scaleX(z ? 1.0f : 0.7f).scaleY(z ? 1.0f : 0.7f).setInterpolator(CubicBezierInterpolator.EASE_OUT_QUINT).setDuration(300L).start();
}
public void lambda$makeSelectedUrl$1(EditTextBoldCursor editTextBoldCursor, Runnable runnable, View view) {
CharSequence charSequence;
try {
charSequence = ((ClipboardManager) getContext().getSystemService("clipboard")).getPrimaryClip().getItemAt(0).coerceToText(getContext());
} catch (Exception e) {
FileLog.e(e);
charSequence = null;
}
if (charSequence != null) {
editTextBoldCursor.setText(charSequence);
editTextBoldCursor.setSelection(0, editTextBoldCursor.getText().length());
}
runnable.run();
}
public void lambda$makeSelectedUrl$2(int i, int i2, EditTextBoldCursor editTextBoldCursor, DialogInterface dialogInterface, int i3) {
Editable text = getText();
CharacterStyle[] characterStyleArr = (CharacterStyle[]) text.getSpans(i, i2, CharacterStyle.class);
if (characterStyleArr != null && characterStyleArr.length > 0) {
for (CharacterStyle characterStyle : characterStyleArr) {
if (!(characterStyle instanceof AnimatedEmojiSpan) && !(characterStyle instanceof QuoteSpan.QuoteStyleSpan)) {
int spanStart = text.getSpanStart(characterStyle);
int spanEnd = text.getSpanEnd(characterStyle);
text.removeSpan(characterStyle);
if (spanStart < i) {
text.setSpan(characterStyle, spanStart, i, 33);
}
if (spanEnd > i2) {
text.setSpan(characterStyle, i2, spanEnd, 33);
}
}
}
}
try {
text.setSpan(new URLSpanReplacement(editTextBoldCursor.getText().toString()), i, i2, 33);
} catch (Exception unused) {
}
EditTextCaptionDelegate editTextCaptionDelegate = this.delegate;
if (editTextCaptionDelegate != null) {
editTextCaptionDelegate.onSpansChanged();
}
}
public void lambda$makeSelectedUrl$3(DialogInterface dialogInterface) {
this.creationLinkDialog = null;
requestFocus();
}
public void lambda$makeSelectedUrl$5(final EditTextBoldCursor editTextBoldCursor, boolean z, final CharSequence charSequence, DialogInterface dialogInterface) {
editTextBoldCursor.requestFocus();
AndroidUtilities.showKeyboard(editTextBoldCursor);
if (z) {
this.creationLinkDialog.getButton(-3).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
EditTextBoldCursor.this.setText(charSequence);
}
});
}
}
public static void lambda$makeSelectedUrl$6(EditTextBoldCursor editTextBoldCursor, DialogInterface dialogInterface) {
editTextBoldCursor.requestFocus();
AndroidUtilities.showKeyboard(editTextBoldCursor);
}
public static void lambda$makeSelectedUrl$8(final EditTextBoldCursor editTextBoldCursor, boolean z, AlertDialog alertDialog, final CharSequence charSequence, DialogInterface dialogInterface) {
editTextBoldCursor.requestFocus();
AndroidUtilities.showKeyboard(editTextBoldCursor);
if (z) {
alertDialog.getButton(-3).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
EditTextBoldCursor.this.setText(charSequence);
}
});
}
}
public boolean closeCreationLinkDialog() {
AlertDialog alertDialog = this.creationLinkDialog;
if (alertDialog == null || !alertDialog.isShowing()) {
return false;
}
this.creationLinkDialog.dismiss();
return true;
}
public void makeSelectedRegular() {
applyTextStyleToSelection(null);
}
public void setSelectionOverride(int start, int end) {
this.selectionStart = start;
this.selectionEnd = end;
}
private void applyTextStyleToSelection(TextStyleSpan span) {
int selectionEnd;
int i = this.selectionStart;
if (i >= 0 && (selectionEnd = this.selectionEnd) >= 0) {
this.selectionEnd = -1;
this.selectionStart = -1;
} else {
i = getSelectionStart();
selectionEnd = getSelectionEnd();
}
MediaDataController.addStyleToText(span, i, selectionEnd, getText(), this.allowTextEntitiesIntersection);
if (span == null) {
Editable text = getText();
for (CodeHighlighting.Span span2 : (CodeHighlighting.Span[]) text.getSpans(i, selectionEnd, CodeHighlighting.Span.class)) {
text.removeSpan(span2);
}
QuoteSpan[] quoteSpanArr = (QuoteSpan[]) text.getSpans(i, selectionEnd, QuoteSpan.class);
for (int i2 = 0; i2 < quoteSpanArr.length; i2++) {
text.removeSpan(quoteSpanArr[i2]);
text.removeSpan(quoteSpanArr[i2].styleSpan);
if (quoteSpanArr[i2].collapsedSpan != null) {
text.removeSpan(quoteSpanArr[i2].collapsedSpan);
}
}
if (quoteSpanArr.length > 0) {
invalidateQuotes(true);
}
}
EditTextCaptionDelegate editTextCaptionDelegate = this.delegate;
if (editTextCaptionDelegate != null) {
editTextCaptionDelegate.onSpansChanged();
}
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
if (Build.VERSION.SDK_INT >= 23 || hasWindowFocus || !this.copyPasteShowed) {
try {
super.onWindowFocusChanged(hasWindowFocus);
} catch (Throwable th) {
FileLog.e(th);
}
}
}
public void makeSelectedMention(int id) {
final int selectionEnd;
final int i = this.selectionStart;
if (i >= 0 && (selectionEnd = this.selectionEnd) >= 0) {
this.selectionEnd = -1;
this.selectionStart = -1;
} else {
i = getSelectionStart();
selectionEnd = getSelectionEnd();
}
if (id > 0) {
getText().setSpan(new URLSpanUserMention(BuildConfig.APP_CENTER_HASH + id, 3), i, selectionEnd, 33);
EditTextCaptionDelegate editTextCaptionDelegate = this.delegate;
if (editTextCaptionDelegate != null) {
editTextCaptionDelegate.onSpansChanged();
return;
}
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(LocaleController.getString("CreateMention", R.string.CreateMention));
final EditTextBoldCursor editTextBoldCursor = new EditTextBoldCursor(this, getContext()) {
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64.0f), 1073741824));
}
};
editTextBoldCursor.setTextSize(1, 18.0f);
if (id > 0) {
editTextBoldCursor.setText(id + BuildConfig.APP_CENTER_HASH);
}
editTextBoldCursor.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
editTextBoldCursor.setHintText(LocaleController.getString("UserId", R.string.UserId));
editTextBoldCursor.setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
editTextBoldCursor.setSingleLine(true);
editTextBoldCursor.setFocusable(true);
editTextBoldCursor.setFilters(new InputFilter[]{new InputFilter.LengthFilter(18)});
editTextBoldCursor.setInputType(8194);
editTextBoldCursor.setTransformHintToHeader(true);
editTextBoldCursor.setLineColors(Theme.getColor(Theme.key_dialogInputField), Theme.getColor(Theme.key_dialogInputFieldActivated), Theme.getColor(Theme.key_text_RedBold));
editTextBoldCursor.setImeOptions(6);
editTextBoldCursor.setBackgroundDrawable(null);
editTextBoldCursor.requestFocus();
editTextBoldCursor.setPadding(0, 0, 0, 0);
editTextBoldCursor.addTextChangedListener(new TextWatcher(this) {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (TextUtils.isEmpty(s) || s.length() > 18) {
return;
}
long j = 0;
try {
j = Long.parseLong(editTextBoldCursor.getText().toString());
} catch (Exception unused) {
}
TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(Long.valueOf(j));
if (user != null) {
editTextBoldCursor.setHintText(UserObject.getUserName(user));
} else {
editTextBoldCursor.setHintText(LocaleController.getString("UserId", R.string.UserId));
}
}
});
builder.setView(editTextBoldCursor);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
@Override
public final void onClick(DialogInterface dialogInterface, int i2) {
EditTextCaption.this.lambda$makeSelectedMention$9(editTextBoldCursor, i, selectionEnd, dialogInterface, i2);
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), (DialogInterface.OnClickListener) null);
final AlertDialog create = builder.create();
final CharSequence text = ((ClipboardManager) ApplicationLoader.applicationContext.getSystemService("clipboard")).getText();
final boolean z = text != null && text.length() > 0 && text.toString().matches("-?(0|[1-9]\\d*)");
if (z) {
builder.setNeutralButton(LocaleController.getString("Paste", android.R.string.paste), (DialogInterface.OnClickListener) null);
}
create.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public final void onShow(DialogInterface dialogInterface) {
EditTextCaption.lambda$makeSelectedMention$11(EditTextBoldCursor.this, z, create, text, dialogInterface);
}
});
create.show();
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) editTextBoldCursor.getLayoutParams();
if (marginLayoutParams != null) {
if (marginLayoutParams instanceof FrameLayout.LayoutParams) {
((FrameLayout.LayoutParams) marginLayoutParams).gravity = 1;
}
int dp = AndroidUtilities.dp(24.0f);
marginLayoutParams.leftMargin = dp;
marginLayoutParams.rightMargin = dp;
marginLayoutParams.height = AndroidUtilities.dp(36.0f);
editTextBoldCursor.setLayoutParams(marginLayoutParams);
}
editTextBoldCursor.setSelection(0, editTextBoldCursor.getText().length());
}
public void lambda$makeSelectedMention$9(EditTextBoldCursor editTextBoldCursor, int i, int i2, DialogInterface dialogInterface, int i3) {
if (TextUtils.isEmpty(editTextBoldCursor.getText())) {
return;
}
long parseLong = Long.parseLong(editTextBoldCursor.getText().toString());
if (MessagesController.getInstance(UserConfig.selectedAccount).getUser(Long.valueOf(parseLong)) != null) {
getText().setSpan(new URLSpanUserMention(BuildConfig.APP_CENTER_HASH + parseLong, 3), i, i2, 33);
EditTextCaptionDelegate editTextCaptionDelegate = this.delegate;
if (editTextCaptionDelegate != null) {
editTextCaptionDelegate.onSpansChanged();
return;
}
return;
}
PlusUtils.showToast(getContext(), LocaleController.getString("UserRestricted", R.string.UserRestricted));
}
public static void lambda$makeSelectedMention$11(final EditTextBoldCursor editTextBoldCursor, boolean z, AlertDialog alertDialog, final CharSequence charSequence, DialogInterface dialogInterface) {
editTextBoldCursor.requestFocus();
AndroidUtilities.showKeyboard(editTextBoldCursor);
if (z) {
alertDialog.getButton(-3).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
EditTextBoldCursor.this.setText(charSequence);
}
});
}
}
public void translateSelection() {
final int selectionEnd;
final int i = this.selectionStart;
if (i >= 0 && (selectionEnd = this.selectionEnd) >= 0) {
this.selectionEnd = -1;
this.selectionStart = -1;
} else {
i = getSelectionStart();
selectionEnd = getSelectionEnd();
}
if (getText() == null) {
return;
}
final Editable text = getText();
PlusUtils.showTranslateDialog(getContext(), text.subSequence(i, selectionEnd).toString(), new PlusUtils.TranslateCallBack() {
@Override
public void onChanged(String str) {
PlusUtils.TranslateCallBack.CC.$default$onChanged(this, str);
}
@Override
public void onProviderChanged(int i2) {
PlusUtils.TranslateCallBack.CC.$default$onProviderChanged(this, i2);
}
@Override
public void onSuccess(String translation) {
text.replace(i, selectionEnd, translation);
if (EditTextCaption.this.delegate != null) {
EditTextCaption.this.delegate.onSpansChanged();
}
}
});
}
private ActionMode.Callback overrideCallback(final ActionMode.Callback callback) {
final ActionMode.Callback callback2 = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
EditTextCaption.this.copyPasteShowed = true;
EditTextCaption.this.onContextMenuOpen();
return callback.onCreateActionMode(mode, menu);
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return callback.onPrepareActionMode(mode, menu);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (EditTextCaption.this.performMenuAction(item.getItemId())) {
mode.finish();
return true;
}
try {
return callback.onActionItemClicked(mode, item);
} catch (Exception unused) {
return true;
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
EditTextCaption.this.copyPasteShowed = false;
EditTextCaption.this.onContextMenuClose();
callback.onDestroyActionMode(mode);
}
};
return Build.VERSION.SDK_INT >= 23 ? new ActionMode.Callback2(this) {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return callback2.onCreateActionMode(mode, menu);
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return callback2.onPrepareActionMode(mode, menu);
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return callback2.onActionItemClicked(mode, item);
}
@Override
public void onDestroyActionMode(ActionMode mode) {
callback2.onDestroyActionMode(mode);
}
@Override
public void onGetContentRect(ActionMode mode, View view, android.graphics.Rect outRect) {
ActionMode.Callback callback3 = callback;
if (callback3 instanceof ActionMode.Callback2) {
((ActionMode.Callback2) callback3).onGetContentRect(mode, view, outRect);
} else {
super.onGetContentRect(mode, view, outRect);
}
}
} : callback2;
}
private void checkDeviceFont(int itemId) {
if (Theme.useDeviceFont.booleanValue()) {
if (itemId == R.id.menu_regular || itemId == R.id.menu_bold || itemId == R.id.menu_italic || itemId == R.id.menu_mono || itemId == R.id.menu_strike || itemId == R.id.menu_underline) {
ApplicationLoader.applicationContext.getSharedPreferences("plusconfig", 0).edit().putBoolean("useDeviceFont", false).apply();
Theme.useDeviceFont = Boolean.FALSE;
}
}
}
public boolean performMenuAction(int itemId) {
checkDeviceFont(itemId);
if (itemId == R.id.menu_regular) {
makeSelectedRegular();
return true;
}
if (itemId == R.id.menu_bold) {
makeSelectedBold();
return true;
}
if (itemId == R.id.menu_italic) {
makeSelectedItalic();
return true;
}
if (itemId == R.id.menu_mono) {
makeSelectedMono();
return true;
}
if (itemId == R.id.menu_link) {
makeSelectedUrl();
return true;
}
if (itemId == R.id.menu_strike) {
makeSelectedStrike();
return true;
}
if (itemId == R.id.menu_underline) {
makeSelectedUnderline();
return true;
}
if (itemId == R.id.menu_spoiler) {
makeSelectedSpoiler();
return true;
}
if (itemId == R.id.menu_quote) {
makeSelectedQuote();
return true;
}
if (itemId == R.id.menu_mention) {
makeSelectedMention(0);
return true;
}
if (itemId != R.id.menu_translate) {
return false;
}
translateSelection();
return true;
}
@Override
public ActionMode startActionMode(final ActionMode.Callback callback, int type) {
return super.startActionMode(overrideCallback(callback), type);
}
@Override
public ActionMode startActionMode(final ActionMode.Callback callback) {
return super.startActionMode(overrideCallback(callback));
}
@Override
@SuppressLint({"DrawAllocation"})
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int indexOf;
try {
this.isInitLineCount = getMeasuredWidth() == 0 && getMeasuredHeight() == 0;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (this.isInitLineCount) {
this.lineCount = getLineCount();
}
this.isInitLineCount = false;
} catch (Exception e) {
setMeasuredDimension(View.MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(51.0f));
FileLog.e(e);
}
this.captionLayout = null;
String str = this.caption;
if (str == null || str.length() <= 0) {
return;
}
Editable text = getText();
if (text.length() <= 1 || text.charAt(0) != '@' || (indexOf = TextUtils.indexOf((CharSequence) text, ' ')) == -1) {
return;
}
TextPaint paint = getPaint();
CharSequence subSequence = text.subSequence(0, indexOf + 1);
int ceil = (int) Math.ceil(paint.measureText(text, 0, r13));
int measuredWidth = (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight();
this.userNameLength = subSequence.length();
int i = measuredWidth - ceil;
CharSequence ellipsize = TextUtils.ellipsize(this.caption, paint, i, TextUtils.TruncateAt.END);
this.xOffset = ceil;
try {
StaticLayout staticLayout = new StaticLayout(ellipsize, getPaint(), i, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
this.captionLayout = staticLayout;
if (staticLayout.getLineCount() > 0) {
this.xOffset = (int) (this.xOffset + (-this.captionLayout.getLineLeft(0)));
}
this.yOffset = ((getMeasuredHeight() - this.captionLayout.getLineBottom(0)) / 2) + AndroidUtilities.dp(0.5f);
} catch (Exception e2) {
FileLog.e(e2);
}
}
public String getCaption() {
return this.caption;
}
@Override
public void setHintColor(int value) {
super.setHintColor(value);
this.hintColor = value;
invalidate();
}
@Override
public void onDraw(Canvas canvas) {
canvas.save();
canvas.translate(0.0f, this.offsetY);
super.onDraw(canvas);
try {
if (this.captionLayout != null && this.userNameLength == length()) {
TextPaint paint = getPaint();
int color = getPaint().getColor();
paint.setColor(this.hintColor);
canvas.save();
canvas.translate(this.xOffset, this.yOffset);
this.captionLayout.draw(canvas);
canvas.restore();
paint.setColor(color);
}
} catch (Exception e) {
FileLog.e(e);
}
canvas.restore();
}
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
AccessibilityNodeInfoCompat wrap = AccessibilityNodeInfoCompat.wrap(info);
if (!TextUtils.isEmpty(this.caption)) {
wrap.setHintText(this.caption);
}
List actionList = wrap.getActionList();
int i = 0;
int size = actionList.size();
while (true) {
if (i >= size) {
break;
}
AccessibilityNodeInfoCompat.AccessibilityActionCompat accessibilityActionCompat = (AccessibilityNodeInfoCompat.AccessibilityActionCompat) actionList.get(i);
if (accessibilityActionCompat.getId() == ACCESSIBILITY_ACTION_SHARE) {
wrap.removeAction(accessibilityActionCompat);
break;
}
i++;
}
if (hasSelection()) {
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_spoiler, LocaleController.getString("Spoiler", R.string.Spoiler)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_bold, LocaleController.getString("Bold", R.string.Bold)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_italic, LocaleController.getString("Italic", R.string.Italic)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_mono, LocaleController.getString("Mono", R.string.Mono)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_strike, LocaleController.getString("Strike", R.string.Strike)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_underline, LocaleController.getString("Underline", R.string.Underline)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_link, LocaleController.getString("CreateLink", R.string.CreateLink)));
wrap.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat(R.id.menu_regular, LocaleController.getString("Regular", R.string.Regular)));
}
}
@Override
public boolean performAccessibilityAction(int action, Bundle arguments) {
return performMenuAction(action) || super.performAccessibilityAction(action, arguments);
}
private int getThemedColor(int key) {
return Theme.getColor(key, this.resourcesProvider);
}
@Override
public boolean onTextContextMenuItem(int id) {
if (id == 16908322) {
ClipData primaryClip = ((ClipboardManager) getContext().getSystemService("clipboard")).getPrimaryClip();
if (primaryClip != null && primaryClip.getItemCount() == 1 && primaryClip.getDescription().hasMimeType("text/html")) {
try {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(CopyUtilities.fromHTML(primaryClip.getItemAt(0).getHtmlText()));
Emoji.replaceEmoji((CharSequence) spannableStringBuilder, getPaint().getFontMetricsInt(), false, (int[]) null);
AnimatedEmojiSpan[] animatedEmojiSpanArr = (AnimatedEmojiSpan[]) spannableStringBuilder.getSpans(0, spannableStringBuilder.length(), AnimatedEmojiSpan.class);
if (animatedEmojiSpanArr != null) {
for (AnimatedEmojiSpan animatedEmojiSpan : animatedEmojiSpanArr) {
animatedEmojiSpan.applyFontMetrics(getPaint().getFontMetricsInt(), AnimatedEmojiDrawable.getCacheTypeForEnterView());
}
}
int max = Math.max(0, getSelectionStart());
int min = Math.min(getText().length(), getSelectionEnd());
QuoteSpan.QuoteStyleSpan[] quoteStyleSpanArr = (QuoteSpan.QuoteStyleSpan[]) getText().getSpans(max, min, QuoteSpan.QuoteStyleSpan.class);
if (quoteStyleSpanArr != null && quoteStyleSpanArr.length > 0) {
QuoteSpan.QuoteStyleSpan[] quoteStyleSpanArr2 = (QuoteSpan.QuoteStyleSpan[]) spannableStringBuilder.getSpans(0, spannableStringBuilder.length(), QuoteSpan.QuoteStyleSpan.class);
for (int i = 0; i < quoteStyleSpanArr2.length; i++) {
spannableStringBuilder.removeSpan(quoteStyleSpanArr2[i]);
spannableStringBuilder.removeSpan(quoteStyleSpanArr2[i].span);
}
} else {
QuoteSpan.normalizeQuotes(spannableStringBuilder);
}
setText(getText().replace(max, min, spannableStringBuilder));
setSelection(spannableStringBuilder.length() + max, max + spannableStringBuilder.length());
return true;
} catch (Exception e) {
FileLog.e(e);
}
}
} else {
try {
if (id == 16908321) {
AndroidUtilities.addToClipboard(getText().subSequence(Math.max(0, getSelectionStart()), Math.min(getText().length(), getSelectionEnd())));
return true;
}
if (id == 16908320) {
int max2 = Math.max(0, getSelectionStart());
int min2 = Math.min(getText().length(), getSelectionEnd());
AndroidUtilities.addToClipboard(getText().subSequence(max2, min2));
SpannableStringBuilder spannableStringBuilder2 = new SpannableStringBuilder();
if (max2 != 0) {
spannableStringBuilder2.append(getText().subSequence(0, max2));
}
if (min2 != getText().length()) {
spannableStringBuilder2.append(getText().subSequence(min2, getText().length()));
}
setText(spannableStringBuilder2);
setSelection(max2, max2);
return true;
}
} catch (Exception unused) {
}
}
return super.onTextContextMenuItem(id);
}
}