Prevent theme colors from being equal

If `vibrantColor` is equal to `dominantColor`, dominant will be darkened 
by 20% and vibrant lightened by 20%
This commit is contained in:
Finn M Glas 2020-05-27 12:53:35 +02:00
parent 0154874b0f
commit 626a032414
No known key found for this signature in database
GPG key ID: 25037A2E81AB459C
2 changed files with 26 additions and 1 deletions

View file

@ -7,7 +7,10 @@ import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.* import android.graphics.Bitmap
import android.graphics.BlendMode
import android.graphics.BlendModeColorFilter
import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
@ -17,6 +20,7 @@ import android.view.animation.*
import android.widget.Button import android.widget.Button
import android.widget.Toast import android.widget.Toast
import com.finnmglas.launcher.R import com.finnmglas.launcher.R
import kotlin.math.roundToInt
/** Variables for all of the app */ /** Variables for all of the app */
var upApp = "" var upApp = ""
@ -316,5 +320,20 @@ fun setButtonColor(btn: Button, color: Int) {
// not setting it here, unable to find a good alternative // not setting it here, unable to find a good alternative
// I tried: // I tried:
// btn.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP) // btn.background.colorFilter = PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)
// TODO at some point (or you do it now)
} }
}
// Taken from: https://stackoverflow.com/a/33072575/12787264
fun manipulateColor(color: Int, factor: Float): Int {
val a = Color.alpha(color)
val r = (Color.red(color) * factor).roundToInt()
val g = (Color.green(color) * factor).roundToInt()
val b = (Color.blue(color) * factor).roundToInt()
return Color.argb(
a,
r.coerceAtMost(255),
g.coerceAtMost(255),
b.coerceAtMost(255)
)
} }

View file

@ -111,6 +111,12 @@ class SettingsFragmentTheme : Fragment() {
dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color)) dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color)) vibrantColor = palette.getVibrantColor(ContextCompat.getColor(context!!, R.color.darkTheme_accent_color))
// never let dominantColor equal vibrantColor
if(dominantColor == vibrantColor) {
vibrantColor = manipulateColor(vibrantColor, 1.2F)
dominantColor = manipulateColor(dominantColor, 0.8F)
}
/* Save image Uri as string */ /* Save image Uri as string */
val editor: SharedPreferences.Editor = context!!.getSharedPreferences( val editor: SharedPreferences.Editor = context!!.getSharedPreferences(
context!!.getString(R.string.preference_file_key), Context.MODE_PRIVATE).edit() context!!.getString(R.string.preference_file_key), Context.MODE_PRIVATE).edit()