Android examples for android.print:PageRange
Gets the number of pages in a normalized range array using PageRange.
/*//from w ww .ja va2 s .co m * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.print.PageRange; import android.print.PrintDocumentInfo; import java.util.Arrays; import java.util.Comparator; public class Main{ /** * 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; } }