mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
#13 add an option to force language X
This commit is contained in:
parent
aa1893c36c
commit
f0cd86b7a5
29 changed files with 184 additions and 2 deletions
40
app/src/main/java/com/geeksville/mesh/BaseActivity.kt
Normal file
40
app/src/main/java/com/geeksville/mesh/BaseActivity.kt
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package com.geeksville.mesh
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.geeksville.android.Logging
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import java.util.*
|
||||
|
||||
open class BaseActivity: AppCompatActivity(), Logging {
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
val res = newBase.resources
|
||||
val config = res.configuration
|
||||
|
||||
// get chosen language from preference
|
||||
val prefs = UIViewModel.getPreferences(newBase)
|
||||
val langCode = prefs.getString("lang","zz")
|
||||
debug("langCode is $langCode")
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 17) {
|
||||
val locale = if (langCode == "zz")
|
||||
Locale.getDefault()
|
||||
else
|
||||
Locale(langCode)
|
||||
config.setLocale(locale)
|
||||
|
||||
if(Build.VERSION.SDK_INT > 24) {
|
||||
//Using createNewConfigurationContext will cause CompanionDeviceManager to crash
|
||||
applyOverrideConfiguration(config)
|
||||
super.attachBaseContext(newBase)
|
||||
}else {
|
||||
super.attachBaseContext(newBase.createConfigurationContext(config))
|
||||
}
|
||||
} else {
|
||||
super.attachBaseContext(newBase)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue