Example #1
0
 public static Hsv ToHsv(this HighColor color)
 {
     return(new Hsv
     {
         H = double.Parse(color.H),
         S = double.Parse(color.S),
         V = double.Parse(color.V),
     });
 }
Example #2
0
        protected void btnAceptar_Click(object sender, DialogClickEventArgs e)
        {
            var       newColor = Color.FromArgb(SliderRed.Progress, SliderGreen.Progress, SliderBlue.Progress).ToHsv();
            var       color    = Color.FromArgb(SliderRed.Progress, SliderGreen.Progress, SliderBlue.Progress).ToAndroidColor();
            LowColor  newLow   = null;
            HighColor newHigh  = null;

            switch (ValueToChange)
            {
            case ColorValue.LowColor:
                newLow = new LowColor
                {
                    H = newColor.H.ToString(),
                    S = newColor.S.ToString(),
                    V = newColor.V.ToString(),
                };
                break;

            case ColorValue.HighColor:
                newHigh = new HighColor
                {
                    H = newColor.H.ToString(),
                    S = newColor.S.ToString(),
                    V = newColor.V.ToString(),
                };
                break;
            }

            if (ColorToChange == typeof(TemperatureColor))
            {
                ColorConfiguration.TemperatureColor.LowColor  = newLow ?? ColorConfiguration.TemperatureColor.LowColor;
                ColorConfiguration.TemperatureColor.HighColor = newHigh ?? ColorConfiguration.TemperatureColor.HighColor;
                if (newLow != null)
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnLowTemp)).SetBackgroundColor(color);
                }
                else
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnHighTemp)).SetBackgroundColor(color);
                }
            }
            else if (ColorToChange == typeof(HumidityColor))
            {
                ColorConfiguration.HumidityColor.LowColor  = newLow ?? ColorConfiguration.HumidityColor.LowColor;
                ColorConfiguration.HumidityColor.HighColor = newHigh ?? ColorConfiguration.HumidityColor.HighColor;
                if (newLow != null)
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnLowHumidity)).SetBackgroundColor(color);
                }
                else
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnHighHumidity)).SetBackgroundColor(color);
                }
            }
            else if (ColorToChange == typeof(ProximityColor))
            {
                ColorConfiguration.ProximityColor.LowColor  = newLow ?? ColorConfiguration.ProximityColor.LowColor;
                ColorConfiguration.ProximityColor.HighColor = newHigh ?? ColorConfiguration.ProximityColor.HighColor;
                if (newLow != null)
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnLowProximity)).SetBackgroundColor(color);
                }
                else
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnHighProximity)).SetBackgroundColor(color);
                }
            }
            else if (ColorToChange == typeof(HourColor))
            {
                ColorConfiguration.HourColor.LowColor  = newLow ?? ColorConfiguration.HourColor.LowColor;
                ColorConfiguration.HourColor.HighColor = newHigh ?? ColorConfiguration.HourColor.HighColor;
                if (newLow != null)
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnLowHour)).SetBackgroundColor(color);
                }
                else
                {
                    ((Button)Activity.FindViewById(Resource.Id.btnHighHour)).SetBackgroundColor(color);
                }
            }

            ColorConfiguration.SaveToXML();
        }
Example #3
0
 public static Color GetGradientColor(double currentValue, LowColor lowerColor, HighColor higherColor, double defaultThreshold)
 {
     try
     {
         var lowColor  = lowerColor.ToHsv();
         var highColor = higherColor.ToHsv();
         var value     = currentValue;
         if (currentValue < double.Parse(lowerColor.Threshold))
         {
             value = double.Parse(lowerColor.Threshold);
         }
         else if (currentValue > double.Parse(higherColor.Threshold))
         {
             value = double.Parse(higherColor.Threshold);
         }
         value = value * 100 / defaultThreshold / 100;
         var gradient = new Hsv
         {
             H = lowColor.H + (value * (highColor.H - lowColor.H)),
             S = lowColor.S + (value * (highColor.S - lowColor.S)),
             V = lowColor.V + (value * (highColor.V - lowColor.V))
         };
         var gradientColor = gradient.ToColor();
         return(gradientColor);
     }
     catch
     {
         GetColorSetupFromXML().SaveToXML();
         return(GetGradientColor(currentValue, lowerColor, higherColor, defaultThreshold));
     }
 }