using System;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public class SocketPage_InstantaneousValue : FrameLayout
|
{
|
static SocketPage_InstantaneousValue bodyView;
|
HorizontalScrolViewLayout instantaneousValueView;
|
|
Function function;
|
public SocketPage_InstantaneousValue(Function function)
|
{
|
this.function = function;
|
bodyView = this;
|
}
|
|
public void LoadPage()
|
{
|
bodyView.BackgroundColor = CSS.CSS_Color.BackgroundColor;
|
FrameLayout contentView = new FrameLayout()
|
{
|
Y= Application .GetRealHeight(64),
|
Height = Application.GetRealHeight(603),
|
};
|
bodyView.AddChidren(contentView);
|
|
instantaneousValueView = new HorizontalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(16),
|
Width = Application.GetRealWidth(343),
|
Height = Application.GetRealHeight(110),
|
Gravity = Gravity.CenterHorizontal,
|
Radius = (uint)Application.GetRealWidth(12),
|
BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
|
ScrollEnabled = false,
|
};
|
contentView.AddChidren(instantaneousValueView);
|
|
var voltageAttr = function.GetAttribute("voltage");//电压
|
if (voltageAttr != null)
|
{
|
var view = new InstantaneousValueView();
|
view.Init(voltageAttr.curValue.ToString(), Language.StringByID(StringId.VoltageAndUnit));
|
view.Tag = "voltage";
|
instantaneousValueView.AddChidren(view);
|
}
|
var currentAttr = function.GetAttribute("current");//电流
|
if (currentAttr != null)
|
{
|
var view = new InstantaneousValueView();
|
view.Init(currentAttr.curValue.ToString(), Language.StringByID(StringId.CurrentAndUnit));
|
view.Tag = "current";
|
instantaneousValueView.AddChidren(view);
|
}
|
var active_powerAttr = function.GetAttribute("active_power");//有功功率
|
if (active_powerAttr != null)
|
{
|
var view = new InstantaneousValueView();
|
view.Init(active_powerAttr.curValue.ToString(), Language.StringByID(StringId.ActivePowerAndUnit));
|
view.Tag = "active_power";
|
instantaneousValueView.AddChidren(view);
|
}
|
|
var btnRefresh = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(539),
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealWidth(44),
|
Radius = (uint)Application.GetRealWidth(22),
|
BackgroundColor = CSS_Color.MainColor,
|
TextColor = CSS_Color.MainBackgroundColor,
|
TextSize = CSS_FontSize.SubheadingFontSize,
|
TextAlignment = TextAlignment.Center,
|
IsBold = true,
|
TextID = StringId.Refresh,
|
};
|
contentView.AddChidren(btnRefresh);
|
btnRefresh.MouseUpEventHandler = (sender, e) => {
|
new System.Threading.Thread(() =>
|
{
|
DriverLayer.Control.Ins.SendReadCommand(function);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
new TopViewDiv(bodyView, Language.StringByID(StringId.InstantaneousValue)).LoadTopView();
|
new System.Threading.Thread(() =>
|
{
|
DriverLayer.Control.Ins.SendReadCommand(function);
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
public static void UpdataView(Function updata)
|
{
|
if (bodyView != null)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
for (int i = 0; i < bodyView.instantaneousValueView.ChildrenCount; i++)
|
{
|
var view = bodyView.instantaneousValueView.GetChildren(i);
|
if (null != view.Tag)
|
{
|
if (view.GetType() == typeof(InstantaneousValueView))
|
{
|
var view2 = view as InstantaneousValueView;
|
switch (view.Tag.ToString())
|
{
|
case "active_power":
|
var attr = updata.GetAttribute("active_power");
|
if (attr != null)
|
{
|
view2.btnValue.Text = attr.curValue.ToString();
|
}
|
break;
|
case "voltage":
|
var attr1 = updata.GetAttribute("voltage");
|
if (attr1 != null)
|
{
|
view2.btnValue.Text = attr1.curValue.ToString();
|
}
|
break;
|
case "current":
|
var attr2 = updata.GetAttribute("current");
|
if (attr2 != null)
|
{
|
view2.btnValue.Text = attr2.curValue.ToString();
|
}
|
break;
|
}
|
}
|
}
|
}
|
});
|
}
|
}
|
}
|
|
|
public class InstantaneousValueView :FrameLayout
|
{
|
public FrameLayout View;
|
public Button btnValue;
|
public Button btnLine;
|
public Button btnUnit;
|
|
public InstantaneousValueView()
|
{
|
View = this;
|
View.Width = Application.GetRealWidth(115);
|
View.Height = Application.GetRealHeight(110);
|
}
|
|
public void Init(string value, string unit)
|
{
|
|
btnValue = new Button()
|
{
|
Height = Application.GetRealHeight(59),
|
Y = Application.GetRealWidth(12),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS.CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS.CSS_FontSize.EmphasisFontSize_FirstLevel,
|
Text = value,
|
};
|
View.AddChidren(btnValue);
|
|
btnLine = new Button()
|
{
|
Height = Application.GetRealHeight(2),
|
Width = Application.GetRealWidth(60),
|
Gravity = Gravity.CenterHorizontal,
|
BackgroundColor = CSS.CSS_Color.MainColor,
|
Y = Application.GetRealHeight(59),
|
};
|
View.AddChidren(btnLine);
|
|
btnUnit = new Button()
|
{
|
Y = Application.GetRealHeight(59),
|
Height = Application.GetRealHeight(33),
|
TextAlignment = TextAlignment.Center,
|
TextColor = CSS.CSS_Color.PromptingColor1,
|
TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel,
|
Text = unit
|
};
|
View.AddChidren(btnUnit);
|
|
|
}
|
}
|
|
}
|