229 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			229 lines
		
	
	
		
			9.4 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
package com.squareup.leakcanary.internal;
 | 
						|
 | 
						|
import android.content.Context;
 | 
						|
import android.content.res.Resources;
 | 
						|
import android.graphics.Bitmap;
 | 
						|
import android.graphics.Canvas;
 | 
						|
import android.graphics.DashPathEffect;
 | 
						|
import android.graphics.Paint;
 | 
						|
import android.graphics.PorterDuff;
 | 
						|
import android.graphics.PorterDuffXfermode;
 | 
						|
import android.util.AttributeSet;
 | 
						|
import android.view.View;
 | 
						|
import com.squareup.leakcanary.R;
 | 
						|
 | 
						|
/* loaded from: classes.dex */
 | 
						|
public final class DisplayLeakConnectorView extends View {
 | 
						|
    private Bitmap cache;
 | 
						|
    private final float circleY;
 | 
						|
    private final Paint classNamePaint;
 | 
						|
    private final Paint clearPaint;
 | 
						|
    private final Paint leakPaint;
 | 
						|
    private final Paint referencePaint;
 | 
						|
    private final float strokeSize;
 | 
						|
    private Type type;
 | 
						|
    private static final float SQRT_TWO = (float) Math.sqrt(2.0d);
 | 
						|
    private static final PorterDuffXfermode CLEAR_XFER_MODE = new PorterDuffXfermode(PorterDuff.Mode.CLEAR);
 | 
						|
 | 
						|
    /* renamed from: com.squareup.leakcanary.internal.DisplayLeakConnectorView$1, reason: invalid class name */
 | 
						|
    static /* synthetic */ class AnonymousClass1 {
 | 
						|
        static final /* synthetic */ int[] $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type = new int[Type.values().length];
 | 
						|
 | 
						|
        static {
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.NODE_UNKNOWN.ordinal()] = 1;
 | 
						|
            } catch (NoSuchFieldError unused) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.NODE_UNREACHABLE.ordinal()] = 2;
 | 
						|
            } catch (NoSuchFieldError unused2) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.NODE_REACHABLE.ordinal()] = 3;
 | 
						|
            } catch (NoSuchFieldError unused3) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.NODE_FIRST_UNREACHABLE.ordinal()] = 4;
 | 
						|
            } catch (NoSuchFieldError unused4) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.NODE_LAST_REACHABLE.ordinal()] = 5;
 | 
						|
            } catch (NoSuchFieldError unused5) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.START.ordinal()] = 6;
 | 
						|
            } catch (NoSuchFieldError unused6) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.START_LAST_REACHABLE.ordinal()] = 7;
 | 
						|
            } catch (NoSuchFieldError unused7) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.END.ordinal()] = 8;
 | 
						|
            } catch (NoSuchFieldError unused8) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.END_FIRST_UNREACHABLE.ordinal()] = 9;
 | 
						|
            } catch (NoSuchFieldError unused9) {
 | 
						|
            }
 | 
						|
            try {
 | 
						|
                $SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[Type.HELP.ordinal()] = 10;
 | 
						|
            } catch (NoSuchFieldError unused10) {
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    public enum Type {
 | 
						|
        HELP,
 | 
						|
        START,
 | 
						|
        START_LAST_REACHABLE,
 | 
						|
        NODE_UNKNOWN,
 | 
						|
        NODE_FIRST_UNREACHABLE,
 | 
						|
        NODE_UNREACHABLE,
 | 
						|
        NODE_REACHABLE,
 | 
						|
        NODE_LAST_REACHABLE,
 | 
						|
        END,
 | 
						|
        END_FIRST_UNREACHABLE
 | 
						|
    }
 | 
						|
 | 
						|
    public DisplayLeakConnectorView(Context context, AttributeSet attributeSet) {
 | 
						|
        super(context, attributeSet);
 | 
						|
        Resources resources = getResources();
 | 
						|
        this.type = Type.NODE_UNKNOWN;
 | 
						|
        this.circleY = resources.getDimensionPixelSize(R.dimen.leak_canary_connector_center_y);
 | 
						|
        this.strokeSize = resources.getDimensionPixelSize(R.dimen.leak_canary_connector_stroke_size);
 | 
						|
        this.classNamePaint = new Paint(1);
 | 
						|
        this.classNamePaint.setColor(resources.getColor(R.color.leak_canary_class_name));
 | 
						|
        this.classNamePaint.setStrokeWidth(this.strokeSize);
 | 
						|
        this.leakPaint = new Paint(1);
 | 
						|
        this.leakPaint.setColor(resources.getColor(R.color.leak_canary_leak));
 | 
						|
        this.leakPaint.setStyle(Paint.Style.STROKE);
 | 
						|
        this.leakPaint.setStrokeWidth(this.strokeSize);
 | 
						|
        this.leakPaint.setPathEffect(new DashPathEffect(new float[]{resources.getDimensionPixelSize(R.dimen.leak_canary_connector_leak_dash_line), resources.getDimensionPixelSize(R.dimen.leak_canary_connector_leak_dash_gap)}, 0.0f));
 | 
						|
        this.clearPaint = new Paint(1);
 | 
						|
        this.clearPaint.setColor(0);
 | 
						|
        this.clearPaint.setXfermode(CLEAR_XFER_MODE);
 | 
						|
        this.referencePaint = new Paint(1);
 | 
						|
        this.referencePaint.setColor(resources.getColor(R.color.leak_canary_reference));
 | 
						|
        this.referencePaint.setStrokeWidth(this.strokeSize);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawArrowHead(Canvas canvas, Paint paint) {
 | 
						|
        float measuredWidth = getMeasuredWidth();
 | 
						|
        float f = measuredWidth / 2.0f;
 | 
						|
        float f2 = measuredWidth / 3.0f;
 | 
						|
        float f3 = (f / 2.0f) * SQRT_TWO;
 | 
						|
        float f4 = this.strokeSize;
 | 
						|
        float f5 = this.circleY;
 | 
						|
        float f6 = ((f5 - f3) - (f2 * 2.0f)) - f4;
 | 
						|
        canvas.drawLine(f, 0.0f, f, (f5 - f2) - (f4 / 2.0f), paint);
 | 
						|
        canvas.translate(f, f6);
 | 
						|
        canvas.rotate(45.0f);
 | 
						|
        canvas.drawLine(0.0f, f, f + (f4 / 2.0f), f, paint);
 | 
						|
        canvas.drawLine(f, 0.0f, f, f, paint);
 | 
						|
        canvas.rotate(-45.0f);
 | 
						|
        canvas.translate(-f, -f6);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawInstanceCircle(Canvas canvas) {
 | 
						|
        float measuredWidth = getMeasuredWidth();
 | 
						|
        canvas.drawCircle(measuredWidth / 2.0f, this.circleY, measuredWidth / 3.0f, this.classNamePaint);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawItems(Canvas canvas, Paint paint, Paint paint2) {
 | 
						|
        if (paint != null) {
 | 
						|
            drawArrowHead(canvas, paint);
 | 
						|
        }
 | 
						|
        if (paint2 != null) {
 | 
						|
            drawNextArrowLine(canvas, paint2);
 | 
						|
        }
 | 
						|
        drawInstanceCircle(canvas);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawNextArrowLine(Canvas canvas, Paint paint) {
 | 
						|
        float measuredWidth = getMeasuredWidth() / 2.0f;
 | 
						|
        canvas.drawLine(measuredWidth, this.circleY, measuredWidth, getMeasuredHeight(), paint);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawRoot(Canvas canvas) {
 | 
						|
        int measuredWidth = getMeasuredWidth();
 | 
						|
        int measuredHeight = getMeasuredHeight();
 | 
						|
        float f = measuredWidth;
 | 
						|
        float f2 = f / 2.0f;
 | 
						|
        float f3 = f2 - (this.strokeSize / 2.0f);
 | 
						|
        canvas.drawRect(0.0f, 0.0f, f, f3, this.classNamePaint);
 | 
						|
        canvas.drawCircle(0.0f, f3, f3, this.clearPaint);
 | 
						|
        canvas.drawCircle(f, f3, f3, this.clearPaint);
 | 
						|
        canvas.drawLine(f2, 0.0f, f2, measuredHeight, this.classNamePaint);
 | 
						|
    }
 | 
						|
 | 
						|
    private void drawStartLine(Canvas canvas) {
 | 
						|
        float measuredWidth = getMeasuredWidth() / 2.0f;
 | 
						|
        canvas.drawLine(measuredWidth, 0.0f, measuredWidth, this.circleY, this.classNamePaint);
 | 
						|
    }
 | 
						|
 | 
						|
    @Override // android.view.View
 | 
						|
    protected void onDraw(Canvas canvas) {
 | 
						|
        int measuredWidth = getMeasuredWidth();
 | 
						|
        int measuredHeight = getMeasuredHeight();
 | 
						|
        Bitmap bitmap = this.cache;
 | 
						|
        if (bitmap != null && (bitmap.getWidth() != measuredWidth || this.cache.getHeight() != measuredHeight)) {
 | 
						|
            this.cache.recycle();
 | 
						|
            this.cache = null;
 | 
						|
        }
 | 
						|
        if (this.cache == null) {
 | 
						|
            this.cache = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_8888);
 | 
						|
            Canvas canvas2 = new Canvas(this.cache);
 | 
						|
            switch (AnonymousClass1.$SwitchMap$com$squareup$leakcanary$internal$DisplayLeakConnectorView$Type[this.type.ordinal()]) {
 | 
						|
                case 1:
 | 
						|
                    Paint paint = this.leakPaint;
 | 
						|
                    drawItems(canvas2, paint, paint);
 | 
						|
                    break;
 | 
						|
                case 2:
 | 
						|
                case 3:
 | 
						|
                    Paint paint2 = this.referencePaint;
 | 
						|
                    drawItems(canvas2, paint2, paint2);
 | 
						|
                    break;
 | 
						|
                case 4:
 | 
						|
                    drawItems(canvas2, this.leakPaint, this.referencePaint);
 | 
						|
                    break;
 | 
						|
                case 5:
 | 
						|
                    drawItems(canvas2, this.referencePaint, this.leakPaint);
 | 
						|
                    break;
 | 
						|
                case 6:
 | 
						|
                    drawStartLine(canvas2);
 | 
						|
                    drawItems(canvas2, null, this.referencePaint);
 | 
						|
                    break;
 | 
						|
                case 7:
 | 
						|
                    drawStartLine(canvas2);
 | 
						|
                    drawItems(canvas2, null, this.leakPaint);
 | 
						|
                    break;
 | 
						|
                case 8:
 | 
						|
                    drawItems(canvas2, this.referencePaint, null);
 | 
						|
                    break;
 | 
						|
                case 9:
 | 
						|
                    drawItems(canvas2, this.leakPaint, null);
 | 
						|
                    break;
 | 
						|
                case 10:
 | 
						|
                    drawRoot(canvas2);
 | 
						|
                    break;
 | 
						|
                default:
 | 
						|
                    throw new UnsupportedOperationException("Unknown type " + this.type);
 | 
						|
            }
 | 
						|
        }
 | 
						|
        canvas.drawBitmap(this.cache, 0.0f, 0.0f, (Paint) null);
 | 
						|
    }
 | 
						|
 | 
						|
    public void setType(Type type) {
 | 
						|
        if (type != this.type) {
 | 
						|
            this.type = type;
 | 
						|
            Bitmap bitmap = this.cache;
 | 
						|
            if (bitmap != null) {
 | 
						|
                bitmap.recycle();
 | 
						|
                this.cache = null;
 | 
						|
            }
 | 
						|
            invalidate();
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |