Beispiel #1
0
        public Stream ProvideBitmap()
        {
            var stream = new MemoryStream();

            if (_cachedData != null)
            {
                var height = _cachedData.Length;
                var width  = _cachedData[0].Length;
                var bitmap = new Bitmap(width, height);
                Log.Info("Rendering bitmap");

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        var c = _cachedData[y][x] == -1
                            ? 0
                            : BitmapFormatter.RescaleValue(_cachedData[y][x], MaxIterations);
                        bitmap.SetPixel(x, y, Color.FromRgb(c, c, c));
                    }
                }

                Log.Info("Copying bitmap to output stream");
                bitmap.Save(stream, ImageFormat.Png);
                stream.Flush();
                stream.Position = 0;
            }

            return(stream);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the color to display for the test status
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public static XFColor Color(this ResultState result)
        {
            switch (result.Status)
            {
            case TestStatus.Passed:
                return(XFColor.Green);

            case TestStatus.Skipped:
                return(XFColor.FromRgb(206, 172, 0));       // Dark Yellow

            case TestStatus.Failed:
                if (result == ResultState.Failure)
                {
                    return(XFColor.Red);
                }
                if (result == ResultState.NotRunnable)
                {
                    return(XFColor.FromRgb(255, 106, 0)); // Orange
                }
                return(XFColor.FromRgb(170, 0, 0));       // Dark Red

            default:
                return(XFColor.Gray);
            }
        }
        static PaintDrawable CreateBadgeBackground(Context context, XColor color)
        {
            var badgeFrameLayoutBackground = new PaintDrawable();

            badgeFrameLayoutBackground.Paint.Color =
                color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

            badgeFrameLayoutBackground.Shape = new RectShape();
            badgeFrameLayoutBackground.SetCornerRadius(TypedValue.ApplyDimension(ComplexUnitType.Dip, 8,
                                                                                 context.Resources.DisplayMetrics));

            return(badgeFrameLayoutBackground);
        }
        public static void ApplyTinyBadge(this BottomNavigationItemView bottomNavigationView, XColor textColor)
        {
            if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                bottomNavigationView.SetClipChildren(false);
                bottomNavigationView.SetClipToPadding(false);

                ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single();
                bottomNavigationView.RemoveView(imageView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                    {
                        Gravity = GravityFlags.CenterHorizontal
                    }
                };

                badgeContainerFrameLayout.AddView(imageView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context);
                badgeContainer.TopMargin += 16;
                badgeContainer.Visibility = ViewStates.Visible;
                badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, XColor.Transparent);
                badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, "●", textColor, 20));

                badgeContainerFrameLayout.AddView(badgeContainer);

                bottomNavigationView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.Visibility = ViewStates.Visible;

                ((PaintDrawable)badgeContainer.Background).Paint.Color = textColor.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : textColor.ToAndroid();
            }
        }
        public static void ApplyBadge(this BottomNavigationItemView bottomNavigationView, XColor color, string text,
                                      XColor textColor)
        {
            if (!bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                bottomNavigationView.SetClipChildren(false);
                bottomNavigationView.SetClipToPadding(false);

                ImageView imageView = bottomNavigationView.GetChildrenOfType <ImageView>().Single();
                bottomNavigationView.RemoveView(imageView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(bottomNavigationView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                    {
                        Gravity = GravityFlags.CenterHorizontal
                    }
                };

                badgeContainerFrameLayout.AddView(imageView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(bottomNavigationView.Context);
                badgeContainer.TopMargin += 12;

                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                badgeContainer.Background = CreateBadgeBackground(bottomNavigationView.Context, color);
                badgeContainer.AddView(CreateBadgeText(bottomNavigationView.Context, text, textColor));

                badgeContainerFrameLayout.AddView(badgeContainer);

                bottomNavigationView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = bottomNavigationView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

                TextView textView = (TextView)badgeContainer.GetChildAt(0);
                textView.Text = text;
                textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid());
            }
        }
        public static void ApplyBadge(this TabLayout.TabView tabView, XColor color, string text,
                                      XColor textColor)
        {
            if (!tabView.GetChildrenOfType <BadgeFrameLayout>().Any())
            {
                tabView.SetClipChildren(false);
                tabView.SetClipToPadding(false);

                TextView tabTextView = tabView.GetChildrenOfType <TextView>().Single();
                tabView.RemoveView(tabTextView);

                FrameLayout badgeContainerFrameLayout = new FrameLayout(tabView.Context)
                {
                    LayoutParameters = new FrameLayout.LayoutParams(LP.WrapContent, LP.WrapContent)
                };

                badgeContainerFrameLayout.AddView(tabTextView);

                BadgeFrameLayout badgeContainer = CreateBadgeContainer(tabView.Context);
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                badgeContainer.Background = CreateBadgeBackground(tabView.Context, color);
                badgeContainer.AddView(CreateBadgeText(tabView.Context, text, textColor));

                badgeContainerFrameLayout.AddView(badgeContainer);

                tabView.AddView(badgeContainerFrameLayout);
            }
            else
            {
                BadgeFrameLayout badgeContainer = tabView.GetChildrenOfType <BadgeFrameLayout>().Single();
                badgeContainer.Visibility = !string.IsNullOrEmpty(text) ? ViewStates.Visible : ViewStates.Invisible;

                ((PaintDrawable)badgeContainer.Background).Paint.Color = color.IsDefault ? XColor.FromRgb(255, 59, 48).ToAndroid() : color.ToAndroid();

                TextView textView = (TextView)badgeContainer.GetChildAt(0);
                textView.Text = text;
                textView.SetTextColor(textColor.IsDefault ? XColor.White.ToAndroid() : textColor.ToAndroid());
            }
        }
 public object ProvideValue(IServiceProvider serviceProvider)
 {
     return(Color.FromRgb(Red, Green, Blue));
 }