UITableViewCell TableViewCellForRowAtIndexPath(UITableView aTableView, NSIndexPath indexPath)
        {
            MasterCell cell = (MasterCell)aTableView.DequeueReusableCell("MasterCell");
            var        item = rows [indexPath.Row];

            if (item.ContainsKey("icon"))
            {
                cell.iconActivity.Image = UIImage.FromFile(item ["icon"].ToString());
            }
            else
            {
                cell.iconActivity.Image = null;
            }
            cell.lblTitle.Text      = item ["title"].ToString();
            cell.lblTitle.Font      = UIFont.FromName("DINPro-Medium", 16);
            cell.lblValue.Text      = ((float)item ["value"]).ToString("N2");
            cell.lblValue.Font      = UIFont.FromName("DINPro-Medium", 20);
            cell.lblValue.TextColor = UIColor.FromHSBA(0.02f, 0.79f, 0.81f, 1.00f);
            cell.lblCurrency.Font   = UIFont.FromName("DINPro-Medium", 20);
            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                cell.lblCurrency.TextColor = UIColor.FromRGBA(0.43f, 0.43f, 0.43f, 1.00f);
            }

            cell.ContentView.BackgroundColor = UIColor.FromPatternImage(UIImage.FromFile("table-row-bkg.png"));

            return(cell);
        }
        public override void Draw(CGRect rect)
        {
            //Stopwatch s = new Stopwatch();
            //s.Start();

            //Console.WriteLine (" ----- SatBrightPickerView Draw");

            CGContext context = UIGraphics.GetCurrentContext();

            CGColor[] gradColors    = new CGColor[] { UIColor.FromHSBA(hue, 1, 1, 1).CGColor, new CGColor(1, 1, 1, 1) };
            nfloat[]  gradLocations = new nfloat[] { 0.0f, 1.0f };

            var colorSpace = CGColorSpace.CreateDeviceRGB();

            CGGradient gradient = new CGGradient(colorSpace, gradColors, gradLocations);

            context.DrawLinearGradient(gradient, new CGPoint(rect.Size.Width, 0), new CGPoint(0, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradColors = new CGColor[] { new CGColor(0, 0, 0, 0), new CGColor(0, 0, 0, 1) };

            gradient = new CGGradient(colorSpace, gradColors, gradLocations);
            context.DrawLinearGradient(gradient, new CGPoint(0, 0), new CGPoint(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);

            gradient.Dispose();
            colorSpace.Dispose();

            //s.Stop();
            //Console.WriteLine("-----> SatBright Draw time: " + s.Elapsed.ToString());
        }         //draw
Example #3
0
        partial void AddAsset(NSObject sender)
        {
            var rnd = new Random();

            // Create a random dummy image.
            var size = (rnd.Next(0, 2) == 0)
                                ? new CGSize(400f, 300f)
                                : new CGSize(300f, 400f);

            var renderer = new UIGraphicsImageRenderer(size);
            var image    = renderer.CreateImage(context => {
                UIColor.FromHSBA((float)rnd.NextDouble(), 1, 1, 1).SetFill();
                context.FillRect(context.Format.Bounds);
            });

            // Add it to the photo library
            PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {
                PHAssetChangeRequest creationRequest = PHAssetChangeRequest.FromImage(image);

                if (AssetCollection != null)
                {
                    var addAssetRequest = PHAssetCollectionChangeRequest.ChangeRequest(AssetCollection);
                    addAssetRequest.AddAssets(new PHObject [] {
                        creationRequest.PlaceholderForCreatedAsset
                    });
                }
            }, (success, error) => {
                if (!success)
                {
                    Console.WriteLine(error.LocalizedDescription);
                }
            });
        }
        partial void AddButtonClickHandler(NSObject sender)
        {
            // Create a random dummy image.
            var rect = new Random().Next(0, 2) == 0 ?
                       new CGRect(0f, 0f, 400f, 300f) : new CGRect(0f, 0f, 300f, 400f);

            UIGraphics.BeginImageContextWithOptions(rect.Size, false, 1f);
            UIColor.FromHSBA(new Random().Next(0, 100) / 100f, 1f, 1f, 1f).SetFill();
            UIGraphics.RectFillUsingBlendMode(rect, CGBlendMode.Normal);
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            // Add it to the photo library
            PHPhotoLibrary.SharedPhotoLibrary.PerformChanges(() => {
                PHAssetChangeRequest assetChangeRequest = PHAssetChangeRequest.FromImage(image);

                if (AssetCollection != null)
                {
                    PHAssetCollectionChangeRequest assetCollectionChangeRequest = PHAssetCollectionChangeRequest.ChangeRequest(AssetCollection);
                    assetCollectionChangeRequest.AddAssets(new PHObject[] {
                        assetChangeRequest.PlaceholderForCreatedAsset
                    });
                }
            }, (success, error) => {
                if (!success)
                {
                    Console.WriteLine(error.LocalizedDescription);
                }
            });
        }
        private void DrawHueCircle()
        {
            var size = new SizeF(this.Bounds.Size.Width, this.Bounds.Size.Height);

            UIGraphics.BeginImageContextWithOptions(size, true, 0f);
            UIColor.FromRGB(83, 83, 83).SetFill();
            UIGraphics.RectFill(new RectangleF(0f, 0f, size.Width, size.Height));

            var          sectors = 180;
            var          radius  = (nfloat)(Math.Min(size.Width, size.Height) / 2);
            var          angle   = 2f * (float)Math.PI / sectors;
            UIBezierPath bezierPath;

            for (var i = 0; i < sectors; i++)
            {
                var center = new PointF(size.Width / 2, size.Height / 2);
                bezierPath = UIBezierPath.FromArc(center, radius, i * angle, (i + 1) * angle, true);
                bezierPath.AddLineTo(center);
                bezierPath.ClosePath();

                var color = UIColor.FromHSBA((float)i / sectors, 1f, 1f, 1f);
                color.SetFill();
                color.SetStroke();

                bezierPath.Fill();
                bezierPath.Stroke();
            }

            var img = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            img.Draw(new PointF(0f, 0f));
        }
Example #6
0
        void RoundtripHSBA(UIColor c, bool supported = true)
        {
            try {
                nfloat h, s, b, a;
                /*bool result =*/
                c.GetHSBA(out h, out s, out b, out a);
                UIColor r = UIColor.FromHSBA(h, s, b, a);
#if true
                Assert.That(r.ToString(), Is.EqualTo(c.ToString()), c.ToString());
#else
                if (result)
                {
                    string cs = c.ToString();
                    float  h2, s2, b2, a2;
                    c.GetHSBA2(out h2, out s2, out b2, out a2);
                    Assert.That(h, Is.EqualTo(h2), cs);
                    Assert.That(s, Is.EqualTo(s2), cs);
                    Assert.That(b, Is.EqualTo(b2), cs);
                    Assert.That(a, Is.EqualTo(a2), cs);
                }
#endif
            } catch (Exception) {
                if (supported)
                {
                    Assert.Fail(c.ToString());
                }
            }
        }
Example #7
0
        void AddMarkerInBounds(CoordinateBounds bounds)
        {
            double latitude = bounds.SouthWest.Latitude + GetRandomNumber() * (bounds.NorthEast.Latitude - bounds.SouthWest.Latitude);

            // If the visible region crosses the antimeridian (the right-most point is
            // "smaller" than the left-most point), adjust the longitude accordingly.
            bool   offset    = (bounds.NorthEast.Longitude < bounds.SouthWest.Longitude);
            double longitude = bounds.SouthWest.Longitude + GetRandomNumber() *
                               (bounds.NorthEast.Longitude - bounds.SouthWest.Longitude + (offset ? 360 : 0));

            if (longitude > 180)
            {
                longitude -= 360;
            }

            var color = UIColor.FromHSBA((float)GetRandomNumber(), 1, 1, 1.0f);

            var position = new CLLocationCoordinate2D(latitude, longitude);
            var marker   = Marker.FromPosition(position);

            marker.Title           = string.Format("Marker {0}", ++markerCount);
            marker.AppearAnimation = MarkerAnimation.Pop;
            marker.Icon            = Marker.MarkerImage(color);
            marker.Map             = mapView;
        }
Example #8
0
        private static UIColor GetColorWithBrightness(this UIColor color, float amount)
        {
            nfloat hue, saturation, brightness, alpha;

            color.GetHSBA(out hue, out saturation, out brightness, out alpha);
            var result = UIColor.FromHSBA(hue, saturation, brightness * amount, alpha);

            return(result);
        }
            public SortNode(int value, int maxValue)
            {
                Value = value;
                var hue = value / (nfloat)maxValue;

                Color = UIColor.FromHSBA(hue, 1, 1, 1);

                Id = new NSUuid().ToString();
            }
Example #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <Switch> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                // do whatever you want to the UISwitch here!
                Control.OnTintColor = UIColor.FromHSBA(0.01f, 0.77f, 0.89f, 1.00f);
            }
        }
        private void CalculateRGB()
        {
            nfloat r, g, b, a;

            UIColor.FromHSBA(_hue, _saturation, _brightness, 1f).GetRGBA(out r, out g, out b, out a);

            this.Red   = (byte)(r * 0xff);
            this.Green = (byte)(g * 0xff);
            this.Blue  = (byte)(b * 0xff);
        }
Example #12
0
 void updateTintColor()
 {
     if (profile.Icon == TTTProfileIcon.X)
     {
         window.TintColor = UIColor.FromHSBA(0f, 1f, 1f, 1f);
     }
     else
     {
         window.TintColor = UIColor.FromHSBA(1f / 3f, 1f, 0.8f, 1f);
     }
 }
        private void PlaceMarkerAtCoord(CLLocationCoordinate2D coord)
        {
            var color  = UIColor.FromHSBA((float)AppUtils.GetRandomNumber(), 1, 1, 1.0f);
            var marker = Marker.FromPosition(coord);

            marker.AppearAnimation = MarkerAnimation.Pop;
            marker.Icon            = Marker.MarkerImage(color);
            marker.Map             = mapView;
            markers.Add(marker);

            UpdateText();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (thisTask == null)
            {
                AppUtils.ShowSimpleDialog(this, "ERROR", "Error loading task data", "Ok");
                NavigationController.PopViewController(true);
                return;
            }

            taskData = JsonConvert.DeserializeObject <MapMarkerTaskData>(thisTask.JsonData);

            markers         = new List <Marker>();
            mapView.MapType = MapViewType.Hybrid;
            mapView.Settings.MyLocationButton = true;

            if (!string.IsNullOrWhiteSpace(thisTask.CompletionData.JsonData))
            {
                // load previously placed markers
                Map_Location[] locs = JsonConvert.DeserializeObject <Map_Location[]>(thisTask.CompletionData.JsonData);

                if (locs != null)
                {
                    foreach (Map_Location loc in locs)
                    {
                        CLLocationCoordinate2D coord = new CLLocationCoordinate2D(loc.Lat, loc.Long);
                        var color  = UIColor.FromHSBA((float)AppUtils.GetRandomNumber(), 1, 1, 1.0f);
                        var marker = Marker.FromPosition(coord);
                        marker.AppearAnimation = MarkerAnimation.Pop;
                        marker.Icon            = Marker.MarkerImage(color);
                        marker.Map             = mapView;
                        markers.Add(marker);
                    }
                }
            }

            UpdateText();
            TaskDescLabel.Text = thisTask.Description;

            // Listen to the myLocation property of GMSMapView.
            mapView.AddObserver(this, new NSString("myLocation"), NSKeyValueObservingOptions.New, IntPtr.Zero);

            mapView.CoordinateTapped += CoordinateTapped;
            mapView.TappedMarker     += TappedMarker;

            // Ask for My Location data after the map has already been added to the UI.
            InvokeOnMainThread(() => mapView.MyLocationEnabled = true);

            MarkLocButton.TouchUpInside        += AddMarkerOnPosition;
            ProgressFinishButton.TouchUpInside += FinishButtonPressed;
        }
Example #15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.
            button = new UIButton()
            {
                BackgroundColor = UIColor.FromHSBA(0.531f, 1, 1, 1),
                Frame           = new RectangleF(0, 0, 140, 140),
            };
            button.SetTitleColor(UIColor.White, UIControlState.Normal);
            button.SetTitle("Tap to start", UIControlState.Normal);
            button.Layer.CornerRadius = 70;

            button.TouchUpInside += delegate {
                var anim = button.PopAnimationForKey("bounce.me");
                if (anim != null)
                {
                    button.PopRemoveAnimationForKey("bounce.me");
                    button.SetTitle("Tap to start", UIControlState.Normal);
                }
                else
                {
                    float              size      = 1;
                    NSValue            fromValue = NSValue.FromSizeF(new SizeF(size, size));
                    NSValue            toValue   = NSValue.FromSizeF(new SizeF(1.4f, 1.4f));
                    POPSpringAnimation bounce    = POPSpringAnimation.AnimationWithPropertyNamed(POPMutableAnimatableProperty.POPViewScaleXY);
                    bounce.SpringBounciness = 14;
                    bounce.FromValue        = fromValue;
                    bounce.ToValue          = toValue;

                    // Note: CompletionBlock is much more reliable than Finished
                    bounce.CompletionBlock = delegate(POPAnimation animation, bool finished) {
                        if (finished)
                        {
                            // Auto-reverse
                            var prevFrom = (animation as POPSpringAnimation).FromValue;
                            (animation as POPSpringAnimation).FromValue = (animation as POPSpringAnimation).ToValue;
                            (animation as POPSpringAnimation).ToValue   = prevFrom;
                            button.PopAddAnimation(animation, "bounce.me");
                        }
                    };

                    button.PopAddAnimation(bounce, "bounce.me");
                    button.SetTitle("Tap to stop", UIControlState.Normal);
                }
            };

            button.Center = View.Center;
            View.Add(button);
        }
Example #16
0
        public void HSBA_No_Saturation()
        {
            nfloat  h = 0.0f;
            nfloat  s = 0.0f;
            nfloat  b = 0.0f;
            nfloat  a = 0.0f;
            UIColor c = UIColor.FromHSBA(h, s, b, a);

            c.GetHSBA(out h, out s, out b, out a);
            Assert.That(h, Is.EqualTo((nfloat)0f), "h");
            Assert.That(s, Is.EqualTo((nfloat)0f), "s");
            Assert.That(b, Is.EqualTo((nfloat)0f), "b");
            Assert.That(a, Is.EqualTo((nfloat)0f), "a");
        }
Example #17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.FromHSBA(220f / 360.0f, 0.08f, 0.93f, 1.0f);

            container = new UIView(View.Bounds)
            {
                AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
            };

            // Creating ComposeBarView and initializing its properties
            composeBarView = new ComposeBarView(new RectangleF(0, View.Bounds.Height - ComposeBarView.InitialHeight, View.Bounds.Width, ComposeBarView.InitialHeight))
            {
                MaxCharCount       = 160,
                MaxLinesCount      = 5,
                Placeholder        = "Type something...",
                UtilityButtonImage = UIImage.FromBundle("Camera")
            };

            // This will handle when the user taps the main button
            composeBarView.DidPressButton += (sender, e) => {
                var composeBar = sender as ComposeBarView;
                Console.WriteLine("Main button pressed. Text:\n{0}", composeBar.Text);
                AppendTextToTextView(string.Format("Main button pressed. Text:\n{0}", composeBar.Text));
                composeBar.Text = string.Empty;
                composeBar.ResignFirstResponder();
            };

            // This will handle when the user taps the Utility button in this case a CameraButton
            composeBarView.DidPressUtilityButton += (sender, e) => {
                Console.WriteLine("Utility button pressed");
                AppendTextToTextView("Utility button pressed");
            };

            // Here we setup the view that will hold everything we write
            textView = new UITextView(new RectangleF(0, 0, View.Bounds.Width, View.Bounds.Height - composeBarView.Bounds.Height))
            {
                AutoresizingMask     = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight,
                Editable             = false,
                BackgroundColor      = UIColor.Clear,
                AlwaysBounceVertical = true,
                Font = UIFont.SystemFontOfSize(UIFont.LabelFontSize),
                Text = "Welcome to the Demo!\n\nThis is just some placeholder text to give you a better feeling of how the compose bar can be used along other Views."
            };

            container.AddSubview(textView);
            container.AddSubview(composeBarView);
            View.AddSubview(container);
        }
        /// <summary>
        /// HACK: just a bit of fun
        /// </summary>
        public override void TouchesMoved(NSSet touches, UIEvent evt)
        {
            base.TouchesMoved(touches, evt);
            UITouch touch = touches.AnyObject as UITouch;

            if (touch != null)
            {
                var force    = touch.Force;
                var maxForce = touch.MaximumPossibleForce;
                var alpha    = force / maxForce;
                alpha = (nfloat)0.5 + (alpha / 2);
                View.BackgroundColor = UIColor.FromHSBA(1, 1, 1, alpha);
//				View.BackgroundColor = UIColor.Red.ColorWithAlpha (alpha);
            }
        }
        private void PlaceMarkerAtCoord(CLLocationCoordinate2D coord)
        {
            var color = UIColor.FromHSBA((float)AppUtils.GetRandomNumber(), 1, 1, 1.0f);

            if (currentMarker != null)
            {
                currentMarker.Map = null;
            }

            currentMarker = Marker.FromPosition(coord);
            currentMarker.AppearAnimation = MarkerAnimation.Pop;
            currentMarker.Icon            = Marker.MarkerImage(color);
            currentMarker.Map             = mapView;
            chosenLocation = new Map_Location(coord.Latitude, coord.Longitude, 15f);
        }
Example #20
0
        private SCNAction FlashAnimation(double duration)
        {
            var action = SCNAction.CustomAction(duration, (node, elapsedTime) => {
                // animate color from HSB 48/100/100 to 48/30/100 and back
                var elapsedTimePercentage = elapsedTime / (float)duration;
                var saturation            = 2.8f * (elapsedTimePercentage - 0.5f) * (elapsedTimePercentage - 0.5f) + 0.3f;
                var material = node.Geometry.FirstMaterial;
                if (material != null)
                {
                    material.Diffuse.Contents = UIColor.FromHSBA(0.1333f, saturation, 1.0f, 1.0f);
                }
            });

            return(action);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // customize slider 1
            Slider1.MaxValue = 255.0f;
            Slider1.PopUpViewCornerRadius = 0.0f;
            Slider1.SetMaxFractionDigitsDisplayed(0);
            Slider1.PopUpViewColor = UIColor.FromHSBA(0.55f, 0.8f, 0.9f, 0.7f);
            Slider1.Font           = UIFont.FromName("GillSans-Bold", 22);
            Slider1.TextColor      = UIColor.FromHSBA(0.55f, 1.0f, 0.5f, 1);
            Slider1.PopUpViewWidthPaddingFactor = 3f;


            // customize slider 2
            NSNumberFormatter formatter = new NSNumberFormatter();

            formatter.NumberStyle           = NSNumberFormatterStyle.Percent;
            Slider2.NumberFormatter         = formatter;
            Slider2.Font                    = UIFont.FromName("Futura-CondensedExtraBold", 26);
            Slider2.PopUpViewAnimatedColors = new UIColor[] { UIColor.Purple, UIColor.Red, UIColor.Orange };
            Slider2.PopUpViewArrowLength    = 20.0f;


            //customize slider 3
            NSNumberFormatter tempFormatter = new NSNumberFormatter();

            tempFormatter.PositiveSuffix = "°C";
            tempFormatter.NegativeSuffix = "°C";

            Slider3.DataSource            = this;
            Slider3.NumberFormatter       = tempFormatter;
            Slider3.MinValue              = -20.0f;
            Slider3.MaxValue              = 60.0f;
            Slider3.PopUpViewCornerRadius = 16.0f;

            Slider3.Font      = UIFont.FromName("HelveticaNeue-CondensedBlack", 26);
            Slider3.TextColor = UIColor.FromWhiteAlpha(0.0f, 0.5f);

            UIColor coldBlue = UIColor.FromHSBA(0.6f, 0.7f, 1.0f, 1.0f);
            UIColor blue     = UIColor.FromHSBA(0.55f, 0.75f, 1.0f, 1.0f);
            UIColor green    = UIColor.FromHSBA(0.3f, 0.65f, 0.8f, 1.0f);
            UIColor yellow   = UIColor.FromHSBA(0.15f, 0.9f, 0.9f, 1.0f);
            UIColor red      = UIColor.FromHSBA(0.0f, 0.8f, 1.0f, 1.0f);

            Slider3.SetPopUpViewAnimatedColors(new UIColor[] { coldBlue, blue, green, yellow, red },
                                               new NSNumber[] { -20, 0, 5, 25, 60 });
        }
Example #22
0
        /*
         * Render the page here: we assume we are already in a normalized coordinate system which maps
         *  our standard aspect ratio (3:4) to (1:1)
         * The reason why we do this is to reuse the same drawing code for both the preview and the
         *  full screen; for full screen rendering, we map the whole view, whereas the preview maps
         *  the whole preview image to a quarter of the page.
         * */
        public RectangleF [] RenderPage(Page page, SizeF size, bool unstyledDrawing)
        {
            var pageRect        = new RectangleF(0, 0, size.Width, size.Height);
            var paragraphBounds = new RectangleF [page.Paragraphs.Count];

            using (var ctxt = UIGraphics.GetCurrentContext()) {
                // fill background
                ctxt.SetFillColor(UIColor.FromHSBA(0.11f, 0.2f, 1, 1).CGColor);
                ctxt.FillRect(pageRect);

                pageRect = pageRect.Inset(20, 20);

                int i = 0;
                foreach (var p in page.Paragraphs)
                {
                    var bounds = new RectangleF(pageRect.X, pageRect.Y, 0, 0);

                    if (UnstyledDrawing)
                    {
                        var text = new NSString(page.StringForParagraph(p));

                        var font = UIFont.FromName("HoeflerText-Regular", 24);

                        // draw text with the old legacy path, setting the font color to black.
                        ctxt.SetFillColor(UIColor.Black.CGColor);
                        bounds.Size = text.DrawString(pageRect, font);
                    }
                    else
                    {
                        // TODO: draw attributed text with new string drawing
                        var text        = page.AttributedStringForParagraph(p);
                        var textContext = new NSStringDrawingContext();

                        text.DrawString(pageRect, NSStringDrawingOptions.UsesLineFragmentOrigin, textContext);

                        bounds = textContext.TotalBounds;
                        bounds.Offset(pageRect.X, pageRect.Y);
                    }

                    paragraphBounds [i++] = bounds;

                    pageRect.Y += bounds.Height;
                }

                return(paragraphBounds);
            }
        }
        private void DrawColorSqure()
        {
            var startX = this.Bounds.GetMinX();
            var startY = this.Bounds.GetMinY();
            var endX   = this.Bounds.GetMaxX();
            var endY   = this.Bounds.GetMaxY();

            using (var context = UIGraphics.GetCurrentContext())
            {
                var path = new CGPath();
                path.AddLines(new PointF[]
                {
                    new PointF(startX, startY),
                    new PointF(endX, startY),
                    new PointF(endX, endY),
                    new PointF(startX, endY)
                });

                path.CloseSubpath();
                context.AddPath(path);
                context.Clip();

                using (var rgb = CGColorSpace.CreateDeviceRGB())
                {
                    nfloat r, g, b, a;
                    UIColor.FromHSBA(_hue, 1f, 1f, 1f).GetRGBA(out r, out g, out b, out a);

                    var gradient1 = new CGGradient(rgb, new CGColor[]
                    {
                        CGColorFromHex(0xff, 0xff, 0xff, 0xff),
                        CGColorFromHex((byte)(r * 0xff), (byte)(g * 0xff), (byte)(b * 0xff), 0xff)
                    });

                    var gradient2 = new CGGradient(rgb, new CGColor[]
                    {
                        CGColorFromHex(0x00, 0x00, 0x00, 0x0f),
                        CGColorFromHex(0x00, 0x00, 0x00, 0xff)
                    });

                    context.DrawLinearGradient(gradient1, new PointF(startX, startY), new PointF(endX, startX), 0);
                    context.DrawLinearGradient(gradient2, new PointF(startX, startY), new PointF(startY, endY), 0);
                }
            }
        }
        public ColorPickerStandardViewController()
            : base()
        {
            _colors = new List <UIColor>();
            var colorCount = 20;

            for (var i = 0; i < colorCount; i++)
            {
                var color = UIColor.FromHSBA(i / (float)colorCount, 1f, 1f, 1f);
                _colors.Add(color);
            }

            colorCount = 8;

            for (var i = 0; i < colorCount; i++)
            {
                var color = UIColor.FromWhiteAlpha(i / (float)(colorCount - 1), 1f);
                _colors.Add(color);
            }
        }
        public override void Draw(CGRect rect)
        {
            using (var colorSpace = CGColorSpace.CreateDeviceRGB())
            {
                var context       = UIGraphics.GetCurrentContext();
                var gradLocations = new nfloat[] { 0.0f, 1.0f };

                var gradColors = new[] { UIColor.FromHSBA(Hue, 1, 1, 1).CGColor, new CGColor(1, 1, 1, 1) };
                using (var gradient = new CGGradient(colorSpace, gradColors, gradLocations))
                {
                    context.DrawLinearGradient(gradient, new CGPoint(rect.Size.Width, 0), new CGPoint(0, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                }

                gradColors = new[] { new CGColor(0, 0, 0, 0), new CGColor(0, 0, 0, 1) };
                using (var gradient = new CGGradient(colorSpace, gradColors, gradLocations))
                {
                    context.DrawLinearGradient(gradient, new CGPoint(0, 0), new CGPoint(0, rect.Size.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                }
            }
        }
        protected override void SetBackgroundColor(Color color)
        {
            base.SetBackgroundColor(color);

            if (Control == null)
            {
                return;
            }

            if (color == Color.Default)
            {
                var c = Control.ProgressTintColor;
                c.GetHSBA(out var hue, out var saturation, out var brightness, out var alpha);
                saturation             = (nfloat)Math.Min((double)saturation * colorDesaturation, 1.0);
                Control.TrackTintColor = UIColor.FromHSBA(hue, saturation, brightness, alpha);
                Control.SetNeedsDisplay();
                return;
            }

            Control.TrackTintColor = color.ToUIColor();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var camera  = CameraPosition.FromCamera(39.13006, -77.508545, 4);
            var mapView = MapView.FromCamera(CGRect.Empty, camera);

            // Create the first polygon.
            var polygon = new Polygon()
            {
                Path        = PathOfNewYorkState(),
                Title       = "New York",
                FillColor   = UIColor.FromRGBA(0.25f, 0, 0, 0.05f),
                StrokeColor = UIColor.Black,
                StrokeWidth = 2,
                Tappable    = true,
                Map         = mapView
            };

            // Copy the existing polygon and its settings and use it as a base for the
            // second polygon.

            polygon           = (Polygon)polygon.Copy();
            polygon.Title     = "North Carolina";
            polygon.Path      = PathOfNorthCarolina();
            polygon.FillColor = UIColor.FromRGBA(0, 0.25f, 0, 0.05f);
            polygon.Map       = mapView;

            mapView.OverlayTapped += (sender, e) => {
                // When a polygon is tapped, randomly change its fill color to a new hue.
                if (e.Overlay is Polygon)
                {
                    var pol = e.Overlay as Polygon;
                    var hue = GetRandomNumber();
                    pol.FillColor = UIColor.FromHSBA(hue, 1, 1, 0.05f);
                }
            };

            View = mapView;
        }
        public ColorPickerHueGridViewController()
            : base()
        {
            _colors = new List <UIColor>();

            for (var i = 0; i < 12; i++)
            {
                var hue        = (float)(i * 30f / 360f);
                var colorCount = DisplayHelper.Is4InchDisplay() ? 32 : 24;

                for (var j = 0; j < colorCount; j++)
                {
                    var row    = j / 4;
                    var column = j % 4;

                    var saturation = (float)column * 0.25f + 0.25f;
                    var luminosity = 1f - (float)row * 0.12f;
                    var color      = UIColor.FromHSBA(hue, saturation, luminosity, 1f);
                    _colors.Add(color);
                }
            }
        }
        private void TouchHandler(NSSet touches)
        {
            // Set reference to the location of the touch in member point
            var touch = touches.FirstOrDefault() as UITouch;

            if (touch == null)
            {
                return;
            }

            _point = touch.LocationInView(this);

            var indicator = GetIndicatorCoordinate(_point);

            _point = indicator.Point;
            var color = (hue : (nfloat)0, saturation : (nfloat)0f);

            if (!indicator.IsCenter)
            {
                color = HueSaturationAtPoint(new CGPoint(x: _point.X * _scale, y: _point.Y * _scale));
            }

            _color = UIColor.FromHSBA(hue: color.hue, saturation: color.saturation, brightness: _brightness, alpha: 1.0f);

            nfloat red   = 0f;
            nfloat green = 0f;
            nfloat blue  = 0f;
            nfloat alpha = 0f;

            _color.GetRGBA(out red, out green, out blue, out alpha);

            Console.WriteLine($"color hue: Red {Math.Round(red, 2)} Green {Math.Round(green, 2)} Blue {Math.Round(blue, 2)}");

            // Notify delegate of the new Hue and Saturation
            //delegate?.hueAndSaturationSelected(color.hue, saturation: color.saturation);

            // Draw the indicator
            DrawIndicator();
        }
            public override AnnotationView GetAnnotationView(MapView mapView, IAnnotation annotation)
            {
                if (!(annotation is PointAnnotation))
                {
                    return(null);
                }

                string reuseIdentifier = ((PointAnnotation)annotation).Coordinate.Longitude.ToString();
                // for better performance, reuse views
                var annotationView = mapView.DequeueReusableAnnotationView(reuseIdentifier);

                if (annotationView == null)
                {
                    annotationView       = new CustomAnnotationView(reuseIdentifier);
                    annotationView.Frame = new CGRect(0, 0, 48, 48);

                    // Set the annotation view's background to a value determined by its longitude
                    float hue = Math.Abs((float)((PointAnnotation)annotation).Coordinate.Longitude / 100);
                    annotationView.BackgroundColor = UIColor.FromHSBA(hue, .5f, 1f, 1f);
                }

                return(annotationView);
            }