using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.Device.CommonForm;
namespace Shared.Phone.Device.Category
{
public class SelectDelayTime : FrameLayout
{
#region ◆ 变量____________________________
///
/// bodyFrameLayout
///
private FrameLayout bodyFrameLayout;
///
/// totalSecond
///
public int totalSecond;
///
/// selectedTimeAction
///
public Action selectedTimeAction;
#endregion
///
/// SelectDelayTime
///
public SelectDelayTime()
{
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
//Tag = "categoryAddScene";
}
///
/// RemoveFromParent
///
public override void RemoveFromParent()
{
base.RemoveFromParent();
}
///
/// sceneTargetDevice
///
public SceneTargetDeviceUI sceneTargetDevice;
///
/// Show
///
public void Show()
{
if (sceneTargetDevice == null)
{
sceneTargetDevice = new SceneTargetDeviceUI { Type = 2 };
}
AddTop();
AddBodyView();
}
#region Add____________________________________
///
/// AddTop
///
private void AddTop()
{
var top = new TopFrameLayout();
AddChidren(top);
top.InitTopview();
top.SetTopTitle(R.MyInternationalizationString.AddDelayTime);
top.backButton.MouseUpEventHandler += (sender, e) =>
{
RemoveFromParent();
};
}
///
/// AddBodyView
///
private void AddBodyView()
{
bodyFrameLayout = new FrameLayout()
{
Y = Application.GetRealHeight(184),
Height = Application.GetRealHeight(1737),
BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
};
AddChidren(bodyFrameLayout);
var bg1 = new FrameLayout
{
Y = Application.GetRealHeight(118),
Height = Application.GetMinRealAverage(207),
Width = Application.GetMinRealAverage(207),
Gravity = Gravity.CenterHorizontal,
Radius = (uint)Application.GetMinRealAverage(207 / 2),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
};
bodyFrameLayout.AddChidren(bg1);
var bg2 = new FrameLayout
{
Height = Application.GetMinRealAverage(184),
Width = Application.GetMinRealAverage(184),
Gravity = Gravity.Center,
Radius = (uint)Application.GetMinRealAverage(184 / 2),
BackgroundColor = ZigbeeColor.Current.GXCSelectedBackgroundColor,
};
bg1.AddChidren(bg2);
var timeImg = new Button
{
Height = Application.GetMinRealAverage(124),
Width = Application.GetMinRealAverage(124),
Gravity = Gravity.Center,
Radius = (uint)Application.GetRealHeight(58),
UnSelectedImagePath = "Item/Timer.png"
};
bg1.AddChidren(timeImg);
var tip = new Button
{
Y = Application.GetRealHeight(350),
Width = Application.GetRealWidth(700),
Height = Application.GetRealHeight(120),
Gravity = Gravity.CenterHorizontal,
TextID = R.MyInternationalizationString.SelectTimeForAction,
TextColor = ZigbeeColor.Current.GXCTextBlackColor,
TextSize=15,
IsMoreLines = true
};
bodyFrameLayout.AddChidren(tip);
var midFL = new FrameLayout
{
Y = Application.GetRealHeight(611),
Height = Application.GetRealHeight(1126),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
Radius = (uint)Application.GetRealHeight(58),
};
bodyFrameLayout.AddChidren(midFL);
var timeFL = new FrameLayout
{
Y = Application.GetRealHeight(127),
Height = Application.GetRealHeight(1126 - 127),
BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
};
midFL.AddChidren(timeFL);
var pickView = new UIPickerView
{
Height = Application.GetRealHeight(153 * 3),
};
timeFL.AddChidren(pickView);
//分
string strMinute = Language.StringByID(R.MyInternationalizationString.uMinute);
//秒
string strSecond = Language.StringByID(R.MyInternationalizationString.uSecond);
var listfirst = new List();
var listSecond = new List>();
for (int i = 0; i <= 59; i++)
{
listfirst.Add(i.ToString().PadLeft(2, '0') + strMinute);
var listTemp = new List();
for (int j = 0; j <= 59; j++)
{
if (i == 0 && j == 0)
{
continue;
}
listTemp.Add(j.ToString().PadLeft(2, '0') + strSecond);
}
listSecond.Add(listTemp);
}
//加一个60分钟吧
listfirst.Add("60" + strMinute);
var listTemp2 = new List() { "00" + strSecond };
listSecond.Add(listTemp2);
pickView.setPicker(listfirst, listSecond);
pickView.setCurrentItems(totalSecond / 60, totalSecond % 60, 0);
pickView.OnSelectChangeEvent += (value1, value2, value3) =>
{
int minute = Convert.ToInt32(listfirst[value1].Substring(0, 2));
int second = Convert.ToInt32(listSecond[value1][value2].Substring(0, 2));
totalSecond = minute * 60 + second;
};
var confirmBtn = new CommonForm.CompleteButton(1656, 907, 127);
AddChidren(confirmBtn);
confirmBtn.SetTitle(R.MyInternationalizationString.Save);
confirmBtn.MouseUpEventHandler += (sender, e) =>
{
if (totalSecond == 0)
{
RemoveFromParent();
}
else
{
sceneTargetDevice.DelayTime = totalSecond;
selectedTimeAction?.Invoke(sceneTargetDevice);
RemoveFromParent();
}
};
}
#endregion
}
}