Search in sources :

Example 1 with PageRange

use of android.print.PageRange in project platform_frameworks_base by android.

the class PageAdapter method computeBoundPagesInDocument.

private PageRange[] computeBoundPagesInDocument() {
    List<PageRange> pagesInDocumentList = new ArrayList<>();
    int fromPage = INVALID_PAGE_INDEX;
    int toPage = INVALID_PAGE_INDEX;
    final int boundPageCount = mBoundPagesInAdapter.size();
    for (int i = 0; i < boundPageCount; i++) {
        // The container is a sparse array, so keys are sorted in ascending order.
        final int boundPageInAdapter = mBoundPagesInAdapter.keyAt(i);
        final int boundPageInDocument = computePageIndexInDocument(boundPageInAdapter);
        if (fromPage == INVALID_PAGE_INDEX) {
            fromPage = boundPageInDocument;
        }
        if (toPage == INVALID_PAGE_INDEX) {
            toPage = boundPageInDocument;
        }
        if (boundPageInDocument > toPage + 1) {
            PageRange pageRange = new PageRange(fromPage, toPage);
            pagesInDocumentList.add(pageRange);
            fromPage = toPage = boundPageInDocument;
        } else {
            toPage = boundPageInDocument;
        }
    }
    if (fromPage != INVALID_PAGE_INDEX && toPage != INVALID_PAGE_INDEX) {
        PageRange pageRange = new PageRange(fromPage, toPage);
        pagesInDocumentList.add(pageRange);
    }
    PageRange[] pageInDocument = new PageRange[pagesInDocumentList.size()];
    pagesInDocumentList.toArray(pageInDocument);
    if (DEBUG) {
        Log.i(LOG_TAG, "Bound pages: " + Arrays.toString(pageInDocument));
    }
    return pageInDocument;
}
Also used : ArrayList(java.util.ArrayList) PageRange(android.print.PageRange)

Example 2 with PageRange

use of android.print.PageRange in project platform_frameworks_base by android.

the class PageAdapter method computePageIndexInDocument.

private int computePageIndexInDocument(int indexInAdapter) {
    int skippedAdapterPages = 0;
    final int selectedPagesCount = mSelectedPages.length;
    for (int i = 0; i < selectedPagesCount; i++) {
        PageRange pageRange = PageRangeUtils.asAbsoluteRange(mSelectedPages[i], mDocumentPageCount);
        skippedAdapterPages += pageRange.getSize();
        if (skippedAdapterPages > indexInAdapter) {
            final int overshoot = skippedAdapterPages - indexInAdapter - 1;
            return pageRange.getEnd() - overshoot;
        }
    }
    return INVALID_PAGE_INDEX;
}
Also used : PageRange(android.print.PageRange)

Example 3 with PageRange

use of android.print.PageRange in project platform_frameworks_base by android.

the class PageAdapter method computePageIndexInFile.

private int computePageIndexInFile(int pageIndexInDocument) {
    if (!PageRangeUtils.contains(mSelectedPages, pageIndexInDocument)) {
        return INVALID_PAGE_INDEX;
    }
    if (mWrittenPages == null) {
        return INVALID_PAGE_INDEX;
    }
    int indexInFile = INVALID_PAGE_INDEX;
    final int rangeCount = mWrittenPages.length;
    for (int i = 0; i < rangeCount; i++) {
        PageRange pageRange = mWrittenPages[i];
        if (!pageRange.contains(pageIndexInDocument)) {
            indexInFile += pageRange.getSize();
        } else {
            indexInFile += pageIndexInDocument - pageRange.getStart() + 1;
            return indexInFile;
        }
    }
    return INVALID_PAGE_INDEX;
}
Also used : PageRange(android.print.PageRange)

Example 4 with PageRange

use of android.print.PageRange in project platform_frameworks_base by android.

the class PageAdapter method setConfirmedPages.

private void setConfirmedPages(PageRange[] pagesInDocument, int documentPageCount) {
    mConfirmedPagesInDocument.clear();
    final int rangeCount = pagesInDocument.length;
    for (int i = 0; i < rangeCount; i++) {
        PageRange pageRange = PageRangeUtils.asAbsoluteRange(pagesInDocument[i], documentPageCount);
        for (int j = pageRange.getStart(); j <= pageRange.getEnd(); j++) {
            mConfirmedPagesInDocument.put(j, null);
        }
    }
}
Also used : PageRange(android.print.PageRange)

Example 5 with PageRange

use of android.print.PageRange in project platform_frameworks_base by android.

the class PageAdapter method computeSelectedPages.

private PageRange[] computeSelectedPages() {
    ArrayList<PageRange> selectedPagesList = new ArrayList<>();
    int startPageIndex = INVALID_PAGE_INDEX;
    int endPageIndex = INVALID_PAGE_INDEX;
    final int pageCount = mConfirmedPagesInDocument.size();
    for (int i = 0; i < pageCount; i++) {
        final int pageIndex = mConfirmedPagesInDocument.keyAt(i);
        if (startPageIndex == INVALID_PAGE_INDEX) {
            startPageIndex = endPageIndex = pageIndex;
        }
        if (endPageIndex + 1 < pageIndex) {
            PageRange pageRange = new PageRange(startPageIndex, endPageIndex);
            selectedPagesList.add(pageRange);
            startPageIndex = pageIndex;
        }
        endPageIndex = pageIndex;
    }
    if (startPageIndex != INVALID_PAGE_INDEX && endPageIndex != INVALID_PAGE_INDEX) {
        PageRange pageRange = new PageRange(startPageIndex, endPageIndex);
        selectedPagesList.add(pageRange);
    }
    PageRange[] selectedPages = new PageRange[selectedPagesList.size()];
    selectedPagesList.toArray(selectedPages);
    return selectedPages;
}
Also used : ArrayList(java.util.ArrayList) PageRange(android.print.PageRange)

Aggregations

PageRange (android.print.PageRange)60 ArrayList (java.util.ArrayList)20 PrintAttributes (android.print.PrintAttributes)5 MediaSize (android.print.PrintAttributes.MediaSize)5 Resolution (android.print.PrintAttributes.Resolution)5 PrintDocumentInfo (android.print.PrintDocumentInfo)5 PrintJobInfo (android.print.PrintJobInfo)5 PrinterCapabilitiesInfo (android.print.PrinterCapabilitiesInfo)5 Pair (android.util.Pair)5 RemotePrintDocumentInfo (com.android.printspooler.model.RemotePrintDocument.RemotePrintDocumentInfo)5