use the TextColor for setting text color

This commit is contained in:
tibbi 2017-11-05 18:11:42 +01:00
parent 3a5d4e96f1
commit 53cf6ba3b6
5 changed files with 51 additions and 27 deletions

View File

@ -39,7 +39,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.35.5'
compile 'com.simplemobiletools:commons:2.35.6'
compile 'me.grantland:autofittextview:0.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

View File

@ -9,8 +9,10 @@ import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.calculator.BuildConfig
import com.simplemobiletools.calculator.R
import com.simplemobiletools.calculator.extensions.config
import com.simplemobiletools.calculator.helpers.*
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.helpers.LICENSE_AUTOFITTEXTVIEW
import com.simplemobiletools.commons.helpers.LICENSE_ESPRESSO
@ -20,6 +22,8 @@ import kotlinx.android.synthetic.main.activity_main.*
import me.grantland.widget.AutofitHelper
class MainActivity : SimpleActivity(), Calculator {
private var mStoredTextColor = 0
companion object {
private lateinit var mCalc: CalculatorImpl
}
@ -42,7 +46,7 @@ class MainActivity : SimpleActivity(), Calculator {
btn_clear.setOnClickListener { mCalc.handleClear() }
btn_clear.setOnLongClickListener { mCalc.handleReset(); true }
arrayOf(btn_decimal, btn_0, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9).forEach {
getButtonIds().forEach {
it.setOnClickListener { mCalc.numpadClicked(it.id) }
}
@ -55,6 +59,18 @@ class MainActivity : SimpleActivity(), Calculator {
AutofitHelper.create(formula)
}
override fun onResume() {
super.onResume()
if (mStoredTextColor != config.textColor) {
updateTextColors(calculator_holder)
}
}
override fun onPause() {
super.onPause()
mStoredTextColor = config.textColor
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu, menu)
return true
@ -77,6 +93,8 @@ class MainActivity : SimpleActivity(), Calculator {
startAboutActivity(R.string.app_name, LICENSE_KOTLIN or LICENSE_AUTOFITTEXTVIEW or LICENSE_ROBOLECTRIC or LICENSE_ESPRESSO, BuildConfig.VERSION_NAME)
}
private fun getButtonIds() = arrayOf(btn_decimal, btn_0, btn_1, btn_2, btn_3, btn_4, btn_5, btn_6, btn_7, btn_8, btn_9)
private fun copyToClipboard(copyResult: Boolean): Boolean {
var value = formula.value
if (copyResult) {

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.activities
import android.os.Bundle
import com.simplemobiletools.calculator.R
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : SimpleActivity() {
@ -9,8 +10,13 @@ class SettingsActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
}
override fun onResume() {
super.onResume()
setupCustomizeColors()
updateTextColors(settings_scrollview)
}
private fun setupCustomizeColors() {

View File

@ -6,9 +6,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.MainActivity">
tools:context=".activities.MainActivity"
tools:ignore="HardcodedText">
<TextView
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/formula"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -20,7 +21,7 @@
android:paddingRight="@dimen/activity_margin"
android:textSize="@dimen/actionbar_text_size"/>
<TextView
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -39,7 +40,7 @@
android:layout_weight="2"
android:orientation="horizontal">
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_modulo"
style="@style/MyButton"
android:layout_width="match_parent"
@ -49,7 +50,7 @@
android:textAllCaps="false"
android:textSize="@dimen/extra_big_text_size"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_power"
style="@style/MyButton"
android:layout_width="match_parent"
@ -57,7 +58,7 @@
android:layout_weight="1"
android:text="^"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_root"
style="@style/MyButton"
android:layout_width="match_parent"
@ -65,7 +66,7 @@
android:layout_weight="1"
android:text="√"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_clear"
style="@style/MyButton"
android:layout_width="match_parent"
@ -73,7 +74,7 @@
android:layout_weight="1"
android:text="C"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_reset"
style="@style/MyButton"
android:layout_width="match_parent"
@ -89,7 +90,7 @@
android:layout_weight="2"
android:orientation="horizontal">
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_7"
style="@style/MyButton"
android:layout_width="match_parent"
@ -97,7 +98,7 @@
android:layout_weight="1"
android:text="7"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_8"
style="@style/MyButton"
android:layout_width="match_parent"
@ -105,7 +106,7 @@
android:layout_weight="1"
android:text="8"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_9"
style="@style/MyButton"
android:layout_width="match_parent"
@ -113,7 +114,7 @@
android:layout_weight="1"
android:text="9"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_divide"
style="@style/MyButton"
android:layout_width="match_parent"
@ -128,7 +129,7 @@
android:layout_weight="2"
android:orientation="horizontal">
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_4"
style="@style/MyButton"
android:layout_width="match_parent"
@ -136,7 +137,7 @@
android:layout_weight="1"
android:text="4"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_5"
style="@style/MyButton"
android:layout_width="match_parent"
@ -144,7 +145,7 @@
android:layout_weight="1"
android:text="5"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_6"
style="@style/MyButton"
android:layout_width="match_parent"
@ -152,7 +153,7 @@
android:layout_weight="1"
android:text="6"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_multiply"
style="@style/MyButton"
android:layout_width="match_parent"
@ -167,7 +168,7 @@
android:layout_weight="2"
android:orientation="horizontal">
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_1"
style="@style/MyButton"
android:layout_width="match_parent"
@ -175,7 +176,7 @@
android:layout_weight="1"
android:text="1"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_2"
style="@style/MyButton"
android:layout_width="match_parent"
@ -183,7 +184,7 @@
android:layout_weight="1"
android:text="2"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_3"
style="@style/MyButton"
android:layout_width="match_parent"
@ -191,7 +192,7 @@
android:layout_weight="1"
android:text="3"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_minus"
style="@style/MyButton"
android:layout_width="match_parent"
@ -206,7 +207,7 @@
android:layout_weight="2"
android:orientation="horizontal">
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_0"
style="@style/MyButton"
android:layout_width="match_parent"
@ -214,7 +215,7 @@
android:layout_weight="1"
android:text="0"/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_decimal"
style="@style/MyButton"
android:layout_width="match_parent"
@ -222,7 +223,7 @@
android:layout_weight="1"
android:text="."/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_equals"
style="@style/MyButton"
android:layout_width="match_parent"
@ -230,7 +231,7 @@
android:layout_weight="1"
android:text="="/>
<Button
<com.simplemobiletools.commons.views.MyButton
android:id="@+id/btn_plus"
style="@style/MyButton"
android:layout_width="match_parent"

View File

@ -3,7 +3,6 @@
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:textColor">@color/color_primary</item>
<item name="android:background">@drawable/button</item>
<item name="android:textSize">@dimen/button_text_size</item>
<item name="android:fontFamily">sans-serif-light</item>