Android: Add language override setting

This commit is contained in:
Connor McLaughlin 2020-12-09 01:29:15 +10:00
parent 98766a490f
commit 300510f20a
5 changed files with 45 additions and 0 deletions

View file

@ -9,6 +9,7 @@ import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;
public class AndroidHostInterface {
public final static int DISPLAY_ALIGNMENT_TOP_OR_LEFT = 0;

View file

@ -6,6 +6,8 @@ import android.content.ClipboardManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
@ -30,6 +32,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
@ -42,6 +45,25 @@ public class MainActivity extends AppCompatActivity {
private ListView mGameListView;
private boolean mHasExternalStoragePermissions = false;
private void setLanguage() {
String language = PreferenceManager.getDefaultSharedPreferences(this).getString("Main/Language", "none");
if (language == null || language.equals("none")) {
return;
}
String[] parts = language.split("-");
if (parts.length < 2)
return;
Locale locale = new Locale(parts[0], parts[1]);
Locale.setDefault(locale);
Resources res = getResources();
Configuration config = res.getConfiguration();
config.setLocale(locale);
res.updateConfiguration(config, res.getDisplayMetrics());
}
private boolean shouldResumeStateByDefault() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
return prefs.getBoolean("Main/SaveStateOnExit", true);
@ -59,6 +81,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setLanguage();
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);

View file

@ -421,4 +421,16 @@
<item>portrait</item>
<item>landscape</item>
</string-array>
<string-array name="settings_language_entries">
<item>Use Device Setting</item>
<item>English</item>
<item>Portuguese (pt) in Brazil (BR)</item>
<item>Italian (it)</item>
</string-array>
<string-array name="settings_language_values">
<item>none</item>
<item>en-EN</item>
<item>pt-rBR</item>
<item>it-IT</item>
</string-array>
</resources>

View file

@ -151,4 +151,5 @@
<string name="main_activity_copy">Copy</string>
<string name="settings_gpu_thread">Threaded GPU Rendering</string>
<string name="settings_summary_gpu_thread">Uses a second thread for drawing graphics. Currently only available for the software renderer, but can provide a significant speed improvement, and is safe to use.</string>
<string name="settings_language">Language (restart to apply)</string>
</resources>

View file

@ -15,6 +15,14 @@
-->
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<ListPreference
app:key="Main/Language"
app:title="@string/settings_language"
app:defaultValue="none"
app:entries="@array/settings_language_entries"
app:entryValues="@array/settings_language_values"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false" />
<ListPreference
app:key="CPU/Overclock"
app:title="@string/settings_cpu_overclocking"