Search in sources :

Example 1 with LocaleHelper

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);
    }
}
Also used : LocaleHelper(org.odk.collect.android.utilities.LocaleHelper)

Example 2 with LocaleHelper

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;
        });
    }
}
Also used : LocaleHelper(org.odk.collect.android.utilities.LocaleHelper) ArrayList(java.util.ArrayList) ListPreference(androidx.preference.ListPreference)

Example 3 with LocaleHelper

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;
            }
        });
    }
}
Also used : LocaleHelper(org.odk.collect.android.utilities.LocaleHelper) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) MainMenuActivity(org.odk.collect.android.activities.MainMenuActivity) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Example 4 with LocaleHelper

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();
}
Also used : LocaleHelper(org.odk.collect.android.utilities.LocaleHelper) Timber(timber.log.Timber)

Aggregations

LocaleHelper (org.odk.collect.android.utilities.LocaleHelper)4 ArrayList (java.util.ArrayList)2 Intent (android.content.Intent)1 ListPreference (android.preference.ListPreference)1 Preference (android.preference.Preference)1 ListPreference (androidx.preference.ListPreference)1 MainMenuActivity (org.odk.collect.android.activities.MainMenuActivity)1 Timber (timber.log.Timber)1