using System;
|
using System.Collections.Generic;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.R;
|
namespace SmartHome.UI.SimpleControl.Phone
|
{
|
public class CurrentYiPanel : FrameLayout
|
{
|
public void Show (YIPanel yipanel, string name)
|
{
|
|
read (yipanel);
|
|
AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (topFrameLayout);
|
|
var btnTitle = new Button {
|
//TextID = MyInternationalizationString.MusicSource,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
Text = name,
|
TextSize = 17,
|
};
|
topFrameLayout.AddChidren (btnTitle);
|
|
var back = new Button {
|
Width = Application.GetRealWidth (82),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth (10),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/HomepageBack.png",
|
};
|
topFrameLayout.AddChidren (back);
|
back.MouseDownEventHandler += (sender, e) => {
|
RemoveFromParent ();
|
};
|
|
var hdl = new Button {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
Gravity = Gravity.CenterVertical,
|
//UnSelectedImagePath = MainPage.LogoString,
|
};
|
topFrameLayout.AddChidren (hdl);
|
|
var tempFrameLayout = new FrameLayout {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (1136 - 126),
|
//BackgroundImagePath = "MusicIcon/HomepageBackgroun.png",
|
BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (tempFrameLayout);
|
|
VerticalScrolViewLayout middle = new VerticalScrolViewLayout ();
|
tempFrameLayout.AddChidren (middle);
|
|
#region 管理设备
|
|
var deviceRowLayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
middle.AddChidren (deviceRowLayout);
|
|
|
var btndevice = new Button {
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.device,
|
//Text = "管理设备",
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (20),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
deviceRowLayout.AddChidren (btndevice);
|
|
var devicenext = new Button {
|
Width = Application.GetRealWidth (87),
|
Height = Application.GetRealHeight (100),
|
UnSelectedImagePath = "MusicIcon/Next.png",
|
SelectedImagePath = "MusicIcon/NextSelecte.png",
|
X = Application.GetRealWidth (550),
|
};
|
deviceRowLayout.AddChidren (devicenext);
|
|
EventHandler<MouseEventArgs> clickdevice = (sender, e) => {
|
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
|
System.Threading.Tasks.Task.Run (() => {
|
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
var panelDeviceType = new PanelDeviceType ();
|
MainPage.MainFrameLayout.AddChidren (panelDeviceType);
|
panelDeviceType.Show (yipanel);
|
});
|
});
|
};
|
deviceRowLayout.MouseUpEventHandler += clickdevice;
|
devicenext.MouseUpEventHandler += clickdevice;
|
btndevice.MouseUpEventHandler += clickdevice;
|
#endregion
|
|
#region 管理场景
|
var scenerowlayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
middle.AddChidren (scenerowlayout);
|
|
|
|
var btnscene = new Button {
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.scene,
|
//Text = "管理场景",
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (20),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
scenerowlayout.AddChidren (btnscene);
|
|
var scenenext = new Button {
|
Width = Application.GetRealWidth (87),
|
Height = Application.GetRealHeight (100),
|
UnSelectedImagePath = "MusicIcon/Next.png",
|
SelectedImagePath = "MusicIcon/NextSelecte.png",
|
X = Application.GetRealWidth (550),
|
};
|
scenerowlayout.AddChidren (scenenext);
|
EventHandler<MouseEventArgs> clickscene = (sender, e) => {
|
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
yipanel.yIPanelSceneList.Clear ();
|
var yiPanelSceneList = new YiPanelSceneList ();
|
MainPage.MainFrameLayout.AddChidren (yiPanelSceneList);
|
yiPanelSceneList.Show (yipanel, btnscene.Text);
|
|
});
|
|
});
|
};
|
|
scenerowlayout.MouseUpEventHandler += clickscene;
|
scenenext.MouseUpEventHandler += clickscene;
|
btnscene.MouseUpEventHandler += clickscene;
|
|
#endregion
|
|
|
}
|
/// <summary>
|
/// 获取有效类型
|
/// </summary>
|
/// <param name="yipanel">Yipanel.</param>
|
void read (YIPanel yipanel)
|
{
|
yipanel.DeviceTypeList.Clear ();
|
new System.Threading.Thread (() => {
|
try {
|
var b1 = (byte)new Random ().Next (0, 255);
|
var b2 = (byte)new Random ().Next (0, 255);
|
var dateTime = DateTime.Now;
|
Action<byte, byte, int, Command, byte, byte, byte [], System.Net.IPEndPoint> receviceAllDadaAction = (subnetID, deviceID, deviceType, command, targetSubnetID, targetDeviceID, usefulBytes, remoteEndPoint) => {
|
if (usefulBytes == null || usefulBytes.Length < 2 + 20 + 3) {
|
return;
|
}
|
|
if (command == Command.ReadDeviceModulACK && subnetID == yipanel.SubnetID && deviceID == yipanel.DeviceID && b1 == usefulBytes [0] && b2 == usefulBytes [1]) {
|
if (0 < yipanel.DeviceTypeList.Count) {
|
return;
|
}
|
for (int i = 0; i < usefulBytes.Length - 25; i += 3) {
|
var deviceifon = new DeviceIfon ();
|
deviceifon.largeclass = usefulBytes [25+i];//大类别
|
deviceifon.subclass = usefulBytes [25+i + 1];//小类别
|
deviceifon.channelnumber = usefulBytes [25+i + 2];//通道号
|
yipanel.DeviceTypeList.Add (deviceifon);
|
}
|
dateTime = DateTime.MinValue;
|
}
|
};
|
Packet.ReceviceAllDadaAction += receviceAllDadaAction;
|
Shared.Control.ControlBytesSend (Command.ReadDeviceModul, yipanel.SubnetID, yipanel.DeviceID, new byte [] { b1, b2 });
|
while ((DateTime.Now - dateTime).TotalMilliseconds < 3000) {
|
System.Threading.Thread.Sleep (100);
|
}
|
Packet.ReceviceAllDadaAction -= receviceAllDadaAction;
|
|
} catch {
|
}
|
}) { IsBackground = true }.Start ();
|
}
|
}
|
}
|