use of android.print.PageRange in project android_frameworks_base by AOSPA.
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;
}
use of android.print.PageRange in project android_frameworks_base by AOSPA.
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;
}
use of android.print.PageRange in project android_frameworks_base by AOSPA.
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);
}
}
}
use of android.print.PageRange in project android_frameworks_base by AOSPA.
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;
}
use of android.print.PageRange in project android_frameworks_base by ResurrectionRemix.
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);
}
}
Aggregations