void ApplyMinTrackTintColor(string propertyName) { if (propertyName == null || propertyName == SliderGloss.MinTrackTintColorProperty.PropertyName) { var minTrackTintColor = (Color)Element.GetValue(SliderGloss.MinTrackTintColorProperty); // Skip assigning anything if all properties are being applied and the color is set to the default value if (propertyName != null || minTrackTintColor != Color.Default) { var aMinTrackTintColor = (minTrackTintColor == Color.Default) ? ThemeUtil.IntToColor(ThemeUtil.ColorAccent(Control.Context, ThemeUtil.DefaultColorControlTrackActivated)) : minTrackTintColor.ToAndroid(); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { // FYI: Lollipop (API 21) has a broken implementation for the ProgressTintList property. // Assigning a value to the property causes the entire track to be colored with the assigned // value, instead of just the track to the left of the thumb. It works as expected on API 22+. Control.ProgressTintList = ColorStateList.ValueOf(aMinTrackTintColor); } else if (XFGloss.Droid.Library.UsingAppCompat) { DrawableCompat.SetTint(DrawableCompat.Wrap(Control.ProgressDrawable), aMinTrackTintColor); // We also have to explicitly set the MaxTrackTintColor to either the specified custom color or // the default color. Otherwise, setting the MinTrackTintColor tints both the left and right // sides of the track ApplyMaxTrackTintColor(null, true); } else { Console.WriteLine(XFGloss.Droid.Library.appCompatWarning); } } } }
void ApplyThumbTintColor(string propertyName) { if (propertyName == null || propertyName == SliderGloss.ThumbTintColorProperty.PropertyName) { var thumbTintColor = (Color)Element.GetValue(SliderGloss.ThumbTintColorProperty); // Skip assigning anything if all properties are being applied and the color is set to the default value if (propertyName != null || thumbTintColor != Color.Default) { var aThumbTintColor = (thumbTintColor == Color.Default) ? ThemeUtil.IntToColor(ThemeUtil.ColorAccent(Control.Context, ThemeUtil.DefaultColorControlThumb)) : thumbTintColor.ToAndroid(); if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { Control.ThumbTintList = ColorStateList.ValueOf(aThumbTintColor); } else if (XFGloss.Droid.Library.UsingAppCompat) { DrawableCompat.SetTint(DrawableCompat.Wrap(Control.Thumb), aThumbTintColor); } else { Console.WriteLine(XFGloss.Droid.Library.appCompatWarning); } } } }
void ApplyMaxTrackTintColor(string propertyName, bool forceApply = false) { // We always want to force the application of the MaxTrackTintColor if we're running an API that is older // than Marshmallow and we're also using the AppCompat library so the track color will be appropriately // clamped. forceApply = forceApply || (Android.OS.Build.VERSION.SdkInt < Android.OS.BuildVersionCodes.M && XFGloss.Droid.Library.UsingAppCompat); if (propertyName == null || propertyName == SliderGloss.MaxTrackTintColorProperty.PropertyName || forceApply) { var maxTrackTintColor = (Color)Element.GetValue(SliderGloss.MaxTrackTintColorProperty); // Skip assigning anything if all properties are being applied and the color is set to the default value if (propertyName != null || maxTrackTintColor != Color.Default || forceApply) { if (maxTrackTintColor != Color.Default) { maxTrackTintColor = new Color(maxTrackTintColor.R, maxTrackTintColor.G, maxTrackTintColor.B, 0.3); } var aMaxTrackTintColor = (maxTrackTintColor == Color.Default) ? ThemeUtil.IntToColor(ThemeUtil.ColorControlNormal(Control.Context, ThemeUtil.DefaultColorControlTrack)) : maxTrackTintColor.ToAndroid(); if (!XFGloss.Droid.Library.UsingAppCompat || XFGloss.Droid.Library.UsingAppCompatAlpha) { // Clamp the track tint colors to 30% opacity - API 24 automatically does this. AppCompat doesn't. aMaxTrackTintColor = new AColor(aMaxTrackTintColor.R, aMaxTrackTintColor.G, aMaxTrackTintColor.B, (byte)77); } if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { // FYI: Lollipop (API 21) has the ProgressBackgroundTintList implemented but it is broken. // Assigning a value to the property has no effect on API 21. It works as expected on API 22+. Control.ProgressBackgroundTintList = ColorStateList.ValueOf(aMaxTrackTintColor); } else if (XFGloss.Droid.Library.UsingAppCompat) { ThemeUtil.SetLayerTint(Control.ProgressDrawable as LayerDrawable, 0, aMaxTrackTintColor); } else { Console.WriteLine(XFGloss.Droid.Library.appCompatWarning); } } } }