package com.scb.phone.view.custom.common; import android.content.Context; import android.text.SpannableString; import android.util.AttributeSet; import android.view.ViewTreeObserver; import android.widget.TextView; import androidx.appcompat.widget.AppCompatTextView; import java.text.BreakIterator; import java.util.Locale; /* loaded from: classes5.dex */ public class ThaiTextView extends AppCompatTextView { private boolean b; private String c; public ThaiTextView(Context context) { this(context, null); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: com.scb.phone.view.custom.common.ThaiTextView.5 private ThaiTextView c; { this.c = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (!this.c.b) { ThaiTextView thaiTextView = this.c; ThaiTextView.a(thaiTextView, thaiTextView.getWidth()); } this.c.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); } public ThaiTextView(Context context, AttributeSet attributeSet) { this(context, attributeSet, 0); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: com.scb.phone.view.custom.common.ThaiTextView.5 private ThaiTextView c; { this.c = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (!this.c.b) { ThaiTextView thaiTextView = this.c; ThaiTextView.a(thaiTextView, thaiTextView.getWidth()); } this.c.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); } public ThaiTextView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener(this) { // from class: com.scb.phone.view.custom.common.ThaiTextView.5 private ThaiTextView c; { this.c = this; } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public final void onGlobalLayout() { if (!this.c.b) { ThaiTextView thaiTextView = this.c; ThaiTextView.a(thaiTextView, thaiTextView.getWidth()); } this.c.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); } @Override // android.widget.TextView public void setText(CharSequence charSequence, TextView.BufferType bufferType) { this.c = charSequence != null ? charSequence.toString() : ""; super.setText(charSequence, bufferType); } static /* synthetic */ int a(ThaiTextView thaiTextView, int i) { StringBuilder sb; if (i == 0) { return 0; } int paddingLeft = i - (thaiTextView.getPaddingLeft() + thaiTextView.getPaddingRight()); String str = thaiTextView.c; if (!thaiTextView.b) { float f = paddingLeft; if (thaiTextView.getPaint().measureText(str) > f && !(thaiTextView.getText() instanceof SpannableString)) { BreakIterator wordInstance = BreakIterator.getWordInstance(new Locale("th")); wordInstance.setText(str); StringBuilder sb2 = new StringBuilder(); int first = wordInstance.first(); while (true) { int next = wordInstance.next(); if (next == -1) { break; } StringBuilder sb3 = new StringBuilder(); sb3.append(str.substring(first, next)); sb3.append("!split!"); sb2.append(sb3.toString()); first = next; } String[] split = sb2.toString().split("!split!"); int length = split.length; StringBuilder sb4 = new StringBuilder(); StringBuilder sb5 = new StringBuilder(); for (int i2 = 0; i2 < length; i2++) { if (sb5.toString().endsWith("\n")) { sb5 = new StringBuilder(); } sb5.append(split[i2]); float measureText = thaiTextView.getPaint().measureText(sb5.toString()); if (f > measureText) { sb4.append(split[i2]); } else { if (f == measureText) { String str2 = split[i2]; sb = new StringBuilder(); sb4.append(str2); if (!sb4.toString().endsWith(" ") && !sb4.toString().endsWith("\n")) { sb4.append("\n"); } } else { String str3 = split[i2]; sb = new StringBuilder(); sb.append(str3); if (!sb4.toString().endsWith(" ") && !sb4.toString().endsWith("\n") && !str3.startsWith(" ") && !str3.startsWith("\n") && !sb4.toString().endsWith(":") && !sb4.toString().isEmpty()) { sb4.append("\n"); } sb4.append(str3); } sb5 = sb; } } thaiTextView.b = true; thaiTextView.setText(sb4.toString()); } } return paddingLeft; } }