@Test public void getNumberOfColumnsTest() { FormEntryPrompt formEntryPrompt = mock(FormEntryPrompt.class); when(formEntryPrompt.getAppearanceHint()).thenReturn(""); assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-2"); assertEquals(2, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-10"); assertEquals(10, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-10 quick"); assertEquals(10, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-5 autocomplete"); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-10quick"); assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-5autocomplete"); assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-5 "); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-5 "); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn(" columns-5"); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("quick columns-5"); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-5"); assertEquals(5, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("compact-9"); assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns-9"); assertEquals(9, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--1"); assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); when(formEntryPrompt.getAppearanceHint()).thenReturn("columns--10"); assertEquals(1, WidgetAppearanceUtils.getNumberOfColumns(formEntryPrompt, null)); }
public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context) { int numColumns = 1; String appearance = getSanitizedAppearanceHint(formEntryPrompt); if (appearance.contains(COLUMNS_N) || appearance.contains(COMPACT_N)) { try { String columnsAppearance = appearance.contains(COLUMNS_N) ? COLUMNS_N : COMPACT_N; try { appearance = appearance.substring(appearance.indexOf(columnsAppearance)); int idx = appearance.indexOf(columnsAppearance); if (idx != -1) { String substringFromNumColumns = appearance.substring(idx + columnsAppearance.length()); numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ") ? substringFromNumColumns.indexOf(' ') : substringFromNumColumns.length())); if (numColumns < 1) { numColumns = 1; } } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } else if (appearance.contains(COLUMNS)) { switch (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_SMALL: numColumns = 2; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: numColumns = 3; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: numColumns = 4; break; case Configuration.SCREENLAYOUT_SIZE_XLARGE: numColumns = 5; break; default: numColumns = 3; } } return numColumns; }
WidgetAppearanceUtils { public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context) { int numColumns = 1; String appearance = getSanitizedAppearanceHint(formEntryPrompt); if (appearance.contains(COLUMNS_N) || appearance.contains(COMPACT_N)) { try { String columnsAppearance = appearance.contains(COLUMNS_N) ? COLUMNS_N : COMPACT_N; try { appearance = appearance.substring(appearance.indexOf(columnsAppearance)); int idx = appearance.indexOf(columnsAppearance); if (idx != -1) { String substringFromNumColumns = appearance.substring(idx + columnsAppearance.length()); numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ") ? substringFromNumColumns.indexOf(' ') : substringFromNumColumns.length())); if (numColumns < 1) { numColumns = 1; } } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } else if (appearance.contains(COLUMNS)) { switch (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_SMALL: numColumns = 2; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: numColumns = 3; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: numColumns = 4; break; case Configuration.SCREENLAYOUT_SIZE_XLARGE: numColumns = 5; break; default: numColumns = 3; } } return numColumns; } }
WidgetAppearanceUtils { public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context) { int numColumns = 1; String appearance = getSanitizedAppearanceHint(formEntryPrompt); if (appearance.contains(COLUMNS_N) || appearance.contains(COMPACT_N)) { try { String columnsAppearance = appearance.contains(COLUMNS_N) ? COLUMNS_N : COMPACT_N; try { appearance = appearance.substring(appearance.indexOf(columnsAppearance)); int idx = appearance.indexOf(columnsAppearance); if (idx != -1) { String substringFromNumColumns = appearance.substring(idx + columnsAppearance.length()); numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ") ? substringFromNumColumns.indexOf(' ') : substringFromNumColumns.length())); if (numColumns < 1) { numColumns = 1; } } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } else if (appearance.contains(COLUMNS)) { switch (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_SMALL: numColumns = 2; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: numColumns = 3; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: numColumns = 4; break; case Configuration.SCREENLAYOUT_SIZE_XLARGE: numColumns = 5; break; default: numColumns = 3; } } return numColumns; } private  WidgetAppearanceUtils(); }
WidgetAppearanceUtils { public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context) { int numColumns = 1; String appearance = getSanitizedAppearanceHint(formEntryPrompt); if (appearance.contains(COLUMNS_N) || appearance.contains(COMPACT_N)) { try { String columnsAppearance = appearance.contains(COLUMNS_N) ? COLUMNS_N : COMPACT_N; try { appearance = appearance.substring(appearance.indexOf(columnsAppearance)); int idx = appearance.indexOf(columnsAppearance); if (idx != -1) { String substringFromNumColumns = appearance.substring(idx + columnsAppearance.length()); numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ") ? substringFromNumColumns.indexOf(' ') : substringFromNumColumns.length())); if (numColumns < 1) { numColumns = 1; } } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } else if (appearance.contains(COLUMNS)) { switch (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_SMALL: numColumns = 2; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: numColumns = 3; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: numColumns = 4; break; case Configuration.SCREENLAYOUT_SIZE_XLARGE: numColumns = 5; break; default: numColumns = 3; } } return numColumns; } private  WidgetAppearanceUtils(); static @NonNull String getSanitizedAppearanceHint(FormEntryPrompt fep); static boolean hasAppearance(FormEntryPrompt fep, String appearance); static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context); static boolean isNoButtonsAppearance(FormEntryPrompt prompt); static boolean isCompactAppearance(FormEntryPrompt prompt); static boolean useThousandSeparator(FormEntryPrompt prompt); }
WidgetAppearanceUtils { public static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context) { int numColumns = 1; String appearance = getSanitizedAppearanceHint(formEntryPrompt); if (appearance.contains(COLUMNS_N) || appearance.contains(COMPACT_N)) { try { String columnsAppearance = appearance.contains(COLUMNS_N) ? COLUMNS_N : COMPACT_N; try { appearance = appearance.substring(appearance.indexOf(columnsAppearance)); int idx = appearance.indexOf(columnsAppearance); if (idx != -1) { String substringFromNumColumns = appearance.substring(idx + columnsAppearance.length()); numColumns = Integer.parseInt(substringFromNumColumns.substring(0, substringFromNumColumns.contains(" ") ? substringFromNumColumns.indexOf(' ') : substringFromNumColumns.length())); if (numColumns < 1) { numColumns = 1; } } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } catch (Exception e) { Timber.e(EXCEPTION_PARSING_COLUMNS); } } else if (appearance.contains(COLUMNS)) { switch (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) { case Configuration.SCREENLAYOUT_SIZE_SMALL: numColumns = 2; break; case Configuration.SCREENLAYOUT_SIZE_NORMAL: numColumns = 3; break; case Configuration.SCREENLAYOUT_SIZE_LARGE: numColumns = 4; break; case Configuration.SCREENLAYOUT_SIZE_XLARGE: numColumns = 5; break; default: numColumns = 3; } } return numColumns; } private  WidgetAppearanceUtils(); static @NonNull String getSanitizedAppearanceHint(FormEntryPrompt fep); static boolean hasAppearance(FormEntryPrompt fep, String appearance); static int getNumberOfColumns(FormEntryPrompt formEntryPrompt, Context context); static boolean isNoButtonsAppearance(FormEntryPrompt prompt); static boolean isCompactAppearance(FormEntryPrompt prompt); static boolean useThousandSeparator(FormEntryPrompt prompt); static final String ETHIOPIAN; static final String COPTIC; static final String ISLAMIC; static final String BIKRAM_SAMBAT; static final String MYANMAR; static final String PERSIAN; static final String NO_CALENDAR; static final String MONTH_YEAR; static final String YEAR; @Deprecated static final String COMPACT; @Deprecated static final String COMPACT_N; static final String MINIMAL; static final String COLUMNS; static final String COLUMNS_N; static final String COLUMNS_PACK; @Deprecated static final String QUICKCOMPACT; @Deprecated static final String SEARCH; static final String AUTOCOMPLETE; static final String LIST_NO_LABEL; static final String LIST; static final String LABEL; static final String IMAGE_MAP; static final String NO_BUTTONS; static final String QUICK; static final String SIGNATURE; static final String ANNOTATE; static final String DRAW; @Deprecated static final String SELFIE; static final String NEW_FRONT; static final String NEW; static final String FRONT; static final String PLACEMENT_MAP; static final String MAPS; static final String NO_APPEARANCE; static final String BEARING; static final String EX; static final String THOUSANDS_SEP; static final String PRINTER; static final String NUMBERS; static final String URL; static final String RATING; }