using System; using Shared; using System.Collections.Generic; namespace HDL_ON.UI.UI2.Intelligence.Automation.LogicView { public class TimeView { /// /// 主控件 /// public FrameLayout frameLayout = new FrameLayout { Y = Application.GetRealHeight(350), Height = Application.GetRealHeight(297), Width = Application.GetRealWidth(343), X = Application.GetRealWidth(16), BackgroundColor = CSS.CSS_Color.view, Radius =(uint)Application.GetRealHeight(12), }; /// /// 时间控件UIPickerView /// public UIPickerView mUIPickerView = new UIPickerView { X= Application.GetRealWidth(12), Height = Application.GetRealHeight(297), Width = Application.GetRealWidth(343-12*2), BackgroundColor =CSS.CSS_Color.viewTranslucence, Radius = (uint)Application.GetRealHeight(12), }; /// /// 取消Btn /// public Button btnCancel = new Button { TextID = StringId.cancelSelected, TextSize = TextSize.text14, TextColor = CSS.CSS_Color.textCancelColor, Width = Application.GetRealWidth(52), Height = Application.GetRealHeight(32), Y = Application.GetRealHeight(6), X = Application.GetRealWidth(8), }; /// /// 确定Btn /// public Button btnConfirm = new Button { TextID = StringId.confirmSelected, TextSize = TextSize.text14, TextColor = CSS.CSS_Color.textConfirmColor, Width = Application.GetRealWidth(52), Height = Application.GetRealHeight(32), X = Application.GetRealWidth(283), Y = Application.GetRealHeight(6), }; /// /// 线 /// public Button btnLine = new Button { BackgroundColor = CSS.CSS_Color.viewLine, Width = Application.GetRealWidth(343), Height = 1, Y = Application.GetRealWidth(44), }; /// /// 时间View的方法 /// /// public void FLayoutView(FrameLayout fLayout) { fLayout.AddChidren(frameLayout); frameLayout.AddChidren(mUIPickerView); frameLayout.AddChidren(btnCancel); frameLayout.AddChidren(btnConfirm); frameLayout.AddChidren(btnLine); } /// /// 选中时间的方法 /// /// 父控件 /// 之前状态值 /// 返回时间值 public void TimePoint(FrameLayout fLayout, string currState, Action action) { //取消点击事件 btnCancel.MouseUpEventHandler += (sender, e1) => { //移除fLayout界面 fLayout.RemoveFromParent(); }; //加载数据界面的设置方法(列表互不联动) mUIPickerView.setNPicker(GethStringList(), GetmStringList(), null); var systemHour = DateTime.Now.Hour; //获取小时 var systeMinute = DateTime.Now.Minute;//获取分钟 int systemHourIndex = 0; int systeMinuteIndex = 0; for (int i = 0; i < GethIntList().Count; i++) { var currhour = GethIntList()[i]; if (systemHour == currhour) { systemHourIndex = i; break; } } for (int i = 0; i < GetmIntList().Count; i++) { var currminute = GetmIntList()[i]; if (systeMinute == currminute) { systeMinuteIndex = i; break; } } //默认初始选中状态 mUIPickerView.setCurrentItems(systemHourIndex, systeMinuteIndex, 0); string currH = ""; string currM = ""; if (systemHour < 10) { currH = "0" + systemHour.ToString(); } else { currH = systemHour.ToString(); } if (systeMinute < 10) { currM = "0" + systeMinute.ToString(); } else { currM = systeMinute.ToString(); } //定义一个局部变量记录选中时间 string timepoint = currH + ":" + currM; if (currState != "") { int hIndex = GetValueIndex(currState, 0, 1, GethIntList()); int mIndex = GetValueIndex(currState, 1, 0, GetmIntList()); //更新初始状态 mUIPickerView.setCurrentItems(hIndex, mIndex, 0); timepoint = currState; } //选中时间回调方法,时间变化一次回调一次 mUIPickerView.OnSelectChangeEvent += (index1, index2, index3) => { string hour = GethStringList()[index1].Split(' ')[0]; string minuet = GetmStringList()[index2].Split(' ')[0]; timepoint = hour + ":" + minuet; }; //确定点击事件 btnConfirm.MouseUpEventHandler += (sender, e3) => { action(timepoint); //移除fLayout界面 fLayout.RemoveFromParent(); }; } /// /// 获取1-24小时列表 /// /// public List GethStringList() { //初始化列表 var hList = new List(); for (int i = 0; i < 24; i++) { if (i < 10) { var a = "0" + i.ToString(); //添加数据 hList.Add(a + " " + Language.StringByID(StringId.h)); } else { //添加数据 hList.Add(i.ToString() + " " + Language.StringByID(StringId.h)); } } return hList; } /// /// 获取0-23小时列表 /// /// public List GethStringList0() { //初始化列表 var hList = new List(); for (int i = 0; i < 24; i++) { if (i < 10) { var a = "0" + i.ToString(); //添加数据 hList.Add(a + " " + Language.StringByID(StringId.h)); } else { //添加数据 hList.Add(i.ToString() + " " + Language.StringByID(StringId.h)); } } return hList; } /// /// 获取60分钟列表 /// /// public List GetmStringList() { //初始化列表 var mList = new List(); for (int i = 0; i < 60; i++) { if (i < 10) { var a = "0" + i.ToString(); //添加数据 mList.Add(a + " " + Language.StringByID(StringId.m)); } else { //添加数据 mList.Add(i.ToString() + " " + Language.StringByID(StringId.m)); } } return mList; } /// /// 获取60秒列表 /// /// public List GetsStringList() { //初始化列表 var mList = new List(); for (int i = 0; i < 60; i++) { if (i < 10) { var a = "0" + i.ToString(); //添加数据 mList.Add(a + " " + Language.StringByID(StringId.s)); } else { //添加数据 mList.Add(i.ToString() + " " + Language.StringByID(StringId.s)); } } return mList; } /// /// 获取023小时列表 /// /// public List GethIntList() { //初始化列表 var hList = new List(); for (int i = 0; i < 24; i++) { //添加数据 hList.Add(i); } return hList; } /// /// 获取60分钟列表 /// /// public List GetmIntList() { //初始化列表 var mList = new List(); for (int i = 0; i < 60; i++) { //添加数据 mList.Add(i); } return mList; } /// /// 获取时间值 /// /// 源数据 /// 返回源数据数组里面某个值索引 /// /// /// public int GetValueIndex(string str, int digit, int startIndex, List list) { int index = 0; int value = 0; if (str.Contains(":")) { value = int.Parse(str.Split(':')[digit]); } for (int i = startIndex; i < list.Count; i++) { if (value == i) { index = i; break; } } return index; } } }