Exemplo n.º 1
0
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.N)
 public void apply(Context context, boolean configChanged) {
   if (!ConcurrentUtils.isMain()) {
     return;
   }
   Resources resources = context.getApplicationContext().getResources();
   Configuration configuration = resources.getConfiguration();
   if (systemLocales == null) {
     systemLocales = list(configuration);
   }
   if (configChanged) {
     ArrayList<Locale> locales = list(configuration);
     if (previousLocales != null) {
       if (locales.equals(previousLocales)) {
         return;
       }
       systemLocales = locales;
     }
   }
   Locale locale = VALUES_LOCALE_OBJECTS.get(Preferences.getLocale());
   boolean applySystem = false;
   if (locale == null) {
     locale = systemLocales.isEmpty() ? Locale.getDefault() : systemLocales.get(0);
     applySystem = true;
   }
   if (C.API_NOUGAT) {
     if (applySystem) {
       configuration.setLocales(new LocaleList(CommonUtils.toArray(systemLocales, Locale.class)));
       previousLocales = systemLocales;
     } else {
       ArrayList<Locale> locales = new ArrayList<>();
       if (!locale.equals(Locale.US)) {
         locales.add(locale);
       }
       locales.add(Locale.US);
       configuration.setLocales(new LocaleList(CommonUtils.toArray(locales, Locale.class)));
       previousLocales = locales;
     }
   } else {
     configuration.locale = locale;
     previousLocales = list(configuration);
   }
   resources.updateConfiguration(configuration, resources.getDisplayMetrics());
   ChanManager.getInstance().updateConfiguration(configuration, resources.getDisplayMetrics());
 }
Exemplo n.º 2
0
 @SuppressWarnings("deprecation")
 @TargetApi(Build.VERSION_CODES.N)
 public void apply(Activity activity) {
   if (previousLocales != null && !previousLocales.isEmpty()) {
     Resources resources = activity.getResources();
     Configuration configuration = resources.getConfiguration();
     if (C.API_NOUGAT) {
       configuration.setLocales(
           new LocaleList(CommonUtils.toArray(previousLocales, Locale.class)));
     } else {
       configuration.locale = previousLocales.get(0);
     }
     resources.updateConfiguration(configuration, resources.getDisplayMetrics());
   }
 }