Loading src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java +17 −1 Original line number Diff line number Diff line Loading @@ -131,6 +131,11 @@ public abstract class LocalePickerBaseListPreferenceController extends ? getSuggestedLocaleList() : getSupportedLocaleList()); // In language selection, list should not contain locale with U extension. if (mParentLocale == null && mIsSuggestedCategory) { result.removeAll(getLocalesWithExtension(result)); } final Map<String, Preference> existingPreferences = mPreferences; mPreferences = new ArrayMap<>(); setupPreference(result, existingPreferences); Loading Loading @@ -246,7 +251,6 @@ public abstract class LocalePickerBaseListPreferenceController extends } else { Log.d(TAG, "Can not get suggested locales because the locale list is null or empty."); } return mLocaleOptions; } Loading Loading @@ -337,6 +341,18 @@ public abstract class LocalePickerBaseListPreferenceController extends || isNumberingMode(); } @VisibleForTesting protected List<LocaleStore.LocaleInfo> getLocalesWithExtension( List<LocaleStore.LocaleInfo> inputList) { List<LocaleStore.LocaleInfo> checklist = new ArrayList<>(); for (LocaleStore.LocaleInfo localeInfo : inputList) { if (localeInfo.getLocale().hasExtensions()) { checklist.add(localeInfo); } } return checklist; } private List<LocaleStore.LocaleInfo> getUserLocaleList() { final List<LocaleStore.LocaleInfo> result = new ArrayList<>(); final LocaleList localeList = LocalePicker.getLocales(); Loading tests/robotests/src/com/android/settings/localepicker/SystemLocaleSuggestedListPreferenceControllerTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class SystemLocaleSuggestedListPreferenceControllerTest { private static final String KEY_CATEGORY_SYSTEM_SUGGESTED_LIST = "system_language_suggested_category"; private static final String KEY_SUGGESTED = "system_locale_suggested_list"; private static final String LOCALE_URDU_INDIA = "اردو (بھارت)"; private Context mContext; private FragmentActivity mActivity; Loading Loading @@ -150,6 +151,35 @@ public class SystemLocaleSuggestedListPreferenceControllerTest { mLocaleList.add(mSuggestedLocaleInfo_2); } private void setupLocaleWithExtensionConditions() { mLocaleList = new ArrayList<>(); when(mSuggestedLocaleInfo_1.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA); when(mSuggestedLocaleInfo_1.getLocale()).thenReturn( LocaleList.forLanguageTags("ur-IN").get(0)); mLocaleList.add(mSuggestedLocaleInfo_1); when(mSuggestedLocaleInfo_2.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA); when(mSuggestedLocaleInfo_2.getLocale()).thenReturn( LocaleList.forLanguageTags("ur-IN-u-nu-latn").get(0)); mLocaleList.add(mSuggestedLocaleInfo_2); } @Test public void removeLocalesWithExtension_localesHasExtension_filterNoExtensionLocales() { setupLocaleWithExtensionConditions(); List<LocaleStore.LocaleInfo> localesWithExtension = mController.getLocalesWithExtension(mLocaleList); mController.displayPreference(mPreferenceScreen); mLocaleList.removeAll(localesWithExtension); mController.setupPreference(mLocaleList, mPreferences); assertThat(mLocaleList.size()).isEqualTo(1); assertThat(mLocaleList.get(0).getFullNameNative()).isEqualTo(LOCALE_URDU_INDIA); assertThat(mLocaleList.get(0).getLocale().hasExtensions()).isFalse(); assertTrue(mPreferenceCategory.isVisible()); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); } @Test public void displayPreference_hasSuggestedPreference_categoryIsVisible() { mController.displayPreference(mPreferenceScreen); Loading Loading
src/com/android/settings/localepicker/LocalePickerBaseListPreferenceController.java +17 −1 Original line number Diff line number Diff line Loading @@ -131,6 +131,11 @@ public abstract class LocalePickerBaseListPreferenceController extends ? getSuggestedLocaleList() : getSupportedLocaleList()); // In language selection, list should not contain locale with U extension. if (mParentLocale == null && mIsSuggestedCategory) { result.removeAll(getLocalesWithExtension(result)); } final Map<String, Preference> existingPreferences = mPreferences; mPreferences = new ArrayMap<>(); setupPreference(result, existingPreferences); Loading Loading @@ -246,7 +251,6 @@ public abstract class LocalePickerBaseListPreferenceController extends } else { Log.d(TAG, "Can not get suggested locales because the locale list is null or empty."); } return mLocaleOptions; } Loading Loading @@ -337,6 +341,18 @@ public abstract class LocalePickerBaseListPreferenceController extends || isNumberingMode(); } @VisibleForTesting protected List<LocaleStore.LocaleInfo> getLocalesWithExtension( List<LocaleStore.LocaleInfo> inputList) { List<LocaleStore.LocaleInfo> checklist = new ArrayList<>(); for (LocaleStore.LocaleInfo localeInfo : inputList) { if (localeInfo.getLocale().hasExtensions()) { checklist.add(localeInfo); } } return checklist; } private List<LocaleStore.LocaleInfo> getUserLocaleList() { final List<LocaleStore.LocaleInfo> result = new ArrayList<>(); final LocaleList localeList = LocalePicker.getLocales(); Loading
tests/robotests/src/com/android/settings/localepicker/SystemLocaleSuggestedListPreferenceControllerTest.java +30 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,7 @@ public class SystemLocaleSuggestedListPreferenceControllerTest { private static final String KEY_CATEGORY_SYSTEM_SUGGESTED_LIST = "system_language_suggested_category"; private static final String KEY_SUGGESTED = "system_locale_suggested_list"; private static final String LOCALE_URDU_INDIA = "اردو (بھارت)"; private Context mContext; private FragmentActivity mActivity; Loading Loading @@ -150,6 +151,35 @@ public class SystemLocaleSuggestedListPreferenceControllerTest { mLocaleList.add(mSuggestedLocaleInfo_2); } private void setupLocaleWithExtensionConditions() { mLocaleList = new ArrayList<>(); when(mSuggestedLocaleInfo_1.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA); when(mSuggestedLocaleInfo_1.getLocale()).thenReturn( LocaleList.forLanguageTags("ur-IN").get(0)); mLocaleList.add(mSuggestedLocaleInfo_1); when(mSuggestedLocaleInfo_2.getFullNameNative()).thenReturn(LOCALE_URDU_INDIA); when(mSuggestedLocaleInfo_2.getLocale()).thenReturn( LocaleList.forLanguageTags("ur-IN-u-nu-latn").get(0)); mLocaleList.add(mSuggestedLocaleInfo_2); } @Test public void removeLocalesWithExtension_localesHasExtension_filterNoExtensionLocales() { setupLocaleWithExtensionConditions(); List<LocaleStore.LocaleInfo> localesWithExtension = mController.getLocalesWithExtension(mLocaleList); mController.displayPreference(mPreferenceScreen); mLocaleList.removeAll(localesWithExtension); mController.setupPreference(mLocaleList, mPreferences); assertThat(mLocaleList.size()).isEqualTo(1); assertThat(mLocaleList.get(0).getFullNameNative()).isEqualTo(LOCALE_URDU_INDIA); assertThat(mLocaleList.get(0).getLocale().hasExtensions()).isFalse(); assertTrue(mPreferenceCategory.isVisible()); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); } @Test public void displayPreference_hasSuggestedPreference_categoryIsVisible() { mController.displayPreference(mPreferenceScreen); Loading