package com.seewo.libmcuservice.model;

import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import android.view.WindowManager;
import com.seewo.libmcuservice.constant.IMcuConstants;
import java.io.Serializable;
import java.math.BigDecimal;

/* JADX INFO: loaded from: classes.dex */
public class NoTouchArea implements Serializable {
    public static final int TOUCH_FRAME_MAX_COORDINATE = 32767;
    private static final long serialVersionUID = -1;
    private Object mExtraMsg;
    public byte mId;
    public int mLeftTopX;
    public int mLeftTopY;
    public int mRightBottomX;
    public int mRightBottomY;
    private int[] mScreenSize;

    public NoTouchArea(Rect rect) {
        this(rect.left, rect.top, rect.right, rect.bottom);
    }

    private static double accurateDiv(double d2, double d3, int i) {
        if (i >= 0) {
            return new BigDecimal(Double.toString(d2)).divide(new BigDecimal(Double.toString(d3)), i, 4).doubleValue();
        }
        throw new IllegalArgumentException("The scale must be a positive integer or zero");
    }

    public static int changeHighLowBitToInt(byte b2, byte b3) {
        return (b2 << 8) + (b3 & IMcuConstants.DEFAULT_VALUE);
    }

    private static byte[] changeIntToByteArrays(int i, int i2) {
        if (i <= 0) {
            return new byte[0];
        }
        byte[] bArr = new byte[i];
        if (i == 2) {
            bArr[1] = (byte) ((i2 >>> 8) & 255);
            bArr[0] = (byte) (i2 & 255);
        } else {
            bArr[0] = (byte) (i2 & 255);
        }
        printHexString(bArr, "OsdService");
        return bArr;
    }

    private int convertToScreenFrameCoordinate(int i, int i2) {
        return (int) (accurateDiv(i, 32767.0d, 3) * ((double) i2));
    }

    private int convertToTouchFrameCoordinate(int i, int i2) {
        int iAccurateDiv = (int) (accurateDiv(32767.0d, i2, 3) * ((double) i));
        if (iAccurateDiv > 32767) {
            iAccurateDiv = 32762;
        }
        if (iAccurateDiv < 0) {
            return 0;
        }
        return iAccurateDiv;
    }

    private void measureScreenSize(Context context) {
        int[] iArr = this.mScreenSize;
        if (iArr[0] == 0 || iArr[1] == 0) {
            Point point = new Point();
            ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getRealSize(point);
            int[] iArr2 = this.mScreenSize;
            iArr2[0] = point.x;
            iArr2[1] = point.y;
        }
    }

    public static void printHexString(byte[] bArr, String str) {
        for (byte b2 : bArr) {
            String hexString = Integer.toHexString(b2 & IMcuConstants.DEFAULT_VALUE);
            if (hexString.length() == 1) {
                hexString = '0' + hexString;
            }
            Log.d(str, hexString + " ");
        }
        Log.d(str, "\n");
    }

    public byte[] convertNoTouchAreaToByte(Context context) {
        measureScreenSize(context);
        byte[] bArr = new byte[9];
        bArr[0] = this.mId;
        System.arraycopy(changeIntToByteArrays(2, convertToTouchFrameCoordinate(this.mLeftTopX, this.mScreenSize[0])), 0, bArr, 1, 2);
        System.arraycopy(changeIntToByteArrays(2, convertToTouchFrameCoordinate(this.mLeftTopY, this.mScreenSize[1])), 0, bArr, 3, 2);
        System.arraycopy(changeIntToByteArrays(2, convertToTouchFrameCoordinate(this.mRightBottomX, this.mScreenSize[0])), 0, bArr, 5, 2);
        System.arraycopy(changeIntToByteArrays(2, convertToTouchFrameCoordinate(this.mRightBottomY, this.mScreenSize[1])), 0, bArr, 7, 2);
        printHexString(bArr, "OsdService");
        return bArr;
    }

    public int[] convertNoTouchAreaToIntArray(Context context) {
        measureScreenSize(context);
        return new int[]{convertToTouchFrameCoordinate(this.mLeftTopX, this.mScreenSize[0]), convertToTouchFrameCoordinate(this.mLeftTopY, this.mScreenSize[1]), convertToTouchFrameCoordinate(this.mRightBottomX, this.mScreenSize[0]), convertToTouchFrameCoordinate(this.mRightBottomY, this.mScreenSize[1])};
    }

    public Object getExtraMsg() {
        return this.mExtraMsg;
    }

    public void setExtraMsg(Object obj) {
        this.mExtraMsg = obj;
    }

    public void setId(byte b2) {
        this.mId = b2;
    }

    public void setScreenSize() {
        this.mScreenSize = new int[]{1920, 1080};
    }

    public String toString() {
        return "mAreaId: " + ((int) this.mId) + " mLeftTop: (" + this.mLeftTopX + "," + this.mLeftTopY + ") mRightBottom:(" + this.mRightBottomX + "," + this.mRightBottomY + ")";
    }

    public NoTouchArea(int i, Rect rect) {
        this((byte) i, rect.left, rect.top, rect.right, rect.bottom);
    }

    public NoTouchArea(int i, int i2, int i3, int i4) {
        this.mId = (byte) -2;
        this.mScreenSize = new int[]{0, 0};
        this.mLeftTopX = i;
        this.mLeftTopY = i2;
        this.mRightBottomX = i3;
        this.mRightBottomY = i4;
    }

    public NoTouchArea(byte b2, int i, int i2, int i3, int i4) {
        this.mId = (byte) -2;
        this.mScreenSize = new int[]{0, 0};
        this.mId = b2;
        this.mLeftTopX = i;
        this.mLeftTopY = i2;
        this.mRightBottomX = i3;
        this.mRightBottomY = i4;
    }

    public NoTouchArea(byte[] bArr, int i, int i2) {
        this.mId = (byte) -2;
        this.mScreenSize = new int[]{0, 0};
        Log.d("OsdConverUtils", "pScreenWidth: " + i + " pScreenHeight: " + i2);
        if (bArr.length == 9) {
            this.mId = bArr[0];
            this.mLeftTopX = convertToScreenFrameCoordinate(changeHighLowBitToInt(bArr[2], bArr[1]), i);
            this.mLeftTopY = convertToScreenFrameCoordinate(changeHighLowBitToInt(bArr[4], bArr[3]), i2);
            this.mRightBottomX = convertToScreenFrameCoordinate(changeHighLowBitToInt(bArr[6], bArr[5]), i);
            this.mRightBottomY = convertToScreenFrameCoordinate(changeHighLowBitToInt(bArr[8], bArr[7]), i2);
        }
    }
}
