- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
177 lines
5.9 KiB
Java
177 lines
5.9 KiB
Java
package com.mbridge.msdk.videocommon.view;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapShader;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Matrix;
|
|
import android.graphics.Paint;
|
|
import android.graphics.RectF;
|
|
import android.graphics.Shader;
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.os.Bundle;
|
|
import android.os.Parcelable;
|
|
import android.util.AttributeSet;
|
|
import android.util.TypedValue;
|
|
import com.mbridge.msdk.foundation.tools.af;
|
|
import com.mbridge.msdk.foundation.tools.ak;
|
|
import com.mbridge.msdk.widget.MBImageView;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class RoundImageView extends MBImageView {
|
|
private int a;
|
|
private int b;
|
|
private Paint c;
|
|
private int d;
|
|
private Matrix e;
|
|
private BitmapShader f;
|
|
private int g;
|
|
private RectF h;
|
|
|
|
public RoundImageView(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.e = new Matrix();
|
|
Paint paint = new Paint();
|
|
this.c = paint;
|
|
paint.setAntiAlias(true);
|
|
this.b = (int) TypedValue.applyDimension(1, 5.0f, getResources().getDisplayMetrics());
|
|
this.a = 1;
|
|
}
|
|
|
|
public RoundImageView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.e = new Matrix();
|
|
Paint paint = new Paint();
|
|
this.c = paint;
|
|
paint.setAntiAlias(true);
|
|
this.b = (int) TypedValue.applyDimension(1, 5.0f, getResources().getDisplayMetrics());
|
|
this.a = 1;
|
|
}
|
|
|
|
public RoundImageView(Context context) {
|
|
super(context);
|
|
this.e = new Matrix();
|
|
Paint paint = new Paint();
|
|
this.c = paint;
|
|
paint.setAntiAlias(true);
|
|
this.b = (int) TypedValue.applyDimension(1, 5.0f, getResources().getDisplayMetrics());
|
|
this.a = 1;
|
|
}
|
|
|
|
@Override // android.widget.ImageView, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
if (this.a == 0) {
|
|
int min = Math.min(getMeasuredWidth(), getMeasuredHeight());
|
|
this.g = min;
|
|
this.d = min / 2;
|
|
setMeasuredDimension(min, min);
|
|
}
|
|
}
|
|
|
|
@Override // com.mbridge.msdk.widget.MBImageView, android.widget.ImageView, android.view.View
|
|
public void onDraw(Canvas canvas) {
|
|
Bitmap a;
|
|
try {
|
|
if (getDrawable() == null) {
|
|
return;
|
|
}
|
|
try {
|
|
Drawable drawable = getDrawable();
|
|
if (drawable != null && (a = a(drawable)) != null && !a.isRecycled()) {
|
|
Shader.TileMode tileMode = Shader.TileMode.CLAMP;
|
|
this.f = new BitmapShader(a, tileMode, tileMode);
|
|
int i = this.a;
|
|
float f = 1.0f;
|
|
if (i == 0) {
|
|
f = (this.g * 1.0f) / Math.min(a.getWidth(), a.getHeight());
|
|
} else if (i == 1) {
|
|
f = Math.max((getWidth() * 1.0f) / a.getWidth(), (getHeight() * 1.0f) / a.getHeight());
|
|
}
|
|
this.e.setScale(f, f);
|
|
this.f.setLocalMatrix(this.e);
|
|
this.c.setShader(this.f);
|
|
}
|
|
} catch (Throwable th) {
|
|
af.b("RoundImageView", th.getMessage());
|
|
}
|
|
if (this.a == 1) {
|
|
RectF rectF = this.h;
|
|
int i2 = this.b;
|
|
canvas.drawRoundRect(rectF, i2, i2, this.c);
|
|
} else {
|
|
int i3 = this.d;
|
|
canvas.drawCircle(i3, i3, i3, this.c);
|
|
}
|
|
} catch (Throwable th2) {
|
|
af.b("RoundImageView", th2.getMessage());
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onSizeChanged(int i, int i2, int i3, int i4) {
|
|
super.onSizeChanged(i, i2, i3, i4);
|
|
if (this.a == 1) {
|
|
this.h = new RectF(0.0f, 0.0f, getWidth(), getHeight());
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public Parcelable onSaveInstanceState() {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putParcelable("state_instance", super.onSaveInstanceState());
|
|
bundle.putInt("state_type", this.a);
|
|
bundle.putInt("state_border_radius", this.b);
|
|
return bundle;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onRestoreInstanceState(Parcelable parcelable) {
|
|
if (parcelable instanceof Bundle) {
|
|
Bundle bundle = (Bundle) parcelable;
|
|
super.onRestoreInstanceState(bundle.getParcelable("state_instance"));
|
|
this.a = bundle.getInt("state_type");
|
|
this.b = bundle.getInt("state_border_radius");
|
|
return;
|
|
}
|
|
super.onRestoreInstanceState(parcelable);
|
|
}
|
|
|
|
public void setBorderRadius(int i) {
|
|
int a = ak.a(getContext(), i);
|
|
if (this.b != a) {
|
|
this.b = a;
|
|
invalidate();
|
|
}
|
|
}
|
|
|
|
public void setType(int i) {
|
|
if (this.a != i) {
|
|
this.a = i;
|
|
if (i != 1 && i != 0) {
|
|
this.a = 0;
|
|
}
|
|
requestLayout();
|
|
}
|
|
}
|
|
|
|
private Bitmap a(Drawable drawable) {
|
|
try {
|
|
if (drawable instanceof BitmapDrawable) {
|
|
return ((BitmapDrawable) drawable).getBitmap();
|
|
}
|
|
int intrinsicWidth = drawable.getIntrinsicWidth();
|
|
int intrinsicHeight = drawable.getIntrinsicHeight();
|
|
Bitmap createBitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_4444);
|
|
Canvas canvas = new Canvas(createBitmap);
|
|
drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight);
|
|
drawable.draw(canvas);
|
|
return createBitmap;
|
|
} catch (Throwable th) {
|
|
af.b("View", th.getMessage());
|
|
return null;
|
|
}
|
|
}
|
|
}
|