package com.scb.phone.view.custom; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.util.AttributeSet; import android.util.TypedValue; import android.widget.TextView; import androidx.appcompat.widget.AppCompatTextView; import com.google.android.gms.maps.model.BitmapDescriptorFactory; import o.AQw; import o.C10314eAj; import o.nMh; /* loaded from: classes5.dex */ public class ImageTextView extends AppCompatTextView { public int a; private int b; public Drawable c; private CharSequence d; public int e; public ImageTextView(Context context) { super(context); } public ImageTextView(Context context, AttributeSet attributeSet) { super(context, attributeSet); aol_(context, attributeSet); b(); } public ImageTextView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); aol_(context, attributeSet); b(); } private void aol_(Context context, AttributeSet attributeSet) { TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, AQw.Sts.ImageTextView, 0, 0); int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(3, (int) TypedValue.applyDimension(1, 24.0f, getResources().getDisplayMetrics())); if (obtainStyledAttributes.hasValue(2) && obtainStyledAttributes.hasValue(5)) { this.a = obtainStyledAttributes.getDimensionPixelSize(2, (int) TypedValue.applyDimension(1, 24.0f, getResources().getDisplayMetrics())); dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(5, (int) TypedValue.applyDimension(1, 24.0f, getResources().getDisplayMetrics())); } else { this.a = dimensionPixelSize; } this.e = dimensionPixelSize; this.b = obtainStyledAttributes.getDimensionPixelSize(4, (int) TypedValue.applyDimension(1, 8.0f, getResources().getDisplayMetrics())); this.c = obtainStyledAttributes.getDrawable(1); this.d = obtainStyledAttributes.getText(6); if (obtainStyledAttributes.getBoolean(0, false)) { a(); } obtainStyledAttributes.recycle(); } private void b() { Drawable drawable = this.c; if (drawable != null) { setDrawable(drawable); } if (TextUtils.isEmpty(this.d)) { return; } setText(this.d); } public void setDrawableBitmap(Bitmap bitmap) { synchronized (this) { if (bitmap == null) { return; } int width = bitmap.getWidth(); int i = this.e; if (width > i) { bitmap = aon_(bitmap, i, this.a); } BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); bitmapDrawable.setBounds(0, 0, this.e, this.a); aom_(bitmapDrawable); } } public void setDrawable(int i) { synchronized (this) { Drawable drawable = nMh.getDrawable(getContext(), i); if (drawable != null) { drawable.setBounds(0, 0, this.e, this.a); } aom_(drawable); } } public void setDrawable(Drawable drawable) { synchronized (this) { if (drawable == null) { return; } if (((BitmapDrawable) drawable).getIntrinsicWidth() > this.e) { drawable = new BitmapDrawable(getResources(), aon_(((BitmapDrawable) drawable).getBitmap(), this.e, this.a)); } drawable.setBounds(0, 0, this.e, this.a); aom_(drawable); } } private void aom_(Drawable drawable) { synchronized (this) { this.c = drawable; SpannableString spannableString = new SpannableString("[scbImage]"); spannableString.setSpan(new C10314eAj(drawable, this.b), 0, 10, 33); setText(new SpannableStringBuilder().append((CharSequence) spannableString).append((CharSequence) getText().toString().trim().replace("[scbImage]", ""))); } } private static Bitmap aon_(Bitmap bitmap, int i, int i2) { Bitmap createBitmap = Bitmap.createBitmap(i, i2, Bitmap.Config.ARGB_8888); Matrix matrix = new Matrix(); matrix.setScale(i / bitmap.getWidth(), i2 / bitmap.getHeight(), BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED); Canvas canvas = new Canvas(createBitmap); canvas.setMatrix(matrix); canvas.drawBitmap(bitmap, BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED, new Paint(2)); return createBitmap; } @Override // android.widget.TextView public void setText(CharSequence charSequence, TextView.BufferType bufferType) { super.setText(charSequence, bufferType); if ((this.c == null || charSequence == null || charSequence.toString().contains("[scbImage]")) && !TextUtils.isEmpty(charSequence)) { return; } aom_(this.c); } @Override // androidx.appcompat.widget.AppCompatTextView, android.widget.TextView public CharSequence getText() { CharSequence text = super.getText(); return (text == null || !text.toString().startsWith("[scbImage]")) ? text : text.toString().substring(10); } @Override // androidx.appcompat.widget.AppCompatTextView, android.widget.TextView, android.view.View public void onMeasure(int i, int i2) { int measuredHeight = getMeasuredHeight(); if (this.c != null && measuredHeight != 0) { Paint.FontMetricsInt fontMetricsInt = getPaint().getFontMetricsInt(); int abs = Math.abs(fontMetricsInt.top) + Math.abs(fontMetricsInt.bottom); Rect bounds = this.c.getBounds(); int abs2 = Math.abs(bounds.top) - Math.abs(bounds.bottom); if (abs < abs2) { int i3 = (abs2 - abs) / 2; int i4 = measuredHeight + i3 + fontMetricsInt.bottom; setPadding(getPaddingLeft(), getPaddingTop() + i3, getPaddingRight(), getPaddingBottom()); if (i4 >= abs2) { abs2 = i4; } setMeasuredDimension(getMeasuredWidth(), abs2); return; } } super.onMeasure(i, i2); } private void a() { Paint.FontMetricsInt fontMetricsInt = getPaint().getFontMetricsInt(); int abs = Math.abs(fontMetricsInt.top) + Math.abs(fontMetricsInt.bottom); int i = this.a; if (i > abs) { this.a = abs; this.e = (int) (this.e * (abs / i)); } } public void setImageWidth(int i) { this.e = i; } public void setImageSize(int i) { this.a = i; this.e = i; } public void setImageHeight(int i) { this.a = i; } }