move languages to preferences
This commit is contained in:
parent
26c70f6932
commit
85f4a93c11
|
@ -2,7 +2,9 @@ package info.nightscout.androidaps;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -101,7 +103,14 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onStatusEvent(final EventRefreshGui ev) {
|
public void onStatusEvent(final EventRefreshGui ev) {
|
||||||
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||||
|
String lang = SP.getString("language", "en");
|
||||||
|
LocaleHelper.setLocale(getApplicationContext(), lang);
|
||||||
|
recreate();
|
||||||
|
try { // activity may be destroyed
|
||||||
setUpTabs(true);
|
setUpTabs(true);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setUpTabs(boolean switchToLast) {
|
private void setUpTabs(boolean switchToLast) {
|
||||||
|
@ -134,22 +143,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
case R.id.nav_resetdb:
|
case R.id.nav_resetdb:
|
||||||
MainApp.getDbHelper().resetDatabases();
|
MainApp.getDbHelper().resetDatabases();
|
||||||
break;
|
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:
|
case R.id.nav_export:
|
||||||
ImportExportPrefs.verifyStoragePermissions(this);
|
ImportExportPrefs.verifyStoragePermissions(this);
|
||||||
ImportExportPrefs.exportSharedPreferences(this);
|
ImportExportPrefs.exportSharedPreferences(this);
|
||||||
|
@ -158,7 +151,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
ImportExportPrefs.verifyStoragePermissions(this);
|
ImportExportPrefs.verifyStoragePermissions(this);
|
||||||
ImportExportPrefs.importSharedPreferences(this);
|
ImportExportPrefs.importSharedPreferences(this);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_testalarm:
|
case R.id.nav_test_alarm:
|
||||||
final int REQUEST_CODE_ASK_PERMISSIONS = 2355;
|
final int REQUEST_CODE_ASK_PERMISSIONS = 2355;
|
||||||
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);
|
int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.SYSTEM_ALERT_WINDOW);
|
||||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
@ -171,7 +164,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Intent alarmServiceIntent = new Intent(getApplicationContext(), AlarmService.class);
|
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);
|
getApplicationContext().startService(alarmServiceIntent);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_exit:
|
case R.id.nav_exit:
|
||||||
|
|
|
@ -4,10 +4,11 @@ import android.content.SharedPreferences;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
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 {
|
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
@Override
|
@Override
|
||||||
|
@ -20,12 +21,20 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
MainApp.bus().post(new EventPreferenceChange());
|
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 {
|
public static class MyPreferenceFragment extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle savedInstanceState) {
|
public void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.pref_language);
|
||||||
addPreferencesFromResource(R.xml.pref_treatments);
|
addPreferencesFromResource(R.xml.pref_treatments);
|
||||||
if (Config.APS)
|
if (Config.APS)
|
||||||
addPreferencesFromResource(R.xml.pref_closedmode);
|
addPreferencesFromResource(R.xml.pref_closedmode);
|
||||||
|
|
|
@ -16,21 +16,6 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_test_alarm"
|
android:id="@+id/nav_test_alarm"
|
||||||
android:title="@string/nav_test_alarm" />
|
android:title="@string/nav_test_alarm" />
|
||||||
<item
|
|
||||||
android:id="@+id/en_lang"
|
|
||||||
android:title="@string/en_lang" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/cs_lang"
|
|
||||||
android:title="@string/cs_lang" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/de_lang"
|
|
||||||
android:title="@string/de_lang" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/bg_lang"
|
|
||||||
android:title="@string/bg_lang" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/nav_testalarm"
|
|
||||||
android:title="@string/testalarm" />
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_exit"
|
android:id="@+id/nav_exit"
|
||||||
android:title="@string/nav_exit" />
|
android:title="@string/nav_exit" />
|
||||||
|
|
|
@ -218,6 +218,6 @@
|
||||||
<string name="openapsma_maxiob_summary">Maximální nebolusové IOB, které může OpenAPS použít</string>
|
<string name="openapsma_maxiob_summary">Maximální nebolusové IOB, které může OpenAPS použít</string>
|
||||||
<string name="openapsma_targetrange_label">Cílový rozsah pro OpenAPS</string>
|
<string name="openapsma_targetrange_label">Cílový rozsah pro OpenAPS</string>
|
||||||
<string name="bg_lang">Bulgarian</string>
|
<string name="bg_lang">Bulgarian</string>
|
||||||
<string name="testalarm">Test alarmu</string>
|
|
||||||
<string name="dismiss">POTVRDIT</string>
|
<string name="dismiss">POTVRDIT</string>
|
||||||
|
<string name="language">Jazyk</string>
|
||||||
</resources>
|
</resources>
|
|
@ -9,4 +9,15 @@
|
||||||
<item>closed</item>
|
<item>closed</item>
|
||||||
<item>open</item>
|
<item>open</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="languagesArray">
|
||||||
|
<item>@string/en_lang</item>
|
||||||
|
<item>@string/cs_lang</item>
|
||||||
|
<item>@string/bg_lang</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="languagesValues" translatable="false">
|
||||||
|
<item>en</item>
|
||||||
|
<item>cs</item>
|
||||||
|
<item>bg</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
|
@ -226,7 +226,7 @@
|
||||||
<string name="openapsma_maxbasal_title">Max Basal</string>
|
<string name="openapsma_maxbasal_title">Max Basal</string>
|
||||||
<string name="openapsma_maxbasaliob_title">Max Basal IOB</string>
|
<string name="openapsma_maxbasaliob_title">Max Basal IOB</string>
|
||||||
<string name="bg_lang">Bulgarian</string>
|
<string name="bg_lang">Bulgarian</string>
|
||||||
<string name="testalarm">Alarm test</string>
|
|
||||||
<string name="dismiss">DISMISS</string>
|
<string name="dismiss">DISMISS</string>
|
||||||
|
<string name="language">Language</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
14
app/src/main/res/xml/pref_language.xml
Normal file
14
app/src/main/res/xml/pref_language.xml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="language"
|
||||||
|
android:title="@string/language">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:title="@string/language"
|
||||||
|
android:defaultValue="en"
|
||||||
|
android:entries="@array/languagesArray"
|
||||||
|
android:entryValues="@array/languagesValues"
|
||||||
|
android:key="language" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
</PreferenceScreen>
|
Loading…
Reference in a new issue