diff --git a/app/src/main/java/info/nightscout/androidaps/MainActivity.java b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
index ac3d722782..79ee307666 100644
--- a/app/src/main/java/info/nightscout/androidaps/MainActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/MainActivity.java
@@ -2,7 +2,9 @@ package info.nightscout.androidaps;
import android.Manifest;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
+import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
@@ -101,7 +103,14 @@ public class MainActivity extends AppCompatActivity {
@Subscribe
public void onStatusEvent(final EventRefreshGui ev) {
- setUpTabs(true);
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ String lang = SP.getString("language", "en");
+ LocaleHelper.setLocale(getApplicationContext(), lang);
+ recreate();
+ try { // activity may be destroyed
+ setUpTabs(true);
+ } catch (IllegalStateException e) {
+ }
}
private void setUpTabs(boolean switchToLast) {
@@ -134,22 +143,6 @@ public class MainActivity extends AppCompatActivity {
case R.id.nav_resetdb:
MainApp.getDbHelper().resetDatabases();
break;
- case R.id.en_lang:
- LocaleHelper.setLocale(this, "en");
- recreate();
- break;
- case R.id.cs_lang:
- LocaleHelper.setLocale(this, "cs");
- recreate();
- break;
- case R.id.de_lang:
- LocaleHelper.setLocale(this, "de");
- recreate();
- break;
- case R.id.bg_lang:
- LocaleHelper.setLocale(this, "bg");
- recreate();
- break;
case R.id.nav_export:
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.exportSharedPreferences(this);
@@ -158,7 +151,7 @@ public class MainActivity extends AppCompatActivity {
ImportExportPrefs.verifyStoragePermissions(this);
ImportExportPrefs.importSharedPreferences(this);
break;
- case R.id.nav_testalarm:
+ case R.id.nav_test_alarm:
final int REQUEST_CODE_ASK_PERMISSIONS = 2355;
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);
if (permission != PackageManager.PERMISSION_GRANTED) {
@@ -171,7 +164,7 @@ public class MainActivity extends AppCompatActivity {
);
}
Intent alarmServiceIntent = new Intent(getApplicationContext(), AlarmService.class);
- alarmServiceIntent.putExtra("alarmText",getString(R.string.testalarm));
+ alarmServiceIntent.putExtra("alarmText", getString(R.string.nav_test_alarm));
getApplicationContext().startService(alarmServiceIntent);
break;
case R.id.nav_exit:
diff --git a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
index 6fe9233979..d3b9a1aca6 100644
--- a/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
+++ b/app/src/main/java/info/nightscout/androidaps/PreferencesActivity.java
@@ -4,10 +4,11 @@ import android.content.SharedPreferences;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
-import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import info.nightscout.androidaps.events.EventPreferenceChange;
+import info.nightscout.androidaps.events.EventRefreshGui;
+import info.nightscout.utils.LocaleHelper;
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
@@ -20,12 +21,20 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
MainApp.bus().post(new EventPreferenceChange());
+ if (key.equals("language")) {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ String lang = SP.getString("language", "en");
+ LocaleHelper.setLocale(getApplicationContext(), lang);
+ recreate();
+ MainApp.bus().post(new EventRefreshGui());
+ }
}
public static class MyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.pref_language);
addPreferencesFromResource(R.xml.pref_treatments);
if (Config.APS)
addPreferencesFromResource(R.xml.pref_closedmode);
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index cd93dc0c16..e47ec49e4b 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -16,21 +16,6 @@
-
-
-
-
-
diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml
index 1e36f5c90a..1fa1bf28a5 100644
--- a/app/src/main/res/values-cs/strings.xml
+++ b/app/src/main/res/values-cs/strings.xml
@@ -218,6 +218,6 @@
Maximální nebolusové IOB, které může OpenAPS použít
Cílový rozsah pro OpenAPS
Bulgarian
- Test alarmu
POTVRDIT
+ Jazyk
\ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 4b4edfe128..f773dd3555 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -9,4 +9,15 @@
- closed
- open
+
+
+ - @string/en_lang
+ - @string/cs_lang
+ - @string/bg_lang
+
+
+ - en
+ - cs
+ - bg
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 22ba73453f..028744ed49 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -226,7 +226,7 @@
Max Basal
Max Basal IOB
Bulgarian
- Alarm test
DISMISS
+ Language
diff --git a/app/src/main/res/xml/pref_language.xml b/app/src/main/res/xml/pref_language.xml
new file mode 100644
index 0000000000..562089e27c
--- /dev/null
+++ b/app/src/main/res/xml/pref_language.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
\ No newline at end of file