use of org.odk.collect.android.utilities.LocaleHelper in project collect by opendatakit.
the class Collect method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// noinspection deprecation
defaultSysLanguage = newConfig.locale.getLanguage();
boolean isUsingSysLanguage = GeneralSharedPreferences.getInstance().get(KEY_APP_LANGUAGE).equals("");
if (!isUsingSysLanguage) {
new LocaleHelper().updateLocale(this);
}
}
use of org.odk.collect.android.utilities.LocaleHelper in project collect by opendatakit.
the class UserInterfacePreferencesFragment method initLanguagePrefs.
private void initLanguagePrefs() {
final ListPreference pref = findPreference(KEY_APP_LANGUAGE);
if (pref != null) {
final LocaleHelper localeHelper = new LocaleHelper();
TreeMap<String, String> languageList = localeHelper.getEntryListValues();
ArrayList<String> entryValues = new ArrayList<>();
entryValues.add(0, "");
entryValues.addAll(languageList.values());
pref.setEntryValues(entryValues.toArray(new String[0]));
ArrayList<String> entries = new ArrayList<>();
entries.add(0, getActivity().getResources().getString(R.string.use_device_language));
entries.addAll(languageList.keySet());
pref.setEntries(entries.toArray(new String[0]));
if (pref.getValue() == null) {
// set Default value to "Use phone locale"
pref.setValueIndex(0);
}
pref.setSummary(pref.getEntry());
pref.setOnPreferenceChangeListener((preference, newValue) -> {
int index = ((ListPreference) preference).findIndexOfValue(newValue.toString());
String entry = (String) ((ListPreference) preference).getEntries()[index];
preference.setSummary(entry);
settingsProvider.getUnprotectedSettings().save(KEY_APP_LANGUAGE, newValue.toString());
startActivityAndCloseAllOthers(getActivity(), MainMenuActivity.class);
return true;
});
}
}
use of org.odk.collect.android.utilities.LocaleHelper in project collect by opendatakit.
the class UserInterfacePreferences method initLanguagePrefs.
private void initLanguagePrefs() {
final ListPreference pref = (ListPreference) findPreference(KEY_APP_LANGUAGE);
if (pref != null) {
final LocaleHelper localeHelper = new LocaleHelper();
TreeMap<String, String> languageList = localeHelper.getEntryListValues();
int length = languageList.size() + 1;
ArrayList<String> entryValues = new ArrayList<>();
entryValues.add(0, "");
entryValues.addAll(languageList.values());
pref.setEntryValues(entryValues.toArray(new String[length]));
ArrayList<String> entries = new ArrayList<>();
entries.add(0, getActivity().getResources().getString(R.string.use_device_language));
entries.addAll(languageList.keySet());
pref.setEntries(entries.toArray(new String[length]));
if (pref.getValue() == null) {
// set Default value to "Use phone locale"
pref.setValueIndex(0);
}
pref.setSummary(pref.getEntry());
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int index = ((ListPreference) preference).findIndexOfValue(newValue.toString());
String entry = (String) ((ListPreference) preference).getEntries()[index];
preference.setSummary(entry);
SharedPreferences.Editor edit = PreferenceManager.getDefaultSharedPreferences(getActivity()).edit();
edit.putString(KEY_APP_LANGUAGE, newValue.toString());
edit.apply();
localeHelper.updateLocale(getActivity());
Intent intent = new Intent(getActivity().getBaseContext(), MainMenuActivity.class);
getActivity().startActivity(intent);
getActivity().overridePendingTransition(0, 0);
getActivity().finishAffinity();
return true;
}
});
}
}
use of org.odk.collect.android.utilities.LocaleHelper in project collect by opendatakit.
the class Collect method onCreate.
@Override
public void onCreate() {
super.onCreate();
singleton = this;
DaggerAppComponent.builder().application(this).build().inject(this);
reloadSharedPreferences();
PRNGFixes.apply();
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
JodaTimeAndroid.init(this);
defaultSysLanguage = Locale.getDefault().getLanguage();
new LocaleHelper().updateLocale(this);
FormMetadataMigrator.migrate(PreferenceManager.getDefaultSharedPreferences(this));
AutoSendPreferenceMigrator.migrate();
initProperties();
AuthDialogUtility.setWebCredentialsFromPreferences();
if (BuildConfig.BUILD_TYPE.equals("odkCollectRelease")) {
Timber.plant(new CrashReportingTree());
} else {
Timber.plant(new Timber.DebugTree());
}
setupLeakCanary();
}
Aggregations