using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.DeviceShard
{
///
/// 网关指定分享设备的信息画面
///
public class ShardDeviceEpointInfoForm : UserCenterCommonForm
{
#region ■ 变量声明___________________________
///
/// 设备名称变更的回调函数(设备名称,房间名)
///
public Action> ActionNameChangedEvent = null;
///
/// 列表控件
///
private VerticalScrolViewLayout listview = null;
///
/// 新上报的设备
///
private CommonDevice newDevice = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 设备
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();
}
///
/// 初始化头部右边的测试图标
///
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);
};
}
///
/// 初始化中部控件
///
public void InitMiddleFrame()
{
this.bodyFrameLayout.RemoveAll();
//房间
List 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);
}
#endregion
#region ■ 修改名字___________________________
///
/// 设备重命名
///
/// Name.
/// Name.
private async void DeviceReName(string name, List 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 ■ 变更图片___________________________
///
/// 显示变更设备图标的界面
///
///
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 listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
this.ActionNameChangedEvent(name, listRoomName);
}
};
}
#endregion
}
}