using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.UserCenter.DeviceShard
|
{
|
/// <summary>
|
/// 网关指定分享设备的信息画面
|
/// </summary>
|
public class ShardDeviceEpointInfoForm : 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()
|
{
|
//清空bodyFrame
|
this.ClearBodyFrame();
|
|
//房间
|
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);
|
}
|
|
#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
|
|
#region ■ 关闭界面___________________________
|
|
/// <summary>
|
/// 画面关闭
|
/// </summary>
|
public override void CloseForm()
|
{
|
this.ActionNameChangedEvent = null;
|
base.CloseForm();
|
}
|
|
#endregion
|
}
|
}
|