Search in sources :

Example 16 with PageRange

use of android.print.PageRange in project android_frameworks_base by DirtyUnicorns.

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 17 with PageRange

use of android.print.PageRange in project android_frameworks_base by DirtyUnicorns.

the class PageRangeUtils method readRange.

/**
     * Read a page range character from a string at a certain position.
     *
     * @param s             The string to parse
     * @param pos           The starting position
     * @param maxPageNumber The highest page number to accept.
     *
     * @return The position after the page range + the page range read or null if the page range was
     *         not found
     */
private static Pair<Integer, PageRange> readRange(CharSequence s, int pos, int maxPageNumber) {
    Pair<Integer, Integer> retInt;
    Pair<Integer, Character> retChar;
    Character comma;
    if (pos == 0) {
        // When we reading the first range, we do not want to have a comma
        comma = ',';
    } else {
        retChar = readChar(s, pos, ',');
        pos = retChar.first;
        comma = retChar.second;
    }
    pos = readWhiteSpace(s, pos);
    retInt = readNumber(s, pos);
    pos = retInt.first;
    Integer start = retInt.second;
    pos = readWhiteSpace(s, pos);
    retChar = readChar(s, pos, '-');
    pos = retChar.first;
    Character separator = retChar.second;
    pos = readWhiteSpace(s, pos);
    retInt = readNumber(s, pos);
    pos = retInt.first;
    Integer end = retInt.second;
    pos = readWhiteSpace(s, pos);
    if (comma != null && // range, maybe unbounded
    ((separator != null && (start != null || end != null)) || // single page
    (separator == null && start != null && end == null))) {
        if (start == null) {
            start = 1;
        }
        if (end == null) {
            if (separator == null) {
                end = start;
            } else {
                end = maxPageNumber;
            }
        }
        if (start <= end && start >= 1 && end <= maxPageNumber) {
            return new Pair<>(pos, new PageRange(start - 1, end - 1));
        }
    }
    return new Pair<>(pos, null);
}
Also used : Pair(android.util.Pair) PageRange(android.print.PageRange)

Example 18 with PageRange

use of android.print.PageRange in project android_frameworks_base by DirtyUnicorns.

the class PageRangeUtils method offset.

/**
     * Offsets a the start and end of page ranges with the given value.
     *
     * @param pageRanges The page ranges to offset.
     * @param offset The offset value.
     */
public static void offset(PageRange[] pageRanges, int offset) {
    if (offset == 0) {
        return;
    }
    final int pageRangeCount = pageRanges.length;
    for (int i = 0; i < pageRangeCount; i++) {
        final int start = pageRanges[i].getStart() + offset;
        final int end = pageRanges[i].getEnd() + offset;
        pageRanges[i] = new PageRange(start, end);
    }
}
Also used : PageRange(android.print.PageRange)

Example 19 with PageRange

use of android.print.PageRange in project android_frameworks_base by DirtyUnicorns.

the class PageRangeUtils method getNormalizedPageCount.

/**
     * Gets the number of pages in a normalized range array.
     *
     * @param pageRanges Normalized page ranges.
     * @param layoutPageCount Page count after reported after layout pass.
     * @return The page count in the ranges.
     */
public static int getNormalizedPageCount(PageRange[] pageRanges, int layoutPageCount) {
    int pageCount = 0;
    if (pageRanges != null) {
        final int pageRangeCount = pageRanges.length;
        for (int i = 0; i < pageRangeCount; i++) {
            PageRange pageRange = pageRanges[i];
            if (PageRange.ALL_PAGES.equals(pageRange)) {
                return layoutPageCount;
            }
            pageCount += pageRange.getSize();
        }
    }
    return pageCount;
}
Also used : PageRange(android.print.PageRange)

Example 20 with PageRange

use of android.print.PageRange in project android_frameworks_base by AOSPA.

the class PageRangeUtils method normalize.

/**
     * Normalizes a page range, which is the resulting page ranges are
     * non-overlapping with the start lesser than or equal to the end
     * and ordered in an ascending order.
     *
     * @param pageRanges The page ranges to normalize.
     * @return The normalized page ranges.
     */
public static PageRange[] normalize(PageRange[] pageRanges) {
    if (pageRanges == null) {
        return null;
    }
    final int oldRangeCount = pageRanges.length;
    if (oldRangeCount <= 1) {
        return pageRanges;
    }
    Arrays.sort(pageRanges, sComparator);
    int newRangeCount = 1;
    for (int i = 0; i < oldRangeCount - 1; i++) {
        PageRange currentRange = pageRanges[i];
        PageRange nextRange = pageRanges[i + 1];
        if (currentRange.getEnd() + 1 >= nextRange.getStart()) {
            pageRanges[i] = null;
            pageRanges[i + 1] = new PageRange(currentRange.getStart(), Math.max(currentRange.getEnd(), nextRange.getEnd()));
        } else {
            newRangeCount++;
        }
    }
    if (newRangeCount == oldRangeCount) {
        return pageRanges;
    }
    int normalRangeIndex = 0;
    PageRange[] normalRanges = new PageRange[newRangeCount];
    for (int i = 0; i < oldRangeCount; i++) {
        PageRange normalRange = pageRanges[i];
        if (normalRange != null) {
            normalRanges[normalRangeIndex] = normalRange;
            normalRangeIndex++;
        }
    }
    return normalRanges;
}
Also used : 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