mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-14 07:05:40 -04:00
Fix languages going back to english.
This commit is contained in:
parent
30370377e6
commit
7349dd54eb
@ -11,14 +11,11 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
LocaleUtils.setLocale(this);
|
||||||
Tools.setFullscreen(this);
|
Tools.setFullscreen(this);
|
||||||
Tools.updateWindowSize(this);
|
Tools.updateWindowSize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void attachBaseContext(Context base) {
|
|
||||||
super.attachBaseContext(LocaleUtils.setLocale(base));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startActivity(Intent i) {
|
public void startActivity(Intent i) {
|
||||||
|
@ -8,7 +8,7 @@ public class DisplayableLocale {
|
|||||||
private static Locale processStringLocale(String locale) {
|
private static Locale processStringLocale(String locale) {
|
||||||
if (locale.contains("-")) {
|
if (locale.contains("-")) {
|
||||||
String[] split = locale.split("-");
|
String[] split = locale.split("-");
|
||||||
return new Locale(split[0], split[1]);
|
return new Locale(split[0], split[1].toUpperCase());
|
||||||
} else {
|
} else {
|
||||||
return new Locale(locale);
|
return new Locale(locale);
|
||||||
}
|
}
|
||||||
|
@ -180,14 +180,7 @@ public class PojavLoginActivity extends BaseActivity {
|
|||||||
setContentView(R.layout.activity_pojav_login);
|
setContentView(R.layout.activity_pojav_login);
|
||||||
|
|
||||||
Spinner spinnerChgLang = findViewById(R.id.login_spinner_language);
|
Spinner spinnerChgLang = findViewById(R.id.login_spinner_language);
|
||||||
|
|
||||||
String defaultLang = LocaleUtils.DEFAULT_LOCALE.getDisplayName();
|
|
||||||
SpannableString defaultLangChar = new SpannableString(defaultLang);
|
|
||||||
defaultLangChar.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, defaultLang.length(), 0);
|
|
||||||
|
|
||||||
final ArrayAdapter<DisplayableLocale> langAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
|
final ArrayAdapter<DisplayableLocale> langAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item);
|
||||||
langAdapter.add(new DisplayableLocale(LocaleUtils.DEFAULT_LOCALE, defaultLangChar));
|
|
||||||
langAdapter.add(new DisplayableLocale(Locale.ENGLISH));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("language_list.txt")));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open("language_list.txt")));
|
||||||
@ -205,17 +198,15 @@ public class PojavLoginActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
langAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
langAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
|
||||||
|
|
||||||
int selectedLang = 0;
|
int selectedLang = getSelectorPosition(langAdapter, LocaleUtils.getLocale());
|
||||||
for (int i = 0; i < langAdapter.getCount(); i++) {
|
if (selectedLang == -1) selectedLang = getSelectorPosition(langAdapter, null);
|
||||||
if (Locale.getDefault().toString().equalsIgnoreCase(langAdapter.getItem(i).mLocale.toString())) {
|
|
||||||
selectedLang = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spinnerChgLang.setAdapter(langAdapter);
|
spinnerChgLang.setAdapter(langAdapter);
|
||||||
spinnerChgLang.setSelection(selectedLang);
|
if (selectedLang != -1){
|
||||||
|
spinnerChgLang.setSelection(selectedLang);
|
||||||
|
}
|
||||||
|
|
||||||
spinnerChgLang.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
spinnerChgLang.setOnItemSelectedListener(new Spinner.OnItemSelectedListener(){
|
||||||
private boolean isInitCalled;
|
private boolean isInitCalled;
|
||||||
@Override
|
@Override
|
||||||
@ -225,15 +216,7 @@ public class PojavLoginActivity extends BaseActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Locale locale;
|
Locale locale = langAdapter.getItem(position).mLocale;
|
||||||
if (position == 0) {
|
|
||||||
locale = LocaleUtils.DEFAULT_LOCALE;
|
|
||||||
} else if (position == 1) {
|
|
||||||
locale = Locale.ENGLISH;
|
|
||||||
} else {
|
|
||||||
locale = langAdapter.getItem(position).mLocale;
|
|
||||||
}
|
|
||||||
|
|
||||||
LauncherPreferences.PREF_LANGUAGE = locale.toString();
|
LauncherPreferences.PREF_LANGUAGE = locale.toString();
|
||||||
LauncherPreferences.DEFAULT_PREF.edit().putString("language", LauncherPreferences.PREF_LANGUAGE).apply();
|
LauncherPreferences.DEFAULT_PREF.edit().putString("language", LauncherPreferences.PREF_LANGUAGE).apply();
|
||||||
|
|
||||||
@ -256,6 +239,18 @@ public class PojavLoginActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
isSkipInit = true;
|
isSkipInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return The index in the array adapter for a given language, or english. -1 if not found */
|
||||||
|
public int getSelectorPosition(@NonNull ArrayAdapter<DisplayableLocale> langAdapter, @Nullable Locale locale){
|
||||||
|
String localeString = locale == null ? Locale.ENGLISH.toString() : locale.toString();
|
||||||
|
for (int i = 0; i < langAdapter.getCount(); i++) {
|
||||||
|
if (localeString.equalsIgnoreCase(langAdapter.getItem(i).mLocale.toString())) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
|
@ -1,37 +1,60 @@
|
|||||||
package net.kdt.pojavlaunch.utils;
|
package net.kdt.pojavlaunch.utils;
|
||||||
|
|
||||||
|
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_LANGUAGE;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.content.res.*;
|
import android.content.res.*;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.preference.*;
|
import androidx.preference.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import net.kdt.pojavlaunch.prefs.*;
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
|
||||||
public class LocaleUtils {
|
public class LocaleUtils {
|
||||||
public static final Locale DEFAULT_LOCALE;
|
|
||||||
|
private static Locale CURRENT_LOCALE;
|
||||||
static {
|
|
||||||
DEFAULT_LOCALE = Locale.getDefault();
|
public static Locale getLocale(){
|
||||||
|
return Locale.getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Context setLocale(Context context) {
|
public static Context setLocale(Context context) {
|
||||||
if (LauncherPreferences.DEFAULT_PREF == null) {
|
if (LauncherPreferences.DEFAULT_PREF == null) {
|
||||||
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context);
|
LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
LauncherPreferences.loadPreferences(context);
|
LauncherPreferences.loadPreferences(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
Locale locale;
|
|
||||||
if (LauncherPreferences.PREF_LANGUAGE.equals("default")) {
|
if (LauncherPreferences.PREF_LANGUAGE.equals("default")) {
|
||||||
locale = DEFAULT_LOCALE;
|
CURRENT_LOCALE = getLocale();
|
||||||
} else {
|
} else {
|
||||||
locale = new Locale(LauncherPreferences.PREF_LANGUAGE);
|
if(CURRENT_LOCALE == null || !PREF_LANGUAGE.equalsIgnoreCase(CURRENT_LOCALE.toString())){
|
||||||
|
String[] localeString;
|
||||||
|
if(PREF_LANGUAGE.contains("_")){
|
||||||
|
localeString = PREF_LANGUAGE.split("_");
|
||||||
|
}else{
|
||||||
|
localeString = new String[]{PREF_LANGUAGE, ""};
|
||||||
|
}
|
||||||
|
CURRENT_LOCALE = new Locale(localeString[0], localeString[1]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Locale.setDefault(locale);
|
Locale.setDefault(CURRENT_LOCALE);
|
||||||
|
|
||||||
Resources res = context.getResources();
|
Resources res = context.getResources();
|
||||||
Configuration config = new Configuration(res.getConfiguration());
|
Configuration config = res.getConfiguration();
|
||||||
config.setLocale(locale);
|
|
||||||
context = context.createConfigurationContext(config);
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
|
config.setLocale(CURRENT_LOCALE);
|
||||||
|
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
|
||||||
|
} else {
|
||||||
|
config.locale = CURRENT_LOCALE;
|
||||||
|
context.getApplicationContext().createConfigurationContext(config);
|
||||||
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user