From 2c3f4bad60ba504089fc91b82a22aabe361f9ed5 Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Fri, 12 Jun 2020 03:50:14 +0400 Subject: [PATCH 1/4] Implemented configuration block Bump version --- .idea/misc.xml | 1 - app/build.gradle | 4 ++-- .../java/com/zeugmasolutions/localeexample/Application.kt | 5 +++++ .../com/zeugmasolutions/localeexample/BaseActivity.kt | 8 ++++++++ build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 4 ++-- localehelper/build.gradle | 2 +- .../java/com/zeugmasolutions/localehelper/LocaleHelper.kt | 7 +++++++ 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d54cfb7..703e5d4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,6 @@ - diff --git a/app/build.gradle b/app/build.gradle index 52ffc7f..51b2f8a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,12 +39,12 @@ dependencies { implementation project(":localehelper") implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'androidx.core:core-ktx:1.2.0' + implementation 'androidx.core:core-ktx:1.3.0' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.1.0' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt index 4379d7c..e0ead54 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt @@ -3,9 +3,14 @@ package com.zeugmasolutions.localeexample import android.content.Context import androidx.multidex.MultiDex import com.zeugmasolutions.localehelper.LocaleAwareApplication +import com.zeugmasolutions.localehelper.LocaleHelper class Application : LocaleAwareApplication() { override fun attachBaseContext(base: Context) { + LocaleHelper.configurationBlock = { + it.fontScale = 1.0f + } + 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 1cf2007..3aecd8e 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt @@ -1,7 +1,15 @@ package com.zeugmasolutions.localeexample +import android.content.Context import com.zeugmasolutions.localehelper.LocaleAwareCompatActivity +import com.zeugmasolutions.localehelper.LocaleHelper open class BaseActivity : LocaleAwareCompatActivity() { + override fun attachBaseContext(newBase: Context) { + LocaleHelper.configurationBlock = { + it.fontScale = 1.0f + } + super.attachBaseContext(newBase) + } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8a2ba82..556dde6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.3.71' + ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.6.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 43b37f6..12be807 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#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 zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/localehelper/build.gradle b/localehelper/build.gradle index 5b3ff2c..139199e 100644 --- a/localehelper/build.gradle +++ b/localehelper/build.gradle @@ -46,7 +46,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' //testing - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt b/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt index 7953bc7..07852f6 100644 --- a/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt +++ b/localehelper/src/main/java/com/zeugmasolutions/localehelper/LocaleHelper.kt @@ -3,6 +3,7 @@ package com.zeugmasolutions.localehelper import android.annotation.TargetApi import android.content.Context import android.content.SharedPreferences +import android.content.res.Configuration import android.os.Build import java.util.* @@ -11,6 +12,8 @@ object LocaleHelper { private const val SELECTED_LANGUAGE = "Locale.Helper.Selected.Language" private const val SELECTED_COUNTRY = "Locale.Helper.Selected.Country" + var configurationBlock: ((Configuration) -> Unit)? = null + fun onAttach(context: Context): Context { val locale = load(context) return setLocale(context, locale) @@ -61,6 +64,8 @@ object LocaleHelper { configuration.setLocale(locale) configuration.setLayoutDirection(locale) + configurationBlock?.invoke(configuration) + return context.createConfigurationContext(configuration) } @@ -76,6 +81,8 @@ object LocaleHelper { configuration.setLayoutDirection(locale) } + configurationBlock?.invoke(configuration) + resources.updateConfiguration(configuration, resources.displayMetrics) return context From 972932ab66b96d3720b19bf85a61f008b7078d5b Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Fri, 12 Jun 2020 03:55:19 +0400 Subject: [PATCH 2/4] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index e71820e..c49b555 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,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)) } @@ -71,6 +76,11 @@ open class BaseActivity : AppCompatActivity() { private val localeDelegate = LocaleHelperActivityDelegateImpl() 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)) } From 8751c565e69c02bcd03a89dbdd80d6ba60989779 Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Tue, 4 Aug 2020 13:54:36 +0400 Subject: [PATCH 3/4] Implemented accessibility font size --- .../localeexample/Application.kt | 7 +- .../localeexample/BaseActivity.kt | 2 +- .../localeexample/MainActivity.kt | 28 +++++ app/src/main/res/layout/activity_main.xml | 102 +++++++++++------- app/src/main/res/values-tr-rTR/strings.xml | 1 + app/src/main/res/values-ur/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 101 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt index 0ab6cb5..db5b83b 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/Application.kt @@ -8,6 +8,11 @@ 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) @@ -15,7 +20,7 @@ class Application : LocaleAwareApplication() { override fun attachBaseContext(base: Context) { LocaleHelper.configurationBlock = { - it.fontScale = 1.0f + it.fontScale = FONT_SCALE } super.attachBaseContext(base) diff --git a/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt b/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt index de8517a..7b49c06 100644 --- a/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt +++ b/app/src/main/java/com/zeugmasolutions/localeexample/BaseActivity.kt @@ -13,7 +13,7 @@ open class BaseActivity : LocaleAwareCompatActivity() { override fun attachBaseContext(newBase: Context) { LocaleHelper.configurationBlock = { - it.fontScale = 1.0f + it.fontScale = Application.FONT_SCALE } super.attachBaseContext(newBase) } 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 4f00a85..315bc0a 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 f68b1bb..308be10 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 46a91fd..76aa4a2 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 25c9fac..6846732 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 From 72275b0255df60c479d07951990151e304e41e83 Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Sun, 27 Sep 2020 12:32:04 +0400 Subject: [PATCH 4/4] added missing configuration line ExternalStorageConfigurationManager --- .idea/misc.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4..d54cfb7 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,6 +5,7 @@ +