325 lines
12 KiB
Java
325 lines
12 KiB
Java
package com.github.mmin18.widget;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Rect;
|
|
import android.util.AttributeSet;
|
|
import android.util.TypedValue;
|
|
import android.view.View;
|
|
import android.view.ViewTreeObserver;
|
|
import androidx.core.view.ViewCompat;
|
|
import c.h.a.a.c;
|
|
import c.h.a.a.d;
|
|
import c.h.a.a.e;
|
|
import com.github.mmin18.realtimeblurview.R;
|
|
public class RealtimeBlurView extends View {
|
|
public static int j;
|
|
public static int k;
|
|
public static b l = new b(null);
|
|
public final ViewTreeObserver.OnPreDrawListener A = new a();
|
|
public float m;
|
|
public int n;
|
|
public float o;
|
|
public final c p = getBlurImpl();
|
|
public boolean q;
|
|
public Bitmap r;
|
|
|
|
/* renamed from: s reason: collision with root package name */
|
|
public Bitmap f2343s;
|
|
public Canvas t;
|
|
public boolean u;
|
|
public Paint v;
|
|
public final Rect w = new Rect();
|
|
|
|
/* renamed from: x reason: collision with root package name */
|
|
public final Rect f2344x = new Rect();
|
|
|
|
/* renamed from: y reason: collision with root package name */
|
|
public View f2345y;
|
|
|
|
/* renamed from: z reason: collision with root package name */
|
|
public boolean f2346z;
|
|
|
|
public class a implements ViewTreeObserver.OnPreDrawListener {
|
|
public a() {
|
|
}
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:35:0x009b */
|
|
@Override // android.view.ViewTreeObserver.OnPreDrawListener
|
|
public boolean onPreDraw() {
|
|
boolean z2;
|
|
RealtimeBlurView realtimeBlurView;
|
|
Bitmap bitmap;
|
|
int[] iArr = new int[2];
|
|
RealtimeBlurView realtimeBlurView2 = RealtimeBlurView.this;
|
|
Bitmap bitmap2 = realtimeBlurView2.f2343s;
|
|
View view = realtimeBlurView2.f2345y;
|
|
if (view != null && realtimeBlurView2.isShown()) {
|
|
RealtimeBlurView realtimeBlurView3 = RealtimeBlurView.this;
|
|
float f = realtimeBlurView3.o;
|
|
if (f == 0.0f) {
|
|
realtimeBlurView3.b();
|
|
} else {
|
|
float f2 = realtimeBlurView3.m;
|
|
float f3 = f / f2;
|
|
if (f3 > 25.0f) {
|
|
f2 = (f2 * f3) / 25.0f;
|
|
f3 = 25.0f;
|
|
}
|
|
int width = realtimeBlurView3.getWidth();
|
|
int height = realtimeBlurView3.getHeight();
|
|
int max = Math.max(1, (int) (((float) width) / f2));
|
|
int max2 = Math.max(1, (int) (((float) height) / f2));
|
|
boolean z3 = realtimeBlurView3.q;
|
|
if (realtimeBlurView3.t == null || (bitmap = realtimeBlurView3.f2343s) == null || bitmap.getWidth() != max || realtimeBlurView3.f2343s.getHeight() != max2) {
|
|
realtimeBlurView3.c();
|
|
try {
|
|
Bitmap createBitmap = Bitmap.createBitmap(max, max2, Bitmap.Config.ARGB_8888);
|
|
realtimeBlurView3.r = createBitmap;
|
|
if (createBitmap != null) {
|
|
realtimeBlurView3.t = new Canvas(realtimeBlurView3.r);
|
|
Bitmap createBitmap2 = Bitmap.createBitmap(max, max2, Bitmap.Config.ARGB_8888);
|
|
realtimeBlurView3.f2343s = createBitmap2;
|
|
if (createBitmap2 != null) {
|
|
z3 = true;
|
|
}
|
|
}
|
|
} catch (OutOfMemoryError unused) {
|
|
}
|
|
realtimeBlurView3.b();
|
|
}
|
|
if (z3) {
|
|
if (realtimeBlurView3.p.b(realtimeBlurView3.getContext(), realtimeBlurView3.r, f3)) {
|
|
realtimeBlurView3.q = false;
|
|
}
|
|
}
|
|
z2 = true;
|
|
if (z2) {
|
|
boolean z4 = RealtimeBlurView.this.f2343s != bitmap2;
|
|
view.getLocationOnScreen(iArr);
|
|
RealtimeBlurView.this.getLocationOnScreen(iArr);
|
|
int i = (-iArr[0]) + iArr[0];
|
|
int i2 = (-iArr[1]) + iArr[1];
|
|
RealtimeBlurView realtimeBlurView4 = RealtimeBlurView.this;
|
|
realtimeBlurView4.r.eraseColor(realtimeBlurView4.n & ViewCompat.MEASURED_SIZE_MASK);
|
|
int save = RealtimeBlurView.this.t.save();
|
|
RealtimeBlurView realtimeBlurView5 = RealtimeBlurView.this;
|
|
realtimeBlurView5.u = true;
|
|
RealtimeBlurView.j++;
|
|
try {
|
|
realtimeBlurView5.t.scale((((float) realtimeBlurView5.r.getWidth()) * 1.0f) / ((float) RealtimeBlurView.this.getWidth()), (((float) RealtimeBlurView.this.r.getHeight()) * 1.0f) / ((float) RealtimeBlurView.this.getHeight()));
|
|
RealtimeBlurView.this.t.translate((float) (-i), (float) (-i2));
|
|
if (view.getBackground() != null) {
|
|
view.getBackground().draw(RealtimeBlurView.this.t);
|
|
}
|
|
view.draw(RealtimeBlurView.this.t);
|
|
RealtimeBlurView.this.u = false;
|
|
RealtimeBlurView.a();
|
|
realtimeBlurView = RealtimeBlurView.this;
|
|
} catch (b unused2) {
|
|
RealtimeBlurView.this.u = false;
|
|
RealtimeBlurView.a();
|
|
realtimeBlurView = RealtimeBlurView.this;
|
|
} catch (Throwable th) {
|
|
RealtimeBlurView.this.u = false;
|
|
RealtimeBlurView.a();
|
|
RealtimeBlurView.this.t.restoreToCount(save);
|
|
throw th;
|
|
}
|
|
realtimeBlurView.t.restoreToCount(save);
|
|
RealtimeBlurView realtimeBlurView6 = RealtimeBlurView.this;
|
|
realtimeBlurView6.p.a(realtimeBlurView6.r, realtimeBlurView6.f2343s);
|
|
if (z4 || RealtimeBlurView.this.f2346z) {
|
|
RealtimeBlurView.this.invalidate();
|
|
}
|
|
}
|
|
}
|
|
z2 = false;
|
|
if (z2) {
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static class b extends RuntimeException {
|
|
public b(a aVar) {
|
|
}
|
|
}
|
|
|
|
public RealtimeBlurView(Context context, AttributeSet attributeSet) {
|
|
super(context, null);
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes((AttributeSet) null, R.a.RealtimeBlurView);
|
|
this.o = obtainStyledAttributes.getDimension(R.a.RealtimeBlurView_realtimeBlurRadius, TypedValue.applyDimension(1, 10.0f, context.getResources().getDisplayMetrics()));
|
|
this.m = obtainStyledAttributes.getFloat(R.a.RealtimeBlurView_realtimeDownsampleFactor, 4.0f);
|
|
this.n = obtainStyledAttributes.getColor(R.a.RealtimeBlurView_realtimeOverlayColor, -1426063361);
|
|
obtainStyledAttributes.recycle();
|
|
this.v = new Paint();
|
|
}
|
|
|
|
public static /* synthetic */ int a() {
|
|
int i = j;
|
|
j = i - 1;
|
|
return i;
|
|
}
|
|
|
|
public void b() {
|
|
c();
|
|
this.p.release();
|
|
}
|
|
|
|
public final void c() {
|
|
Bitmap bitmap = this.r;
|
|
if (bitmap != null) {
|
|
bitmap.recycle();
|
|
this.r = null;
|
|
}
|
|
Bitmap bitmap2 = this.f2343s;
|
|
if (bitmap2 != null) {
|
|
bitmap2.recycle();
|
|
this.f2343s = null;
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void draw(Canvas canvas) {
|
|
if (this.u) {
|
|
throw l;
|
|
} else if (j <= 0) {
|
|
super.draw(canvas);
|
|
}
|
|
}
|
|
|
|
public View getActivityDecorView() {
|
|
Context context = getContext();
|
|
for (int i = 0; i < 4 && context != null && !(context instanceof Activity) && (context instanceof ContextWrapper); i++) {
|
|
context = ((ContextWrapper) context).getBaseContext();
|
|
}
|
|
if (context instanceof Activity) {
|
|
return ((Activity) context).getWindow().getDecorView();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public c getBlurImpl() {
|
|
if (k == 0) {
|
|
try {
|
|
c.h.a.a.a aVar = new c.h.a.a.a();
|
|
Bitmap createBitmap = Bitmap.createBitmap(4, 4, Bitmap.Config.ARGB_8888);
|
|
aVar.b(getContext(), createBitmap, 4.0f);
|
|
aVar.release();
|
|
createBitmap.recycle();
|
|
k = 3;
|
|
} catch (Throwable unused) {
|
|
}
|
|
}
|
|
if (k == 0) {
|
|
try {
|
|
getClass().getClassLoader().loadClass("androidx.renderscript.RenderScript");
|
|
c.h.a.a.b bVar = new c.h.a.a.b();
|
|
Bitmap createBitmap2 = Bitmap.createBitmap(4, 4, Bitmap.Config.ARGB_8888);
|
|
bVar.b(getContext(), createBitmap2, 4.0f);
|
|
bVar.release();
|
|
createBitmap2.recycle();
|
|
k = 1;
|
|
} catch (Throwable unused2) {
|
|
}
|
|
}
|
|
if (k == 0) {
|
|
try {
|
|
getClass().getClassLoader().loadClass("androidx.renderscript.RenderScript");
|
|
e eVar = new e();
|
|
Bitmap createBitmap3 = Bitmap.createBitmap(4, 4, Bitmap.Config.ARGB_8888);
|
|
eVar.b(getContext(), createBitmap3, 4.0f);
|
|
eVar.release();
|
|
createBitmap3.recycle();
|
|
k = 2;
|
|
} catch (Throwable unused3) {
|
|
}
|
|
}
|
|
if (k == 0) {
|
|
k = -1;
|
|
}
|
|
int i = k;
|
|
return i != 1 ? i != 2 ? i != 3 ? new d() : new c.h.a.a.a() : new e() : new c.h.a.a.b();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
View activityDecorView = getActivityDecorView();
|
|
this.f2345y = activityDecorView;
|
|
boolean z2 = false;
|
|
if (activityDecorView != null) {
|
|
activityDecorView.getViewTreeObserver().addOnPreDrawListener(this.A);
|
|
if (this.f2345y.getRootView() != getRootView()) {
|
|
z2 = true;
|
|
}
|
|
this.f2346z = z2;
|
|
if (z2) {
|
|
this.f2345y.postInvalidate();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
this.f2346z = false;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onDetachedFromWindow() {
|
|
View view = this.f2345y;
|
|
if (view != null) {
|
|
view.getViewTreeObserver().removeOnPreDrawListener(this.A);
|
|
}
|
|
b();
|
|
super.onDetachedFromWindow();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onDraw(Canvas canvas) {
|
|
super.onDraw(canvas);
|
|
Bitmap bitmap = this.f2343s;
|
|
int i = this.n;
|
|
if (bitmap != null) {
|
|
this.w.right = bitmap.getWidth();
|
|
this.w.bottom = bitmap.getHeight();
|
|
this.f2344x.right = getWidth();
|
|
this.f2344x.bottom = getHeight();
|
|
canvas.drawBitmap(bitmap, this.w, this.f2344x, (Paint) null);
|
|
}
|
|
this.v.setColor(i);
|
|
canvas.drawRect(this.f2344x, this.v);
|
|
}
|
|
|
|
public void setBlurRadius(float f) {
|
|
if (this.o != f) {
|
|
this.o = f;
|
|
this.q = true;
|
|
invalidate();
|
|
}
|
|
}
|
|
|
|
public void setDownsampleFactor(float f) {
|
|
if (f <= 0.0f) {
|
|
throw new IllegalArgumentException("Downsample factor must be greater than 0.");
|
|
} else if (this.m != f) {
|
|
this.m = f;
|
|
this.q = true;
|
|
c();
|
|
invalidate();
|
|
}
|
|
}
|
|
|
|
public void setOverlayColor(int i) {
|
|
if (this.n != i) {
|
|
this.n = i;
|
|
invalidate();
|
|
}
|
|
}
|
|
}
|