using System; using System.Collections.Generic; using Shared; using Shared.R; using Shared.Phone; using Shared.Common; namespace Shared.Phone.Device.Logic { public class CyclicCycle:FrameLayout { Action action; public CyclicCycle(Action action) { this.action = action; } public CyclicCycle() { Tag = "Logic"; } public int value = 0; public void Show() { var weeklist = new List(); ///记录之前值 value = Common.Logic.CurrentLogic.TimeAttribute.WeekDay; this.BackgroundColor = ZigbeeColor.Current.LogicTopViewBackgroundColor; var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight(140), Y = Application.GetRealHeight(80), }; AddChidren(topFrameLayout); var titleName = new Button { TextID = MyInternationalizationString.cycle, TextSize = 16, TextColor = ZigbeeColor.Current.LogicTextBlackColor, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth(150), }; topFrameLayout.AddChidren(titleName); var back = new Button { Width = Application.GetRealWidth(110), Height = Application.GetRealHeight(110), X = Application.GetRealWidth(20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "ZigeeLogic/Back.png", }; topFrameLayout.AddChidren(back); back.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); //if (action != null) //action(); }; var middle = new VerticalScrolViewLayout(); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight(1920 - 220-200); middle.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor; this.AddChidren(middle); if (Common.Logic.CurrentLogic.TimeAttribute.Repeat == 5) { string len = ""; var maxvalue = Convert.ToString(Common.Logic.CurrentLogic.TimeAttribute.WeekDay, 2); var str = maxvalue.Insert(0, new string('0', 8 - maxvalue.Length)); for (int j = 7; j >= 0; j--) { len += str.Substring(j, 1); } for (int j = 0; j < len.Length; j++) { var strvalue = len.Substring(j, 1); if (strvalue == "1") { if ((j + 1) == 1) { weeklist.Add(Language.StringByID(MyInternationalizationString.mon)); } else if ((j + 1) == 2) { weeklist.Add(Language.StringByID(MyInternationalizationString.tue)); } else if ((j + 1) == 3) { weeklist.Add(Language.StringByID(MyInternationalizationString.wed)); } else if ((j + 1) == 4) { weeklist.Add(Language.StringByID(MyInternationalizationString.thu)); } else if ((j + 1) == 5) { weeklist.Add(Language.StringByID(MyInternationalizationString.frl)); } else if ((j + 1) == 6) { weeklist.Add(Language.StringByID(MyInternationalizationString.sat)); } else if ((j + 1) == 7) { weeklist.Add(Language.StringByID(MyInternationalizationString.sun)); } } } } var cyclelist = new List(); cyclelist.AddRange(new string[] { Language.StringByID(MyInternationalizationString.mon), Language.StringByID(MyInternationalizationString.tue), Language.StringByID(MyInternationalizationString.wed), Language.StringByID(MyInternationalizationString.thu), Language.StringByID(MyInternationalizationString.frl), Language.StringByID(MyInternationalizationString.sat), Language.StringByID(MyInternationalizationString.sun), }); foreach (var name in cyclelist) { var cyclerwLayout = new RowLayout { Height = Application.GetRealHeight(180), }; middle.AddChidren(cyclerwLayout); var btnname = new Button { X = Application.GetRealWidth(40), Width = Application.GetRealWidth(600), Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.CenterLeft, Text = name, TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; cyclerwLayout.AddChidren(btnname); var btnCheck = new Button { Width = Application.GetRealWidth(115), Height = Application.GetRealHeight(110), Gravity = Gravity.CenterVertical, X = Application.GetRealWidth(1080 - 140), SelectedImagePath = "ZigeeLogic/CheckOn.png", UnSelectedImagePath = "ZigeeLogic/Check.png", }; cyclerwLayout.AddChidren(btnCheck); var str = weeklist.Find((o) => { return o == name; }); if (str != null) { btnCheck.IsSelected = true; } ///选中时间 EventHandler weekclick = (sender, e) => { btnCheck.IsSelected = !btnCheck.IsSelected; if (btnCheck.IsSelected) { var d = weeklist.Find((o) => { return o == name; }); if (d == null) { weeklist.Add(name); } } else { weeklist.RemoveAll((o) => { return o == name; }); } int weekvalue = 0; foreach (var strname in weeklist) { if (Language.StringByID(MyInternationalizationString.mon) == strname) { weekvalue += 1; } else if (Language.StringByID(MyInternationalizationString.tue) == strname) { weekvalue += 2; } else if (Language.StringByID(MyInternationalizationString.wed) == strname) { weekvalue += 4; } else if (Language.StringByID(MyInternationalizationString.thu) == strname) { weekvalue += 8; } else if (Language.StringByID(MyInternationalizationString.frl) == strname) { weekvalue += 16; } else if (Language.StringByID(MyInternationalizationString.sat) == strname) { weekvalue += 32; } else if (Language.StringByID(MyInternationalizationString.sun) == strname) { weekvalue += 64; } } //Common.Logic.CurrentLogic.TimeAttribute.Repeat = 5; //Common.Logic.CurrentLogic.TimeAttribute.WeekDay = weekvalue; value = weekvalue; }; cyclerwLayout.MouseUpEventHandler += weekclick; btnname.MouseUpEventHandler += weekclick; btnCheck.MouseUpEventHandler += weekclick; } var fra = new FrameLayout { Y = middle.Bottom, Height = Application.GetRealHeight(200), BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor, }; this.AddChidren(fra); var btncomplete = new Button { X = Application.GetRealWidth(290), Height = Application.GetRealHeight(150),//194 Width = Application.GetRealWidth(500), Radius = (uint)Application.GetRealHeight(50), BackgroundColor = ZigbeeColor.Current.LogicButtonBlueColor, TextID = MyInternationalizationString.Save, }; fra.AddChidren(btncomplete); EventHandler completeclick = (sender, e) => { RemoveFromParent(); Common.Logic.CurrentLogic.TimeAttribute.Repeat = 5; Common.Logic.CurrentLogic.TimeAttribute.WeekDay =value; if (action != null) action(); }; fra.MouseUpEventHandler += completeclick; btncomplete.MouseUpEventHandler += completeclick; } } }