diff options
| author | 2013-09-18 14:09:47 -0700 | |
|---|---|---|
| committer | 2013-09-18 14:13:06 -0700 | |
| commit | f0c48a72fd8476afd063d4ef593b473b8cf9a9d0 (patch) | |
| tree | 1cbd75c1f53303ad6a3f156025080372ffd18a5d | |
| parent | 013b816ac7d723a0116c039e6266d93d13851fe1 (diff) | |
Fixes in the page range selection and verification logic.
1. Typing a range where the start is greater than the end was
leading to a crash.
2. Typing the same single range, e.g. "2,2", was leading to a crash.
3. If two ranges are non-overlapping but consecutive they were
not merged
4. Typing multiple times a digit that is less than the page count,
e.g. page count "2" and typing "11", was not caught by the input
verification.
bug:10812904
Change-Id: I754715b5d792a1a6c3a4f9f644edfa9aea7ac127
| -rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java index 8ab46453e372..34e87cc2e3d7 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java @@ -139,7 +139,7 @@ public class PrintJobConfigActivity extends Activity { private static final int MIN_COPIES = 1; private static final String MIN_COPIES_STRING = String.valueOf(MIN_COPIES); - private static final Pattern PATTERN_DIGITS = Pattern.compile("\\d"); + private static final Pattern PATTERN_DIGITS = Pattern.compile("[\\d]+"); private static final Pattern PATTERN_ESCAPE_SPECIAL_CHARS = Pattern.compile( "(?=[]\\[+&|!(){}^\"~*?:\\\\])"); @@ -1484,7 +1484,8 @@ public class PrintJobConfigActivity extends Activity { fromIndex = toIndex = Integer.parseInt(range) - 1; } - PageRange pageRange = new PageRange(fromIndex, toIndex); + PageRange pageRange = new PageRange(Math.min(fromIndex, toIndex), + Math.max(fromIndex, toIndex)); pageRanges.add(pageRange); } @@ -2166,6 +2167,11 @@ public class PrintJobConfigActivity extends Activity { return false; } + if (ourPageRanges.length == 1 + && PageRange.ALL_PAGES.equals(ourPageRanges[0])) { + return true; + } + otherPageRanges = normalize(otherPageRanges); int otherPageIdx = 0; @@ -2197,28 +2203,28 @@ public class PrintJobConfigActivity extends Activity { if (pageRanges == null) { return null; } - final int oldPageCount = pageRanges.length; - if (oldPageCount <= 1) { + final int oldRangeCount = pageRanges.length; + if (oldRangeCount <= 1) { return pageRanges; } Arrays.sort(pageRanges, sComparator); - int newRangeCount = 0; - for (int i = 0; i < oldPageCount - 1; i++) { + int newRangeCount = 1; + for (int i = 0; i < oldRangeCount - 1; i++) { newRangeCount++; PageRange currentRange = pageRanges[i]; PageRange nextRange = pageRanges[i + 1]; - if (currentRange.getEnd() >= nextRange.getStart()) { + if (currentRange.getEnd() + 1 >= nextRange.getStart()) { newRangeCount--; pageRanges[i] = null; pageRanges[i + 1] = new PageRange(currentRange.getStart(), - nextRange.getEnd()); + Math.max(currentRange.getEnd(), nextRange.getEnd())); } } - if (newRangeCount == oldPageCount) { + if (newRangeCount == oldRangeCount) { return pageRanges; } - return Arrays.copyOfRange(pageRanges, oldPageCount - newRangeCount, - oldPageCount - 1); + return Arrays.copyOfRange(pageRanges, oldRangeCount - newRangeCount, + oldRangeCount); } public static void offsetStart(PageRange[] pageRanges, int offset) { |