diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseActivity.java index 45a52a59b..248fa7b34 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/BaseActivity.java @@ -8,6 +8,12 @@ import net.kdt.pojavlaunch.utils.*; import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH; public abstract class BaseActivity extends AppCompatActivity { + + @Override + protected void attachBaseContext(Context newBase) { + super.attachBaseContext(LocaleUtils.setLocale(newBase)); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java index 9a1c22167..fe8f31c14 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/LocaleUtils.java @@ -6,31 +6,47 @@ import static net.kdt.pojavlaunch.prefs.LauncherPreferences.DEFAULT_PREF; import android.content.*; import android.content.res.*; import android.os.Build; +import android.os.LocaleList; +import androidx.core.os.ConfigurationCompat; import androidx.preference.*; import java.util.*; import net.kdt.pojavlaunch.prefs.*; -public class LocaleUtils { +public class LocaleUtils extends ContextWrapper { + + public LocaleUtils(Context base) { + super(base); + } public static Locale getLocale(){ return Locale.getDefault(); } - public static Context setLocale(Context context) { + public static ContextWrapper setLocale(Context context) { if (DEFAULT_PREF == null) { DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context); LauncherPreferences.loadPreferences(context); } if(DEFAULT_PREF.getBoolean("force_english", false)){ - Locale locale = Locale.ENGLISH; - Locale.setDefault(locale); - Configuration config = context.getResources().getConfiguration(); - config.locale = locale; - context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); + Resources resources = context.getResources(); + Configuration configuration = resources.getConfiguration(); + + configuration.setLocale(Locale.ENGLISH); + Locale.setDefault(Locale.ENGLISH); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ + LocaleList localeList = new LocaleList(Locale.ENGLISH); + LocaleList.setDefault(localeList); + configuration.setLocales(localeList); + } + + resources.updateConfiguration(configuration, resources.getDisplayMetrics()); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1){ + context = context.createConfigurationContext(configuration); + } } - return context; + return new LocaleUtils(context); } }