LocalesDetector { HashSet<Locale> fetchAvailableLocales(int stringId) { DisplayMetrics dm = mContext.getResources().getDisplayMetrics(); Configuration conf = mContext.getResources().getConfiguration(); Locale originalLocale = conf.locale; Locale baseLocale = LocalesUtils.getBaseLocale(); conf.locale = baseLocale; ArrayList<String> references = new ArrayList<>(); references.add(new Resources(mContext.getAssets(), dm, conf).getString(stringId)); HashSet<Locale> result = new HashSet<>(); result.add(baseLocale); for(String loc : mContext.getAssets().getLocales()) { if(loc.isEmpty()){ continue; } Locale l; boolean referencesUpdateLock = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { l = Locale.forLanguageTag(loc); } else { l = new Locale(loc.substring(0, 2)); } conf.locale = l; String tmpString = new Resources(mContext.getAssets(), dm, conf).getString(stringId); for (String reference: references) { if(reference.equals(tmpString)){ referencesUpdateLock = true; break; } } if(!referencesUpdateLock) { result.add(l); references.add(tmpString); } } conf.locale = originalLocale; return result; } LocalesDetector(Context context);   }
@Test public void testFetchAvailableLocales() throws Exception { }