using System;
using System.Collections.Generic;
using Shared;
using Shared.SimpleControl;
using Shared.SimpleControl.R;
namespace SuperGateWay
{
public class TimePage : FrameLayout
{
public TimePage ()
{
Tag = "Logic";
}
public bool IsDeviceEditor;
public string str;
///
/// 开始时间;
///
Button btnStartTime;
///
/// 结束时间;
///
Button btnEndTime;
///
/// 日头选择
///
Button btnSun;
///
/// 时间显示RowLayout
///
RowLayout timerowlayout;
//inputifon.sid=common.functions.
///
/// 显示开始时间和结束时间方法;
///
/// View group.
void initTime (ViewGroup viewGroup)
{
var startTimeRowLayout = new RowLayout {
Height = Application.GetRealHeight (100),
};
viewGroup.AddChidren (startTimeRowLayout);
var starttext = new Button {
X = Application.GetRealWidth (40),
TextAlignment = TextAlignment.CenterLeft,
Gravity = Gravity.CenterVertical,
//Text = "开始时间",
Width = Application.GetRealWidth (210),
TextID = MyInternationalizationString.starttime,
};
startTimeRowLayout.AddChidren (starttext);
///显示开始时间控件
btnStartTime = new Button {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (100),
X = Application.GetRealWidth (250),
Gravity = Gravity.CenterVertical,
Tag = 0,
TextAlignment = TextAlignment.CenterLeft,
};
startTimeRowLayout.AddChidren (btnStartTime);
var btnStartback = new Button {
Width = Application.GetRealWidth (87),
Height = Application.GetRealHeight (100),
UnSelectedImagePath = "MusicIcon/Next.png",
SelectedImagePath = "MusicIcon/NextSelecte.png",
X = Application.GetRealWidth (550),
};
startTimeRowLayout.AddChidren (btnStartback);
///开始时间点击事件
EventHandler startclick = (sender, e) => {
#region 年,月,日,时,分,秒
//Shared.TimeView
//Shared.DateView
//var year = 18, m = 1, d = 3;
//var v = (((uint)year) << 24) | (((uint)month) << 16 | ((uint (d) << 8));
//compare,<,=,>,
#endregion
startTimeRowLayout.BackgroundColor = 0xffFE5E00;
timerowlayout.BackgroundColor = 0x00000000;
var dialogTime = new DiaLogTime ();
dialogTime.Action = (time) => {
startTimeRowLayout.BackgroundColor = 0x00000000;
if (time < 0) {
return;
}
if (btnEndTime.Tag.ToString () != "0" && time > int.Parse (btnEndTime.Tag.ToString ())) {
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
Language.StringByID (MyInternationalizationString.timesetting),
Language.StringByID (MyInternationalizationString.OK));
alert.Show ();
} else {
string h = "";
string s = "";
if ((time / 60) < 10) {
h = "0" + time / 60;
}else{
h = (time / 60).ToString();
}
if ((time % 60) < 10) {
s = "0" + time % 60;
} else {
s = (time % 60).ToString ();
}
btnStartTime.Text = h + ":" + s;//time / 60 + ":" + time % 60;
btnStartTime.Tag = time;
if (string.IsNullOrEmpty (btnEndTime.Text)) {
btnEndTime.Text = h + ":" + s;//time / 60 + ":" + time % 60;
btnEndTime.Tag = time;
}
}
};
dialogTime.Show ();
};
startTimeRowLayout.MouseUpEventHandler += startclick;
btnStartTime.MouseUpEventHandler += startclick;
starttext.MouseUpEventHandler += startclick;
btnStartback.MouseUpEventHandler += startclick;
var endTimeRowLayout = new RowLayout {
Height = Application.GetRealHeight (100),
};
viewGroup.AddChidren (endTimeRowLayout);
var endtext = new Button {
X = Application.GetRealWidth (40),
TextAlignment = TextAlignment.CenterLeft,
Gravity = Gravity.CenterVertical,
TextID = MyInternationalizationString.endtime,
Width = Application.GetRealWidth (210),
//Text = "结束时间",
};
endTimeRowLayout.AddChidren (endtext);
///显示结束时间控件
btnEndTime = new Button {
Width = Application.GetRealWidth (200),
Height = Application.GetRealHeight (100),
X = Application.GetRealWidth (250),
Gravity = Gravity.CenterVertical,
Tag = 0,
TextAlignment = TextAlignment.CenterLeft,
};
endTimeRowLayout.AddChidren (btnEndTime);
var btnendback = new Button {
Width = Application.GetRealWidth (87),
Height = Application.GetRealHeight (100),
UnSelectedImagePath = "MusicIcon/Next.png",
SelectedImagePath = "MusicIcon/NextSelecte.png",
X = Application.GetRealWidth (550),
};
endTimeRowLayout.AddChidren (btnendback);
///结束时间点击事件
EventHandler endclick = (sender, e) => {
endTimeRowLayout.BackgroundColor = 0xffFE5E00;
timerowlayout.BackgroundColor = 0x00000000;
var dialogTime = new DiaLogTime ();
dialogTime.Action = (time) => {
endTimeRowLayout.BackgroundColor = 0x00000000;
if (time < 0) {
return;
}
if (btnStartTime.Tag.ToString () != "0" && time < int.Parse (btnStartTime.Tag.ToString ())) {
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
Language.StringByID (MyInternationalizationString.timesetting),
Language.StringByID (MyInternationalizationString.OK));
alert.Show ();
} else {
string h = "";
string s = "";
if ((time / 60) < 10) {
h = "0" + time / 60;
} else {
h = (time / 60).ToString ();
}
if ((time % 60) < 10) {
s = "0" + time %60;
} else {
s = (time % 60).ToString ();
}
btnEndTime.Text = h + ":" + s; //time / 60 + ":" + time % 60;
btnEndTime.Tag = time;
if (string.IsNullOrEmpty (btnStartTime.Text)) {
btnStartTime.Text = h + ":" + s;//time / 60 + ":" + time % 60;
btnStartTime.Tag = time;
}
}
};
dialogTime.Show ();
};
endTimeRowLayout.MouseUpEventHandler += endclick;
btnEndTime.MouseUpEventHandler += endclick;
endtext.MouseUpEventHandler += endclick;
btnendback.MouseUpEventHandler += endclick;
}
public void Show (GateWay superGateWay)
{
this.AddChidren (new Button {
Height = Application.GetRealHeight (30),
BackgroundColor = 0xFF1F1F1F,
});
var topFrameLayout = new FrameLayout {
Height = Application.GetRealHeight (100),
Y = Application.GetRealHeight (30),
BackgroundColor = 0xFF1F1F1F,
};
AddChidren (topFrameLayout);
var titleName = new Button {
Text = Language.StringByID (MyInternationalizationString.timecondition),
TextSize = 17,
};
topFrameLayout.AddChidren (titleName);
var hdl = new Button {
Width = Application.GetRealWidth (154),
Height = Application.GetRealHeight (90),
X = Application.GetRealWidth (486),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "Logo/Logo.png",
};
topFrameLayout.AddChidren (hdl);
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 ();
IsDeviceEditor = false;
};
var titlerl = new RowLayout {
Y = topFrameLayout.Bottom,
Height = Application.GetRealHeight (110),
BackgroundColor = 0xff0f0f0f,
};
AddChidren (titlerl);
///时间条件
var btntitlerl = new Button {
//Text = "请根据你的需要设置日程",
TextSize = 17,
TextID = MyInternationalizationString.schedule,
X = Application.GetRealWidth (40),
Width = Application.GetRealWidth (500),
Gravity = Gravity.CenterVertical,
TextAlignment = TextAlignment.CenterLeft,
};
titlerl.AddChidren (btntitlerl);
var middle = new VerticalScrolViewLayout ();
middle.Y = titlerl.Bottom;
middle.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 80 - 110);
middle.BackgroundColor = 0xff2F2F2F;
this.AddChidren (middle);
timerowlayout = new RowLayout {
Height = Application.GetRealHeight (100),
};
if (str != "false"||str==null) {
middle.AddChidren (timerowlayout);
}
///时间
var btntime = new Button {
//Text = "时间",
TextAlignment = TextAlignment.CenterLeft,
Width = Application.GetRealWidth (150),
X = Application.GetRealWidth (40),
TextID = MyInternationalizationString.time
};
timerowlayout.AddChidren (btntime);
///显示时间段的控件
var Btntime = new Button {
X = Application.GetRealWidth (200),
Gravity = Gravity.CenterVertical,
Width = Application.GetRealWidth (300),
TextAlignment = TextAlignment.CenterLeft,
};
timerowlayout.AddChidren (Btntime);
var btntimeback = new Button {
Width = Application.GetRealWidth (87),
Height = Application.GetRealHeight (100),
UnSelectedImagePath = "MusicIcon/Next.png",
SelectedImagePath = "MusicIcon/NextSelecte.png",
X = Application.GetRealWidth (550),
};
timerowlayout.AddChidren (btntimeback);
var timeVerticalScrolViewLayout = new VerticalScrolViewLayout {
Height = 0,
BackgroundColor = 0xff121212,
};
middle.AddChidren (timeVerticalScrolViewLayout);
var sunriserowlayout = new RowLayout {
Height = Application.GetRealHeight (100),
};
if (str == "false" || str == null) {
middle.AddChidren (sunriserowlayout);
}
///日出/日落
var btnsunrise = new Button {
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth (40),
Width = Application.GetRealWidth (150),
Gravity = Gravity.CenterVertical,
TextID = MyInternationalizationString.Sunrisesunset,
};
sunriserowlayout.AddChidren (btnsunrise);
///显示选中(日出/日落)的控件
btnSun = new Button {
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth (200),
Width = Application.GetRealWidth (300),
Gravity = Gravity.CenterVertical,
Text = Language.StringByID (MyInternationalizationString.disable1),
};
sunriserowlayout.AddChidren (btnSun);
var btnSunriseback = new Button {
Width = Application.GetRealWidth (87),
Height = Application.GetRealHeight (100),
UnSelectedImagePath = "MusicIcon/Next.png",
SelectedImagePath = "MusicIcon/NextSelecte.png",
X = Application.GetRealWidth (550),
};
sunriserowlayout.AddChidren (btnSunriseback);
initTime (timeVerticalScrolViewLayout);
if (IsDeviceEditor) {
if (str != null && str != "false") {
string h1 = "";
string s1 = "";
string h2 = "";
string s2 = "";
string [] timestr = str.Split ('-');
string [] starttime = timestr [0].Split (':');
string [] endtime = timestr [1].Split (':');
if (starttime [0].Length < 2) {
h1 = "0" + starttime [0];
} else {
h1 = starttime [0];
}
if (starttime [1].Length < 2) {
s1 = "0" + starttime [1];
} else {
s1 = starttime [1];
}
if (endtime [0].Length < 2) {
h2 = "0" + endtime [0];
} else {
h2 = endtime [0];
}
if (endtime [1].Length < 2) {
s2 = "0" + endtime [1];
} else {
s2 = endtime [1];
}
btnStartTime.Text = h1 + ":" + s1;
btnEndTime.Text = h2 + ":" + s2;
Btntime.Text = btnStartTime.Text + "-" + btnEndTime.Text;
btnStartTime.Tag = int.Parse (starttime [0]) * 60 + int.Parse (starttime [1]);
btnEndTime.Tag = int.Parse (endtime [0]) * 60 + int.Parse (endtime [1]);
}
string strleng = "";
if (Logic.CurrentLogic.sunrise.type == 1) {
strleng = Language.StringByID (MyInternationalizationString.sunrise);
} else if (Logic.CurrentLogic.sunrise.type == 2) {
strleng = Language.StringByID (MyInternationalizationString.sunset);
} else if (Logic.CurrentLogic.sunrise.type == 3) {
strleng = Language.StringByID (MyInternationalizationString.beforesunrise1);
} else if (Logic.CurrentLogic.sunrise.type == 4) {
strleng = Language.StringByID (MyInternationalizationString.aftersunrise1);
} else if (Logic.CurrentLogic.sunrise.type == 5) {
strleng = Language.StringByID (MyInternationalizationString.beforesunset);
} else if (Logic.CurrentLogic.sunrise.type == 6) {
strleng = Language.StringByID (MyInternationalizationString.aftersunset);
}
if (Logic.CurrentLogic.sunrise.time != "") {
string [] min = Logic.CurrentLogic.sunrise.time.Split (':');
btnSun.Text = strleng + min[1].ToString()+Language.StringByID (MyInternationalizationString.minute1);
}else{
btnSun.Text = strleng;
}
}
///时间点击事件
EventHandler timesclick = (sender, e) => {
timerowlayout.BackgroundColor = 0xffFE5E00;
sunriserowlayout.BackgroundColor = 0x00000000;
btntime.IsSelected = !btntime.IsSelected;
if (btntime.IsSelected) {
timeVerticalScrolViewLayout.Height = Application.GetRealWidth (200);
} else {
timerowlayout.BackgroundColor = 0x00000000;//
timeVerticalScrolViewLayout.Height = 0;
}
};
timerowlayout.MouseUpEventHandler += timesclick;
btntime.MouseUpEventHandler += timesclick;
btntimeback.MouseUpEventHandler += timesclick;
Btntime.MouseUpEventHandler += timesclick;
///(日出/日落)点击事件
EventHandler sunclick = (sender, e) => {
//sunriserowlayout.BackgroundColor = 0xffFE5E00;
//timerowlayout.BackgroundColor = 0x00000000;
//PickerView.Show (new List {
// Language.StringByID (MyInternationalizationString.disable1),
// Language.StringByID (MyInternationalizationString.sunrise),
// Language.StringByID (MyInternationalizationString.sunset),
// Language.StringByID (MyInternationalizationString.beforesunrise1),
// Language.StringByID (MyInternationalizationString.aftersunrise1),
// Language.StringByID (MyInternationalizationString.beforesunset),
// Language.StringByID (MyInternationalizationString.aftersunset),
//}, (s) => {
// switch (s) {
// case "不启用":
// case "Disable":
// Logic.CurrentLogic.sunrise.type = 0;
// break;
// case "日出":
// case "Sunrise":
// Logic.CurrentLogic.sunrise.type = 1;
// break;
// case "日落":
// case "Sunset":
// Logic.CurrentLogic.sunrise.type = 2;
// break;
// case "日出前":
// case "Before sunrise":
// Logic.CurrentLogic.sunrise.type = 3;
// break;
// case "日出后":
// case "After sunrise":
// Logic.CurrentLogic.sunrise.type = 4;
// break;
// case "日落前":
// case "Before sunset":
// Logic.CurrentLogic.sunrise.type = 5;
// break;
// case "日落后":
// case "After sunset":
// Logic.CurrentLogic.sunrise.type = 6;
// break;
// }
// if (Logic.CurrentLogic.sunrise.type == 3 || Logic.CurrentLogic.sunrise.type == 4 || Logic.CurrentLogic.sunrise.type == 5|| Logic.CurrentLogic.sunrise.type == 6) {
// new System.Threading.Thread (() => {
// var list = new List ();
// for (int min = 1; min <= 60; min++) {
// list.Add (min.ToString () + " " + Language.StringByID (MyInternationalizationString.minute1));
// }
// System.Threading.Thread.Sleep (500);
// Application.RunOnMainThread (() => {
// PickerView.Show (list, (time) => {
// var min = time.Split (' ') [0];
// btnSun.Text = s + time;
// Logic.CurrentLogic.sunrise.time = "00:" + min + ":00";
// sunriserowlayout.BackgroundColor = 0x00000000;
// }, Language.StringByID (MyInternationalizationString.complete), "112");
// });
// }) { IsBackground = true }.Start ();
// }else{
// btnSun.Text = s;
// sunriserowlayout.BackgroundColor = 0x00000000;
// Logic.CurrentLogic.sunrise.time = "";
// }
//}, Language.StringByID (MyInternationalizationString.complete), Language.StringByID (MyInternationalizationString.sunrisebefore));
};
sunriserowlayout.MouseUpEventHandler += sunclick;
btnsunrise.MouseUpEventHandler += sunclick;
btnSun.MouseUpEventHandler += sunclick;
btnSunriseback.MouseUpEventHandler += sunclick;
///
var btnComplete = new Button {
Y = middle.Bottom,
Height = Application.GetRealHeight (80),
TextID = MyInternationalizationString.complete,
BackgroundColor = 0xff1F1F1F,
TextSize = 16,
};
AddChidren (btnComplete);
///完成点击事件
btnComplete.MouseUpEventHandler += (sender, e) => {
if (btnStartTime.Text == null && btnEndTime.Text == null && btnSun.Text == Language.StringByID (MyInternationalizationString.disable1)) {
var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
Language.StringByID (MyInternationalizationString.completeNext),
Language.StringByID (MyInternationalizationString.OK));
alert.Show ();
return;
} else if (btnStartTime.Text == null && btnEndTime.Text != null) {
btnStartTime.Text = btnEndTime.Text;
} else if (btnEndTime.Text == null && btnStartTime.Text != null) {
btnEndTime.Text = btnStartTime.Text;
}
//else {
// var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt),
// Language.StringByID (MyInternationalizationString.Support8),
// Language.StringByID (MyInternationalizationString.OK));
// alert.Show ();
// return;
//}
if (Logic.CurrentLogic.time.Count == 8) {
new Alert (Language.StringByID (MyInternationalizationString.Tip),Language.StringByID (MyInternationalizationString.Support8), Language.StringByID (MyInternationalizationString.Close)).Show ();
return;
}
if (IsDeviceEditor) {
for (int i = 0; i < Logic.CurrentLogic.time.Count; i++) {
if (Logic.CurrentLogic.time [i] == str) {
Logic.CurrentLogic.time.RemoveAt (i);
Logic.CurrentLogic.time.Insert (i, btnStartTime.Text+":00" + "-" + btnEndTime.Text+":00");
break;
}
}
} else {
if (btnStartTime.Text != null && btnEndTime.Text != null) {
Logic.CurrentLogic.time.Add (btnStartTime.Text + ":00" + "-" + btnEndTime.Text + ":00");
}
}
var logicCommunalPage = new LogicCommunalPage () { };
MainPage.MainFrameLayout.AddChidren (logicCommunalPage);
logicCommunalPage.Show (superGateWay, () => { });
};
}
class DiaLogTime : Dialog
{
public DiaLogTime ()
{
//点击到空白的地方后自动退出
flMain.MouseUpEventHandler += (sender, e) => {
flMain.RemoveFromParent ();
this.Close ();
if (Action != null) {
Action (-1);
}
};
}
///
/// 背景控件
///
FrameLayout flMain = new FrameLayout { BackgroundColor = 0x00000000 };
///
/// 取消或者确定的结果
///
public Action Action;
public void Show ()
{
base.Show ();
base.AddChidren (flMain);
var timeViewStart = new TimeView {
Y = Application.GetRealHeight (Application.DesignHeight - 320),
Height = Application.GetRealHeight (320),
BackgroundColor = 0xFFFFFFFF
};
flMain.AddChidren (timeViewStart);
var btnSave = new Button {
Y = Application.GetRealHeight (Application.DesignHeight - 320),
Width = Application.GetRealWidth (100),
Height = Application.GetRealHeight (100),
Text = Language.StringByID (MyInternationalizationString.complete),
TextColor = 0xFF121212,
//TextAlignment = TextAlignment.CenterRight
X = Application.GetRealWidth (640 - 100),
};
flMain.AddChidren (btnSave);
btnSave.MouseUpEventHandler += (sender2, e2) => {
Action (timeViewStart.Hour * 60 + timeViewStart.Minute);
this.Close ();
///
flMain.RemoveFromParent ();
};
}
}
}
}