package epson.print.copy.Component.ecopycomponent;

import com.box.androidsdk.content.requests.BoxRequestsMetadata;

import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

import java.io.File;
import java.util.ArrayList;

import javax.xml.parsers.SAXParserFactory;

/* compiled from: RemoteCopyPhotoTask */
class CopyPhotoSettingHandler extends DefaultHandler {

    /* renamed from: b */
    final String f351b = "b";
    final String copies = "copies";
    final String dpi = "dpi";

    /* renamed from: g */
    final String f352g = "g";
    final String height = "height";
    String path;
    final String photoCopySetting = "photoCopySetting";
    final String photoCopySettings = "photoCopySettings";

    /* renamed from: r */
    final String f353r = "r";
    public ArrayList<String> scanAreaHeight = new ArrayList<>();
    public ArrayList<String> scanAreaResolution = new ArrayList<>();
    public ArrayList<String> scanAreaWidth = new ArrayList<>();
    public ArrayList<String> scanAreaX = new ArrayList<>();
    public ArrayList<String> scanAreaY = new ArrayList<>();
    public ArrayList<String> scanCopies = new ArrayList<>();
    final String trimmingRect = "trimmingRect";
    final String value = BoxRequestsMetadata.UpdateItemMetadata.BoxMetadataUpdateTask.VALUE;
    final String width = "width";

    /* renamed from: x */
    final String f354x = "x";
    public ArrayList<String> xFitGamma = new ArrayList<>();
    public ArrayList<String> xFitMatrix = new ArrayList<>();
    final String xGamma = "xGamma";
    final String xMatrix = "xMatrix";

    /* renamed from: y */
    final String f355y = "y";

    public CopyPhotoSettingHandler(String str) {
        path = str;
    }

    public int getScanCount() {
        return scanCopies.size();
    }

    public boolean parse() {
        try {
            SAXParserFactory.newInstance().newSAXParser().parse(new File(this.path), this);
        } catch (Exception e) {
            scanCopies.clear();
            e.printStackTrace();
        }
        return scanCopies.size() > 0;
    }

    private String xFormat(String str, String str2) {
        StringBuffer stringBuffer = new StringBuffer();
        String[] split = str.split(PreferencesConstants.COOKIE_DELIMITER);
        int length = split.length;
        for (int i = 0; i < length; i++) {
            stringBuffer.append(String.format(str2, new Object[]{Integer.valueOf(Integer.parseInt(split[i], 16))}));
        }
        return stringBuffer.toString();
    }

    public void startElement(String str, String str2, String str3, Attributes attributes) {
        if (str2.equalsIgnoreCase("photoCopySettings") || str2.equalsIgnoreCase("photoCopySetting")) {
            return;
        }
        if (str2.equalsIgnoreCase("xGamma")) {
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(xFormat(attributes.getValue("r"), "%02X"));
            stringBuffer.append(xFormat(attributes.getValue("g"), "%02X"));
            stringBuffer.append(xFormat(attributes.getValue("b"), "%02X"));
            xFitGamma.add(stringBuffer.toString());
        } else if (str2.equalsIgnoreCase("xMatrix")) {
            xFitMatrix.add(xFormat(attributes.getValue(BoxRequestsMetadata.UpdateItemMetadata.BoxMetadataUpdateTask.VALUE), "%04X"));
        } else if (str2.equalsIgnoreCase("copies")) {
            scanCopies.add(attributes.getValue(BoxRequestsMetadata.UpdateItemMetadata.BoxMetadataUpdateTask.VALUE));
        } else if (str2.equalsIgnoreCase("trimmingRect")) {
            scanAreaResolution.add(attributes.getValue("dpi"));
            scanAreaX.add(attributes.getValue("x"));
            scanAreaY.add(attributes.getValue("y"));
            scanAreaWidth.add(attributes.getValue("width"));
            scanAreaHeight.add(attributes.getValue("height"));
        }
    }
}
