diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b6022be --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 46161db..caed06f 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ class MyApp : Application() { private val localeAppDelegate = LocaleHelperApplicationDelegate() override fun attachBaseContext(base: Context) { + LocaleHelper.configurationBlock = { + //Access configuration object to set exta setting + //For eg: FontScale + it.fontScale = 1.0f + } super.attachBaseContext(localeAppDelegate.attachBaseContext(base)) } @@ -77,6 +82,11 @@ open class BaseActivity : AppCompatActivity() { override fun getDelegate() = localeDelegate.getAppCompatDelegate(super.getDelegate()) override fun attachBaseContext(newBase: Context) { + LocaleHelper.configurationBlock = { + //Access configuration object to set exta setting + //For eg: FontScale + it.fontScale = 1.0f + } super.attachBaseContext(localeDelegate.attachBaseContext(newBase)) } diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt index 9df914e..db5b83b 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt @@ -5,14 +5,24 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM import androidx.multidex.MultiDex import com.zeugmasolutions.localehelper.LocaleAwareApplication +import com.zeugmasolutions.localehelper.LocaleHelper class Application : LocaleAwareApplication() { + + companion object { + var FONT_SCALE = 1.0f + } + override fun onCreate() { super.onCreate() AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM) } override fun attachBaseContext(base: Context) { + LocaleHelper.configurationBlock = { + it.fontScale = FONT_SCALE + } + super.attachBaseContext(base) MultiDex.install(this) } diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt b/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt index 2ca9d40..7b49c06 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt @@ -1,13 +1,23 @@ package com.zeugmasolutions.localeexample +import android.content.Context import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AppCompatDelegate import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES import com.zeugmasolutions.localehelper.LocaleAwareCompatActivity +import com.zeugmasolutions.localehelper.LocaleHelper open class BaseActivity : LocaleAwareCompatActivity() { + + override fun attachBaseContext(newBase: Context) { + LocaleHelper.configurationBlock = { + it.fontScale = Application.FONT_SCALE + } + super.attachBaseContext(newBase) + } + override fun onCreateOptionsMenu(menu: Menu?): Boolean { menuInflater.inflate(R.menu.main_menu, menu) return true diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/MainActivity.kt b/app/src/main/java/com/zeugmasolutions/localeexample/MainActivity.kt index 0041f6d..59d1889 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/MainActivity.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/MainActivity.kt @@ -1,11 +1,14 @@ package com.zeugmasolutions.localeexample import android.content.Intent +import android.os.Build import android.os.Bundle +import android.widget.SeekBar import com.zeugmasolutions.localehelper.Locales import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.view_language_buttons.* import java.util.* +import kotlin.math.roundToInt class MainActivity : BaseActivity() { @@ -21,8 +24,33 @@ class MainActivity : BaseActivity() { toURButton.setOnClickListener { updateLocale(Locales.Urdu) } secondButton.setOnClickListener { startActivity(Intent(this, SecondActivity::class.java)) } + + fontSizeSeekbar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + fontSizeSeekbar?.setProgress(progress, true) + } + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) {} + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + seekBar?.run { + Application.FONT_SCALE = getFontScale(progress) + recreate() + } + } + + }) + + fontSizeSeekbar.max = 3 + fontSizeSeekbar.progress = getSeekBarProgress(resources.configuration.fontScale) } + private fun getSeekBarProgress(fontScale: Float) = ((fontScale - 0.8F) / 1.5F).roundToInt() + + private fun getFontScale(progressValue: Int) = 0.8F + (progressValue * 1.5F) + override fun updateLocale(locale: Locale) { super.updateLocale(locale) setTitle(R.string.main_activity_title) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 88c3aeb..15d6f06 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,44 +1,66 @@ - - - + - + android:orientation="vertical" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingTop="@dimen/activity_vertical_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:paddingBottom="@dimen/activity_vertical_margin" + tools:context=".MainActivity"> - - - - - - + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index de6ddf4..42c404f 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -13,5 +13,6 @@ Ikinci sayfa > Urduca + Erişilebilirlik: Yazı Tipi Boyutu \ No newline at end of file diff --git a/app/src/main/res/values-ur/strings.xml b/app/src/main/res/values-ur/strings.xml index cc22288..de8218e 100644 --- a/app/src/main/res/values-ur/strings.xml +++ b/app/src/main/res/values-ur/strings.xml @@ -12,5 +12,6 @@ دوسرا صفحہ> اردو + رسائی: فونٹ سائز diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 98d2268..6d3f3c7 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -13,5 +13,6 @@ 第二页 > 乌尔都语 + 輔助功能:字體大小 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b73a90b..98c14e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -14,4 +14,5 @@ Urdu Dark Light + Accessibality: Font Size diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index eda1d05..12be807 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Sun Apr 19 15:29:34 BST 2020 +#Fri Jun 12 03:43:17 GST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt b/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt index df2128b..a394a25 100644 --- a/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt +++ b/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt @@ -2,6 +2,7 @@ package com.zeugmasolutions.localehelper import android.content.Context import android.content.SharedPreferences +import android.content.res.Configuration import android.os.Build import java.util.* @@ -10,6 +11,8 @@ object LocaleHelper { private const val SELECTED_COUNTRY = "Locale.Helper.Selected.Country" private var initialized = false + var configurationBlock: ((Configuration) -> Unit)? = null + /** * Attach the selected or default [Locale] to the [context] */ @@ -68,6 +71,8 @@ object LocaleHelper { configuration.setLayoutDirection(locale) } + configurationBlock?.invoke(configuration) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { context.createConfigurationContext(configuration) } else {