package com.ifpdos.factorytest;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import androidx.core.internal.view.SupportMenu;

/* JADX INFO: loaded from: classes.dex */
public class DrawView extends View {
    final int VIEW_HEIGHT;
    final int VIEW_WIDTH;
    Bitmap cacheBitmap;
    Canvas cacheCanvas;
    public Paint paint;
    private Path path;
    float preX;
    float preY;

    public DrawView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.VIEW_WIDTH = 1920;
        this.VIEW_HEIGHT = 1080;
        this.cacheBitmap = null;
        this.cacheCanvas = null;
        this.cacheBitmap = Bitmap.createBitmap(1920, 1080, Bitmap.Config.ARGB_8888);
        this.cacheCanvas = new Canvas();
        this.path = new Path();
        this.cacheCanvas.setBitmap(this.cacheBitmap);
        Paint paint = new Paint(4);
        this.paint = paint;
        paint.setColor(SupportMenu.CATEGORY_MASK);
        this.paint.setStyle(Paint.Style.STROKE);
        this.paint.setStrokeWidth(1.0f);
        this.paint.setAntiAlias(true);
        this.paint.setDither(true);
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        float x = motionEvent.getX();
        float y = motionEvent.getY();
        int action = motionEvent.getAction();
        if (action == 0) {
            this.path.moveTo(x, y);
            this.preX = x;
            this.preY = y;
        } else if (action == 1) {
            this.cacheCanvas.drawPath(this.path, this.paint);
            this.path.reset();
        } else if (action == 2) {
            this.path.quadTo(this.preX, this.preY, x, y);
            this.preX = x;
            this.preY = y;
        }
        invalidate();
        return true;
    }

    public void reset() {
        Log.d("dengguangxi", "reset");
        this.cacheCanvas.drawColor(0, PorterDuff.Mode.CLEAR);
        this.cacheCanvas.drawLine(0.0f, 0.0f, 0.0f, 0.0f, this.paint);
        invalidate();
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        canvas.drawBitmap(this.cacheBitmap, 0.0f, 0.0f, new Paint());
        canvas.drawPath(this.path, this.paint);
    }
}
