what-the-bank/sources/com/scb/phone/view/custom/investment/CustomHyperLinkTextView.java

81 lines
3.2 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.scb.phone.view.custom.investment;
import android.content.Context;
import android.text.Html;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.method.LinkMovementMethod;
import android.text.method.Touch;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatTextView;
/* loaded from: classes5.dex */
public class CustomHyperLinkTextView extends AppCompatTextView {
public CustomHyperLinkTextView(Context context) {
super(context);
}
public CustomHyperLinkTextView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
public CustomHyperLinkTextView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
}
public void setTextViewHTML(String str) {
setText(new SpannableStringBuilder(Html.fromHtml(str)));
}
/* loaded from: classes5.dex */
public static class HBt extends LinkMovementMethod {
private RVV c;
/* loaded from: classes5.dex */
public interface RVV {
void q();
}
public HBt(RVV rvv) {
this.c = rvv;
}
@Override // android.text.method.LinkMovementMethod, android.text.method.ScrollingMovementMethod, android.text.method.BaseMovementMethod, android.text.method.MovementMethod
public final boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent motionEvent) {
int action = motionEvent.getAction();
if (action == 1 || action == 0) {
int x = (int) motionEvent.getX();
int y = (int) motionEvent.getY();
int totalPaddingLeft = textView.getTotalPaddingLeft();
int totalPaddingTop = textView.getTotalPaddingTop();
int scrollX = textView.getScrollX();
int scrollY = textView.getScrollY();
Layout layout = textView.getLayout();
int offsetForHorizontal = layout.getOffsetForHorizontal(layout.getLineForVertical((y - totalPaddingTop) + scrollY), (x - totalPaddingLeft) + scrollX);
ClickableSpan[] clickableSpanArr = (ClickableSpan[]) spannable.getSpans(offsetForHorizontal, offsetForHorizontal, ClickableSpan.class);
if (clickableSpanArr.length == 0) {
Selection.removeSelection(spannable);
Touch.onTouchEvent(textView, spannable, motionEvent);
return false;
}
if (action == 1) {
clickableSpanArr[0].onClick(textView);
RVV rvv = this.c;
if (rvv != null) {
rvv.q();
}
} else {
Selection.setSelection(spannable, spannable.getSpanStart(clickableSpanArr[0]), spannable.getSpanEnd(clickableSpanArr[0]));
}
return true;
}
return Touch.onTouchEvent(textView, spannable, motionEvent);
}
}
}