@Test public void testExtractSeparatorsForDifferentLocales() throws Throwable { TimePicker timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "h:mm a"; } }; List<CharSequence> actualSeparators = timePicker.extractSeparators(); List<String> expectedSeparators = Arrays.asList(new String[] {"", ":", "", ""}); assertEquals(expectedSeparators, actualSeparators); timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "aK:mm"; } @Override public boolean is24Hour() { return false; } }; actualSeparators = timePicker.extractSeparators(); expectedSeparators = Arrays.asList(new String[] {"", "", ":", ""}); assertEquals(expectedSeparators, actualSeparators); timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "HH 'h' mm"; } @Override public boolean is24Hour() { return true; } }; actualSeparators = timePicker.extractSeparators(); expectedSeparators = Arrays.asList(new String[] {"", "h", ""}); assertEquals(expectedSeparators, actualSeparators); timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "H:mm 'hodz'"; } @Override public boolean is24Hour() { return true; } }; actualSeparators = timePicker.extractSeparators(); expectedSeparators = Arrays.asList(new String[] {"", ":", "hodz"}); assertEquals(expectedSeparators, actualSeparators); timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "a h:mm"; } @Override public boolean is24Hour() { return false; } }; actualSeparators = timePicker.extractSeparators(); expectedSeparators = Arrays.asList(new String[] {"", "", ":", ""}); assertEquals(expectedSeparators, actualSeparators); timePicker = new TimePicker(mContext, null) { @Override String getBestHourMinutePattern() { return "H:mm"; } @Override public boolean is24Hour() { return true; } }; actualSeparators = timePicker.extractSeparators(); expectedSeparators = Arrays.asList(new String[] {"", ":", ""}); assertEquals(expectedSeparators, actualSeparators); }
List<CharSequence> extractSeparators() { String hmaPattern = getBestHourMinutePattern(); List<CharSequence> separators = new ArrayList<>(); StringBuilder sb = new StringBuilder(); char lastChar = '\0'; final char[] timeFormats = {'H', 'h', 'K', 'k', 'm', 'M', 'a'}; boolean processingQuote = false; for (int i = 0; i < hmaPattern.length(); i++) { char c = hmaPattern.charAt(i); if (c == ' ') { continue; } if (c == '\'') { if (!processingQuote) { sb.setLength(0); processingQuote = true; } else { processingQuote = false; } continue; } if (processingQuote) { sb.append(c); } else { if (isAnyOf(c, timeFormats)) { if (c != lastChar) { separators.add(sb.toString()); sb.setLength(0); } } else { sb.append(c); } } lastChar = c; } separators.add(sb.toString()); return separators; }
TimePicker extends Picker { List<CharSequence> extractSeparators() { String hmaPattern = getBestHourMinutePattern(); List<CharSequence> separators = new ArrayList<>(); StringBuilder sb = new StringBuilder(); char lastChar = '\0'; final char[] timeFormats = {'H', 'h', 'K', 'k', 'm', 'M', 'a'}; boolean processingQuote = false; for (int i = 0; i < hmaPattern.length(); i++) { char c = hmaPattern.charAt(i); if (c == ' ') { continue; } if (c == '\'') { if (!processingQuote) { sb.setLength(0); processingQuote = true; } else { processingQuote = false; } continue; } if (processingQuote) { sb.append(c); } else { if (isAnyOf(c, timeFormats)) { if (c != lastChar) { separators.add(sb.toString()); sb.setLength(0); } } else { sb.append(c); } } lastChar = c; } separators.add(sb.toString()); return separators; } }
TimePicker extends Picker { List<CharSequence> extractSeparators() { String hmaPattern = getBestHourMinutePattern(); List<CharSequence> separators = new ArrayList<>(); StringBuilder sb = new StringBuilder(); char lastChar = '\0'; final char[] timeFormats = {'H', 'h', 'K', 'k', 'm', 'M', 'a'}; boolean processingQuote = false; for (int i = 0; i < hmaPattern.length(); i++) { char c = hmaPattern.charAt(i); if (c == ' ') { continue; } if (c == '\'') { if (!processingQuote) { sb.setLength(0); processingQuote = true; } else { processingQuote = false; } continue; } if (processingQuote) { sb.append(c); } else { if (isAnyOf(c, timeFormats)) { if (c != lastChar) { separators.add(sb.toString()); sb.setLength(0); } } else { sb.append(c); } } lastChar = c; } separators.add(sb.toString()); return separators; } TimePicker(Context context, AttributeSet attrs);  TimePicker(Context context, AttributeSet attrs, int defStyleAttr); }
TimePicker extends Picker { List<CharSequence> extractSeparators() { String hmaPattern = getBestHourMinutePattern(); List<CharSequence> separators = new ArrayList<>(); StringBuilder sb = new StringBuilder(); char lastChar = '\0'; final char[] timeFormats = {'H', 'h', 'K', 'k', 'm', 'M', 'a'}; boolean processingQuote = false; for (int i = 0; i < hmaPattern.length(); i++) { char c = hmaPattern.charAt(i); if (c == ' ') { continue; } if (c == '\'') { if (!processingQuote) { sb.setLength(0); processingQuote = true; } else { processingQuote = false; } continue; } if (processingQuote) { sb.append(c); } else { if (isAnyOf(c, timeFormats)) { if (c != lastChar) { separators.add(sb.toString()); sb.setLength(0); } } else { sb.append(c); } } lastChar = c; } separators.add(sb.toString()); return separators; } TimePicker(Context context, AttributeSet attrs);  TimePicker(Context context, AttributeSet attrs, int defStyleAttr); void setHour(@IntRange(from = 0, to = 23) int hour); int getHour(); void setMinute(@IntRange(from = 0, to = 59) int minute); int getMinute(); void setIs24Hour(boolean is24Hour); boolean is24Hour(); boolean isPm(); @Override void onColumnValueChanged(int columnIndex, int newValue); }
TimePicker extends Picker { List<CharSequence> extractSeparators() { String hmaPattern = getBestHourMinutePattern(); List<CharSequence> separators = new ArrayList<>(); StringBuilder sb = new StringBuilder(); char lastChar = '\0'; final char[] timeFormats = {'H', 'h', 'K', 'k', 'm', 'M', 'a'}; boolean processingQuote = false; for (int i = 0; i < hmaPattern.length(); i++) { char c = hmaPattern.charAt(i); if (c == ' ') { continue; } if (c == '\'') { if (!processingQuote) { sb.setLength(0); processingQuote = true; } else { processingQuote = false; } continue; } if (processingQuote) { sb.append(c); } else { if (isAnyOf(c, timeFormats)) { if (c != lastChar) { separators.add(sb.toString()); sb.setLength(0); } } else { sb.append(c); } } lastChar = c; } separators.add(sb.toString()); return separators; } TimePicker(Context context, AttributeSet attrs);  TimePicker(Context context, AttributeSet attrs, int defStyleAttr); void setHour(@IntRange(from = 0, to = 23) int hour); int getHour(); void setMinute(@IntRange(from = 0, to = 59) int minute); int getMinute(); void setIs24Hour(boolean is24Hour); boolean is24Hour(); boolean isPm(); @Override void onColumnValueChanged(int columnIndex, int newValue);  }