From f7a2a79d0011af7f391ce8285ac72005e6afbac6 Mon Sep 17 00:00:00 2001 From: Bart Date: Tue, 5 Jan 2021 16:20:43 +0100 Subject: [PATCH] Language can be changed, doesn't refresh automatically yet --- .../com/a1/nextlocation/MainActivity.java | 4 ++-- .../fragments/SettingsFragment.java | 11 +++++----- app/src/main/res/values-nl/strings.xml | 20 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/values-nl/strings.xml diff --git a/app/src/main/java/com/a1/nextlocation/MainActivity.java b/app/src/main/java/com/a1/nextlocation/MainActivity.java index dc3b7cf..91268f0 100644 --- a/app/src/main/java/com/a1/nextlocation/MainActivity.java +++ b/app/src/main/java/com/a1/nextlocation/MainActivity.java @@ -70,7 +70,7 @@ public class MainActivity extends AppCompatActivity { */ private String loadLocale(){ SharedPreferences sharedPreferences = getSharedPreferences("Settings", Activity.MODE_PRIVATE); - return sharedPreferences.getString("Language", ""); + return sharedPreferences.getString("Language", "nl"); } /** @@ -82,7 +82,7 @@ public class MainActivity extends AppCompatActivity { Locale.setDefault(locale); Configuration configuration = new Configuration(); configuration.setLocale(locale); - getBaseContext().getResources().getConfiguration().updateFrom(configuration); + getBaseContext().getResources().updateConfiguration(configuration, getBaseContext().getResources().getDisplayMetrics()); } diff --git a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java index 236ea8c..eaffcb0 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/SettingsFragment.java @@ -55,7 +55,8 @@ public class SettingsFragment extends Fragment { languageDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { - setLocale(dropdownPositionToLanguage(position)); + setLocale(dropdownPositionToLanguage(id)); + } @Override @@ -67,11 +68,11 @@ public class SettingsFragment extends Fragment { /** * converts the languageDropdown position to the belonging language - * @param position desired position to convert + * @param id desired position to convert * @return the language belonging to the position of the languageDropdown */ - private String dropdownPositionToLanguage(int position) { - switch (position){ + private String dropdownPositionToLanguage(long id) { + switch ((int) id){ case 0: return "nl"; case 1: @@ -106,7 +107,7 @@ public class SettingsFragment extends Fragment { Locale.setDefault(locale); Configuration config = new Configuration(); config.setLocale(locale); - getContext().getResources().getConfiguration().updateFrom(config); + getContext().getResources().updateConfiguration(config, getContext().getResources().getDisplayMetrics()); editor.putString("Language", language); editor.apply(); } diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml new file mode 100644 index 0000000..289db4c --- /dev/null +++ b/app/src/main/res/values-nl/strings.xml @@ -0,0 +1,20 @@ + + + + Next Location + Locaties + Routes + Statistieken + Instellingen + Taal + Imperiaal systeem + 65+ stand + Kleurenblind + Totale afstand: + Bezochte locaties: + Totale tijd: + Coupons gespaard: + Coupons + Start Route + + \ No newline at end of file