using System;
using Shared;
using Shared.SimpleControl.R;
using System.Collections.Generic;
using Shared.SimpleControl;
using Shared.SimpleControl.Phone;
namespace SmartHome.UI.SimpleControl.Phone
{
public class PanelListPage : FrameLayout
{
public void Show ()
{
this.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.panellist,
TextColor = SkinStyle.Current.MusicTextColor,
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);
RefreshView (middle);
}
///
/// 加载毅面板的界面
///
///
void RefreshView (VerticalScrolViewLayout middle)
{
middle.RemoveAll ();
for (int i = 0; i < YIPanel.yIPaneList.Count; i++) {
var yipanel = YIPanel.yIPaneList [i];
var rowpanel = new RowLayout {
Height = Application.GetRealHeight (100),
};
middle.AddChidren (rowpanel);
var panelname = new Button {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (100),
X = Application.GetRealWidth (20),
Gravity = Gravity.CenterVertical,
Text = yipanel.Name,
TextAlignment = TextAlignment.CenterLeft,
};
rowpanel.AddChidren (panelname);
var buteditor = new Button {
Height = Application.GetRealHeight (90),
Width = Application.GetRealWidth (70),
UnSelectedImagePath = "Item/Editor.png",
SelectedImagePath = "Item/EditorSelected.png",
Gravity = Gravity.CenterVertical,
X = Application.GetRealWidth (525),
};
rowpanel.AddChidren (buteditor);
buteditor.MouseUpEventHandler += (sender, e) => {
#region 编辑名称View
var dialog = new Dialog {
Height = Application.GetRealHeight (350),
Width = Application.GetRealWidth (520),
BackgroundColor = 0xffffffff,
};
var btnname = new Button {
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth (520),
Height = Application.GetRealHeight (80),
//Text = "修改名称",
TextID = MyInternationalizationString.thename,
TextSize = 16,
BackgroundColor = 0xff838383,
};
dialog.AddChidren (btnname);
var yipanelTextBox = new EditText () {
Y = btnname.Bottom + Application.GetRealHeight (55),
Width = Application.GetRealWidth (460),
Height = Application.GetRealHeight (80),
X = Application.GetRealWidth (30),
Radius = (uint)Application.GetRealHeight (2),
Text = yipanel.Name,
BorderWidth = 1,
BorderColor = 0xff838383,
TextColor = 0xff838383,
TextAlignment = TextAlignment.Center,
};
dialog.AddChidren (yipanelTextBox);
var BottomView = new FrameLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (80),
Y = dialog.Height - Application.GetRealHeight (80),
};
dialog.AddChidren (BottomView);
var cancel = new Button {
//Text = "取消",
TextID = MyInternationalizationString.cancel,
TextSize = 16,
Width = Application.GetRealWidth (259),
Height = Application.GetRealHeight (80),
BackgroundColor = 0xff838383,
};
BottomView.AddChidren (cancel);
cancel.MouseUpEventHandler += (sender11, e11) => {
dialog.Close ();
};
var btnLineS = new Button () {
Width = Application.GetRealWidth (2),
Height = Application.GetRealHeight (80),
X = cancel.Right,
};
BottomView.AddChidren (btnLineS);
var Confirm = new Button {
X = btnLineS.Right,
//Text = "确定",
TextID = MyInternationalizationString.confirm,
TextSize = 16,
BackgroundColor = 0xff838383,
Width = Application.GetRealWidth (260),
Height = Application.GetRealHeight (80),
};
BottomView.AddChidren (Confirm);
Confirm.MouseUpEventHandler += (sender1, e1) => {
var Name = yipanelTextBox.Text.Trim ();
if (string.IsNullOrEmpty (Name)) {
new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.PleaseEnterLogicName), Language.StringByID (MyInternationalizationString.Close)).Show ();
return;
}
var yipanelname = YIPanel.yIPaneList.Find ((yIPanel) => yIPanel.Name == Name);
if (yipanelname != null) {
new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.Rename), Language.StringByID (MyInternationalizationString.Close)).Show ();
return;
}
yipanel.Name = Name;
dialog.Close ();
System.Threading.Tasks.Task.Run ((() => {
try {
var bytes = new byte [20];
var pathBytes = System.Text.Encoding.UTF8.GetBytes (yipanel.Name);
Array.Copy (pathBytes, 0, bytes, 0, pathBytes.Length > 20 ? 20 : pathBytes.Length);
Shared.Control.ControlBytesSend (Command.YIPanelName, yipanel.SubnetID, yipanel.DeviceID, bytes);
} catch { } finally {
Application.RunOnMainThread (() => {
UserMiddle.DevicePageView.PageIndex = 0;
var panelListPage = new PanelListPage ();
UserMiddle.DevicePageView.AddChidren (panelListPage);
panelListPage.Show ();
UserMiddle.DevicePageView.PageIndex = 1;
});
}
}));
};
var btnLine1 = new Button () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (2),
BackgroundColor = 0xff121212,
};
BottomView.AddChidren (btnLine1);
dialog.Show ();
#endregion
};
EventHandler clickpanellist = (sender, e) => {
YIPanel.Current = yipanel;
var currentYiPanel = new CurrentYiPanel ();
MainPage.MainFrameLayout.AddChidren (currentYiPanel);
currentYiPanel.Show (yipanel, panelname.Text);
};
rowpanel.MouseUpEventHandler += clickpanellist;
panelname.MouseUpEventHandler += clickpanellist;
var btnDel = new Button {
BackgroundColor = 0xFFFF0000,
Text = Language.StringByID (MyInternationalizationString.del),
};
rowpanel.AddRightView (btnDel);
btnDel.MouseUpEventHandler += (sender, e) => {
Shared.IO.FileUtils.DeleteFile ("Equipment_YIPanel_" + yipanel.SubnetID + "_" + yipanel.DeviceID);
YIPanel.yIPaneList.Remove (yipanel);
RefreshView (middle);
};
}
}
}
}