package com.ubt.jimu.widgets; import android.annotation.SuppressLint; import android.content.res.ColorStateList; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.util.Log; import android.widget.ImageView; /* loaded from: classes2.dex */ public class RoundedDrawable extends Drawable { private final Bitmap d; private final Paint e; private final int f; private final int g; private final Paint i; private BitmapShader k; private Shader.TileMode l; private Shader.TileMode m; private boolean n; private float o; private boolean p; private float q; private ColorStateList r; private ImageView.ScaleType s; private final RectF a = new RectF(); private final RectF b = new RectF(); private final RectF c = new RectF(); private final RectF h = new RectF(); private final Matrix j = new Matrix(); /* renamed from: com.ubt.jimu.widgets.RoundedDrawable$1, reason: invalid class name */ static /* synthetic */ class AnonymousClass1 { static final /* synthetic */ int[] a = new int[ImageView.ScaleType.values().length]; static { try { a[ImageView.ScaleType.CENTER.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } try { a[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3; } catch (NoSuchFieldError unused3) { } try { a[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4; } catch (NoSuchFieldError unused4) { } try { a[ImageView.ScaleType.FIT_END.ordinal()] = 5; } catch (NoSuchFieldError unused5) { } try { a[ImageView.ScaleType.FIT_START.ordinal()] = 6; } catch (NoSuchFieldError unused6) { } try { a[ImageView.ScaleType.FIT_XY.ordinal()] = 7; } catch (NoSuchFieldError unused7) { } } } public RoundedDrawable(Bitmap bitmap) { Shader.TileMode tileMode = Shader.TileMode.CLAMP; this.l = tileMode; this.m = tileMode; this.n = true; this.o = 0.0f; this.p = false; this.q = 0.0f; this.r = ColorStateList.valueOf(-16777216); this.s = ImageView.ScaleType.FIT_CENTER; this.d = bitmap; this.f = bitmap.getWidth(); this.g = bitmap.getHeight(); this.c.set(0.0f, 0.0f, this.f, this.g); this.e = new Paint(); this.e.setStyle(Paint.Style.FILL); this.e.setAntiAlias(true); this.i = new Paint(); this.i.setStyle(Paint.Style.STROKE); this.i.setAntiAlias(true); this.i.setColor(this.r.getColorForState(getState(), -16777216)); this.i.setStrokeWidth(this.q); } public static RoundedDrawable a(Bitmap bitmap) { if (bitmap != null) { return new RoundedDrawable(bitmap); } return null; } public static Drawable b(Drawable drawable) { if (drawable == null || (drawable instanceof RoundedDrawable)) { return drawable; } if (!(drawable instanceof LayerDrawable)) { Bitmap a = a(drawable); return a != null ? new RoundedDrawable(a) : drawable; } LayerDrawable layerDrawable = (LayerDrawable) drawable; int numberOfLayers = layerDrawable.getNumberOfLayers(); for (int i = 0; i < numberOfLayers; i++) { layerDrawable.setDrawableByLayerId(layerDrawable.getId(i), b(layerDrawable.getDrawable(i))); } return layerDrawable; } @Override // android.graphics.drawable.Drawable public void draw(Canvas canvas) { if (this.n) { this.k = new BitmapShader(this.d, this.l, this.m); Shader.TileMode tileMode = this.l; Shader.TileMode tileMode2 = Shader.TileMode.CLAMP; if (tileMode == tileMode2 && this.m == tileMode2) { this.k.setLocalMatrix(this.j); } this.e.setShader(this.k); this.n = false; } if (this.p) { if (this.q <= 0.0f) { canvas.drawOval(this.b, this.e); return; } else { canvas.drawOval(this.b, this.e); canvas.drawOval(this.h, this.i); return; } } if (this.q <= 0.0f) { RectF rectF = this.b; float f = this.o; canvas.drawRoundRect(rectF, f, f, this.e); } else { canvas.drawRoundRect(this.b, Math.max(this.o, 0.0f), Math.max(this.o, 0.0f), this.e); RectF rectF2 = this.h; float f2 = this.o; canvas.drawRoundRect(rectF2, f2, f2, this.i); } } @Override // android.graphics.drawable.Drawable public int getAlpha() { return this.e.getAlpha(); } @Override // android.graphics.drawable.Drawable @SuppressLint({"Override"}) public ColorFilter getColorFilter() { return this.e.getColorFilter(); } @Override // android.graphics.drawable.Drawable public int getIntrinsicHeight() { return this.g; } @Override // android.graphics.drawable.Drawable public int getIntrinsicWidth() { return this.f; } @Override // android.graphics.drawable.Drawable public int getOpacity() { return -3; } @Override // android.graphics.drawable.Drawable public boolean isStateful() { return this.r.isStateful(); } @Override // android.graphics.drawable.Drawable protected void onBoundsChange(Rect rect) { super.onBoundsChange(rect); this.a.set(rect); a(); } @Override // android.graphics.drawable.Drawable protected boolean onStateChange(int[] iArr) { int colorForState = this.r.getColorForState(iArr, 0); if (this.i.getColor() == colorForState) { return super.onStateChange(iArr); } this.i.setColor(colorForState); return true; } @Override // android.graphics.drawable.Drawable public void setAlpha(int i) { this.e.setAlpha(i); invalidateSelf(); } @Override // android.graphics.drawable.Drawable public void setColorFilter(ColorFilter colorFilter) { this.e.setColorFilter(colorFilter); invalidateSelf(); } @Override // android.graphics.drawable.Drawable public void setDither(boolean z) { this.e.setDither(z); invalidateSelf(); } @Override // android.graphics.drawable.Drawable public void setFilterBitmap(boolean z) { this.e.setFilterBitmap(z); invalidateSelf(); } public static Bitmap a(Drawable drawable) { if (drawable instanceof BitmapDrawable) { return ((BitmapDrawable) drawable).getBitmap(); } try { Bitmap createBitmap = Bitmap.createBitmap(Math.max(drawable.getIntrinsicWidth(), 2), Math.max(drawable.getIntrinsicHeight(), 2), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(createBitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return createBitmap; } catch (Exception e) { e.printStackTrace(); Log.w("RoundedDrawable", "Failed to create bitmap from drawable!"); return null; } } public RoundedDrawable b(float f) { this.o = f; return this; } public RoundedDrawable b(Shader.TileMode tileMode) { if (this.m != tileMode) { this.m = tileMode; this.n = true; invalidateSelf(); } return this; } private void a() { float width; float f; int i = AnonymousClass1.a[this.s.ordinal()]; if (i == 1) { this.h.set(this.a); RectF rectF = this.h; float f2 = this.q; rectF.inset(f2 / 2.0f, f2 / 2.0f); this.j.reset(); this.j.setTranslate((int) (((this.h.width() - this.f) * 0.5f) + 0.5f), (int) (((this.h.height() - this.g) * 0.5f) + 0.5f)); } else if (i == 2) { this.h.set(this.a); RectF rectF2 = this.h; float f3 = this.q; rectF2.inset(f3 / 2.0f, f3 / 2.0f); this.j.reset(); float f4 = 0.0f; if (this.f * this.h.height() > this.h.width() * this.g) { width = this.h.height() / this.g; f = (this.h.width() - (this.f * width)) * 0.5f; } else { width = this.h.width() / this.f; f4 = (this.h.height() - (this.g * width)) * 0.5f; f = 0.0f; } this.j.setScale(width, width); Matrix matrix = this.j; float f5 = this.q; matrix.postTranslate(((int) (f + 0.5f)) + f5, ((int) (f4 + 0.5f)) + f5); } else if (i == 3) { this.j.reset(); float min = (((float) this.f) > this.a.width() || ((float) this.g) > this.a.height()) ? Math.min(this.a.width() / this.f, this.a.height() / this.g) : 1.0f; float width2 = (int) (((this.a.width() - (this.f * min)) * 0.5f) + 0.5f); float height = (int) (((this.a.height() - (this.g * min)) * 0.5f) + 0.5f); this.j.setScale(min, min); this.j.postTranslate(width2, height); this.h.set(this.c); this.j.mapRect(this.h); RectF rectF3 = this.h; float f6 = this.q; rectF3.inset(f6 / 2.0f, f6 / 2.0f); this.j.setRectToRect(this.c, this.h, Matrix.ScaleToFit.FILL); } else if (i == 5) { this.h.set(this.c); this.j.setRectToRect(this.c, this.a, Matrix.ScaleToFit.END); this.j.mapRect(this.h); RectF rectF4 = this.h; float f7 = this.q; rectF4.inset(f7 / 2.0f, f7 / 2.0f); this.j.setRectToRect(this.c, this.h, Matrix.ScaleToFit.FILL); } else if (i == 6) { this.h.set(this.c); this.j.setRectToRect(this.c, this.a, Matrix.ScaleToFit.START); this.j.mapRect(this.h); RectF rectF5 = this.h; float f8 = this.q; rectF5.inset(f8 / 2.0f, f8 / 2.0f); this.j.setRectToRect(this.c, this.h, Matrix.ScaleToFit.FILL); } else if (i != 7) { this.h.set(this.c); this.j.setRectToRect(this.c, this.a, Matrix.ScaleToFit.CENTER); this.j.mapRect(this.h); RectF rectF6 = this.h; float f9 = this.q; rectF6.inset(f9 / 2.0f, f9 / 2.0f); this.j.setRectToRect(this.c, this.h, Matrix.ScaleToFit.FILL); } else { this.h.set(this.a); RectF rectF7 = this.h; float f10 = this.q; rectF7.inset(f10 / 2.0f, f10 / 2.0f); this.j.reset(); this.j.setRectToRect(this.c, this.h, Matrix.ScaleToFit.FILL); } this.b.set(this.h); } public RoundedDrawable a(float f) { this.q = f; this.i.setStrokeWidth(this.q); return this; } public RoundedDrawable a(ColorStateList colorStateList) { if (colorStateList == null) { colorStateList = ColorStateList.valueOf(0); } this.r = colorStateList; this.i.setColor(this.r.getColorForState(getState(), -16777216)); return this; } public RoundedDrawable a(boolean z) { this.p = z; return this; } public RoundedDrawable a(ImageView.ScaleType scaleType) { if (scaleType == null) { scaleType = ImageView.ScaleType.FIT_CENTER; } if (this.s != scaleType) { this.s = scaleType; a(); } return this; } public RoundedDrawable a(Shader.TileMode tileMode) { if (this.l != tileMode) { this.l = tileMode; this.n = true; invalidateSelf(); } return this; } }