/// <summary> /// Implementation of method required by the <see cref="T:XFGloss.IXFGlossRenderer"/> interface that the /// <see cref="T:XFGloss.IGradientRenderer"/> interface extends. Applies the passed /// <see cref="T:XFGloss.XFGlossElement"/> properties to the Android cell controls. /// </summary> /// <param name="propertyName">The name of the XFGloss attached BindableProperty that changed</param> /// <param name="element">The <see cref="T:XFGloss.XFGlossElement"/> instance that changed</param> /// <typeparam name="TElement">The type <see cref="T:XFGloss.XFGlossElement"/> that changed</typeparam> public void CreateNativeElement <TElement>(string propertyName, TElement element) where TElement : XFGlossElement { // No need to check property name yet. BackgroundGradient is the only property currently supported. //if (propertyName == CellGloss.BackgroundGradientProperty.PropertyName && element is Gradient) var nativeCell = GetNativeCell(); if (nativeCell != null) { RemoveBackgroundGradientDrawable(nativeCell); // The material design ripple effect was introduced in Lollipop. Use it if we're running on that or newer if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { var ripple = BackgroundRippleDrawable.Create(new XFGlossPaintDrawable(element as Gradient), (element as Gradient).AverageColor.ToAndroid()); nativeCell.SetOnTouchListener(ripple); nativeCell.Background = ripple; } else { // Otherwise we just darken/lighten the cell background depending on how dark the background is nativeCell.Background = BackgroundStateListDrawable.Create(new XFGlossPaintDrawable(element as Gradient), (element as Gradient).AverageColor.ToAndroid()); } } }
/// <summary> /// Implementation of the cross-platform base class's abstract UpdateProperties method. Used to apply the /// XFGloss attached BindableProperty values for the property specified by the propertyName parameter. /// </summary> /// <param name="cell">The associated <see cref="T:Xamarin.Forms.Cell"/> instance</param> /// <param name="nativeCell">The native Android view used to display the cell contents</param> /// <param name="propertyName">The name of the XFGloss attached BindableProperty that changed</param> protected override void UpdateProperties(Cell cell, AView nativeCell, string propertyName) { // BackgroundColor and BackgroundGradient properties // We shouldn't apply BOTH a background gradient and solid color. The gradient takes preference. Gradient bkgrndGradient = (Gradient)cell.GetValue(CellGloss.BackgroundGradientProperty); if (bkgrndGradient != null && bkgrndGradient.UpdateProperties(CellGloss.BackgroundGradientProperty.PropertyName, this, propertyName)) { // We don't need to handle BackgroundColor if a BackgroundGradient is assigned/updated return; } // We only process background color if a gradient wasn't applied by the base class. // BackgroundColor property if (propertyName == null || propertyName == CellGloss.BackgroundColorProperty.PropertyName) { var bk = nativeCell.Background; Color bkgrndColor = (Color)cell.GetValue(CellGloss.BackgroundColorProperty); // We don't want to assign a background color if the default color is specified // and we're updating all properties. if (propertyName != null || bkgrndColor != Color.Default) { AColor aBkColor = (bkgrndColor != Color.Default) ? bkgrndColor.ToAndroid() : AColor.Transparent; // The material design ripple effect was introduced in Lollipop. Use it if we're running on that or newer if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { var ripple = BackgroundRippleDrawable.Create(aBkColor); nativeCell.SetOnTouchListener(ripple); nativeCell.Background = ripple; } else { // Pre-lollipop means no ripple available // See FAQ at bottom of http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html // Q: Why are there no ripples on pre-Lollipop? // A: A lot of what allows RippleDrawable to run smoothly is Android 5.0’s new RenderThread. // To optimize for performance on previous versions of Android, we've left RippleDrawable out // for now. nativeCell.Background = BackgroundStateListDrawable.Create(aBkColor); } } } }
public static BackgroundStateListDrawable Create(AColor backgroundColor) { return(BackgroundStateListDrawable.Create(new ColorDrawable(backgroundColor), backgroundColor)); }