Example #1
0
        private void TimerMove(TimerTile timerTile, double Start, double End)
        {
            try
            {
                Storyboard MoveTile = new Storyboard();
                QuadraticEase ease = new QuadraticEase();
                ease.EasingMode = EasingMode.EaseIn;

                DoubleAnimation MoveAnimation = new DoubleAnimation();
                MoveAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(250));
                MoveAnimation.From = Start;
                MoveAnimation.To = End;
                MoveAnimation.EasingFunction = ease;

                Storyboard.SetTarget(MoveAnimation, timerTile);
                Storyboard.SetTargetProperty(MoveAnimation, "(Canvas.Top)");

                MoveTile.Children.Add(MoveAnimation);
                MoveTile.Begin();
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #2
0
        public void TimerFastForward(TimerTile timerTile)
        {
            try
            {
                Appliance appl = Appliances.Find(e => (e.Name == timerTile.Name));

                appl.Time += new TimeSpan(0, 1, 0);

                ApplyTime(appl);
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #3
0
        public void TimerUnload(TimerTile timerTile)
        {
            try
            {
                Storyboard sbClose = new Storyboard();
                DoubleAnimation animClose = new DoubleAnimation();
                animClose.Duration = new Duration(TimeSpan.FromMilliseconds(400));
                animClose.From = 1.0;
                animClose.To = 0.0;

                Storyboard.SetTarget(animClose, timerTile);
                Storyboard.SetTargetProperty(animClose, "(UserControl.Opacity)");
                sbClose.Children.Add(animClose);

                sbClose.Completed +=
                    (sendr, evts) =>
                    {
                        Appliance appl = Appliances.Find(e => (e.Name == timerTile.Name));
                        double dTop = 0;

                        //Just in case
                        if (appl != null)
                        {
                            Appliances.Remove(appl);
                            appl = null;
                        }
                        mMainPage.Timers.Children.Remove(timerTile);

                        //Move all other timers up
                        if (mMainPage.Timers.Children.Count > 0)
                        {
                            //TODO: Issiw with where the Removed Tile is.
                            foreach(TimerTile tmrTile in mMainPage.Timers.Children)
                            {
                                var transform = tmrTile.TransformToVisual(mMainPage.Timers);
                                var controlPosition = transform.TransformPoint(new Point(0, 0));

                                if (controlPosition.Y > dTop)
                                {
                                    TimerMove(tmrTile, controlPosition.Y ,dTop); 
                                }
                                dTop = controlPosition.Y + tmrTile.ActualHeight;
                            }
                        }
                    };
                sbClose.Begin();
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #4
0
        public void TimerPlayStop(TimerTile timerTile)
        {
            try
            {
                Appliance appl = Appliances.Find(e => (e.Name == timerTile.Name));

                //Just in case
                if (appl != null)
                {
                    appl.IsRunning = !appl.IsRunning;

                    //Start the timer
                    if (mbIsRunning == false)
                    {
                        mbIsRunning = true;
                        TimerRun();
                    }
                    appl = null;
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #5
0
        public void TimerApplianceChange(TimerTile timerTile)
        {
            try
            {
                Appliance appl = Appliances.Find(e => (e.Name == timerTile.Name));
             
                //Don't change it if its running
                if (appl.IsRunning == false)
                {
                    Appliances.Remove(appl); //Remove previous appliance from list
                    string[] types = Enum.GetNames(typeof(Appliance.ApplianceType));
                    string type = "";

                    for (Byte b = 0; b < types.Count(); b++)
                    {
                        type = types[b];

                        if (type == appl.Type.ToString())
                        {
                            if ((b + 2) > types.Count())
                            {
                                type = types[0];
                            }
                            else
                            {
                                type = types[b + 1];
                            }

                            //Update everything
                            appl.Type = ApplianceTypeFromType(type);
                            appl = ApplianceByType(appl.Type);
                            timerTile.Name = appl.Name;
                            Appliances.Add(appl);
                            TimerSetIcon(timerTile, appl);
                            TimerSetTime(timerTile, appl.Time);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #6
0
        public void TimerSetTime(TimerTile timerTile, TimeSpan Time)
        { 
            try
            {
                if (timerTile == null) { return; } //In case user selects SETTINGS while timers are running.

                string sValue = "";
      
                //HOURS
                if (Time.Hours != tsPreviousTime.Hours)
                {
                    if (Time.Hours > 0)
                    {
                        sValue = Time.Hours.ToString();
                        TextChange(timerTile.TimeHoursColon, ":");
                        timerTile.grdTime.ColumnDefinitions[1].Width = new GridLength(1, GridUnitType.Star); 
                    }
                    else
                    {
                        TextChange(timerTile.TimeHoursColon, "");
                        timerTile.grdTime.ColumnDefinitions[1].Width = new GridLength(0);   
                    }
                    TextChange(timerTile.TimeHours, sValue);
                }

                //MINUTES - TENS
                if (Time.Minutes.ToString("00").Substring(0, 1) != tsPreviousTime.Minutes.ToString("00").Substring(0, 1))
                {
                    if (Time.Minutes.ToString("00").Substring(0, 1) == "0")
                    {
                        //If there are hours, show the minutes
                        if (Time.Hours > 0)
                        {
                            sValue = "0";
                            timerTile.grdTime.ColumnDefinitions[2].Width = new GridLength(1, GridUnitType.Star); 
                        }
                        else
                        {
                            sValue = "";
                            timerTile.grdTime.ColumnDefinitions[2].Width = new GridLength(0);  
                        }    
                    }
                    else
                    {
                        sValue = Time.Minutes.ToString("00").Substring(0, 1);
                        timerTile.grdTime.ColumnDefinitions[2].Width = new GridLength(1, GridUnitType.Star); 
                    }

                    TextChange(timerTile.TimeMinutesTen, sValue);
                }

                //MINUTES - ONES
                if (Time.Minutes.ToString("00").Substring(1, 1) != tsPreviousTime.Minutes.ToString("00").Substring(1, 1))
                {
                    TextChange(timerTile.TimeMinutesOne, Time.Minutes.ToString("00").Substring(1, 1));
                }

                //SECONDS - TENS
                if (Time.Seconds.ToString("00").Substring(0, 1) != tsPreviousTime.Seconds.ToString("00").Substring(0, 1))
                {
                    TextChange(timerTile.TimeSecondsTen, Time.Seconds.ToString("00").Substring(0, 1));
                }

                //SECONDS - ONES
                if (Time.Seconds.ToString("00").Substring(1, 1) != tsPreviousTime.Seconds.ToString("00").Substring(1, 1))
                {
                    TextChange(timerTile.TimeSecondsOne, Time.Seconds.ToString("00").Substring(1, 1));
                }
            }
            catch (Exception ex)
            {
                logException(ex);
            }
            finally
            {
                tsPreviousTime = Time;
            }
        }
Example #7
0
        public void TimerSetIcon(TimerTile timerTile, Appliance appl)
        {
            try
            {
                Storyboard sb = new Storyboard();

                DoubleAnimation FadeOut = new DoubleAnimation();
                FadeOut.Duration = new Duration(TimeSpan.FromMilliseconds(400));
                FadeOut.From = timerTile.ApplianceIcon.Opacity; ;
                FadeOut.To = 0.0;

                Storyboard.SetTarget(FadeOut, timerTile.ApplianceIcon);
                Storyboard.SetTargetProperty(FadeOut, "(Image.Opacity)");
                sb.Children.Add(FadeOut);
                sb.Completed += (sendr, e) =>
                {
                   
                    Storyboard sbFadeIn = new Storyboard();
                    DoubleAnimation FadeIn = new DoubleAnimation();
                    FadeIn.Duration = new Duration(TimeSpan.FromMilliseconds(400));
                    FadeIn.From = 0.0;
                    FadeIn.To = 1.0;
                    timerTile.ApplianceIcon.Source = ApplianceIconFromType(appl.Type).Source;

                    Storyboard.SetTarget(FadeIn, timerTile.ApplianceIcon);
                    Storyboard.SetTargetProperty(FadeIn, "(Image.Opacity)");
                    sbFadeIn.Children.Add(FadeIn);
                    sbFadeIn.Begin();
                };
                sb.Begin();
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }
Example #8
0
        public void TimerAdd(Appliance.ApplianceType Type)
        {
            try
            {
                double dTop = 0;
                Appliance newAppliance = ApplianceByType(Type);
                TimerTile timerTile = new TimerTile(this.TileColor, this.ApplianceIconFromType(Type), mMainPage);
                timerTile.Width = this.mMainPage.ActualWidth;
                timerTile.Height = this.mdTileSize;
                timerTile.Name = newAppliance.Name;

                TimerSetTime(timerTile, newAppliance.Time);

                Appliances.Add(newAppliance);

                if (Appliances.Count > 1)
                {
                    dTop = ((Appliances.Count - 1) * this.mdTileSize);
                    TimerTile tile = (TimerTile)this.mMainPage.Timers.Children[(this.mMainPage.Timers.Children.Count - 1)];
                    GeneralTransform transform = tile.TransformToVisual(mMainPage.Timers);
                    Point controlPosition = transform.TransformPoint(new Point(0, 0));

                    dTop = (controlPosition.Y + this.mdTileSize);
                }

                this.mMainPage.Timers.Children.Add(timerTile); //Must be after the check of top, just above here

                TimerMove(timerTile, this.mMainPage.ActualHeight, dTop);

                //Cleanup
                newAppliance = null;
                timerTile = null;
            }
            catch (Exception ex)
            {
                logException(ex);
            }
        }