using System;
|
using System.Collections.Generic;
|
using Shared.SimpleControl.R;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserSensorAutomationConditionSettingPage : FrameLayout
|
{
|
List<Common> sensorList;
|
SensorAutomationDevice autonmationDevice;
|
SensorAutomation sensorAutomation;
|
public UserSensorAutomationConditionSettingPage (List<Common> commonList,SensorAutomationDevice ad, SensorAutomation sa)
|
{
|
autonmationDevice = ad;
|
sensorAutomation = sa;
|
sensorList = commonList;
|
}
|
public void ShowPage (Action<SensorAutomation> action)
|
{
|
this.BackgroundColor = SkinStyle.Current.MainColor;
|
#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,
|
TextID = R.MyInternationalizationString.AutomationSetting,
|
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;
|
};
|
#endregion
|
|
var bodyScrolView = new VerticalScrolViewLayout () {
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
Height = Application.GetRealHeight (1136 - 126),
|
ScrollEnabled = false
|
};
|
AddChidren (bodyScrolView);
|
|
FrameLayout tipTopView = new FrameLayout () {
|
Height = Application.GetRealHeight (110),
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
bodyScrolView.AddChidren (tipTopView);
|
Button btnTipText = new Button () {
|
X = Application.GetRealWidth (60),
|
Width = Application.GetRealWidth (500),
|
TextID = R.MyInternationalizationString.ConditionType,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
tipTopView.AddChidren (btnTipText);
|
|
foreach (var common in sensorList) {
|
var device = common as Sensor;
|
RowLayout rowView = new RowLayout () {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
bodyScrolView.AddChidren (rowView);
|
|
var btnPoint = new Button () {
|
Width = Application.GetMinRealAverage (10),
|
Height = Application.GetMinRealAverage (10),
|
Radius = (uint)Application.GetMinRealAverage (5),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
BackgroundColor = SkinStyle.Current.TextColor1,
|
SelectedBackgroundColor = SkinStyle.Current.SelectedColor,
|
};
|
rowView.AddChidren (btnPoint);
|
|
var btnDeviceName = new Button () {
|
Width = Application.GetRealWidth (300),
|
X = Application.GetRealWidth (80),
|
Text = device.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.SelectedColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
rowView.AddChidren (btnDeviceName);
|
|
var rightButton = new Button () {
|
Width = Application.GetRealWidth (46),
|
Height = Application.GetRealHeight (47),
|
Gravity = Gravity.CenterVertical,
|
X = Application.GetRealWidth (580),
|
UnSelectedImagePath = "Item/Down.png",
|
SelectedImagePath = "Item/DownSelected.png",
|
};
|
rowView.AddChidren (rightButton);
|
|
EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
|
if (rightButton.IsSelected) {
|
btnPoint.IsSelected = rightButton.IsSelected = btnDeviceName.IsSelected = false;
|
} else {
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
var dialogConditionTypeChoose = new Dialog ();
|
var dialogView = new FrameLayout () {
|
BackgroundColor = SkinStyle.Current.Black50Transparent,
|
};
|
dialogConditionTypeChoose.AddChidren (dialogView);
|
|
dialogView.MouseUpEventHandler += (ddd, fff) => {
|
btnPoint.IsSelected = rightButton.IsSelected = btnDeviceName.IsSelected = false;
|
dialogView.RemoveAll ();
|
dialogView.RemoveFromParent ();
|
dialogConditionTypeChoose.Close ();
|
};
|
|
var levelListView = new FrameLayout () {
|
Y = Application.GetRealHeight (1136 - 360),
|
Height = Application.GetRealHeight (90 * 4) + 3,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
dialogView.AddChidren (levelListView);
|
|
btnPoint.IsSelected = rightButton.IsSelected = btnDeviceName.IsSelected = true;
|
|
EventHandler<MouseEventArgs> hander = (ddd, eee) => {
|
dialogConditionTypeChoose.Close ();
|
byte iddd = Convert.ToByte (((Button)ddd).Tag);
|
|
List<byte> conditionIdList = new List<byte> ();
|
conditionIdList.AddRange (autonmationDevice.ConditionIdList);
|
|
//if (autonmationDevice.ConditionEnableList [iddd] == 255 || autonmationDevice.ConditionEnableList [iddd] == 0) {
|
if (!conditionIdList.Contains (iddd)) {
|
if (!sensorAutomation.AutomationConditionIdList.Contains (iddd)) {
|
sensorAutomation.AutomationConditionIdList.Add (iddd);
|
action (sensorAutomation);
|
(Parent as PageLayout).PageIndex -= 1;
|
} else {
|
new Alert ("", Language.StringByID (MyInternationalizationString.SensorHadChoose),
|
Language.StringByID (MyInternationalizationString.Close)).Show ();
|
}
|
} else {
|
new Alert ("", Language.StringByID (MyInternationalizationString.SensorHadChoose),
|
Language.StringByID (MyInternationalizationString.Close)).Show ();
|
}
|
//}
|
};
|
|
switch (device.Type) {
|
case DeviceType.SensorPM25:
|
var btnPM25Type1 = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipPM25Level1,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 0
|
};
|
levelListView.AddChidren (btnPM25Type1);
|
btnPM25Type1.MouseUpEventHandler += hander;
|
|
var btnPM25Type2 = new Button () {
|
Y = btnPM25Type1.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipPM25Level2,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 1
|
};
|
levelListView.AddChidren (btnPM25Type2);
|
btnPM25Type2.MouseUpEventHandler += hander;
|
|
|
var btnPM25Type3 = new Button () {
|
Y = btnPM25Type2.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipPM25Level3,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 2
|
};
|
levelListView.AddChidren (btnPM25Type3);
|
btnPM25Type3.MouseUpEventHandler += hander;
|
|
|
var btnPM25Type4 = new Button () {
|
Y = btnPM25Type3.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipPM25Level4,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 3
|
};
|
levelListView.AddChidren (btnPM25Type4);
|
btnPM25Type4.MouseUpEventHandler += hander;
|
|
break;
|
case DeviceType.SensorCO2:
|
var btnCO2Type1 = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipCO2Level1,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 0 + 8
|
};
|
levelListView.AddChidren (btnCO2Type1);
|
btnCO2Type1.MouseUpEventHandler += hander;
|
|
var btnCO2Type2 = new Button () {
|
Y = btnCO2Type1.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipCO2Level2,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 1 + 8
|
};
|
levelListView.AddChidren (btnCO2Type2);
|
btnCO2Type2.MouseUpEventHandler += hander;
|
|
var btnCO2Type3 = new Button () {
|
Y = btnCO2Type2.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipCO2Level3,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 2 + 8
|
};
|
levelListView.AddChidren (btnCO2Type3);
|
btnCO2Type3.MouseUpEventHandler += hander;
|
|
var btnCO2Type4 = new Button () {
|
Y = btnCO2Type3.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTipCO2Level4,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 3 + 8
|
};
|
levelListView.AddChidren (btnCO2Type4);
|
btnCO2Type4.MouseUpEventHandler += hander;
|
break;
|
case DeviceType.SensorTVOC:
|
var btnTVOCType1 = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTVOCTipLevel1,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 0 + 8 + 8
|
};
|
levelListView.AddChidren (btnTVOCType1);
|
btnTVOCType1.MouseUpEventHandler += hander;
|
|
var btnTVOCType2 = new Button () {
|
Y = btnTVOCType1.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTVOCTipLevel2,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 1 + 8 + 8
|
};
|
levelListView.AddChidren (btnTVOCType2);
|
btnTVOCType2.MouseUpEventHandler += hander;
|
|
var btnTVOCType3 = new Button () {
|
Y = btnTVOCType2.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTVOCTipLevel3,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 2 + 8 + 8
|
};
|
levelListView.AddChidren (btnTVOCType3);
|
btnTVOCType3.MouseUpEventHandler += hander;
|
|
var btnTVOCType4 = new Button () {
|
Y = btnTVOCType3.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTVOCTipLevel4,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 3 + 8 + 8
|
};
|
levelListView.AddChidren (btnTVOCType4);
|
btnTVOCType4.MouseUpEventHandler += hander;
|
break;
|
case DeviceType.SensorTemperature:
|
var btnTemperatureType1 = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.Overheat,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnTemperatureType1);
|
|
btnTemperatureType1.MouseUpEventHandler += (te, ddd) => {
|
levelListView.RemoveAll ();
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
var TriggerTemp = Language.StringByID (R.MyInternationalizationString.TriggerTemp);
|
for (int i = 0; i < 4; i++) {
|
int pushTemp = 0;
|
var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i });
|
if (pushValuesRevertBytes == null) {
|
pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 };
|
}
|
pushTemp = pushValuesRevertBytes [2] * 256 + pushValuesRevertBytes [3];
|
|
#region ---温度推送设置---
|
string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C";
|
Button btnTip = new Button () {
|
Y = Application.GetRealHeight (90) * i + i,
|
Height = Application.GetRealHeight (90) ,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = i + 8 + 8 +8
|
};
|
levelListView.AddChidren (btnTip);
|
btnTip.Text = TriggerTemp + ":> " + setTemp;
|
btnTip.MouseUpEventHandler += hander;
|
#endregion
|
}
|
});
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
var btnTemperatureType2 = new Button () {
|
Y = btnTemperatureType1.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.Overcooling,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnTemperatureType2);
|
|
|
btnTemperatureType2.MouseUpEventHandler += (te, ddd) => {
|
levelListView.RemoveAll ();
|
MainPage.Loading.Start ("Please wait...");
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
var TriggerTemp = Language.StringByID (R.MyInternationalizationString.TriggerTemp);
|
for (int i = 0; i < 4; i++) {
|
int pushTemp = 0;
|
var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i });
|
if (pushValuesRevertBytes == null) {
|
pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 };
|
}
|
pushTemp = pushValuesRevertBytes [4] * 256 + pushValuesRevertBytes [5];
|
|
#region ---温度推送设置---
|
string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C";
|
Button btnTip = new Button () {
|
Y = Application.GetRealHeight (90) * i + i,
|
Height = Application.GetRealHeight (90),
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = i + 8 + 8 + 8
|
};
|
levelListView.AddChidren (btnTip);
|
btnTip.Text = TriggerTemp + ":< " + setTemp;
|
btnTip.MouseUpEventHandler += hander;
|
#endregion
|
}
|
});
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
var btnTemNull = new Button () {
|
Y = btnTemperatureType2.Bottom+1,
|
Height = Application.GetRealHeight (185),
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnTemNull);
|
break;
|
case DeviceType.SensorHumidity:
|
var btnHumidityType1 = new Button () {
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceHumidityTipLevel3,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
Tag = 0 + 8 + 8 + 16,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnHumidityType1);
|
btnHumidityType1.MouseUpEventHandler += hander;
|
|
var btnHumidityType2 = new Button () {
|
Y = btnHumidityType1.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceTempTipLevel1,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
Tag = 1 + 8 + 8 + 16
|
};
|
levelListView.AddChidren (btnHumidityType2);
|
btnHumidityType2.MouseUpEventHandler += hander;
|
|
var btnHumidityType3 = new Button () {
|
Y = btnHumidityType2.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceHumidityTipLevel1,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
Tag = 2 + 8 + 8 + 16,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnHumidityType3);
|
btnHumidityType3.MouseUpEventHandler += hander;
|
|
var btnHumidityType4 = new Button () {
|
Y = btnHumidityType3.Bottom + 1,
|
Height = Application.GetRealHeight (90),
|
TextID = R.MyInternationalizationString.SensorReferenceHumidityTipLevel2,
|
TextColor = SkinStyle.Current.TextColor,
|
TextAlignment = TextAlignment.Center,
|
Tag = 3 + 8 + 8 + 16,
|
BackgroundColor = SkinStyle.Current.DialogColor,
|
};
|
levelListView.AddChidren (btnHumidityType4);
|
btnHumidityType4.MouseUpEventHandler += hander;
|
break;
|
}
|
dialogConditionTypeChoose.Show ();
|
});
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
};
|
|
|
|
|
rightButton.MouseUpEventHandler += eventHandler;
|
btnDeviceName.MouseUpEventHandler += eventHandler;
|
rowView.MouseUpEventHandler += eventHandler;
|
|
|
}
|
}
|
}
|
}
|