adding a toggle for forcing english
This commit is contained in:
parent
c64cdc681c
commit
e2f1593be7
|
@ -10,6 +10,7 @@
|
||||||
tools:node="remove"/>
|
tools:node="remove"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:name=".App"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_launcher_name"
|
android:label="@string/app_launcher_name"
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.simplemobiletools.calculator
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import com.simplemobiletools.calculator.extensions.config
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
class App : Application() {
|
||||||
|
override fun onCreate() {
|
||||||
|
super.onCreate()
|
||||||
|
if (config.useEnglish) {
|
||||||
|
val conf = resources.configuration
|
||||||
|
conf.locale = Locale.ENGLISH
|
||||||
|
resources.updateConfiguration(conf, resources.displayMetrics)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ import me.grantland.widget.AutofitHelper
|
||||||
class MainActivity : SimpleActivity(), Calculator {
|
class MainActivity : SimpleActivity(), Calculator {
|
||||||
private var storedTextColor = 0
|
private var storedTextColor = 0
|
||||||
private var vibrateOnButtonPress = true
|
private var vibrateOnButtonPress = true
|
||||||
|
private var storedUseEnglish = false
|
||||||
|
|
||||||
lateinit var calc: CalculatorImpl
|
lateinit var calc: CalculatorImpl
|
||||||
|
|
||||||
|
@ -53,10 +54,16 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||||
|
|
||||||
AutofitHelper.create(result)
|
AutofitHelper.create(result)
|
||||||
AutofitHelper.create(formula)
|
AutofitHelper.create(formula)
|
||||||
|
storeStateVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
if (storedUseEnglish != config.useEnglish) {
|
||||||
|
restartActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (storedTextColor != config.textColor) {
|
if (storedTextColor != config.textColor) {
|
||||||
updateViewColors(calculator_holder, config.textColor)
|
updateViewColors(calculator_holder, config.textColor)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +72,7 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
storedTextColor = config.textColor
|
storeStateVariables()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
|
@ -82,6 +89,13 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun storeStateVariables() {
|
||||||
|
config.apply {
|
||||||
|
storedTextColor = textColor
|
||||||
|
storedUseEnglish = useEnglish
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkHaptic(view: View) {
|
private fun checkHaptic(view: View) {
|
||||||
if (vibrateOnButtonPress) {
|
if (vibrateOnButtonPress) {
|
||||||
view.performHapticFeedback()
|
view.performHapticFeedback()
|
||||||
|
|
|
@ -3,8 +3,11 @@ package com.simplemobiletools.calculator.activities
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import com.simplemobiletools.calculator.R
|
import com.simplemobiletools.calculator.R
|
||||||
import com.simplemobiletools.calculator.extensions.config
|
import com.simplemobiletools.calculator.extensions.config
|
||||||
|
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||||
|
import com.simplemobiletools.commons.extensions.useEnglishToggled
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
class SettingsActivity : SimpleActivity() {
|
class SettingsActivity : SimpleActivity() {
|
||||||
|
|
||||||
|
@ -17,6 +20,7 @@ class SettingsActivity : SimpleActivity() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
setupCustomizeColors()
|
setupCustomizeColors()
|
||||||
|
setupUseEnglish()
|
||||||
setupVibrate()
|
setupVibrate()
|
||||||
updateTextColors(settings_scrollview)
|
updateTextColors(settings_scrollview)
|
||||||
}
|
}
|
||||||
|
@ -27,6 +31,16 @@ class SettingsActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupUseEnglish() {
|
||||||
|
settings_use_english_holder.beVisibleIf(config.wasUseEnglishToggled || Locale.getDefault().language != "en")
|
||||||
|
settings_use_english.isChecked = config.useEnglish
|
||||||
|
settings_use_english_holder.setOnClickListener {
|
||||||
|
settings_use_english.toggle()
|
||||||
|
config.useEnglish = settings_use_english.isChecked
|
||||||
|
useEnglishToggled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupVibrate() {
|
private fun setupVibrate() {
|
||||||
settings_vibrate.isChecked = config.vibrateOnButtonPress
|
settings_vibrate.isChecked = config.vibrateOnButtonPress
|
||||||
settings_vibrate_holder.setOnClickListener {
|
settings_vibrate_holder.setOnClickListener {
|
||||||
|
|
|
@ -30,6 +30,25 @@
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/settings_use_english_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:padding="@dimen/activity_margin">
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MySwitchCompat
|
||||||
|
android:id="@+id/settings_use_english"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@null"
|
||||||
|
android:clickable="false"
|
||||||
|
android:paddingLeft="@dimen/medium_margin"
|
||||||
|
android:paddingStart="@dimen/medium_margin"
|
||||||
|
android:text="@string/use_english_language"/>
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/settings_vibrate_holder"
|
android:id="@+id/settings_vibrate_holder"
|
||||||
|
|
Loading…
Reference in New Issue