protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (Control != null) { try { almeButton = e.NewElement as AlmeButton; GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.SetShape(ShapeType.Rectangle); gradientDrawable.SetCornerRadius(almeButton.BorderRadius * 2); if (almeButton.CenterColor != Xamarin.Forms.Color.Transparent) { gradientDrawable.SetColors(new int[] { almeButton.EndColor.ToAndroid(), almeButton.CenterColor.ToAndroid(), almeButton.StartColor.ToAndroid() }); } else { gradientDrawable.SetColors(new int[] { almeButton.EndColor.ToAndroid(), almeButton.StartColor.ToAndroid() }); } gradientDrawable.SetGradientType(GradientType.LinearGradient); gradientDrawable.SetOrientation(GradientDrawable.Orientation.RightLeft); #pragma warning disable CS0618 // Type or member is obsolete Control.SetBackgroundDrawable(gradientDrawable); #pragma warning restore CS0618 // Type or member is obsolete Control.SetTextColor(almeButton.TextColor.ToAndroid()); if (almeButton.FontFamily != null) { Control.Typeface = Typeface.CreateFromAsset(Forms.Context.ApplicationContext.Assets, almeButton.FontFamily.Split('#')[0]); } } catch { } } }
private void WalletPagerOnPageScrolled(object sender, ViewPager.PageScrolledEventArgs e) { if (e.Position == Presenter.Balances.Count) { _transferBtn.Enabled = false; _claimBtn.Enabled = false; _transferBtnBg.SetColors(new int[] { Style.R230G230B230, Style.R230G230B230 }); WalletAdapter.SetAccountHistory(null); LoadNextAccount(); } else { _transferBtn.Enabled = true; _claimBtn.Enabled = true; _transferBtnBg.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 }); } _transferBtn.Background = _transferBtnBg; if (_walletPager.CurrentItem < Presenter.Balances.Count && Presenter.Balances[_walletPager.CurrentItem].UserInfo != _prevUser) { _prevUser = Presenter.Balances[_walletPager.CurrentItem].UserInfo; if (Presenter.ConnectedUsers.ContainsKey(_prevUser.Id)) { _trxHistory.Post(() => _walletAdapter.SetAccountHistory(_prevUser.AccountHistory)); } } }
public static void UpdateBackground(this GradientDrawable gradientDrawable, Brush brush, int height, int width) { if (gradientDrawable == null || brush == null || brush.IsEmpty) { return; } if (brush is SolidColorBrush solidColorBrush) { Color bgColor = solidColorBrush.Color; gradientDrawable.SetColor(bgColor.IsDefault ? Color.Default.ToAndroid() : bgColor.ToAndroid()); } if (brush is LinearGradientBrush linearGradientBrush) { var p1 = linearGradientBrush.StartPoint; var x1 = (float)p1.X; var y1 = (float)p1.Y; var p2 = linearGradientBrush.EndPoint; var x2 = (float)p2.X; var y2 = (float)p2.Y; const double Rad2Deg = 180.0 / Math.PI; var angle = Math.Atan2(y2 - y1, x2 - x1) * Rad2Deg; var gradientBrushData = linearGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.LinearGradient); gradientDrawable.SetColors(colors); gradientDrawable.SetGradientOrientation(angle); } if (brush is RadialGradientBrush radialGradientBrush) { var center = radialGradientBrush.Center; float centerX = (float)center.X; float centerY = (float)center.Y; float radius = (float)radialGradientBrush.Radius; var gradientBrushData = radialGradientBrush.GetGradientBrushData(); var colors = gradientBrushData.Item1; if (colors.Length < 2) { return; } gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientCenter(centerX, centerY); gradientDrawable.SetGradientRadius(Math.Max(height, width) * radius); gradientDrawable.SetColors(colors); } }
/// <summary> /// Setup the gradient layer /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <GradientContentView> e) { base.OnElementChanged(e); if (GradientContentView != null) { ShapeDrawable = new ShapeDrawable(new RoundRectShape(new float[] { 8, 8, 8, 8, 8, 8, 8, 8 }, null, null)); GradientDrawable = new GradientDrawable(); GradientDrawable.SetColors(new int[] { GradientContentView.StartColor.ToAndroid(), GradientContentView.EndColor.ToAndroid() }); //this.SetBackgroundResource(Resource.Drawable.); // var gradient1 = new GradientDrawable(GradientDrawable.Orientation.TopBottom, new[] { // Color.FromRgba(255, 255, 255, 255).ToAndroid().ToArgb(), // Color.FromRgba(70, 70, 70, 50).ToAndroid().ToArgb() //}); // GradientDrawable.SetCornerRadius(270); // var element = (GradientContentView)e.NewElement; // var linearGradientBrush = new LinearGradientBrush(); // var linearGradientBrush = new LinearGradientBrush((System.Windows.Media.Color)ColorConverter.ConvertFromString("#FFDFD991"), (System.Windows.Media.Color)ColorConverter.ConvertFromString("#FFDFD991"),(double)220); //var linearGradientBrush = new LinearGradientBrush(new GradientStopCollection() //{ new GradientStop() { Color =new System.Windows.Media.Color.() }, //new GradientStop() { Color = new Windows.UI.Color() { A = Convert.ToByte((element.EndColor.A)*255), B = Convert.ToByte((element.EndColor.B)*255), G = Convert.ToByte((element.EndColor.G)*255), R= Convert.ToByte((element.EndColor.R)*255) }, Offset = 1 } }, 90); //linearGradientBrush.StartPoint = new Windows.Foundation.Point(0, 0); //linearGradientBrush.EndPoint = new Windows.Foundation.Point(0, 1); // GradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); // Background = GradientDrawable; } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); //var resources = Control.Context.Resources; //var metrics = resources.DisplayMetrics; //float dp = 5 * ((float)metrics.DensityDpi / (float)DisplayMetricsDensity.Default); var formsButton = Element as CustomGradientButton; var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(formsButton.BorderRadius); gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); gradientDrawable.SetColors(new int[] { formsButton.EndColor.MultiplyAlpha(formsButton.AlphaMultiplier).ToAndroid().ToArgb(), formsButton.StartColor.MultiplyAlpha(formsButton.AlphaMultiplier).ToAndroid().ToArgb() }); if (formsButton.HasBorder) { gradientDrawable.SetStroke((int)formsButton.BorderWidth, formsButton.BorderColor.ToAndroid()); } if (Control != null) { Control.Background = gradientDrawable; Control.SetTextColor(formsButton.TextColor.ToAndroid()); } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { var button = Control; // See ButtonRendererWithNavFix.cs CustomClickHandler(button); // Applies a "blue" gradient to our Android navigation buttons var gradientDrawable = new GradientDrawable(); gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr); gradientDrawable.SetColors(new int[] { Color.Argb(255, 20, 143, 194), Color.Argb(255, 0, 44, 119) }); gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientRadius(300); gradientDrawable.SetGradientCenter(0.5f, 0); button.SetBackgroundDrawable(gradientDrawable); // Sets a small drop shadow to the buttons' text button.SetShadowLayer(1, 1, 1, Color.Black); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName.Equals(MyButtonRenderer.StaticColorProperty.PropertyName)) { MyButtonRenderer myButtonRenderer = (MyButtonRenderer)Element; GradientDrawable gradientDrawable = (GradientDrawable)Control.Background; gradientDrawable.SetColor(myButtonRenderer.StaticColor.ToAndroid()); } if (e.PropertyName.Equals(MyButtonRenderer.IsEnabledProperty.PropertyName)) { MyButtonRenderer myButtonRenderer = (MyButtonRenderer)Element; GradientDrawable gradientDrawable = (GradientDrawable)Control.Background; if (!myButtonRenderer.IsEnabled) { if (myButtonRenderer.IsGradient) { Color StartColor = System.Drawing.Color.FromArgb(70, myButtonRenderer.StartColor); Color EndColor = System.Drawing.Color.FromArgb(70, myButtonRenderer.EndColor); gradientDrawable.SetColors(new int[] { StartColor.ToAndroid(), EndColor.ToAndroid() }); } else { Color staticColor = System.Drawing.Color.FromArgb(70, myButtonRenderer.StaticColor); gradientDrawable.SetColor(staticColor.ToAndroid()); } } else { if (myButtonRenderer.IsGradient) { gradientDrawable.SetColors(new int[] { myButtonRenderer.StartColor.ToAndroid(), myButtonRenderer.EndColor.ToAndroid() }); } else { gradientDrawable.SetColor(myButtonRenderer.StaticColor.ToAndroid()); } } } }
/// <summary> /// Method triggered when changes occures on gradient parameters /// </summary> private void UpdateBackgroundColor(GradientDrawable gradientDrawable) { var customFrame = (Element as CrossRoundedFrame); var startColor = customFrame?.StartColor; var endColor = customFrame?.EndColor; var gradientDirection = customFrame?.GradientDirection; if (startColor.Value.IsDefault && endColor.Value.IsDefault) { var aColor = customFrame.BackgroundColor.IsDefault ? Xamarin.Forms.Color.Accent.ToAndroid() : customFrame.BackgroundColor.ToAndroid(); gradientDrawable.SetColor(aColor); return; } int[] colors = new int[2]; colors[0] = startColor.Value.ToAndroid(); colors[1] = endColor.Value.ToAndroid(); switch (gradientDirection.Value) { default: case GradientDirections.ToRight: gradientDrawable.SetOrientation(GradientDrawable.Orientation.LeftRight); break; case GradientDirections.ToLeft: gradientDrawable.SetOrientation(GradientDrawable.Orientation.RightLeft); break; case GradientDirections.ToTop: gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); break; case GradientDirections.ToBottom: gradientDrawable.SetOrientation(GradientDrawable.Orientation.TopBottom); break; case GradientDirections.ToTopLeft: gradientDrawable.SetOrientation(GradientDrawable.Orientation.BrTl); break; case GradientDirections.ToTopRight: gradientDrawable.SetOrientation(GradientDrawable.Orientation.BlTr); break; case GradientDirections.ToBottomLeft: gradientDrawable.SetOrientation(GradientDrawable.Orientation.TrBl); break; case GradientDirections.ToBottomRight: gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr); break; } gradientDrawable.SetColors(colors); }
public static Drawable CreateBackgroundColor(Color color, float cornerRadius) { GradientDrawable drawble = new GradientDrawable(); drawble.SetShape(ShapeType.Rectangle); drawble.SetCornerRadius(cornerRadius); drawble.SetColors(new int[] { color, color }); return(drawble); }
protected override void OnElementChanged(ElementChangedEventArgs <GradientContentView> e) { base.OnElementChanged(e); if (GradientContentView != null) { GradientDrawable = new GradientDrawable(); GradientDrawable.SetColors(new int[] { GradientContentView.StartColor.ToAndroid(), GradientContentView.EndColor.ToAndroid() }); } }
public static Drawable CreateBackgroundGradient(Color startColor, Color endColor, Color centerColor, float cornerRadius, GradientDrawable.Orientation orientation) { GradientDrawable gradientDrawable = new GradientDrawable(); gradientDrawable.SetShape(ShapeType.Rectangle); gradientDrawable.SetCornerRadius(cornerRadius); if (centerColor != Xamarin.Forms.Color.Transparent.ToAndroid()) { gradientDrawable.SetColors(new int[] { startColor, centerColor, endColor }); } else { gradientDrawable.SetColors(new int[] { startColor, endColor }); } gradientDrawable.SetGradientType(GradientType.LinearGradient); gradientDrawable.SetOrientation(orientation); return(gradientDrawable); }
/// <summary> /// Setup the gradient layer /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs<EasyGradientView> e) { base.OnElementChanged(e); if (EasyGradientView != null) { //ShapeDrawable sd = new ShapeDrawable(new RectShape()); GradientDrawable = new GradientDrawable(); GradientDrawable.SetColors(new int[] { EasyGradientView.StartColor.ToAndroid(), EasyGradientView.EndColor.ToAndroid() }); } }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.NewElement != null) { var view = (Colaboro.ColabControls.CustomEntry)Element; if (view.IsCurvedCornersEnabled) { // creating gradient drawable for the curved background var _gradientBackground = new GradientDrawable(); _gradientBackground.SetShape(ShapeType.Rectangle); //_gradientBackground.SetColor(Color.Red);//view.BackgroundColor.ToAndroid() _gradientBackground.SetColors(new int[] { Android.Graphics.Color.Red }); // Thickness of the stroke line _gradientBackground.SetStroke(view.BorderWidth, view.BorderColor.ToAndroid()); // Radius for the curves _gradientBackground.SetCornerRadius( DpToPixels(this.Context, Convert.ToSingle(view.CornerRadius))); // set the background of the label Control.SetBackground(_gradientBackground); /*var sdk = Android.OS.Build.VERSION.SdkInt; * if (sdk < Android.OS.BuildVersionCodes.JellyBean) * { * Control.SetBackgroundDrawable(_gradientBackground); * } * else * { * Control.SetBackground(_gradientBackground); * }*/ } // Set padding for the internal text from border Control.SetPadding( (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingTop, (int)DpToPixels(this.Context, Convert.ToSingle(12)), Control.PaddingBottom); } }
void UpdateGradient() { var colors = Gradient.GetColors(Element); if (colors == null) { return; } _gradient.SetColors(colors.Select(x => (int)x.ToAndroid()).ToArray()); _gradient.SetOrientation(ConvertOrientation()); _view.ClipToOutline = true; //not to overflow children _view.SetBackground(_gradient); }
public void OnAnimationUpdate(ValueAnimator animation) { try { var evaluator = new ArgbEvaluator(); var newStart = (int)evaluator.Evaluate(animation.AnimatedFraction, Start, End); var newMid = (int)evaluator.Evaluate(animation.AnimatedFraction, Mid, Start); var newEnd = (int)evaluator.Evaluate(animation.AnimatedFraction, End, Mid); int[] newArray = { newStart, newMid, newEnd }; GradientDrawableView.SetColors(newArray); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
void SetColors() { var effect = (PQGradiantEffect)Element.Effects.FirstOrDefault(e => e is PQGradiantEffect); if (effect == null) { return; } var colors = effect.Colors; if (colors != null && colors.Length > 0) { int[] androidcolors = colors.Select(s => s.ToAndroid()).Select(s => s.ToArgb()).ToArray(); gradientDrawable.SetColors(androidcolors); } }
public void OnAnimationUpdate(ValueAnimator animation) { try { var evaluator = new ArgbEvaluator(); var newStart = (int)evaluator.Evaluate(animation.AnimatedFraction, Start, End); var newMid = (int)evaluator.Evaluate(animation.AnimatedFraction, Mid, Start); var newEnd = (int)evaluator.Evaluate(animation.AnimatedFraction, End, Mid); int[] newArray = { newStart, newMid, newEnd }; GradientDrawableView.SetColors(newArray); } catch (Exception e) { Console.WriteLine(e); } }
public static void UpdateFrom(this View nativeControl, Controls.RoundedBoxView.RoundedBoxView formsControl, string propertyChanged) { if (nativeControl == null || formsControl == null) { return; } if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.CornerRadiusProperty.PropertyName) { nativeControl.UpdateCornerRadius(formsControl.CornerRadius); } if (propertyChanged == VisualElement.BackgroundColorProperty.PropertyName) { var background = nativeControl.Background as GradientDrawable; if (background != null) { background.SetColor(formsControl.BackgroundColor.ToAndroid()); } else { var grad = new GradientDrawable(); grad.SetOrientation(GradientDrawable.Orientation.TopBottom); grad.SetColors(new[] { formsControl.BackgroundColor.ToAndroid().ToArgb(), formsControl.BackgroundColor.ToAndroid().ToArgb() }); nativeControl.Background = grad; } nativeControl.UpdateCornerRadius(formsControl.CornerRadius); nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); } if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.BorderColorProperty.PropertyName) { nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); } if (propertyChanged == Controls.RoundedBoxView.RoundedBoxView.BorderThicknessProperty.PropertyName) { nativeControl.UpdateBorder(formsControl.BorderColor, formsControl.BorderThickness); } }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="colors">new int[]{Color.LightGreen,Color.DarkGreen,}</param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="showBorderWhite">Set 3 pixels width solid color border</param> /// <param name="showCornerRadius">Set CornerRadius 10</param> /// <returns></returns> public static (GradientDrawable, Bitmap) GetGradientDrawable(Activity context, int[] colors, int width, int height, bool showBorderWhite = false, bool showCornerRadius = false) { try { // Initialize a new GradientDrawable var gd = new GradientDrawable(); // Set the color array to draw gradient gd.SetColors(colors); // Set the GradientDrawable gradient type linear gradient gd.SetGradientType(GradientType.LinearGradient); // Set GradientDrawable shape is a rectangle gd.SetShape(ShapeType.Rectangle); // Set 3 pixels width solid color border if (showBorderWhite) { gd.SetStroke(3, Color.White); } // Set GradientDrawable width and in pixels gd.SetSize(width, height); // Width 450 pixels and height 150 pixels // Set CornerRadius if (showCornerRadius) { gd.SetCornerRadius(10); } var bitmap = BitmapUtil.ConvertToBitmap(gd, width, height); return(gd, bitmap); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(null, null); } }
private void UpdateColors() { if (_drawable == null) { return; } var colors = Element.Colors; if (colors == null) { colors = new Xamarin.Forms.Color[] { Element.BackgroundColor, Element.BackgroundColor }; } else if (colors.Count() == 1) { colors = new Xamarin.Forms.Color[] { colors.First(), colors.First() }; } _drawable.SetColors(colors.Select(s => s.ToAndroid().ToArgb()).ToArray()); }
private void ApplyStyle() { var frame = Element as CustomFrame; var gradientDrawable = new GradientDrawable(); gradientDrawable.SetCornerRadius(frame.CornerRadius); gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop); gradientDrawable.SetColors(new int[] { frame.EndColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(), frame.StartColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb() }); if (frame.HasBorder) { gradientDrawable.SetStroke((int)frame.StrokeThickness, frame.OutlineColor.ToAndroid()); } var ld = default(LayerDrawable); if (frame.HasShadow) { var shadow = new GradientDrawable(); int[] colors1 = { frame.ShadowColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(), Color.Transparent.ToAndroid().ToArgb() }; shadow.SetOrientation(GradientDrawable.Orientation.TopBottom); //shadow.SetColors(colors1); shadow.SetStroke((int)frame.StrokeThickness + 5, frame.ShadowColor.ToAndroid()); shadow.SetCornerRadius(frame.CornerRadius); ld = new LayerDrawable(new Drawable[] { shadow, gradientDrawable }); ld.SetLayerInset(0, 0, 0, 0, 0); ld.SetLayerInset(1, 0, 6, 0, 0); } else { ld = new LayerDrawable(new Drawable[] { gradientDrawable }); ld.SetLayerInset(0, 0, 0, 0, 0); } Background = ld; }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (GradientDrawable != null && GradientContentView != null) { if (e.PropertyName == GradientContentView.StartColorProperty.PropertyName || e.PropertyName == GradientContentView.EndColorProperty.PropertyName) { GradientDrawable.SetColors(new int[] { GradientContentView.StartColor.ToAndroid(), GradientContentView.EndColor.ToAndroid() }); Invalidate(); } if (e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == GradientContentView.OrientationProperty.PropertyName) { Invalidate(); } } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { var button = Control; // Applies a "gray" gradient to our Android popup buttons var gradientDrawable = new GradientDrawable(); gradientDrawable.SetOrientation(GradientDrawable.Orientation.TlBr); gradientDrawable.SetColors(new int[] { Color.Argb(255, 167, 169, 172), Color.Argb(255, 76, 76, 76) }); gradientDrawable.SetGradientType(GradientType.RadialGradient); gradientDrawable.SetGradientRadius(300); gradientDrawable.SetGradientCenter(0.5f, 0); button.SetBackgroundDrawable(gradientDrawable); // Sets a small drop shadow to the buttons' text button.SetShadowLayer(1, 1, 1, Color.Black); } }
void SetGradientOrientation() { var control = (GradientTabbedPage)this.Element; gradient.SetGradientType(GradientType.LinearGradient); if (control.Orientation == GradientOrientation.Horizontal) { gradient.SetOrientation(GradientDrawable.Orientation.LeftRight); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } else if (control.Orientation == GradientOrientation.Vertical) { gradient.SetOrientation(GradientDrawable.Orientation.TopBottom); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } else if (control.Orientation == GradientOrientation.BlTr) { gradient.SetOrientation(GradientDrawable.Orientation.BlTr); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } else if (control.Orientation == GradientOrientation.BrTl) { gradient.SetOrientation(GradientDrawable.Orientation.BlTr); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } else if (control.Orientation == GradientOrientation.TlBr) { gradient.SetOrientation(GradientDrawable.Orientation.TlBr); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } else if (control.Orientation == GradientOrientation.TrBl) { gradient.SetOrientation(GradientDrawable.Orientation.TrBl); gradient.SetColors(new int[] { control.StartColor.ToAndroid(), control.EndColor.ToAndroid() }); } }
public void UpdateData(UserFriend userFriends) { _userFriends = userFriends; if (string.IsNullOrEmpty(userFriends.Name)) { _friendName.Visibility = ViewStates.Gone; } else { _friendName.Visibility = ViewStates.Visible; _friendName.Text = userFriends.Name; } if (userFriends.AmountSbd != 0) { _sbdAmount.Visibility = ViewStates.Visible; _sbdAmount.Text = $"{(userFriends.AmountSbd > 0 ? "+" : "-")}${Math.Abs(userFriends.AmountSbd)}"; } else { _sbdAmount.Visibility = ViewStates.Gone; } _friendLogin.Text = userFriends.Author; if (!string.IsNullOrEmpty(_userFriends.Avatar)) { Picasso.With(_context).Load(_userFriends.Avatar.GetProxy(_friendAvatar.LayoutParameters.Width, _friendAvatar.LayoutParameters.Height)) .Placeholder(Resource.Drawable.ic_holder) .NoFade() .Priority(Picasso.Priority.Normal) .Into(_friendAvatar, null, OnError); } else { Picasso.With(_context).Load(Resource.Drawable.ic_holder).Into(_friendAvatar); } _followButton.Visibility = AppSettings.User.Login == _friendLogin.Text ? ViewStates.Gone : ViewStates.Visible; if (string.Equals(AppSettings.User.Login, userFriends.Author, StringComparison.OrdinalIgnoreCase)) { _followButton.Visibility = ViewStates.Invisible; } else { var background = new GradientDrawable(); _followButton.Background = null; if (userFriends.FollowedChanging) { background.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 }); background.SetOrientation(GradientDrawable.Orientation.LeftRight); background.SetStroke(0, Color.White); _followButton.Text = string.Empty; _followButton.SetTextColor(Color.White); _followButton.Enabled = false; _loader.Visibility = ViewStates.Visible; } else { if (userFriends.HasFollowed) { background.SetColors(new int[] { Color.White, Color.White }); background.SetStroke(3, Style.R244G244B246); _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Unfollow); _followButton.SetTextColor(Style.R15G24B30); } else { background.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 }); background.SetOrientation(GradientDrawable.Orientation.LeftRight); background.SetStroke(0, Color.White); _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Follow); _followButton.SetTextColor(Color.White); } _followButton.Enabled = true; _loader.Visibility = ViewStates.Gone; } background.SetCornerRadius(100); _followButton.Background = background; } }
public void UpdateHeader(UserProfileResponse profile) { if (profile == null) { return; } _profile = profile; _userAvatar = profile.ProfileImage; if (!string.IsNullOrEmpty(_userAvatar)) { Picasso.With(_context).Load(_userAvatar.GetImageProxy(_profileImage.LayoutParameters.Width, _profileImage.LayoutParameters.Height)) .Placeholder(Resource.Drawable.ic_holder) .NoFade() .Into(_profileImage, null, OnError); } else { Picasso.With(_context).Load(Resource.Drawable.ic_holder).Into(_profileImage); } _transferButton.Visibility = AppSettings.User.HasPostingPermission ? ViewStates.Visible : ViewStates.Gone; if (profile.Username.Equals(AppSettings.User.Login, StringComparison.OrdinalIgnoreCase)) { _votingPower.VotingPower = (float)profile.VotingPower; _votingPower.Draw = true; _followContainer.Visibility = ViewStates.Gone; } else { if (profile.FollowedChanging) { _followBtnBackground.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 }); _followBtnBackground.SetOrientation(GradientDrawable.Orientation.LeftRight); _followBtnBackground.SetStroke(0, Color.White); _followButton.Text = string.Empty; _followButton.SetTextColor(Color.White); _followButton.Enabled = false; _loadingSpinner.Visibility = ViewStates.Visible; } else { if (profile.HasFollowed) { _followBtnBackground.SetColors(new int[] { Color.White, Color.White }); _followBtnBackground.SetStroke(3, Style.R244G244B246); _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Unfollow); _followButton.SetTextColor(Style.R15G24B30); } else { _followBtnBackground.SetColors(new int[] { Style.R255G121B4, Style.R255G22B5 }); _followBtnBackground.SetOrientation(GradientDrawable.Orientation.LeftRight); _followBtnBackground.SetStroke(0, Color.White); _followButton.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.Follow); _followButton.SetTextColor(Color.White); } _followButton.Enabled = true; _loadingSpinner.Visibility = ViewStates.Gone; } } if (!string.IsNullOrEmpty(profile.Name)) { _name.Text = profile.Name; _name.SetTextColor(Style.R15G24B30); } else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase)) { _name.Visibility = ViewStates.Gone; } if (!string.IsNullOrEmpty(profile.Location)) { _place.Text = profile.Location.Trim(); } else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase)) { _place.Visibility = ViewStates.Gone; } if (!string.IsNullOrEmpty(profile.About)) { _description.Text = profile.About; _description.SetTextColor(Style.R15G24B30); } else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase)) { _description.Visibility = ViewStates.Gone; } if (!string.IsNullOrEmpty(profile.Website)) { _site.AutoLinkText = profile.Website; _site.SetTextColor(Style.R231G72B00); } else if (!string.Equals(AppSettings.User.Login, profile.Username, StringComparison.OrdinalIgnoreCase)) { _site.Visibility = ViewStates.Gone; } _photosCount.Text = profile.PostCount.ToString("N0"); _followingCount.Text = profile.FollowingCount.ToString("#,##0"); _followersCount.Text = profile.FollowersCount.ToString("#,##0"); _balance.Text = StringHelper.ToFormatedCurrencyString(profile.EstimatedBalance, App.MainChain); }