From 5a7aa1b8de4c34c3c73fc1c3679601161783beb0 Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Sun, 24 Jun 2018 22:57:47 +0200 Subject: [PATCH] Adding theming in the player view. --- MusicApp/Resources/Portable Class/Player.cs | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/MusicApp/Resources/Portable Class/Player.cs b/MusicApp/Resources/Portable Class/Player.cs index 6cf89b5..1121e68 100644 --- a/MusicApp/Resources/Portable Class/Player.cs +++ b/MusicApp/Resources/Portable Class/Player.cs @@ -1,6 +1,7 @@ using Android.App; using Android.Content; using Android.Content.PM; +using Android.Content.Res; using Android.Graphics; using Android.Graphics.Drawables; using Android.OS; @@ -486,11 +487,52 @@ namespace MusicApp.Resources.Portable_Class return; } + Palette.Swatch accent = null; + if (isColorDark(swatch.Rgb)) + { + accent = palette.LightVibrantSwatch; + + if (accent == null) + accent = palette.LightMutedSwatch; + + if (accent == null) + accent = swatch; + } + else + { + accent = palette.DarkVibrantSwatch; + + if (accent == null) + accent = palette.DarkMutedSwatch; + + if (accent == null) + accent = swatch; + } + Color text = Color.Argb(Color.GetAlphaComponent(swatch.BodyTextColor), Color.GetRedComponent(swatch.BodyTextColor), Color.GetGreenComponent(swatch.BodyTextColor), Color.GetBlueComponent(swatch.BodyTextColor)); Color background = Color.Argb(Color.GetAlphaComponent(swatch.Rgb), Color.GetRedComponent(swatch.Rgb), Color.GetGreenComponent(swatch.Rgb), Color.GetBlueComponent(swatch.Rgb)); + Color accentColor = Color.Argb(Color.GetAlphaComponent(accent.Rgb), Color.GetRedComponent(accent.Rgb), Color.GetGreenComponent(accent.Rgb), Color.GetBlueComponent(accent.Rgb)); FindViewById(Resource.Id.playerTitle).SetTextColor(text); FindViewById(Resource.Id.playerArtist).SetTextColor(text); FindViewById(Resource.Id.infoPanel).SetBackgroundColor(background); + FindViewById(Resource.Id.downFAB).BackgroundTintList = ColorStateList.ValueOf(accentColor); + FindViewById(Resource.Id.downFAB).RippleColor = accent.Rgb; + FindViewById(Resource.Id.songTimer).SetThumbColor(accent.Rgb, accent.Rgb); + FindViewById(Resource.Id.songTimer).SetScrubberColor(accent.Rgb); + FindViewById(Resource.Id.songTimer).SetRippleColor(accent.Rgb); + } + + public bool isColorDark(int color) + { + double darkness = 1 - (0.299 * Color.GetRedComponent(color) + 0.587 * Color.GetGreenComponent(color) + 0.114 * Color.GetBlueComponent(color)) / 255; + if (darkness < 0.5) + { + return false; // It's a light color + } + else + { + return true; // It's a dark color + } } } } \ No newline at end of file