use of android.print.PageRange in project android_frameworks_base by DirtyUnicorns.
the class PageRangeUtils method contains.
/**
* Checks whether one page range array contains another one.
*
* @param ourRanges The container page ranges.
* @param otherRanges The contained page ranges.
* @param pageCount The total number of pages.
* @return Whether the container page ranges contains the contained ones.
*/
public static boolean contains(PageRange[] ourRanges, PageRange[] otherRanges, int pageCount) {
if (ourRanges == null || otherRanges == null) {
return false;
}
if (Arrays.equals(ourRanges, ALL_PAGES_RANGE)) {
return true;
}
if (Arrays.equals(otherRanges, ALL_PAGES_RANGE)) {
otherRanges[0] = new PageRange(0, pageCount - 1);
}
ourRanges = normalize(ourRanges);
otherRanges = normalize(otherRanges);
// Note that the code below relies on the ranges being normalized
// which is they contain monotonically increasing non-intersecting
// sub-ranges whose start is less that or equal to the end.
int otherRangeIdx = 0;
final int ourRangeCount = ourRanges.length;
final int otherRangeCount = otherRanges.length;
for (int ourRangeIdx = 0; ourRangeIdx < ourRangeCount; ourRangeIdx++) {
PageRange ourRange = ourRanges[ourRangeIdx];
for (; otherRangeIdx < otherRangeCount; otherRangeIdx++) {
PageRange otherRange = otherRanges[otherRangeIdx];
if (otherRange.getStart() > ourRange.getEnd()) {
break;
}
if (otherRange.getStart() < ourRange.getStart() || otherRange.getEnd() > ourRange.getEnd()) {
return false;
}
}
}
return (otherRangeIdx >= otherRangeCount);
}
use of android.print.PageRange in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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 crdroidandroid.
the class PageRangeUtils method contains.
/**
* Checks whether one page range array contains another one.
*
* @param ourRanges The container page ranges.
* @param otherRanges The contained page ranges.
* @param pageCount The total number of pages.
* @return Whether the container page ranges contains the contained ones.
*/
public static boolean contains(PageRange[] ourRanges, PageRange[] otherRanges, int pageCount) {
if (ourRanges == null || otherRanges == null) {
return false;
}
if (Arrays.equals(ourRanges, ALL_PAGES_RANGE)) {
return true;
}
if (Arrays.equals(otherRanges, ALL_PAGES_RANGE)) {
otherRanges[0] = new PageRange(0, pageCount - 1);
}
ourRanges = normalize(ourRanges);
otherRanges = normalize(otherRanges);
// Note that the code below relies on the ranges being normalized
// which is they contain monotonically increasing non-intersecting
// sub-ranges whose start is less that or equal to the end.
int otherRangeIdx = 0;
final int ourRangeCount = ourRanges.length;
final int otherRangeCount = otherRanges.length;
for (int ourRangeIdx = 0; ourRangeIdx < ourRangeCount; ourRangeIdx++) {
PageRange ourRange = ourRanges[ourRangeIdx];
for (; otherRangeIdx < otherRangeCount; otherRangeIdx++) {
PageRange otherRange = otherRanges[otherRangeIdx];
if (otherRange.getStart() > ourRange.getEnd()) {
break;
}
if (otherRange.getStart() < ourRange.getStart() || otherRange.getEnd() > ourRange.getEnd()) {
return false;
}
}
}
return (otherRangeIdx >= otherRangeCount);
}
use of android.print.PageRange in project android_frameworks_base by crdroidandroid.
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;
}
Aggregations