From 902f19750cbf3e0e3dba7139947421ecb461f93f Mon Sep 17 00:00:00 2001
From: 陈嘉乐 <cjl@hdlchina.com.cn>
Date: 星期二, 16 三月 2021 17:50:41 +0800
Subject: [PATCH] 2021-3-16-5

---
 HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection2Page.cs |  308 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 308 insertions(+), 0 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection2Page.cs b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection2Page.cs
new file mode 100644
index 0000000..8f46dd9
--- /dev/null
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection2Page.cs
@@ -0,0 +1,308 @@
+锘縰sing HDL_ON.Stan;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HDL_ON.UI
+{
+    /// <summary>
+    /// 娣诲姞Evoyo鐨凪ini鏅鸿兘閬ユ帶鍣ㄦ楠�2鐣岄潰
+    /// </summary>
+    public class AddMiniRemoteControlDirection2Page : EditorCommonForm
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// wifi鍚�
+        /// </summary>
+        private string wifiName = string.Empty;
+        /// <summary>
+        /// wifi瀵嗙爜
+        /// </summary>
+        private string wifiPassword = string.Empty;
+        /// <summary>
+        /// 钃濈墮璁惧
+        /// </summary>
+        private List<HdlBluetoothLogic.BluetoothInfo> listDevice = new List<HdlBluetoothLogic.BluetoothInfo>();
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        /// <param name="i_wifiName">wifi鍚�(鍒殑鐣岄潰浼犺繃鏉ョ殑)</param>
+        /// <param name="i_wifiPassword">(鍒殑鐣岄潰浼犺繃鏉ョ殑)</param>
+        public void ShowForm(string i_wifiName, string i_wifiPassword)
+        {
+            this.wifiName = i_wifiName;
+            this.wifiPassword = i_wifiPassword;
+
+            //璁剧疆澶撮儴淇℃伅
+            base.SetTitleText(Language.StringByID(StringId.AddInfraredRemoteControl));
+            //杩欎釜鐣岄潰鐨勮儗鏅渶瑕佺櫧鑹�
+            bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
+
+            //鍒濆鍖栦腑閮ㄤ俊鎭�
+            this.InitMiddleFrame();
+        }
+
+        /// <summary>
+        /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+        /// </summary>
+        private void InitMiddleFrame()
+        {
+            //娓呯┖body
+            this.ClearBodyFrame();
+
+            //杩涘害鏉�
+            var btnProgress = new ProgressRowBar(180, 6);
+            btnProgress.Y = Application.GetRealHeight(218);
+            btnProgress.Gravity = Gravity.CenterHorizontal;
+            bodyFrameLayout.AddChidren(btnProgress);
+            btnProgress.StartMode1(true);
+
+            //璁惧鎼滅储涓�...
+            var btnSearch = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(20), false);
+            btnSearch.Y = btnProgress.Bottom + Application.GetRealHeight(40);
+            btnSearch.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
+            btnSearch.TextID = StringId.SearchingDevice;
+            btnSearch.TextAlignment = TextAlignment.Center;
+            bodyFrameLayout.AddChidren(btnSearch);
+
+            //璇风‘淇濇偍鐨勮摑鐗欏凡寮�鍚苟澶勪簬鍙互琚悳绱㈢姸鎬�
+            var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg2);
+            this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize,
+                CSS.CSS_Color.FirstLevelTitleColor, Application.GetRealHeight(20), btnSearch.Bottom + Application.GetRealHeight(4));
+
+            //寮�鍚繘搴︽潯鐗规晥
+            this.StartProgressSpecialEffects(btnProgress);
+        }
+
+        #endregion
+
+        #region 鈻� 鎼滅储钃濈墮___________________________
+
+        /// <summary>
+        /// 鎼滅储钃濈墮
+        /// </summary>
+        private void StartSearchBluetooth()
+        {
+            //寮�濮嬫悳绱㈣摑鐗�
+            HdlBluetoothLogic.Current.ScanBluetooth(2, (listBluetooth) =>
+            {
+                foreach (var device in listBluetooth)
+                {
+                    //鍙湁杩欎釜鏍囪瘑,鎵嶆槸绾㈠瀹�
+                    if (device.Name.StartsWith("MIR01R-LK.10") == true)
+                    {
+                        //鏄寚瀹氱殑绾㈠瀹濊澶�
+                        listDevice.Add(device);
+                    }
+                }
+                if (listDevice.Count == 0)
+                {
+                    //鎽ф瘉钃濈墮缂撳瓨
+                    HdlBluetoothLogic.Current.Dispone();
+                }
+                else if (listDevice.Count == 1)
+                {
+                    //濡傛灉鍙娴嬪埌涓�涓�,鍒欑洿鎺ヨ繛鎺�
+                    HdlBluetoothLogic.Current.ContectBluetooth(listDevice[0], (result) =>
+                    {
+                        if (result == true && this.Parent != null)
+                        {
+                            //杩炴帴鎴愬姛,鍒欒烦杞埌涓嬩竴涓晫闈�
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                this.CloseForm();
+                                var form = new AddMiniRemoteControlDirection3Page();
+                                form.AddForm(this.wifiName, this.wifiPassword);
+                            });
+                        }
+                        else
+                        {
+                            HdlBluetoothLogic.Current.Dispone();
+                        }
+                    });
+                }
+                else
+                {
+                    var listName = new List<string>();
+                    foreach (var device in listDevice)
+                    {
+                        listName.Add(device.Name);
+                    }
+                    //鏄剧ず閫夋嫨钃濈墮鍒楄〃鐨勭晫闈�(褰撳尮閰嶅埌澶氫釜钃濈墮鐨勬椂鍊欎娇鐢�)
+                    this.ShowBluetoothListView(listName, (index) =>
+                    {
+                        //濡傛灉鍙娴嬪埌涓�涓�,鍒欑洿鎺ヨ繛鎺�
+                        HdlBluetoothLogic.Current.ContectBluetooth(listDevice[index], (result) =>
+                        {
+                            if (result == true)
+                            {
+                                //杩炴帴鎴愬姛,鍒欒烦杞埌涓嬩竴涓晫闈�
+                                HdlThreadLogic.Current.RunMain(() =>
+                                {
+                                    this.CloseForm();
+                                    var form = new AddMiniRemoteControlDirection3Page();
+                                    form.AddForm(this.wifiName, this.wifiPassword);
+                                });
+                            }
+                            else
+                            {
+                                HdlBluetoothLogic.Current.Dispone();
+                            }
+                        });
+                    });
+                }
+            });
+        }
+
+        /// <summary>
+        /// 寮�鍚繘搴︽潯鐗规晥
+        /// </summary>
+        private void StartProgressSpecialEffects(ProgressRowBar btnProgress)
+        {
+            //鎼滅储鏃堕棿(绉�)
+            int searchTime = 180;
+            HdlThreadLogic.Current.RunThread(() =>
+            {
+                //杩涘害鏉$壒鏁�
+                for (int i = 1; i <= searchTime; i++)
+                {
+                    System.Threading.Thread.Sleep(1000);
+                    HdlThreadLogic.Current.RunMain(() =>
+                    {
+                        //杩涘害鏉$壒鏁�
+                        btnProgress.SetValue(i, searchTime);
+                    });
+
+                    //鐣岄潰鍏抽棴
+                    if (this.Parent == null)
+                    {
+                        break;
+                    }
+                    //濡傛灉宸茬粡鎼滅储鍒拌摑鐗�,鍒欑洿鎺ュ埌100%
+                    if (listDevice.Count > 0)
+                    {
+                        HdlThreadLogic.Current.RunMain(() =>
+                        {
+                            btnProgress.SetValue(searchTime, searchTime);
+                        });
+                        break;
+                    }
+                    if (i % 5 == 1)
+                    {
+                        //姣�5绉掓悳绱竴娆�
+                        this.StartSearchBluetooth();
+                    }
+                    //瓒呮椂
+                    if (i >= searchTime)
+                    {
+                        System.Threading.Thread.Sleep(3000);
+                        //鏈�鍚庣殑鏃堕棿杩樻槸鎼滀笉鍒扮殑璇�
+                        if (listDevice.Count == 0)
+                        {
+                            //鏄剧ず澶辫触鐣岄潰
+                            HdlThreadLogic.Current.RunMain(() =>
+                            {
+                                this.ShowFailView();
+                            });
+                        }
+                        break;
+                    }
+                }
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鏄剧ず閫夋嫨钃濈墮鍒楄〃鐨勭晫闈____________
+
+        /// <summary>
+        /// 鏄剧ず閫夋嫨钃濈墮鍒楄〃鐨勭晫闈�(褰撳尮閰嶅埌澶氫釜钃濈墮鐨勬椂鍊欎娇鐢�)
+        /// </summary>
+        /// <param name="listName">钃濈墮鍚嶅瓧鍒楄〃</param>
+        /// <param name="selectEvent">閫夋嫨浜嬩欢(鑰冭檻鍒癐os鍜屽畨鍗�,鎵�浠ヨ繖鏍峰畾鍙傛暟)</param>
+        private void ShowBluetoothListView(List<string> listName, Action<int> selectEvent)
+        {
+            if (this.Parent == null) { return; }
+
+            HdlThreadLogic.Current.RunMain(() =>
+            {
+                var contr = new BottomItemSelectControl(listName.Count, Language.StringByID(StringId.ChooseInfraredRemoteControl), false);
+                //鍒濆鍖�
+                contr.AddRowMenu(listName, new List<int>());
+                contr.FinishOnlyEvent += (div, value) =>
+                {
+                    if (div == 0)
+                    {
+                        //濡傛灉鐐瑰嚮浜嗗彇娑�,鍒欏叧闂繖涓晫闈�,涓嶇浜�
+                        this.CloseForm();
+                    }
+                    else
+                    {
+                        //璋冪敤鍥炶皟鍑芥暟
+                        selectEvent?.Invoke(value);
+                    }
+                };
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 鏄剧ず澶辫触鐣岄潰_______________________
+
+        /// <summary>
+        /// 鏄剧ず澶辫触鐣岄潰
+        /// </summary>
+        private void ShowFailView()
+        {
+            //娓呯┖body
+            this.ClearBodyFrame();
+            //鍥剧墖
+            var btnPic = new PicViewControl(180, 180);
+            btnPic.Y = Application.GetRealHeight(48);
+            btnPic.Gravity = Gravity.CenterHorizontal;
+            btnPic.UnSelectedImagePath = "Public/TipIcon_Failed.png";
+            bodyFrameLayout.AddChidren(btnPic);
+            //娌℃湁鍙戠幇绾㈠閬ユ帶鍣�
+            var btnMsgNot = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(22), false);
+            btnMsgNot.Y = btnPic.Bottom + Application.GetRealHeight(16);
+            btnMsgNot.TextAlignment = TextAlignment.Center;
+            btnMsgNot.TextColor = CSS.CSS_Color.AuxiliaryColor2;
+            btnMsgNot.TextSize = CSS.CSS_FontSize.SubheadingFontSize;
+            btnMsgNot.TextID = StringId.NoInfraredRemoteControlFound;
+            bodyFrameLayout.AddChidren(btnMsgNot);
+            //1銆佽妫�鏌ヨ澶囨槸鍚︽甯搁�氱數
+            //2銆佽妫�鏌ヨ摑鐗欏姛鑳芥槸鍚︽甯稿紑鍚�
+            //3銆佽妫�鏌ユ寚绀虹伅鏄惁钃濊壊蹇棯鐘舵��
+            var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg3);
+            this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize,
+                CSS.CSS_Color.TextualColor, Application.GetRealHeight(20), btnMsgNot.Bottom + Application.GetRealHeight(8),
+                 TextAlignment.Center, true);
+
+            //閲嶆柊鎼滅储
+            var btnReSearch = this.AddBottomClickButton(Language.StringByID(StringId.ReSearch));
+            btnReSearch.ButtonClickEvent += (sender, e) =>
+            {
+                //妫�娴嬭摑鐗欓渶瑕佺殑涓滆タ
+                btnReSearch.CanClick = false;
+                HdlBluetoothLogic.Current.CheckCanScanBluetooth((result) =>
+                {
+                    btnReSearch.CanClick = true;
+                    if (result == true)
+                    {
+                        //鍒濆鍖栦腑閮ㄤ俊鎭�
+                        this.InitMiddleFrame();
+                    }
+                });
+            };
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0