public void updatePrintJobUserConfigurableOptionsNoPersistence(PrintJobInfo printJob) { synchronized (mLock) { final int printJobCount = mPrintJobs.size(); for (int i = 0; i < printJobCount; i++) { PrintJobInfo cachedPrintJob = mPrintJobs.get(i); if (cachedPrintJob.getId().equals(printJob.getId())) { cachedPrintJob.setPrinterId(printJob.getPrinterId()); cachedPrintJob.setPrinterName(printJob.getPrinterName()); cachedPrintJob.setCopies(printJob.getCopies()); cachedPrintJob.setDocumentInfo(printJob.getDocumentInfo()); cachedPrintJob.setPages(printJob.getPages()); cachedPrintJob.setAttributes(printJob.getAttributes()); cachedPrintJob.setAdvancedOptions(printJob.getAdvancedOptions()); return; } } throw new IllegalArgumentException("No print job with id:" + printJob.getId()); } }
private boolean parsePrintJob(XmlPullParser parser) throws IOException, XmlPullParserException { skipEmptyTextTags(parser); if (!accept(parser, XmlPullParser.START_TAG, TAG_JOB)) { return false; } PrintJobInfo printJob = new PrintJobInfo(); PrintJobId printJobId = PrintJobId.unflattenFromString(parser.getAttributeValue(null, ATTR_ID)); printJob.setId(printJobId); String label = parser.getAttributeValue(null, ATTR_LABEL); printJob.setLabel(label); final int state = Integer.parseInt(parser.getAttributeValue(null, ATTR_STATE)); printJob.setState(state); final int appId = Integer.parseInt(parser.getAttributeValue(null, ATTR_APP_ID)); printJob.setAppId(appId); String tag = parser.getAttributeValue(null, ATTR_TAG); printJob.setTag(tag); String creationTime = parser.getAttributeValue(null, ATTR_CREATION_TIME); printJob.setCreationTime(Long.parseLong(creationTime)); String copies = parser.getAttributeValue(null, ATTR_COPIES); printJob.setCopies(Integer.parseInt(copies)); String printerName = parser.getAttributeValue(null, ATTR_PRINTER_NAME); printJob.setPrinterName(printerName); String stateReason = parser.getAttributeValue(null, ATTR_STATE_REASON); printJob.setStateReason(stateReason); String cancelling = parser.getAttributeValue(null, ATTR_CANCELLING); printJob.setCancelling( !TextUtils.isEmpty(cancelling) ? Boolean.parseBoolean(cancelling) : false); parser.next(); skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_PRINTER_ID)) { String localId = parser.getAttributeValue(null, ATTR_LOCAL_ID); ComponentName service = ComponentName.unflattenFromString(parser.getAttributeValue(null, ATTR_SERVICE_NAME)); printJob.setPrinterId(new PrinterId(service, localId)); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_PRINTER_ID); parser.next(); } skipEmptyTextTags(parser); List<PageRange> pageRanges = null; while (accept(parser, XmlPullParser.START_TAG, TAG_PAGE_RANGE)) { final int start = Integer.parseInt(parser.getAttributeValue(null, ATTR_START)); final int end = Integer.parseInt(parser.getAttributeValue(null, ATTR_END)); PageRange pageRange = new PageRange(start, end); if (pageRanges == null) { pageRanges = new ArrayList<PageRange>(); } pageRanges.add(pageRange); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_PAGE_RANGE); parser.next(); skipEmptyTextTags(parser); } if (pageRanges != null) { PageRange[] pageRangesArray = new PageRange[pageRanges.size()]; pageRanges.toArray(pageRangesArray); printJob.setPages(pageRangesArray); } skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_ATTRIBUTES)) { PrintAttributes.Builder builder = new PrintAttributes.Builder(); String colorMode = parser.getAttributeValue(null, ATTR_COLOR_MODE); builder.setColorMode(Integer.parseInt(colorMode)); parser.next(); skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_MEDIA_SIZE)) { String id = parser.getAttributeValue(null, ATTR_ID); label = parser.getAttributeValue(null, ATTR_LABEL); final int widthMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_WIDTH_MILS)); final int heightMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_HEIGHT_MILS)); String packageName = parser.getAttributeValue(null, ATTR_PACKAGE_NAME); String labelResIdString = parser.getAttributeValue(null, ATTR_LABEL_RES_ID); final int labelResId = (labelResIdString != null) ? Integer.parseInt(labelResIdString) : 0; label = parser.getAttributeValue(null, ATTR_LABEL); MediaSize mediaSize = new MediaSize(id, label, packageName, widthMils, heightMils, labelResId); builder.setMediaSize(mediaSize); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_MEDIA_SIZE); parser.next(); } skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_RESOLUTION)) { String id = parser.getAttributeValue(null, ATTR_ID); label = parser.getAttributeValue(null, ATTR_LABEL); final int horizontalDpi = Integer.parseInt(parser.getAttributeValue(null, ATTR_HORIZONTAL_DPI)); final int verticalDpi = Integer.parseInt(parser.getAttributeValue(null, ATTR_VERTICAL_DPI)); Resolution resolution = new Resolution(id, label, horizontalDpi, verticalDpi); builder.setResolution(resolution); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_RESOLUTION); parser.next(); } skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_MARGINS)) { final int leftMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_LEFT_MILS)); final int topMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_TOP_MILS)); final int rightMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_RIGHT_MILS)); final int bottomMils = Integer.parseInt(parser.getAttributeValue(null, ATTR_BOTTOM_MILS)); Margins margins = new Margins(leftMils, topMils, rightMils, bottomMils); builder.setMinMargins(margins); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_MARGINS); parser.next(); } printJob.setAttributes(builder.build()); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_ATTRIBUTES); parser.next(); } skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_DOCUMENT_INFO)) { String name = parser.getAttributeValue(null, ATTR_NAME); final int pageCount = Integer.parseInt(parser.getAttributeValue(null, ATTR_PAGE_COUNT)); final int contentType = Integer.parseInt(parser.getAttributeValue(null, ATTR_CONTENT_TYPE)); final int dataSize = Integer.parseInt(parser.getAttributeValue(null, ATTR_DATA_SIZE)); PrintDocumentInfo info = new PrintDocumentInfo.Builder(name) .setPageCount(pageCount) .setContentType(contentType) .build(); printJob.setDocumentInfo(info); info.setDataSize(dataSize); parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_DOCUMENT_INFO); parser.next(); } skipEmptyTextTags(parser); if (accept(parser, XmlPullParser.START_TAG, TAG_ADVANCED_OPTIONS)) { parser.next(); skipEmptyTextTags(parser); Bundle advancedOptions = new Bundle(); while (accept(parser, XmlPullParser.START_TAG, TAG_ADVANCED_OPTION)) { String key = parser.getAttributeValue(null, ATTR_KEY); String value = parser.getAttributeValue(null, ATTR_VALUE); String type = parser.getAttributeValue(null, ATTR_TYPE); if (TYPE_STRING.equals(type)) { advancedOptions.putString(key, value); } else if (TYPE_INT.equals(type)) { advancedOptions.putInt(key, Integer.valueOf(value)); } parser.next(); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_ADVANCED_OPTION); parser.next(); skipEmptyTextTags(parser); } printJob.setAdvancedOptions(advancedOptions); skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_ADVANCED_OPTIONS); parser.next(); } mPrintJobs.add(printJob); if (DEBUG_PERSISTENCE) { Log.i(LOG_TAG, "[RESTORED] " + printJob); } skipEmptyTextTags(parser); expect(parser, XmlPullParser.END_TAG, TAG_JOB); return true; }