diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d1998103..fbb68289f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt index 2d9ccf445..b53c1c7cc 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/AboutActivity.kt @@ -8,6 +8,7 @@ import android.text.method.LinkMovementMethod import android.view.View import com.simplemobiletools.commons.BuildConfig import com.simplemobiletools.commons.R +import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.APP_LICENSES import com.simplemobiletools.commons.helpers.APP_NAME import kotlinx.android.synthetic.main.activity_about.* @@ -25,6 +26,7 @@ class AboutActivity : BaseSimpleActivity() { override fun onResume() { super.onResume() updateTextColors(about_holder) + setupWebsite() setupEmail() setupMoreApps() diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt index c20066ea9..31663606b 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/BaseSimpleActivity.kt @@ -4,23 +4,16 @@ import android.annotation.TargetApi import android.app.Activity import android.content.Intent import android.graphics.Color -import android.graphics.PorterDuff import android.graphics.drawable.ColorDrawable import android.net.Uri import android.os.Build import android.os.Bundle import android.support.v7.app.AppCompatActivity -import android.support.v7.widget.AppCompatEditText -import android.support.v7.widget.AppCompatTextView import android.view.MenuItem -import android.view.ViewGroup import com.simplemobiletools.commons.helpers.APP_LICENSES import com.simplemobiletools.commons.helpers.APP_NAME import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.OPEN_DOCUMENT_TREE -import com.simplemobiletools.commons.views.MyAppCompatSpinner -import com.simplemobiletools.commons.views.MyCompatRadioButton -import com.simplemobiletools.commons.views.MySwitchCompat import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions import java.io.File @@ -66,30 +59,6 @@ open class BaseSimpleActivity : AppCompatActivity() { } } - fun updateTextColors(viewGroup: ViewGroup, textColor: Int = baseConfig.textColor) { - val cnt = viewGroup.childCount - (0..cnt - 1).map { viewGroup.getChildAt(it) } - .forEach { - if (it is AppCompatEditText) { - it.background.mutate().setColorFilter(baseConfig.primaryColor, PorterDuff.Mode.SRC_ATOP) - it.setTextColor(textColor) - } else if (it is AppCompatTextView) { - it.setTextColor(textColor) - it.setLinkTextColor(baseConfig.primaryColor) - } else if (it is MyAppCompatSpinner) { - it.setColors(textColor, baseConfig.backgroundColor) - } else if (it is MySwitchCompat) { - it.setTextColor(textColor) - it.setColor(baseConfig.primaryColor) - } else if (it is MyCompatRadioButton) { - it.setTextColor(textColor) - it.setColor(baseConfig.primaryColor) - } else if (it is ViewGroup) { - updateTextColors(it, textColor) - } - } - } - override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) if (requestCode == OPEN_DOCUMENT_TREE && resultCode == Activity.RESULT_OK && resultData != null) { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt index 9fcc19ebd..44791c129 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/CustomizationActivity.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.R import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.getContrastColor +import com.simplemobiletools.commons.extensions.updateTextColors import kotlinx.android.synthetic.main.activity_customization.* import yuku.ambilwarna.AmbilWarnaDialog @@ -22,9 +23,9 @@ class CustomizationActivity : BaseSimpleActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_customization) + updateTextColors(customization_holder) initColorVariables() setupColorsPickers() - updateTextColors(customization_holder) customization_text_color_holder.setOnClickListener { pickTextColor() } customization_background_color_holder.setOnClickListener { pickBackgroundColor() } @@ -92,10 +93,10 @@ class CustomizationActivity : BaseSimpleActivity() { hasUnsavedChanges = false initColorVariables() setupColorsPickers() - updateTextColors(customization_holder) updateBackgroundColor() updateActionbarColor() invalidateOptionsMenu() + updateTextColors(customization_holder) } private fun initColorVariables() { diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/LicenseActivity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/LicenseActivity.kt index 0bec3b529..8279239dd 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/activities/LicenseActivity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/activities/LicenseActivity.kt @@ -5,6 +5,7 @@ import android.text.SpannableString import android.text.style.UnderlineSpan import android.view.LayoutInflater import com.simplemobiletools.commons.R +import com.simplemobiletools.commons.extensions.updateTextColors import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.License import kotlinx.android.synthetic.main.activity_license.* diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt index f4105c38e..3d35e6b0e 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context.kt @@ -1,12 +1,24 @@ package com.simplemobiletools.commons.extensions +import android.app.AlertDialog import android.content.Context import android.graphics.Color +import android.graphics.PorterDuff import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable +import android.support.v7.widget.AppCompatEditText +import android.support.v7.widget.AppCompatTextView +import android.view.LayoutInflater +import android.view.ViewGroup +import android.view.Window import android.widget.Toast import com.simplemobiletools.commons.R +import com.simplemobiletools.commons.helpers.BaseConfig import com.simplemobiletools.commons.helpers.PREFS_KEY +import com.simplemobiletools.commons.views.MyAppCompatSpinner +import com.simplemobiletools.commons.views.MyCompatRadioButton +import com.simplemobiletools.commons.views.MySwitchCompat +import kotlinx.android.synthetic.main.dialog_title.view.* fun Context.toast(id: Int, length: Int = Toast.LENGTH_SHORT) = Toast.makeText(this, id, length).show() @@ -21,3 +33,52 @@ fun Context.getDialogBackgroundColor(backgroundColor: Int): Drawable { backgroundColor }) } + +fun Context.updateTextColors(viewGroup: ViewGroup, color: Int = 0) { + val baseConfig = BaseConfig.newInstance(this) + val textColor = if (color == 0) baseConfig.textColor else color + val cnt = viewGroup.childCount + (0..cnt - 1) + .map { viewGroup.getChildAt(it) } + .forEach { + if (it is AppCompatEditText) { + it.background.mutate().setColorFilter(baseConfig.primaryColor, PorterDuff.Mode.SRC_ATOP) + it.setTextColor(textColor) + } else if (it is AppCompatTextView) { + it.setTextColor(textColor) + it.setLinkTextColor(baseConfig.primaryColor) + } else if (it is MyAppCompatSpinner) { + it.setColors(textColor, baseConfig.backgroundColor) + } else if (it is MySwitchCompat) { + it.setTextColor(textColor) + it.setColor(baseConfig.primaryColor) + } else if (it is MyCompatRadioButton) { + it.setTextColor(textColor) + it.setColor(baseConfig.primaryColor) + } else if (it is ViewGroup) { + updateTextColors(it, textColor) + } + } +} + +fun Context.setupDialogStuff(view: ViewGroup, dialog: AlertDialog, titleId: Int) { + updateTextColors(view.getChildAt(0) as ViewGroup) + val baseConfig = BaseConfig.newInstance(this) + val primaryColor = baseConfig.primaryColor + val title = LayoutInflater.from(this).inflate(R.layout.dialog_title, null) + title.dialog_title_textview.apply { + setText(titleId) + setTextColor(baseConfig.textColor) + } + + dialog.apply { + requestWindowFeature(Window.FEATURE_NO_TITLE) + setCustomTitle(title) + setCanceledOnTouchOutside(true) + show() + getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(primaryColor) + getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(primaryColor) + getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(primaryColor) + window.setBackgroundDrawable(context.getDialogBackgroundColor(baseConfig.backgroundColor)) + } +} diff --git a/commons/src/main/res/layout/dialog_title.xml b/commons/src/main/res/layout/dialog_title.xml new file mode 100644 index 000000000..220da8a9a --- /dev/null +++ b/commons/src/main/res/layout/dialog_title.xml @@ -0,0 +1,11 @@ + +