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/AddMiniRemoteControlDirection4Page.cs | 533 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 533 insertions(+), 0 deletions(-)
diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs
new file mode 100644
index 0000000..3d66b86
--- /dev/null
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/AddDevice/AddMiniRemoteControlDirection4Page.cs
@@ -0,0 +1,533 @@
+锘縰sing HDL_ON.Stan;
+using Shared;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace HDL_ON.UI
+{
+ /// <summary>
+ /// 娣诲姞Evoyo鐨凪ini鏅鸿兘閬ユ帶鍣ㄦ楠�4鐣岄潰
+ /// </summary>
+ public class AddMiniRemoteControlDirection4Page : EditorCommonForm
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// wifi鍚嶅瓧
+ /// </summary>
+ private string wifiName = string.Empty;
+ /// <summary>
+ /// wifi瀵嗙爜
+ /// </summary>
+ private string wifiPsw = string.Empty;
+ /// <summary>
+ /// 瓒呮椂绾跨▼鏄惁杩愯
+ /// </summary>
+ private bool timeoutThreadActivity = false;
+ /// <summary>
+ /// 涓婁紶鍒颁簯鐨勫浘鏍�
+ /// </summary>
+ private IconViewControl btnClound = null;
+ /// <summary>
+ /// 涓婁紶鍒颁簯
+ /// </summary>
+ private NormalViewControl btnCloundView = null;
+ /// <summary>
+ /// 杩炴帴鎴愬姛鐨勫浘鏍�
+ /// </summary>
+ private IconViewControl btnConnect = null;
+ /// <summary>
+ /// 杩炴帴鎴愬姛
+ /// </summary>
+ private NormalViewControl btnConnetView = null;
+
+ #endregion
+
+ #region 鈻� 鍒濆鍖朹____________________________
+
+ /// <summary>
+ /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+ /// </summary>
+ /// <param name="i_wifiName">wifi鍚嶅瓧</param>
+ /// <param name="i_wifiPsw">wifi瀵嗙爜</param>
+ public void ShowForm(string i_wifiName, string i_wifiPsw)
+ {
+ this.wifiName = i_wifiName;
+ this.wifiPsw = i_wifiPsw;
+
+ //璁剧疆澶撮儴淇℃伅
+ base.SetTitleText(Language.StringByID(StringId.AddInfraredRemoteControl));
+ //杩欎釜鐣岄潰鐨勮儗鏅渶瑕佺櫧鑹�
+ bodyFrameLayout.BackgroundColor = UI.CSS.CSS_Color.MainBackgroundColor;
+
+ //娣诲姞鎺ユ敹钃濈墮鍙嶉鐨勪簨浠�
+ HdlBluetoothLogic.Current.AddReceiveEvent(this.BluetoothReceiveEvent);
+
+ //娣诲姞浜戠鍙嶉浜嬩欢
+ HdlCloudReceiveLogic.Current.AddCloudReceiveEvent("AddMiniRemoteControlDirection4Page", this.CloudReceiveEvent);
+
+ //鍒濆鍖栦腑閮ㄤ俊鎭�
+ this.InitMiddleFrame();
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栦腑閮ㄤ俊鎭�
+ /// </summary>
+ private void InitMiddleFrame()
+ {
+ //娓呯┖body
+ this.ClearBodyFrame();
+ //鍥剧墖
+ var btnPic = new PicViewControl(282, 121);
+ btnPic.Y = Application.GetRealHeight(122);
+ btnPic.Gravity = Gravity.CenterHorizontal;
+ btnPic.UnSelectedImagePath = "PersonalCenter/AddDevice/WifiAndPhoneConnect.png";
+ bodyFrameLayout.AddChidren(btnPic);
+ //姝e湪杩炴帴涓�...
+ var btnSearch = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(20), false);
+ btnSearch.Y = btnPic.Bottom + Application.GetRealHeight(40);
+ btnSearch.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
+ btnSearch.TextID = StringId.NowConnectting;
+ btnSearch.TextAlignment = TextAlignment.Center;
+ bodyFrameLayout.AddChidren(btnSearch);
+ //璇疯绾㈠閬ユ帶灏介噺鎺ヨ繎WIFI璺敱鍣�
+ var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg5);
+ this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize,
+ CSS.CSS_Color.PromptingColor1, Application.GetRealHeight(20), btnSearch.Bottom + Application.GetRealHeight(4));
+
+ //缃戠粶杩炴帴涓�
+ var btnNetIcon = new IconViewControl(20);
+ btnNetIcon.X = Application.GetRealWidth(60);
+ btnNetIcon.Y = btnPic.Bottom + Application.GetRealHeight(265);
+ btnNetIcon.UnSelectedImagePath = "PersonalCenter/AddDevice/NetConnectSelect.png";
+ bodyFrameLayout.AddChidren(btnNetIcon);
+ var btnNetView = new NormalViewControl(140, 18, true);//宸﹀彸闂磋窛40鍐嶅姞鏂囨湰60
+ btnNetView.Y = btnNetIcon.Bottom + Application.GetRealHeight(16);
+ btnNetView.TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel;
+ btnNetView.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
+ btnNetView.TextAlignment = TextAlignment.Center;
+ btnNetView.TextID = StringId.InTheNetworkLink;
+ bodyFrameLayout.AddChidren(btnNetView);
+
+ //涓�鏉℃í绾�
+ var btnLine1 = new NormalViewControl(Application.GetRealWidth(92), 2, false);
+ btnLine1.X = btnNetIcon.Right + Application.GetRealWidth(3);
+ btnLine1.Y = btnNetIcon.Y + (btnNetIcon.Height + 2) / 2;
+ btnLine1.BackgroundColor = CSS.CSS_Color.PromptingColor1;
+ bodyFrameLayout.AddChidren(btnLine1);
+
+ //涓婁紶鍒颁簯
+ this.btnClound = new IconViewControl(20);
+ btnClound.Gravity = Gravity.CenterHorizontal;
+ btnClound.Y = btnNetIcon.Y;
+ btnClound.UnSelectedImagePath = "PersonalCenter/AddDevice/UploadToClound.png";
+ btnClound.SelectedImagePath = "PersonalCenter/AddDevice/UploadToCloundSelect.png";
+ bodyFrameLayout.AddChidren(btnClound);
+ this.btnCloundView = new NormalViewControl(btnNetView.Width, btnNetView.Height, false);
+ btnCloundView.Y = btnNetView.Y;
+ btnCloundView.Gravity = Gravity.CenterHorizontal;
+ btnCloundView.TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel;
+ btnCloundView.TextColor = CSS.CSS_Color.PromptingColor1;
+ btnCloundView.TextAlignment = TextAlignment.Center;
+ btnCloundView.TextID = StringId.UploadToCloud;
+ bodyFrameLayout.AddChidren(btnCloundView);
+
+ //涓�鏉℃í绾�
+ var btnLine2 = new NormalViewControl(btnLine1.Width, btnLine1.Height, false);
+ btnLine2.X = btnClound.Right + Application.GetRealWidth(3);
+ btnLine2.Y = btnLine1.Y;
+ btnLine2.BackgroundColor = CSS.CSS_Color.PromptingColor1;
+ bodyFrameLayout.AddChidren(btnLine2);
+
+ //杩炴帴鎴愬姛
+ this.btnConnect = new IconViewControl(20);
+ btnConnect.X = bodyFrameLayout.Width - btnNetIcon.X - btnConnect.IconSize;
+ btnConnect.Y = btnNetIcon.Y;
+ btnConnect.UnSelectedImagePath = "PersonalCenter/AddDevice/ConnectSuccess.png";
+ btnConnect.SelectedImagePath = "PersonalCenter/AddDevice/ConnectSuccessSelect.png";
+ bodyFrameLayout.AddChidren(btnConnect);
+ this.btnConnetView = new NormalViewControl(btnNetView.Width, btnNetView.Height, false);
+ btnConnetView.X = bodyFrameLayout.Width - btnNetView.Width - btnNetView.X;
+ btnConnetView.Y = btnNetView.Y;
+ btnConnetView.TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel;
+ btnConnetView.TextColor = CSS.CSS_Color.PromptingColor1;
+ btnConnetView.TextAlignment = TextAlignment.Center;
+ btnConnetView.TextID = StringId.ConnectSuccess;
+ bodyFrameLayout.AddChidren(btnConnetView);
+
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ System.Threading.Thread.Sleep(2000);
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鍙戦�佽处鍙峰拰瀵嗙爜缁欒摑鐗�
+ this.SendAccountAndPswToBluetooth();
+ });
+ //鍚姩瓒呮椂绾跨▼
+ this.StartTimeoutThread();
+ });
+ }
+
+ #endregion
+
+ #region 鈻� 鏄剧ず鎴愬姛鐣岄潰_______________________
+
+ /// <summary>
+ /// 鏄剧ず鎴愬姛鐣岄潰
+ /// </summary>
+ private void ShowSuccessView()
+ {
+ //娓呯┖body
+ this.ClearBodyFrame();
+
+ //鍥剧墖
+ var btnPic = new PicViewControl(180, 180);
+ btnPic.Y = Application.GetRealHeight(48);
+ btnPic.Gravity = Gravity.CenterHorizontal;
+ btnPic.UnSelectedImagePath = "Public/TipIcon_Successfully.png";
+ bodyFrameLayout.AddChidren(btnPic);
+
+ //娣诲姞鎴愬姛
+ var btnFail = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(22), false);
+ btnFail.Y = btnPic.Bottom + Application.GetRealHeight(16);
+ btnFail.TextSize = CSS.CSS_FontSize.SubheadingFontSize;
+ btnFail.TextColor = CSS.CSS_Color.MainColor;
+ btnFail.TextAlignment = TextAlignment.Center;
+ btnFail.TextID = StringId.AddSuccess;
+ bodyFrameLayout.AddChidren(btnFail);
+
+ //鍙互寮�濮嬩娇鐢ㄧ孩澶栭仴鎺у姛鑳斤紒
+ var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg7);
+ int yy = this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize, CSS.CSS_Color.TextualColor,
+ Application.GetRealHeight(20), btnFail.Bottom + Application.GetRealHeight(8));
+
+ //寮�濮嬩娇鐢�
+ var btnUse = new BottomClickButton(220);
+ btnUse.Y = yy + Application.GetRealHeight(60);
+ btnUse.TextID = StringId.StartUse;
+ bodyFrameLayout.AddChidren(btnUse);
+ btnUse.ButtonClickEvent += (sender, e) =>
+ {
+ //鍏虫帀鐣岄潰
+ this.CloseForm();
+ HdlFormLogic.Current.CloseFormByFormName("AddThirdPartyDeviceMenuListPage");
+ HDL_ON.UI.UI2.PersonalCenter.PirDevice.Method.GetPirDeviceList(this, () =>
+ {
+ Application.RunOnMainThread(() =>
+ {
+ var page = new UI2.PersonalCenter.PirDevice.PirMain();
+ MainPage.BasePageView.AddChidren(page);
+ page.Show();
+ MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+ });
+ });
+ };
+ }
+
+ #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 btnFail = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(22), false);
+ btnFail.Y = btnPic.Bottom + Application.GetRealHeight(16);
+ btnFail.TextSize = CSS.CSS_FontSize.SubheadingFontSize;
+ btnFail.TextColor = CSS.CSS_Color.AuxiliaryColor2;
+ btnFail.TextAlignment = TextAlignment.Center;
+ btnFail.TextID = StringId.AddFail;
+ bodyFrameLayout.AddChidren(btnFail);
+ //1銆佽妫�鏌ヨ澶囨槸鍚︽甯搁�氱數
+ //2銆佽寮�鍚摑鐗欏姛鑳�
+ //3銆佸苟闀挎寜鎸夐挳10s锛屾寚绀虹伅甯镐寒
+ var strMsg = Language.StringByID(StringId.AddInfraredRemoteControlMsg6);
+ this.AddListMsgControls(bodyFrameLayout, strMsg, CSS.CSS_FontSize.TextFontSize, CSS.CSS_Color.TextualColor,
+ Application.GetRealHeight(20), btnFail.Bottom + Application.GetRealHeight(8),
+ TextAlignment.Center, true);
+
+ //閲嶈瘯
+ var btnReDo = this.AddBottomClickButton(Language.StringByID(StringId.Retry));
+ btnReDo.ButtonClickEvent += (sender, e) =>
+ {
+ //閲嶆柊鍒濆鍖栦腑閮ㄤ俊鎭�
+ this.CloseForm();
+ var form = new AddMiniRemoteControlDirection2Page();
+ form.AddForm(this.wifiName, this.wifiPsw);
+ };
+ }
+
+ #endregion
+
+ #region 鈻� 鍙戦�佽处鍙峰拰瀵嗙爜缁欒摑鐗檁______________
+
+ /// <summary>
+ /// 鍙戦�佽处鍙峰拰瀵嗙爜缁欒摑鐗�
+ /// </summary>
+ private void SendAccountAndPswToBluetooth()
+ {
+ //鑾峰彇鍙戦�佸埌钃濈墮鐨勬暟鎹�
+ var sendData = this.GetSendToBluetoothData();
+ //涓嶇瓑寰�
+ HdlBluetoothLogic.Current.SendData(sendData);
+ }
+
+ #endregion
+
+ #region 鈻� 绾㈠瀹濈浉鍏虫柟娉昣____________________
+
+ /// <summary>
+ /// 妫�娴嬫槸鍚︽槸鏂扮殑绾㈠瀹�
+ /// </summary>
+ /// <param name="pushEnum">鎺ㄩ�佹灇涓�</param>
+ /// <param name="i_data">鎺ㄩ�佺殑鏁版嵁</param>
+ /// <returns></returns>
+ private bool CheckIsNewMiniRemoteControl(CloudPushEnum pushEnum, string i_data)
+ {
+ if (pushEnum != CloudPushEnum.A鏂拌澶囦笂鎶�) { return false; }
+
+ try
+ {
+ var strSpk = string.Empty;
+ //杞负json
+ var json = Newtonsoft.Json.Linq.JObject.Parse(i_data);
+ var linqArry = json["objects"] as Newtonsoft.Json.Linq.JArray;
+ if (linqArry != null)
+ {
+ //鏁扮粍绫诲瀷
+ if (linqArry.Count == 0) { return false; }
+ strSpk = linqArry[0]["spk"].ToString();
+ }
+ else
+ {
+ //闈炴暟缁勭被鍨�
+ strSpk = json["objects"]["spk"].ToString();
+ }
+ if (strSpk != Entity.SPK.IrModule)
+ {
+ //濡傛灉涓嶆槸绾㈠瀹濈殑璇�
+ return false;
+ }
+ return true;
+ }
+ catch { return false; }
+ }
+
+ /// <summary>
+ /// 鍒锋柊绾㈠瀹濅俊鎭�
+ /// </summary>
+ /// <param name="successEvent">鎴愬姛鐨勫洖璋冧簨浠�</param>
+ private void RefreshMiniRemoteControlInfo(Action successEvent)
+ {
+ var pra = new Dictionary<string, object>();
+ pra.Add("homeId", Entity.DB_ResidenceData.Instance.CurrentRegion.RegionID);
+ pra.Add("spk", Entity.SPK.IrModule);
+
+ var requestJson = DAL.Server.HttpUtil.GetSignRequestJson(pra);
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ int count = 0;
+ while (this.Parent != null)
+ {
+ try
+ {
+ //瓒呰繃5娆¢兘涓嶆垚鍔�,鐪熶笉澶勭悊浜�
+ count++;
+ if (count > 5) { return; }
+
+ //鑾峰彇鍏ㄩ儴绾㈠瀹濆垪琛�
+ var result = DAL.Server.HttpUtil.RequestHttpsPostFroHome(DAL.Server.NewAPI.Api_Post_GetDevcieList, requestJson);
+ if (result == null || result.Code != DAL.Server.StateCode.SUCCESS)
+ {
+ System.Threading.Thread.Sleep(3000);
+ continue;
+ }
+ var listDevice = Newtonsoft.Json.JsonConvert.DeserializeObject<Entity.DevcieApiPack>(result.Data.ToString());
+ foreach (var newFunction in listDevice.list)
+ {
+ //娣诲姞鍒扮紦瀛樺綋涓�
+ newFunction.SaveFunctionFile();
+ Entity.FunctionList.List.IniFunctionList(newFunction.savePath, true);
+ }
+ //璋冪敤鍥炶皟鍑芥暟
+ successEvent?.Invoke();
+ return;
+ }
+ catch
+ {
+ System.Threading.Thread.Sleep(3000);
+ }
+ }
+ });
+ }
+
+ #endregion
+
+ #region 鈻� 浜戠鍙嶉___________________________
+
+ /// <summary>
+ /// 浜戠鍙嶉
+ /// </summary>
+ /// <param name="pushEnum">鏋氫妇</param>
+ /// <param name="i_data">鎺ㄩ�佺殑鍐呭</param>
+ private void CloudReceiveEvent(CloudPushEnum pushEnum, string i_data)
+ {
+ //妫�娴嬫槸鍚︽槸鏂扮殑绾㈠瀹�
+ if (this.CheckIsNewMiniRemoteControl(pushEnum, i_data) == false)
+ {
+ return;
+ }
+ //鍒锋柊绾㈠瀹濅俊鎭�
+ this.RefreshMiniRemoteControlInfo(() =>
+ {
+ //绉婚櫎杩欎釜浜嬩欢
+ HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
+ //鍋滄绾跨▼
+ this.timeoutThreadActivity = false;
+
+ //娣诲姞璁惧鎴愬姛涔嬪悗,澶勭悊涓�浜涗笢瑗�
+ this.DoSomethingAfterAddDeviceSuccess();
+ });
+ }
+
+ /// <summary>
+ /// 娣诲姞璁惧鎴愬姛涔嬪悗,澶勭悊涓�浜涗笢瑗�
+ /// </summary>
+ private void DoSomethingAfterAddDeviceSuccess()
+ {
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ //鏁寸偣鐗规晥鑰屽凡
+ for (int i = 1; i <= 6; i++)
+ {
+ System.Threading.Thread.Sleep(1000);
+ if (i == 1)
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鏁寸偣鐗规晥鑰屽凡
+ this.btnClound.IsSelected = true;
+ this.btnCloundView.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
+ });
+ }
+ else if (i == 4)
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鏁寸偣鐗规晥鑰屽凡
+ this.btnConnect.IsSelected = true;
+ this.btnConnetView.TextColor = CSS.CSS_Color.FirstLevelTitleColor;
+ });
+ }
+ else if (i == 6)
+ {
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ //鏄剧ず鎴愬姛鐣岄潰
+ this.ShowSuccessView();
+ });
+ }
+ }
+ });
+ }
+
+ #endregion
+
+ #region 鈻� 钃濈墮鍙嶉___________________________
+
+ /// <summary>
+ /// 钃濈墮鍙嶉
+ /// </summary>
+ /// <param name="i_receviceData">钃濈墮鍙嶉鐨勬暟鎹�</param>
+ private void BluetoothReceiveEvent(string i_receviceData)
+ {
+#if DEBUG
+ System.Console.WriteLine("钃濈墮杩斿洖锛�" + i_receviceData);
+#endif
+ }
+
+ #endregion
+
+ #region 鈻� 瓒呮椂绾跨▼___________________________
+
+ /// <summary>
+ /// 鍚姩瓒呮椂绾跨▼
+ /// </summary>
+ private void StartTimeoutThread()
+ {
+ HdlThreadLogic.Current.RunThread(() =>
+ {
+ //360绉掕秴鏃�
+ int timeout = 360;
+ while (this.timeoutThreadActivity == false && this.Parent != null)
+ {
+ System.Threading.Thread.Sleep(1000);
+ timeout--;
+ if (timeout == 0)
+ {
+ break;
+ }
+ }
+ if (timeout <= 0)
+ {
+ //鏄剧ず澶辫触鐣岄潰
+ HdlThreadLogic.Current.RunMain(() =>
+ {
+ this.ShowFailView();
+ });
+ }
+ });
+ }
+
+ #endregion
+
+ #region 鈻� 鐣岄潰鍏抽棴___________________________
+
+ /// <summary>
+ /// 鐣岄潰鍏抽棴
+ /// </summary>
+ public override void CloseFormBefore()
+ {
+ //鎽ф瘉钃濈墮
+ HdlBluetoothLogic.Current.Dispone();
+ HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
+
+ base.CloseFormBefore();
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 鑾峰彇鍙戦�佸埌钃濈墮鐨勬暟鎹�
+ /// </summary>
+ /// <returns></returns>
+ private string GetSendToBluetoothData()
+ {
+ var pra = new { id = "id010203", ssid = this.wifiName, password = this.wifiPsw };
+ var praData = Newtonsoft.Json.JsonConvert.SerializeObject(pra);
+
+ var sendData = "Topic:/user/id/custom/wifi/set\r\n";
+ sendData += "Length:" + praData.Length + "\r\n\r\n";
+ sendData += praData;
+ return sendData;
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0