package epson.scan.lib;

import android.graphics.Point;
import com.epson.mobilephone.common.PrintingLib.define.Constants;
import com.epson.mobilephone.common.escpr.MediaInfo;
import epson.print.R;
import java.util.ArrayList;
import java.util.Locale;

public class ScanSizeHelper {
    public static final int SUPPORT_A3 = 3;
    public static final int SUPPORT_A4 = 1;
    public static final int SUPPORT_LEGAL = 2;
    public static final int SUPPORT_NONE = 0;

    public static Point getPaperSize(int i, int i2) {
        Point point;
        Point point2 = new Point(0, 0);
        if (i2 == 0) {
            return point2;
        }
        if (i == 5) {
            point = new Point(1820, 2570);
        } else if (i != 62) {
            switch (i) {
                case 0:
                    point = new Point(2100, 2970);
                    break;
                case 1:
                    point = new Point(2159, 2794);
                    break;
                case 2:
                    point = new Point(2159, 3556);
                    break;
                default:
                    if (getDefaultScanSize() == 1) {
                        point = new Point(2159, 2794);
                        break;
                    } else {
                        point = new Point(2100, 2970);
                        break;
                    }
            }
        } else {
            point = new Point(2970, 4200);
        }
        return new Point((int) (((float) (point.x * i2)) * 0.003937008f), (int) (((float) (point.y * i2)) * 0.003937008f));
    }

    private static int getMaxScanSize(int i, int i2, int i3) {
        if (i3 == 0) {
            return 0;
        }
        Point paperSize = getPaperSize(Constants.PaperName.EPS_MSID_A3.getCode(), i3);
        if (i >= paperSize.x && i2 >= paperSize.y) {
            return 3;
        }
        Point paperSize2 = getPaperSize(Constants.PaperName.EPS_MSID_LEGAL.getCode(), i3);
        if (i >= paperSize2.x && i2 >= paperSize2.y) {
            return 2;
        }
        Point paperSize3 = getPaperSize(Constants.PaperName.EPS_MSID_A4.getCode(), i3);
        if (i < paperSize3.x || i2 < paperSize3.y) {
            return 0;
        }
        return 1;
    }

    public static int[] getSupportedScanSizeList(int i, int i2, int i3, int i4, int i5) {
        ArrayList arrayList = new ArrayList();
        int maxScanSize = getMaxScanSize(i3, i4, i5);
        switch (i) {
            case 0:
                if (maxScanSize >= 1) {
                    arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_B5.getCode()));
                    arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_A4.getCode()));
                    arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_LETTER.getCode()));
                }
                if (maxScanSize >= 2) {
                    arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_LEGAL.getCode()));
                }
                if (maxScanSize >= 3) {
                    arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_A3.getCode()));
                }
                arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_USER.getCode()));
                break;
            case 1:
                switch (i2) {
                    case 0:
                        if (maxScanSize >= 1) {
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_A4.getCode()));
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_LETTER.getCode()));
                        }
                        if (maxScanSize >= 2) {
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_LEGAL.getCode()));
                        }
                        if (maxScanSize >= 3) {
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_A3.getCode()));
                            break;
                        }
                        break;
                    case 1:
                        if (maxScanSize >= 1) {
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_A4.getCode()));
                            arrayList.add(Integer.valueOf(Constants.PaperName.EPS_MSID_LETTER.getCode()));
                            break;
                        }
                        break;
                }
        }
        int[] iArr = new int[arrayList.size()];
        for (int i6 = 0; i6 < arrayList.size(); i6++) {
            iArr[i6] = ((Integer) arrayList.get(i6)).intValue();
        }
        return iArr;
    }

    public static Point getMaxScanSize(int i, int i2, int i3, int i4, int i5) {
        Point point = new Point(0, 0);
        switch (i) {
            case 0:
                return new Point(i3, i4);
            case 1:
                int[] supportedScanSizeList = getSupportedScanSizeList(i, i2, i3, i4, i5);
                return supportedScanSizeList.length > 0 ? getPaperSize(supportedScanSizeList[supportedScanSizeList.length - 1], i5) : point;
            default:
                return point;
        }
    }

    public static int getDefaultScanSize() {
        String country = Locale.getDefault().getCountry();
        if (country.equals(Locale.US.getCountry()) || country.equals(Locale.CANADA.getCountry())) {
            return Constants.PaperName.EPS_MSID_LETTER.getCode();
        }
        return Constants.PaperName.EPS_MSID_A4.getCode();
    }

    public static int getScanSizeName(int i) {
        if (i == Constants.PaperName.EPS_MSID_UNKNOWN.getCode()) {
            return R.string.str_settings_undefine_scansize;
        }
        if (i == Constants.PaperName.EPS_MSID_USER.getCode()) {
            return R.string.str_scanning_size_max;
        }
        return new MediaInfo.PaperSize().getStringId(i);
    }
}
