mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Merge pull request #37 from finnmglas/fix/same-color
Prevent theme colors from being equal
This commit is contained in:
commit
2b4a2c6757
2 changed files with 26 additions and 1 deletions
|
@ -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)
|
||||||
|
)
|
||||||
|
}
|
|
@ -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()
|
||||||
|
|
Loading…
Add table
Reference in a new issue