using System;
using System.Threading;
namespace Shared.SimpleControl.Phone
{
public class UserDeviceToUniversalDevice : FrameLayout
{
///
/// 当前设备界面
///
static UserDeviceToUniversalDevice curView;
VerticalScrolViewLayout equipmentListScrolView;
VerticalScrolViewLayout bodyScrolView;
///
/// 构造函数
///
public UserDeviceToUniversalDevice ()
{
curView = this;
}
///
/// 更新当前灯光
///
public static void UpdateStatus (string updataFlag, byte brightness)
{
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => {
if (curView == null) {
return;
}
if (curView.equipmentListScrolView.Decelerating) {
return;
}
for (int i = 0; i < curView.equipmentListScrolView.ChildrenCount; i++) {
if (curView.equipmentListScrolView.GetChildren (i).GetType () == typeof (FrameLayout)) {
var lightRow = (FrameLayout)curView.equipmentListScrolView.GetChildren (i);
var o = lightRow.GetTagByKey ("UpdataKey");
if (o != null && o.ToString () == updataFlag) {
for (int j = 0; j < lightRow.ChildrenCount; j++) {
if (lightRow.GetChildren (j).GetType () == typeof (Button)) {
}
}
}
}
}
});
});
}
///
/// 通过设备类型方式选择设备
///
public void ShowUniversalDevice ()
{
#region 标题
var topView = new FrameLayout () {
Y = Application.GetRealHeight (36),
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren (topView);
var title = new Button () {
TextAlignment = TextAlignment.Center,
Text = Language.StringByID (R.MyInternationalizationString.UniversalDevice),
TextColor = SkinStyle.Current.TextColor1,
TextSize = 19,
};
topView.AddChidren (title);
var logo = new Button () {
Width = Application.GetRealWidth (154),
Height = Application.GetRealHeight (90),
X = Application.GetRealWidth (486),
UnSelectedImagePath = MainPage.LogoString,
};
topView.AddChidren (logo);
var back = new Button () {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (85),
UnSelectedImagePath = "Item/Back.png",
SelectedImagePath = "Item/BackSelected.png",
};
topView.AddChidren (back);
back.MouseUpEventHandler += (sender, e) => {
(Parent as PageLayout).PageIndex -= 1;
curView = null;
};
#endregion
bodyScrolView = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (Application.DesignHeight - 126),
Y = Application.GetRealHeight (126),
};
AddChidren (bodyScrolView);
//显示有多少个房间,每个房间有多少个灯开
foreach (var room in Room.Lists) {
if (string.IsNullOrEmpty(room.Name)) {
continue;
}
var udList = room.DeviceList.FindAll ((obj) => { return obj.Type == DeviceType.UniversalDevice; });
if (udList == null || udList.Count == 0) {
continue;
}
FrameLayout roomView = new FrameLayout () {
Height = Application.GetRealHeight (110),
BackgroundColor = SkinStyle.Current.ViewColor,
Tag = room.Name
};
bodyScrolView.AddChidren (roomView);
Button btnRoomNull = new Button () {
Height = 1,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
BackgroundColor = SkinStyle.Current.MainColor,
};
bodyScrolView.AddChidren (btnRoomNull);
Button btnPoint = new Button () {
Width = Application.GetRealWidth (10),
Height = Application.GetRealHeight (10),
X = Application.GetRealWidth (30),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/Point.png",
SelectedImagePath = "Item/Point.png",
};
roomView.AddChidren (btnPoint);
Button btnRoomName = new Button () {
Text = room.Name,
X = btnPoint.Right + Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
};
roomView.AddChidren (btnRoomName);
EditText btnNumber = new EditText () {
Width = Application.GetMinRealAverage (50),
Height = Application.GetMinRealAverage (35),
X = Application.GetRealWidth (640 - 100 - 50 - 20),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Item/LightingCount.png",
SelectedImagePath = "Item/LightingCount.png",
Enable = false,
Text = udList.Count.ToString (),
TextColor = SkinStyle.Current.TextColor1,
TextAlignment = TextAlignment.Center,
Tag = room.Name
};
roomView.AddChidren (btnNumber);
Button btnLightIcon = new Button () {
Width = Application.GetRealWidth (50),
Height = Application.GetRealHeight (50),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "UniversalDevice/UniversalDevice.png",
SelectedImagePath = "UniversalDevice/UniversalDeviceOn.png",
X = btnNumber.Right + Application.GetRealWidth(30)
};
roomView.AddChidren (btnLightIcon);
btnRoomName.MouseUpEventHandler += (sender, e) => {
var userUniversalPage = new UserUniversalPage (room);
UserMiddle.DevicePageView.AddChidren (userUniversalPage);
userUniversalPage.ShowUniversalRoom ();
UserMiddle.DevicePageView.PageIndex = 2;
};
}
#region 显示全部
FrameLayout ShowAllView = new FrameLayout () {
Height = Application.GetRealHeight (85),
BackgroundColor = SkinStyle.Current.MainColor,
};
bodyScrolView.AddChidren (ShowAllView);
Button btnShowAll = new Button () {
X = Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
Text = Language.StringByID (R.MyInternationalizationString.Device),
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1
};
ShowAllView.AddChidren (btnShowAll);
Button downSelectedButton = new Button () {
X = Application.GetRealWidth (550),
Height = Application.GetRealHeight (50),
Width = Application.GetRealWidth (55),
UnSelectedImagePath = "Item/Down.png",
SelectedImagePath = "Item/DownSelected.png",
Gravity = Gravity.CenterVertical,
IsSelected = true,
};
ShowAllView.AddChidren (downSelectedButton);
//显示出所有
equipmentListScrolView = new VerticalScrolViewLayout () {
Height = bodyScrolView.Height - ShowAllView.Height,
};
bodyScrolView.AddChidren (equipmentListScrolView);
int LightCount = 0;
EventHandler eHandler = (sender, e) => {
btnShowAll.IsSelected = !btnShowAll.IsSelected;
downSelectedButton.IsSelected = btnShowAll.IsSelected;
UserConfig.Instance.ShowRoomLightList = btnShowAll.IsSelected;
UserConfig.Instance.SaveUserConfig ();
if (btnShowAll.IsSelected) {
equipmentListScrolView.RemoveAll ();
foreach (var room in Room.Lists) {
if (string.IsNullOrEmpty(room.Name)) {
continue;
}
foreach (var common in room.DeviceList) {
if (common.Type == DeviceType.UniversalDevice) {
LightCount++;
var udDevice = common as UniversalDevice;
byte sendLoopID = udDevice.LoopID;
FrameLayout universalView = new FrameLayout () {
Height = Application.GetRealHeight (130),
Radius = 1,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = (uint)Application.GetMinRealAverage (5),
};
universalView.AddTag ("UpdataKey", common.CommonLoopID);
equipmentListScrolView.AddChidren (universalView);
Button btnLightViewBottomNull = new Button () {
Y = Application.GetRealHeight (127),
Height = Application.GetRealHeight (3),
BackgroundColor = SkinStyle.Current.MainColor,
SelectedBackgroundColor = SkinStyle.Current.MainColor,
};
universalView.AddChidren (btnLightViewBottomNull);
//灯名
var tempDeviceName = new Button () {
X = Application.GetRealWidth (20),
TextAlignment = TextAlignment.CenterLeft,
Text = room.Name + "-" + udDevice.Name,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
Width = Application.GetRealWidth (400),
//Enable = false,
};
universalView.AddChidren (tempDeviceName);
if((int)udDevice.CustomTextSize != 0) {
tempDeviceName.TextSize = (int)udDevice.CustomTextSize;
}
tempDeviceName.MouseLongEventHandler += (sende4r, ob) => {
var changeSizeDialog = new Dialog ();
var changeBodyView = new FrameLayout () {
Gravity = Gravity.Center,
Width = Application.GetRealWidth(500),
Height = Application.GetRealHeight(400),
BackgroundColor = SkinStyle.Current.ViewColor,
BorderColor = SkinStyle.Current.Transparent,
BorderWidth = 1,
Radius = 5,
};
changeSizeDialog.AddChidren (changeBodyView);
udDevice.CustomTextSize = tempDeviceName.TextSize;
var btnChangeName = new Button () {
Y = Application.GetRealHeight(40),
X = Application.GetRealWidth(50),
Width = Application.GetRealWidth(400),
Height = Application.GetRealHeight(130),
TextAlignment = TextAlignment.CenterLeft,
TextSize = tempDeviceName.TextSize,
Text = udDevice.Name,
TextColor = SkinStyle.Current.TextColor1,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 1,
BackgroundColor = SkinStyle.Current.ButtonColor,
Radius = 1,
};
changeBodyView.AddChidren (btnChangeName);
var btnSmaller = new Button () {
X = Application.GetRealWidth(50),
Y = btnChangeName.Bottom + Application.GetRealHeight(40),
Width = Application.GetRealHeight(150),
Height = Application.GetRealHeight(80),
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.Smaller,
TextAlignment = TextAlignment.Center,
BorderWidth = 2,
BorderColor = SkinStyle.Current.BorderColor,
BackgroundColor = SkinStyle.Current.ButtonColor,
Radius = 5,
};
changeBodyView.AddChidren (btnSmaller);
btnSmaller.MouseUpEventHandler += (ddfa, fds) => {
if (udDevice.CustomTextSize < 7)
return;
tempDeviceName.TextSize = btnChangeName.TextSize = udDevice.CustomTextSize --;
Console.WriteLine ("btnChangeName.TextSize : " + btnChangeName.TextSize);
btnChangeName.Text = udDevice.Name;
};
var btnBigger = new Button () {
X = btnSmaller.Right + Application.GetRealWidth (100),
Y = btnChangeName.Bottom + Application.GetRealHeight (40),
Width = Application.GetRealHeight (150),
Height = Application.GetRealHeight (80),
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.Bigger,
TextAlignment = TextAlignment.Center,
BorderWidth = 2,
BorderColor = SkinStyle.Current.BorderColor,
BackgroundColor = SkinStyle.Current.ButtonColor,
Radius = 5,
};
changeBodyView.AddChidren (btnBigger);
btnBigger.MouseUpEventHandler += (ddfa, fds) => {
if (udDevice.CustomTextSize >= 50)
return;
tempDeviceName.TextSize = btnChangeName.TextSize = udDevice.CustomTextSize ++;
Console.WriteLine ("btnChangeName.TextSize : "+btnChangeName.TextSize);
btnChangeName.Text = udDevice.Name;
};
var btnSave = new Button () {
Y = Application.GetRealHeight(400-91),
Height = Application.GetRealHeight(90),
BackgroundColor = SkinStyle.Current.ButtonColor,
TextColor = SkinStyle.Current.TextColor1,
TextID = R.MyInternationalizationString.SAVE,
TextAlignment = TextAlignment.Center,
};
changeBodyView.AddChidren (btnSave);
btnSave.MouseUpEventHandler += (dd, dda) => {
IO.FileUtils.SaveEquipmentMessage (udDevice, udDevice.LoopID.ToString ());
changeSizeDialog.Close ();
};
changeSizeDialog.Show ();
};
Button tempSwitch = new Button () {
Width = Application.GetRealWidth (110),
Height = Application.GetRealHeight (70),
X = Application.GetRealWidth (640 - 110 - 20),
Gravity = Gravity.CenterVertical,
Radius = 2,
BorderColor = SkinStyle.Current.BorderColor,
TextColor = SkinStyle.Current.TextColor1,
BorderWidth = 2,
};
universalView.AddChidren (tempSwitch);
if (udDevice.ActionType == 0) {
tempSwitch.Text = udDevice.ON_Text;
} else if (udDevice.ActionType == 1) {
tempSwitch.Text = udDevice.OFF_Text;
} else if (udDevice.ActionType == 2) {
tempSwitch.Text = udDevice.OFF_Text;
//tempSiwtch.TextID = R.MyInternationalizationString.OFF;
Button tempON = new Button () {
Width = Application.GetRealWidth (110),
Height = Application.GetRealHeight (70),
X = Application.GetRealWidth (640 - 250 - 20),
Gravity = Gravity.CenterVertical,
Radius = 2,
BorderColor = SkinStyle.Current.BorderColor,
BorderWidth = 2,
Text = udDevice.ON_Text,
//TextID = R.MyInternationalizationString.ON,
TextColor = SkinStyle.Current.TextColor1,
SelectedTextColor = SkinStyle.Current.TextColor1,
};
universalView.AddChidren (tempON);
tempON.MouseUpEventHandler += (sender3, e3) => {
if (udDevice.UniversalType == 0xE01C) {
Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero);
}
universalView.BorderColor = SkinStyle.Current.Transparent;
tempON.BorderColor = SkinStyle.Current.BorderColor;
};
tempON.MouseDownEventHandler += (sende3r, e3) => {
universalView.BorderColor = SkinStyle.Current.SelectedColor;
tempON.BorderColor = SkinStyle.Current.SelectedColor;
};
}
tempSwitch.MouseUpEventHandler += (sender3, e3) => {
if (udDevice.UniversalType == 0xE01C) {
if (udDevice.ActionType == 0) {
Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 255 }, SendCount.Zero);
} else if (udDevice.ActionType == 1) {
Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
} else if (udDevice.ActionType == 2) {
Control.ControlBytesSend (Command.SetCommonSwitch, udDevice.SubnetID, udDevice.DeviceID, new byte [] { udDevice.SendBytes [0], 0 }, SendCount.Zero);
}
}
universalView.BorderColor = SkinStyle.Current.Transparent;
tempSwitch.BorderColor = SkinStyle.Current.BorderColor;
};
tempSwitch.MouseDownEventHandler += (sende3r, e3) => {
universalView.BorderColor = SkinStyle.Current.SelectedColor;
tempSwitch.BorderColor = SkinStyle.Current.SelectedColor;
};
}
}
equipmentListScrolView.Height = bodyScrolView.Height;
}
} else {
equipmentListScrolView.Height = 0;
LightCount = 0;
}
};
btnShowAll.MouseUpEventHandler += eHandler;
downSelectedButton.MouseUpEventHandler += eHandler;
//默认是选中状态
if (UserConfig.Instance.ShowRoomLightList)
eHandler (btnShowAll, new MouseEventArgs ());
#endregion
}
}
}