using System;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.Device
|
{
|
/// <summary>
|
/// 网关指定设备的信息画面(这个画面会修改设备的物理名字)★
|
/// </summary>
|
public class DeviceEpointInfoForm : UserCenterCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 设备名称变更的回调函数(设备名称,房间名)
|
/// </summary>
|
public Action<string, List<string>> ActionNameChangedEvent = null;
|
/// <summary>
|
/// 列表控件
|
/// </summary>
|
private VerticalScrolViewLayout listview = null;
|
/// <summary>
|
/// 新上报的设备
|
/// </summary>
|
private CommonDevice newDevice = null;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
/// </summary>
|
/// <param name="device">设备</param>
|
public void ShowForm(CommonDevice device)
|
{
|
this.newDevice = device;
|
|
//设置标题信息
|
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceSettingUp));
|
|
//检测设备是否拥有测试的功能
|
if (Common.LocalDevice.Current.DeviceIsCanTest(device) == true)
|
{
|
//初始化头部右边的测试图标
|
this.InitTopLayoutRightIcon();
|
}
|
|
//初始化中部控件
|
this.InitMiddleFrame();
|
}
|
|
/// <summary>
|
/// 初始化头部右边的测试图标
|
/// </summary>
|
private void InitTopLayoutRightIcon()
|
{
|
var btnIcon = new TopLayoutMostRightView();
|
btnIcon.UnSelectedImagePath = "Item/Test.png";
|
btnIcon.SelectedImagePath = "Item/TestSelected.png";
|
topFrameLayout.AddChidren(btnIcon);
|
|
btnIcon.MouseUpEventHandler += (sender, e) =>
|
{
|
//测试
|
Common.LocalDevice.Current.SetTestCommand(newDevice);
|
};
|
}
|
|
/// <summary>
|
/// 初始化中部控件
|
/// </summary>
|
public void InitMiddleFrame()
|
{
|
this.bodyFrameLayout.RemoveAll();
|
|
//房间
|
List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
|
|
//图标
|
var btnImage = new IconViewControl(332);
|
btnImage.Y = Application.GetRealHeight(40);
|
btnImage.Gravity = Gravity.CenterHorizontal;
|
//设置大图
|
Common.LocalDevice.Current.SetDeviceBigIconToControl(btnImage, this.newDevice);
|
bodyFrameLayout.AddChidren(btnImage);
|
btnImage.MouseUpEventHandler += (sender, e) =>
|
{
|
//显示变更设备图标的界面
|
this.ShowChangedIconForm(btnImage);
|
};
|
|
listview = new VerticalScrolViewLayout();
|
listview.Y = btnImage.Bottom + Application.GetRealHeight(50);
|
listview.Height = bodyFrameLayout.Height - btnImage.Bottom - Application.GetRealHeight(50);
|
bodyFrameLayout.AddChidren(listview);
|
|
//设备名称
|
string caption = Language.StringByID(R.MyInternationalizationString.uDeviceName);
|
string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(newDevice);
|
var btnDeviceView = new EditorNameValueRow(caption, nameValue);
|
listview.AddChidren(btnDeviceView);
|
btnDeviceView.InitControl();
|
//请输入设备名称
|
btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uDeviceNameMastInput));
|
//编辑设备名称
|
btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorDeviceName));
|
btnDeviceView.ActionNameChangedEvent += (deviceName) =>
|
{
|
//设备重命名
|
this.DeviceReName(deviceName, listRoomName);
|
};
|
|
var statuRow = new StatuRowLayout(listview);
|
//所属区域
|
var btnBelongAreaView = new RowTopGrayView(false);
|
btnBelongAreaView.TextID = R.MyInternationalizationString.uBelongArea;
|
statuRow.AddChidren(btnBelongAreaView);
|
|
var btnBelongArea = new RowBottomBlackView(false);
|
btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(listRoomName);
|
statuRow.AddChidren(btnBelongArea);
|
|
//向右图标
|
statuRow.AddRightIconControl();
|
|
statuRow.MouseUpEvent += (sender, e) =>
|
{
|
var form = new SelectRoomForm();
|
this.AddForm(form, listRoomName);
|
form.ActionSelectRoom = (list) =>
|
{
|
if (list != null)
|
{
|
//变更房间
|
Common.Room.CurrentRoom.ChangedRoom(newDevice, list);
|
|
btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(list);
|
listRoomName = list;
|
|
if (this.ActionNameChangedEvent != null)
|
{
|
string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
|
this.ActionNameChangedEvent(name, listRoomName);
|
}
|
}
|
};
|
};
|
|
//所属模块
|
var row = new RowLayout();
|
row.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(row);
|
|
var btnBelongObjectView = new RowTopGrayView(false);
|
btnBelongObjectView.TextID = R.MyInternationalizationString.uBelongObject;
|
row.AddChidren(btnBelongObjectView);
|
|
var btnBelongObject = new RowBottomBlackView(false);
|
btnBelongObject.Text = Common.LocalDevice.Current.GetDeviceMacName(newDevice);
|
row.AddChidren(btnBelongObject);
|
|
//添加所有菜单
|
this.AddAllMenu();
|
}
|
|
#endregion
|
|
#region ■ 添加菜单___________________________
|
|
/// <summary>
|
/// 添加所有菜单
|
/// </summary>
|
private async void AddAllMenu()
|
{
|
//开启进度条
|
this.ShowProgressBar();
|
|
//添加按键面板的【指示灯设置】行 这个东西需要判断功能
|
bool result = await this.AddPanelPilolightSettionRow();
|
if (result == false)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
//PIR传感器的信息
|
IASZone.ConfigureParamates Pirconfigure = null;
|
//如果是PIR传感器并且支持开关,只能河东的设备使用 (这里判断的是输出簇)
|
if ((newDevice is IASZone) == true
|
&& Common.LocalDevice.Current.IsHdlDevice(newDevice) == true
|
&& Common.LocalDevice.Current.OutDeviceIsCanOnOff(newDevice) == true)
|
{
|
//获取PIR传感器的【灯光配置】,错误时返回null
|
Pirconfigure = await Common.LocalDevice.Current.GetPirSensorLightSettion((IASZone)newDevice);
|
if (Pirconfigure == null)
|
{
|
//关闭进度条
|
this.CloseProgressBar(ShowReLoadMode.YES);
|
return;
|
}
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
//添加按键面板的【绑定目标】行
|
this.AddPanelBindTargetRow();
|
|
//添加PIR传感器的【绑定目标】行
|
this.AddPirSensorBindTargetRow(Pirconfigure);
|
|
//关闭进度条
|
this.CloseProgressBar();
|
});
|
}
|
|
#endregion
|
|
#region ■ 按键面板指示灯设置_________________
|
|
/// <summary>
|
/// 添加按键面板的【指示灯设置】行
|
/// </summary>
|
private async Task<bool> AddPanelPilolightSettionRow()
|
{
|
if (newDevice.Type != DeviceType.OnOffSwitch)
|
{
|
//如果是不是按键面板的话
|
return true;
|
}
|
if (Common.LocalDevice.Current.IsHdlDevice(newDevice) == false)
|
{
|
//只有河东的设备能使用
|
return true;
|
}
|
|
//检测控制面板(灯类)所拥有的功能:需要颜色调节功能
|
Dictionary<string, bool> dicCheck = await Common.LocalDevice.Current.CheckPanelLightFunctionLevel2((Panel)newDevice);
|
if (dicCheck == null)
|
{
|
return false;
|
}
|
if (dicCheck["颜色调节"] == false)
|
{
|
//这个面板没有颜色调节的功能
|
return true;
|
}
|
|
Application.RunOnMainThread(() =>
|
{
|
//指示灯设置
|
var staRow = new StatuRowLayout(listview);
|
var btnPilolight = new RowCenterView(false);
|
btnPilolight.TextID = R.MyInternationalizationString.uPilolightSettion;
|
staRow.AddChidren(btnPilolight);
|
//向右图标
|
staRow.AddRightIconControl();
|
|
staRow.MouseUpEvent += (sender, e) =>
|
{
|
var form = new DevicePanel.PanelPilolightSettionMenuForm();
|
this.AddForm(form, (Panel)newDevice);
|
};
|
});
|
return true;
|
}
|
|
#endregion
|
|
#region ■ 按键面板绑定目标___________________
|
|
/// <summary>
|
/// 添加按键面板的【绑定目标】行
|
/// </summary>
|
private void AddPanelBindTargetRow()
|
{
|
if (newDevice.Type != DeviceType.OnOffSwitch)
|
{
|
//如果是不是按键面板的话
|
return;
|
}
|
|
//绑定目标
|
var staRow = new StatuRowLayout(listview);
|
var btnBind = new RowCenterView(false);
|
btnBind.TextID = R.MyInternationalizationString.uBindTargets;
|
staRow.AddChidren(btnBind);
|
//向右图标
|
staRow.AddRightIconControl();
|
|
staRow.MouseUpEvent += (sender, e) =>
|
{
|
var panel = newDevice as ZigBee.Device.Panel;
|
var bindPage = new Shared.Phone.UserCenter.Bind.PanelBindPage();
|
Shared.Phone.UserView.HomePage.Instance.AddChidren(bindPage);
|
Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
|
bindPage.Show(panel.Gateway, panel);
|
};
|
}
|
|
#endregion
|
|
#region ■ PIR传感器绑定目标__________________
|
|
/// <summary>
|
/// 添加PIR传感器的【绑定目标】行
|
/// </summary>
|
/// <param name="configure">灯光配置</param>
|
private void AddPirSensorBindTargetRow(IASZone.ConfigureParamates configure)
|
{
|
//如果是PIR传感器并且支持开关 (这里判断的是输出簇)
|
if (configure == null || (newDevice is IASZone) == false || Common.LocalDevice.Current.OutDeviceIsCanOnOff(newDevice) == false)
|
{
|
return;
|
}
|
|
//绑定目标
|
var staRow = new StatuRowLayout(listview);
|
var btnBind = new RowCenterView(false);
|
btnBind.TextID = R.MyInternationalizationString.uBindTargets;
|
staRow.AddChidren(btnBind);
|
//向右图标
|
staRow.AddRightIconControl();
|
|
staRow.MouseUpEvent += (sender, e) =>
|
{
|
var form = new DevicePir.PirSensorBindTargetForm();
|
this.AddForm(form, (IASZone)newDevice);
|
};
|
|
//检测目标推送
|
var SenRow = new RowLayout();
|
SenRow.Height = ControlCommonResourse.ListViewRowHeight;
|
listview.AddChidren(SenRow);
|
|
var btnSend = new RowCenterView(false);
|
btnSend.TextID = R.MyInternationalizationString.uTestTargetPush;
|
SenRow.AddChidren(btnSend);
|
|
var btnSendSwich = new SwichControl();
|
SenRow.AddChidren(btnSendSwich);
|
btnSendSwich.IsSelected = configure.controlDevEnable;
|
btnSendSwich.MouseUpEventHandler += async (sender, e) =>
|
{
|
configure.controlDevEnable = !configure.controlDevEnable;
|
//开启进度条
|
this.ShowProgressBar();
|
var result = await Common.LocalDevice.Current.SetPirSensorLightSettion((IASZone)newDevice, configure);
|
//关闭进度条
|
this.CloseProgressBar();
|
if (result == false)
|
{
|
//将缓存值改回来
|
configure.controlDevEnable = !configure.controlDevEnable;
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
btnSendSwich.IsSelected = !btnSendSwich.IsSelected;
|
});
|
};
|
}
|
|
#endregion
|
|
#region ■ 修改名字___________________________
|
|
/// <summary>
|
/// 设备重命名
|
/// </summary>
|
/// <param name="name">Name.</param>
|
/// <param name="listRoomName">Name.</param>
|
private async void DeviceReName(string name, List<string> listRoomName)
|
{
|
//设备名称修改
|
var result = await Common.LocalDevice.Current.ReName(this.newDevice, name);
|
if (result == false)
|
{
|
return;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
if (this.ActionNameChangedEvent != null)
|
{
|
name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
|
this.ActionNameChangedEvent(name, listRoomName);
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 变更图片___________________________
|
|
/// <summary>
|
/// 显示变更设备图标的界面
|
/// </summary>
|
/// <param name="btnIcon"></param>
|
private void ShowChangedIconForm(IconViewControl btnIcon)
|
{
|
var form = new Phone.Device.CommonForm.DeviceIconSelectedIMGByLocal();
|
UserView.HomePage.Instance.AddChidren(form);
|
UserView.HomePage.Instance.PageIndex += 1;
|
form.Show();
|
form.action = (unSelectedImagePath, selectedImagePath) =>
|
{
|
btnIcon.UnSelectedImagePath = selectedImagePath;
|
|
//变更图标
|
Common.LocalDevice.Current.ChangedDeviceIcon(newDevice, unSelectedImagePath);
|
|
if (this.ActionNameChangedEvent != null)
|
{
|
List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
|
string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
|
this.ActionNameChangedEvent(name, listRoomName);
|
}
|
};
|
}
|
|
#endregion
|
}
|
}
|