wxr
2021-06-09 cb6e11c5067ecaba4d8f9907989154167c1e8943
HDL_ON/UI/UI2/3-Intelligence/Automation/LogicView/TimeView.cs
@@ -15,17 +15,18 @@
            Width = Application.GetRealWidth(343),
            X = Application.GetRealWidth(16),
            BackgroundColor = CSS.CSS_Color.view,
            Radius=(uint)Application.GetRealHeight(12),
            Radius =(uint)Application.GetRealHeight(12),
        };
        /// <summary>
        /// 时间控件UIPickerView 
        /// </summary>
        public UIPickerView mUIPickerView = new UIPickerView
        {
            //Y = Application.GetRealHeight(44),
            X= Application.GetRealWidth(12),
            Height = Application.GetRealHeight(297),
            Width = Application.GetRealWidth(343),
            BackgroundColor = CSS.CSS_Color.viewTranslucence,
            Width = Application.GetRealWidth(343-12*2),
            BackgroundColor =CSS.CSS_Color.viewTranslucence,
            Radius = (uint)Application.GetRealHeight(12),
        };
        /// <summary>
@@ -39,7 +40,8 @@
            Width = Application.GetRealWidth(52),
            Height = Application.GetRealHeight(32),
            Y = Application.GetRealHeight(6),
            X = Application.GetRealWidth(8)
            X = Application.GetRealWidth(8),
        };
        /// <summary>
        /// 确定Btn
@@ -62,29 +64,146 @@
            BackgroundColor = CSS.CSS_Color.viewLine,
            Width = Application.GetRealWidth(343),
            Height = 1,
            Y = Application.GetRealWidth(44)
            Y = Application.GetRealWidth(44),
        };
        /// <summary>
        /// 时间View的方法
        /// </summary>
        /// <returns></returns>
        public void FLayoutView(FrameLayout fLayout)
        //public void FLayoutView(FrameLayout fLayout, string currState, Action<string> action)
        {
            fLayout.AddChidren(frameLayout);
            frameLayout.AddChidren(mUIPickerView);
            frameLayout.AddChidren(btnCancel);
            frameLayout.AddChidren(btnConfirm);
            frameLayout.AddChidren(btnLine);
            fLayout.AddChidren(frameLayout);
            //TimePoint(fLayout, action,currState);
        }
        /// <summary>
        /// 获取24小时列表
        /// 选中时间的方法
        /// </summary>
        /// <param name="fLayout">父控件</param>
        /// <param name="currState">之前状态值</param>
        /// <param name="action">返回时间值</param>
        public void TimePoint(FrameLayout fLayout, string currState, Action<string> 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();
            };
        }
        /// <summary>
        /// 获取1-24小时列表
        /// </summary>
        /// <returns></returns>
        public List<string> GethStringList()
        {
            //初始化列表
            var hList = new List<string>();
            for (int i = 1; i < 24; i++)
            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;
        }
        /// <summary>
        /// 获取0-23小时列表
        /// </summary>
        /// <returns></returns>
        public List<string> GethStringList0()
        {
            //初始化列表
            var hList = new List<string>();
            for (int i = 0; i < 24; i++)
            {
                if (i < 10)
                {
@@ -131,14 +250,14 @@
        }
        /// <summary>
        /// 获取24小时列表
        /// 获取023小时列表
        /// </summary>
        /// <returns></returns>
        public List<int> GethIntList()
        {
            //初始化列表
            var hList = new List<int>();
            for (int i = 1; i < 24; i++)
            for (int i = 0; i < 24; i++)
            {
                //添加数据
                hList.Add(i);
@@ -147,6 +266,7 @@
        }
        /// <summary>
        /// 获取60分钟列表
        /// </summary>
@@ -163,37 +283,6 @@
            return mList;
        }
       
        /// <summary>
        /// 返回指定单位列表
        /// </summary>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        /// <param name="name">单位(时,分,秒)</param>
        /// <param name="digit">位数(10以下用(1位还是2位)显示)</param>
        /// <returns></returns>
        public List<string> GetStringList(int min, int max, string name, int digit)
        {
            //初始化列表
            var list = new List<string>();
            for (int i = min; i < max; i++)
            {
                if (i < 10 && digit == 2)
                {
                    var a = "0" + i.ToString();
                    //添加数据
                    list.Add(a + " " + name);
                }
                else
                {
                    //添加数据
                    list.Add(i.ToString() + " " + name);
                }
            }
            return list;
        }
        /// <summary>
        /// 获取时间值
        /// </summary>