using System;
|
using System.Collections.Generic;
|
using HDL_ON.DriverLayer;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public partial class FunctionControlZone
|
{
|
/// <summary>
|
/// 更新在线状态
|
/// </summary>
|
public void UpdataOnline(bool online)
|
{
|
if (bodyDiv != null)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
bodyDiv.BackgroundColor = online ? CSS_Color.MainBackgroundColor : CSS_Color.PromptingColor2;
|
bodyDiv.btnOffline.Visible = !online;
|
});
|
}
|
}
|
|
/// <summary>
|
/// 加载功能收藏按钮事件
|
/// </summary>
|
void LoadEvent_FunctionCollection()
|
{
|
btnCollectionIcon.MouseUpEventHandler += (sender, e) =>
|
{
|
btnCollectionIcon.IsSelected = function.collect = !btnCollectionIcon.IsSelected;
|
function.CollectFunction();
|
};
|
}
|
|
/// <summary>
|
/// 开关事件
|
/// </summary>
|
void LoadEvent_SwitchFunction(Button btnSwitch,FunctionAttributes fadeTime = null)
|
{
|
|
btnSwitch.MouseUpEventHandler = (sender, e) =>
|
{
|
if (!function.isOnline())//离线不允许操作
|
{
|
new Tip()
|
{
|
CloseTime = 1,
|
Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
Direction = AMPopTipDirection.None,
|
}.Show(MainPage.BaseView);
|
return;
|
}
|
btnSwitch.IsSelected = !btnSwitch.IsSelected;
|
|
|
new System.Threading.Thread(() =>
|
{
|
function.trait_on_off.curValue = btnSwitch.IsSelected ? "on" : "off";
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
if(fadeTime!= null)
|
{
|
int result = 0;
|
int.TryParse(fadeTime.curValue.ToString(), out result);
|
d.Add(FunctionAttributeKey.FadeTime, result.ToString());
|
}
|
Control.Ins.SendWriteCommand(function, d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
}
|
#region 灯光的事件列表
|
|
|
|
/// <summary>
|
/// 灯光亮度调节事件
|
/// </summary>
|
void LoadEvent_LightDimming(DiyImageSeekBar dimmerControlBar)
|
{
|
if (!function.isOnline())//离线不允许操作
|
{
|
//new Tip()
|
//{
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
//}.Show(MainPage.BaseView);
|
return;
|
}
|
if (function.spk == SPK.LightDimming || function.spk == SPK.LightRGB || function.spk == SPK.LightCCT)
|
{
|
dimmerControlBar.OnStartTrackingTouchEvent = (sender, e) => {
|
onDimmerBar = true;
|
(bodyDiv.Parent as VerticalScrolViewLayout).ScrollEnabled = false;
|
};
|
dimmerControlBar.OnStopTrackingTouchEvent = (sender, e) => {
|
onDimmerBar = false;
|
(bodyDiv.Parent as VerticalScrolViewLayout).ScrollEnabled = true;
|
function.SetAttrState(FunctionAttributeKey.Brightness, dimmerControlBar.Progress.ToString());
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, dimmerControlBar.Progress.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
};
|
dimmerControlBar.OnProgressChangedEvent = (sender, e) => {
|
dimmerControlBar.ProgressBarColor = CSS.CSS_Color.AuxiliaryColor1;
|
function.SetAttrState(FunctionAttributeKey.Brightness, e);
|
function.trait_on_off.curValue = e > 0 ? "on" : "off";
|
|
if (e == 0 || e == 100)
|
{
|
//Control.Send(CommandType_A.write, light);
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add("brightness", e.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
}
|
else
|
{
|
var tm = (DateTime.Now - function.refreshTime).TotalMilliseconds;
|
Console.WriteLine("skip time " + tm);
|
if (500 < tm)
|
{
|
function.refreshTime = DateTime.Now;
|
new System.Threading.Thread(() =>
|
{
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add("brightness", e.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
};
|
}
|
|
}
|
#endregion
|
|
|
#region 窗帘的事件列表
|
/// <summary>
|
/// 加载窗帘控制事件
|
/// </summary>
|
/// <param name="btnStop"></param>
|
/// <param name="btnOpen"></param>
|
/// <param name="btnClose"></param>
|
void LoadEvent_ControlCurtain(Button btnStop, Button btnOpen, Button btnClose)
|
{
|
btnClose.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)//离线不允许操作
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
btnClose.IsSelected = true;
|
btnStop.IsSelected = false;
|
btnOpen.IsSelected = false;
|
function.trait_on_off.curValue = "off";
|
function.SetAttrState(FunctionAttributeKey.Percent, 0);
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
};
|
|
btnStop.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)//离线不允许操作
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
btnStop.IsSelected = true;
|
btnClose.IsSelected = false;
|
btnOpen.IsSelected = false;
|
function.trait_on_off.curValue = "stop";
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
};
|
|
btnOpen.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)//离线不允许操作
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
btnOpen.IsSelected = true;
|
btnClose.IsSelected = false;
|
btnStop.IsSelected = false;
|
function.trait_on_off.curValue = "on";
|
function.SetAttrState(FunctionAttributeKey.Percent, 100);
|
Dictionary<string, string> d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
Control.Ins.SendWriteCommand(function, d);
|
};
|
}
|
#endregion
|
|
|
#region 空调事件
|
#endregion
|
|
|
/// <summary>
|
/// 控制界面跳转
|
/// </summary>
|
void LoadEvent_DivSkipEvent()
|
{
|
var eventHandler = new PublicAssmebly().LoadEvent_SkipFunctionControlPage(function, btnCollectionIcon, btnName, btnFromFloor, this.action);
|
this.MouseUpEventHandler = eventHandler;
|
btnName.MouseUpEventHandler = eventHandler;
|
btnFromFloor.MouseUpEventHandler = eventHandler;
|
}
|
|
|
}
|
}
|