update some colorizing extensions
This commit is contained in:
parent
84e6467a6a
commit
041976c280
7 changed files with 79 additions and 34 deletions
|
@ -37,7 +37,7 @@
|
|||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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.*
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
11
commons/src/main/res/layout/dialog_title.xml
Normal file
11
commons/src/main/res/layout/dialog_title.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/dialog_title_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingEnd="@dimen/activity_margin"
|
||||
android:paddingLeft="@dimen/big_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:paddingStart="@dimen/big_margin"
|
||||
android:paddingTop="@dimen/activity_margin"/>
|
Loading…
Reference in a new issue