diff --git a/gradle.properties b/gradle.properties index d8a67c0e6..c33871539 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=3.3.2-SNAPSHOT +VERSION_NAME=4.0.0-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application diff --git a/opensrp-app/build.gradle b/opensrp-app/build.gradle index ab514892b..9d7ede221 100644 --- a/opensrp-app/build.gradle +++ b/opensrp-app/build.gradle @@ -164,7 +164,7 @@ dependencies { implementation 'net.zetetic:android-database-sqlcipher:4.2.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'org.codehaus.jackson:jackson-core-asl:1.9.13' - implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation "org.apache.httpcomponents:httpmime:4.5.6" implementation group: 'commons-codec', name: 'commons-codec', version: '1.10' diff --git a/opensrp-app/src/main/java/org/smartregister/util/LangUtils.java b/opensrp-app/src/main/java/org/smartregister/util/LangUtils.java index b2decf860..4532f402c 100644 --- a/opensrp-app/src/main/java/org/smartregister/util/LangUtils.java +++ b/opensrp-app/src/main/java/org/smartregister/util/LangUtils.java @@ -3,6 +3,8 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; +import android.os.Build; +import android.os.LocaleList; import android.preference.PreferenceManager; import org.smartregister.repository.AllSharedPreferences; @@ -25,19 +27,34 @@ public static String getLanguage(Context ctx) { return allSharedPreferences.fetchLanguagePreference(); } - public static Context setAppLocale(Context context, String language) { - Locale locale = new Locale(language); - + public static Configuration setAppLocale(Context context, String language) { Resources res = context.getResources(); - Configuration conf = res.getConfiguration(); - conf.setLocale(locale); + Configuration configuration = res.getConfiguration(); + try { - context = context.createConfigurationContext(conf); + Locale locale = new Locale(language); + + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + configuration.setLocale(locale); + + LocaleList localeList = new LocaleList(locale); + LocaleList.setDefault(localeList); + configuration.setLocales(localeList); + + context.createConfigurationContext(configuration); + + } else { + configuration.locale = locale; + res.updateConfiguration(configuration, res.getDisplayMetrics()); + } + + } catch (Exception e) { Timber.e(e); } - return context; + return configuration; } } diff --git a/opensrp-app/src/main/java/org/smartregister/view/activity/BarcodeScanActivity.java b/opensrp-app/src/main/java/org/smartregister/view/activity/BarcodeScanActivity.java index 11ab66b19..8c4936197 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/activity/BarcodeScanActivity.java +++ b/opensrp-app/src/main/java/org/smartregister/view/activity/BarcodeScanActivity.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.res.Configuration; import android.os.Bundle; import android.os.Vibrator; import android.util.SparseArray; @@ -31,12 +32,15 @@ public class BarcodeScanActivity extends Activity implements Detector.Processor< private CameraSource cameraSource; private CameraSourcePreview cameraSourcePreview; - @Override protected void attachBaseContext(Context base) { // get language from prefs String lang = LangUtils.getLanguage(base.getApplicationContext()); - super.attachBaseContext(LangUtils.setAppLocale(base, lang)); + Configuration newConfiguration = LangUtils.setAppLocale(base, lang); + + super.attachBaseContext(base); + + applyOverrideConfiguration(newConfiguration); } @Override diff --git a/opensrp-app/src/main/java/org/smartregister/view/activity/MultiLanguageActivity.java b/opensrp-app/src/main/java/org/smartregister/view/activity/MultiLanguageActivity.java index e907e5d3f..0886edc49 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/activity/MultiLanguageActivity.java +++ b/opensrp-app/src/main/java/org/smartregister/view/activity/MultiLanguageActivity.java @@ -1,14 +1,15 @@ package org.smartregister.view.activity; import android.content.res.Configuration; -import android.os.Build; import androidx.appcompat.app.AppCompatActivity; import org.smartregister.util.LangUtils; -/** Use this class to ensure your activities have multi-language support +/** + * Use this class to ensure your activities have multi-language support + * * @author Rodgers Andati * @since 2019-05-03 */ @@ -18,20 +19,12 @@ public class MultiLanguageActivity extends AppCompatActivity { protected void attachBaseContext(android.content.Context base) { // get language from prefs String lang = LangUtils.getLanguage(base.getApplicationContext()); - super.attachBaseContext(LangUtils.setAppLocale(base, lang)); - } + Configuration newConfiguration = LangUtils.setAppLocale(base, lang); - //solution borrowed from - // https://stackoverflow.com/questions/55265834/change-locale-not-work-after-migrate-to-androidx/61420643#61420643 - @Override - public void applyOverrideConfiguration(Configuration overrideConfiguration) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && - Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - // add this to fix androidx.appcompat:appcompat 1.1.0 bug - // which happens on Android 6.x ~ 7.x - getResources(); - } - super.applyOverrideConfiguration(overrideConfiguration); + super.attachBaseContext(base); + + applyOverrideConfiguration(newConfiguration); } + } diff --git a/opensrp-app/src/main/java/org/smartregister/view/activity/SettingsActivity.java b/opensrp-app/src/main/java/org/smartregister/view/activity/SettingsActivity.java index 1839e8e47..d83f2a023 100644 --- a/opensrp-app/src/main/java/org/smartregister/view/activity/SettingsActivity.java +++ b/opensrp-app/src/main/java/org/smartregister/view/activity/SettingsActivity.java @@ -3,6 +3,7 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; +import android.content.res.Configuration; import android.os.Bundle; import android.preference.EditTextPreference; import android.preference.Preference; @@ -32,8 +33,13 @@ public class SettingsActivity extends PreferenceActivity implements Preference.O @Override protected void attachBaseContext(android.content.Context base) { // get language from prefs + String lang = LangUtils.getLanguage(base.getApplicationContext()); - super.attachBaseContext(LangUtils.setAppLocale(base, lang)); + Configuration newConfiguration = LangUtils.setAppLocale(base, lang); + + super.attachBaseContext(base); + + applyOverrideConfiguration(newConfiguration); } @Override