using HDL_ON.Stan;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
namespace HDL_ON.UI
{
///
/// 添加Evoyo的Mini智能遥控器步骤4界面
///
public class AddMiniRemoteControlDirection4Page : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// wifi名字
///
private string wifiName = string.Empty;
///
/// wifi密码
///
private string wifiPsw = string.Empty;
///
/// 超时线程是否运行
///
private bool timeoutThreadActivity = false;
///
/// 上传到云的图标
///
private IconViewControl btnClound = null;
///
/// 上传到云
///
private NormalViewControl btnCloundView = null;
///
/// 连接成功的图标
///
private IconViewControl btnConnect = null;
///
/// 连接成功
///
private NormalViewControl btnConnetView = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// wifi名字
/// wifi密码
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;
#if __IOS__
#endif
#if __Android__
//添加接收蓝牙反馈的事件
HdlAndroidBluetoothLogic.Current.AddReceiveEvent(this.BluetoothReceiveEvent);
#endif
//添加云端反馈事件
HdlCloudReceiveLogic.Current.AddCloudReceiveEvent("AddMiniRemoteControlDirection4Page", this.CloudReceiveEvent);
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
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);
//正在连接中...
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 ■ 显示成功界面_______________________
///
/// 显示成功界面
///
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) =>
{
};
}
#endregion
#region ■ 显示失败界面_______________________
///
/// 显示失败界面
///
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.InitMiddleFrame();
};
}
#endregion
#region ■ 发送账号和密码给蓝牙_______________
///
/// 发送账号和密码给蓝牙
///
private void SendAccountAndPswToBluetooth()
{
#if __IOS__
#endif
#if __Android__
//获取发送到蓝牙的数据
var sendData = this.GetSendToBluetoothData();
//不等待
HdlAndroidBluetoothLogic.Current.SendData(sendData);
#endif
}
#endregion
#region ■ 云端反馈___________________________
///
/// 云端反馈
///
/// 枚举
/// 推送的内容
private void CloudReceiveEvent(CloudPushEnum pushEnum, string i_data)
{
if (pushEnum != CloudPushEnum.A新设备上报) { return; }
//接收到就移除这个事件
HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
//停止线程
this.timeoutThreadActivity = false;
//添加设备成功之后,处理一些东西
this.DoSomethingAfterAddDeviceSuccess();
}
///
/// 添加设备成功之后,处理一些东西
///
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 ■ 蓝牙反馈___________________________
///
/// 蓝牙反馈
///
/// 蓝牙反馈的数据
private void BluetoothReceiveEvent(string i_receviceData)
{
#if DEBUG
System.Console.WriteLine("蓝牙返回:" + i_receviceData);
#endif
}
#endregion
#region ■ 超时线程___________________________
///
/// 启动超时线程
///
private void StartTimeoutThread()
{
HdlThreadLogic.Current.RunThread(() =>
{
//300秒超时
int timeout = 300;
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 ■ 界面关闭___________________________
///
/// 界面关闭
///
public override void CloseFormBefore()
{
//摧毁蓝牙
#if __IOS__
#endif
#if __Android__
HdlAndroidBluetoothLogic.Current.Dispone();
#endif
HdlCloudReceiveLogic.Current.RemoveCloudReceiveEvent("AddMiniRemoteControlDirection4Page");
base.CloseFormBefore();
}
#endregion
#region ■ 一般方法___________________________
///
/// 获取发送到蓝牙的数据
///
///
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
}
}