using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
public class TuyaWaterValvePage : DeviceFunctionCardCommonForm
{
#region ■ 变量声明___________________________
///
/// 图片控件
///
private PicViewControl btnPictrue = null;
///
/// 开关控件
///
private IconViewControl btnSwitch = null;
#endregion
#region ■ 初始化_____________________________
///
/// 初始化白色区域的内容
///
public override void InitFrameWhiteContent()
{
base.SetTitleText(Language.StringByID(StringId.AirCleaner));
//添加第二索引页
this.AddSecondPage();
//初始化第一个索引页的内容
this.InitFrameWhiteContent1();
//刷新界面状态
this.RefreshFormStatu();
}
///
/// 初始化第一个索引页的内容
///
private void InitFrameWhiteContent1()
{
//图片控件
this.btnPictrue = new PicViewControl(130, 118);
btnPictrue.Y = Application.GetRealHeight(95);
btnPictrue.Gravity = Gravity.CenterHorizontal;
btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveBg.png";
btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveOnBg.png";
FrameWhiteCentet1.AddChidren(btnPictrue);
btnPictrue.ButtonClickEvent += (sender, e) =>
{
//发送开关命令
this.SendSwitchComand();
};
//开关图标
this.btnSwitch = new IconViewControl(40);
btnSwitch.Gravity = Gravity.CenterHorizontal;
btnSwitch.Y = Application.GetRealHeight(468);
btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
FrameWhiteCentet1.AddChidren(btnSwitch);
btnSwitch.ButtonClickEvent += (sender, e) =>
{
//发送开关命令
this.SendSwitchComand();
};
}
#endregion
#region ■ 设备状态反馈_______________________
///
/// 设备状态反馈
///
///
public override void DeviceStatuPush(Function i_LocalDevice)
{
//不是同一个东西
if (this.device.sid != i_LocalDevice.sid) { return; }
//刷新界面状态
this.RefreshFormStatu();
}
#endregion
#region ■ 发送各种命令_______________________
///
/// 发送开关命令
///
private void SendSwitchComand()
{
this.btnPictrue.CanClick = false;
this.btnSwitch.CanClick = false;
string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
//btnSwitch.IsSelected = !btnSwitch.IsSelected;
HdlThreadLogic.Current.RunThread(() =>
{
var dic = new Dictionary();
dic.Add(FunctionAttributeKey.OnOff, statu);
Control.Ins.SendWriteCommand(this.device, dic, true);
HdlThreadLogic.Current.RunMain(() =>
{
this.btnPictrue.CanClick = true;
this.btnSwitch.CanClick = true;
});
});
}
#endregion
#region ■ 刷新界面状态_______________________
///
/// 刷新界面状态
///
private void RefreshFormStatu()
{
Application.RunOnMainThread(() =>
{
foreach (var data in this.device.attributes)
{
if (data.key == FunctionAttributeKey.OnOff)
{
this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = data.curValue.ToString() == "on";
}
}
});
}
#endregion
}
}