wxr
2020-04-21 f718d23a262a5a8e1241fdeaeb4153399f95e79d
HDL_ON/UI/UI0-Public/PublicAssmebly.cs
@@ -1,83 +1,461 @@
using System;
using System.Threading;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON.UI
{
    public class PublicAssmebly
    public partial class PublicAssmebly
    {
        public void LoadTopView(FrameLayout frame, string tilte)
        /// <summary>
        /// 加载修改参数的小弹窗
        /// 保存按钮事件需要将
        /// </summary>
        /// <param name="callBackAction">回调函数</param>
        public void LoadDialog_EditParater(int titleId, string editParater, Action<string> callBackAction)
        {
            FrameLayout view = new FrameLayout()
            Dialog dialog = new Dialog()
            {
                Height = Application.GetRealHeight(64),
                BackgroundColor = CSS_Color.TopViewColor,
            };
            frame.AddChidren(view);
            Button btnBack = new Button()
            {
                X = Application.GetRealWidth(10),
                Y = Application.GetRealHeight(30),
                Width = Application.GetRealWidth(24),
                Height = Application.GetRealHeight(24),
                UnSelectedImagePath = "Public/BackIcon.png",
            };
            frame.AddChidren(btnBack);
            btnBack.MouseUpEventHandler += (sender, e) =>
            {
                frame.RemoveFromParent();
                BackgroundColor = CSS_Color.DialogTransparentColor1,
            };
            Button btnTilte = new Button()
            FrameLayout contentView = new FrameLayout()
            {
                X = Application.GetRealWidth(10),
                Y = Application.GetRealHeight(30),
                Width = Application.GetRealWidth(150),
                Height = Application.GetRealHeight(34),
                Gravity = Gravity.Center,
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(172),
                BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(10),
            };
            dialog.AddChidren(contentView);
            Button btnTitle = new Button()
            {
                Y = Application.GetRealHeight(10),
                Height = Application.GetRealHeight(42),
                TextColor = CSS.CSS_Color.MainColor,
                TextSize = CSS.CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.HeadlineFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Text = tilte
                IsBold = true,
                TextID = titleId,
            };
            frame.AddChidren(btnTilte);
        }
            contentView.AddChidren(btnTitle);
        public void LoadTopView(Dialog dialog, FrameLayout frame, string tilte)
        {
            FrameLayout view = new FrameLayout()
            FrameLayout editView = new FrameLayout()
            {
                Height = Application.GetRealHeight(64),
                BackgroundColor = CSS_Color.TopViewColor,
                Gravity = Gravity.CenterHorizontal,
                Y = btnTitle.Bottom + Application.GetRealHeight(6),
                Width = Application.GetRealWidth(222),
                Height = Application.GetRealHeight(40),
                BackgroundColor = CSS.CSS_Color.BackgroundColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(4),
            };
            frame.AddChidren(view);
            contentView.AddChidren(editView);
            Button btnBack = new Button()
            EditText etParater = new EditText()
            {
                X = Application.GetRealWidth(10),
                Y = Application.GetRealHeight(29),
                Width = Application.GetRealWidth(40),
                Height = Application.GetRealHeight(25),//24
                UnSelectedImagePath = "Public/BackIcon.png",
                X = Application.GetRealWidth(12),
                Width = Application.GetRealWidth(182),
                Text = editParater,
                TextColor = CSS.CSS_Color.FirstLevelTitleColor,
                TextSize = CSS.CSS_FontSize.TextFontSize,
            };
            frame.AddChidren(btnBack);
            btnBack.MouseUpEventHandler += (sender, e) =>
            editView.AddChidren(etParater);
            Button btnLine = new Button()
            {
                Y = Application.GetRealHeight(128),
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS.CSS_Color.DividingLineColor,
            };
            contentView.AddChidren(btnLine);
            Button btnCancel = new Button()
            {
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(134),
                Height = Application.GetRealHeight(43),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Cancel,
            };
            contentView.AddChidren(btnCancel);
            Button btnBottomLine = new Button()
            {
                X = btnCancel.Right,
                Y = btnLine.Bottom,
                Height = Application.GetRealHeight(43),
                Width = Application.GetRealWidth(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            contentView.AddChidren(btnBottomLine);
            Button btnConfirm = new Button()
            {
                X = btnBottomLine.Right,
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(43),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS.CSS_Color.TextualColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Confirm,
            };
            contentView.AddChidren(btnConfirm);
            dialog.Show();
            btnCancel.MouseDownEventHandler += (sender, e) => {
                btnCancel.IsSelected = true;
            };
            btnCancel.MouseUpEventHandler += (sender, e) => {
                btnCancel.IsSelected = false;
                dialog.Close();
            };
            btnConfirm.MouseDownEventHandler += (sender, e) => {
                btnConfirm.IsSelected = true;
            };
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                btnConfirm.IsSelected = false;
                //需要提示错误信息在窗口弹窗之上的
                if ((titleId == StringId.EditFloorName && etParater.Text.Trim() != editParater) || titleId == StringId.AddFloors)
                {
                    var tipMsgString = titleId == StringId.EditFloorName ? Language.StringByID(StringId.AddFloorFailed_FloorAlreadyExist) : Language.StringByID(StringId.AddFloorFailed_FloorAlreadyExist);
                    if (string.IsNullOrEmpty(etParater.Text.Trim()))
                    {
                        tipMsgString = Language.StringByID(StringId.FloorNameCannotBeEmpty);
                        return;
                    }
                    if (DB_ResidenceData.residenceData.floors.Contains(etParater.Text.Trim()))
                    {
                        contentView.Height = Application.GetRealHeight(183);
                        btnLine.Y = Application.GetRealHeight(139);
                        btnBottomLine.Y = btnLine.Bottom;
                        btnCancel.Y = btnLine.Bottom;
                        btnConfirm.Y = btnLine.Bottom;
                        var btnTip = new Button()
                        {
                            X = editView.X,
                            Y = editView.Bottom,
                            Width = Application.GetRealWidth(182),
                            Height = Application.GetRealHeight(30),
                            Text = tipMsgString,
                            TextColor = CSS_Color.WarningColor,
                            TextSize = CSS_FontSize.TextFontSize,
                        };
                        contentView.AddChidren(btnTip);
                        return;
                    }
                    callBackAction(etParater.Text.Trim());
                }
                if(titleId == StringId.RoomName || titleId == StringId.ChangeName || titleId == StringId.ResidenceName  || titleId == StringId.UesrName)
                {
                    if(editParater != etParater.Text.Trim())
                    {
                        callBackAction(etParater.Text.Trim());
                    }
                }
                dialog.Close();
            };
            Button btnTilte = new Button()
        }
        /// <summary>
        /// 加载提示弹窗
        /// </summary>
        /// <param name="titleId"></param>
        /// <param name="msgId"></param>
        /// <param name="callBackAction"></param>
        public void TipMsg(int titleId, int msgId, Action callBackAction)
        {
            Dialog dialog = new Dialog()
            {
                BackgroundColor = CSS_Color.DialogTransparentColor1,
            };
            FrameLayout contentView = new FrameLayout()
            {
                Gravity = Gravity.Center,
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(140),
                BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(10),
            };
            dialog.AddChidren(contentView);
            Button btnTitle = new Button()
            {
                Y = Application.GetRealHeight(16),
                Height = Application.GetRealHeight(30),
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = titleId,
            };
            contentView.AddChidren(btnTitle);
            Button btnMsg = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(30),
                Width = Application.GetRealWidth(150),
                Height = Application.GetRealHeight(25),
                Y = btnTitle.Bottom,
                Width = Application.GetRealHeight(200),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.HeadlineFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Text = tilte
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = msgId,
            };
            frame.AddChidren(btnTilte);
            contentView.AddChidren(btnMsg);
            Button btnLine = new Button()
            {
                Y = Application.GetRealHeight(96),
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS.CSS_Color.DividingLineColor,
            };
            contentView.AddChidren(btnLine);
            Button btnCancel = new Button()
            {
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(134),
                Height = Application.GetRealHeight(43),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Cancel,
            };
            contentView.AddChidren(btnCancel);
            Button btnBottomLine = new Button()
            {
                X = btnCancel.Right,
                Y = btnLine.Bottom,
                Height = Application.GetRealHeight(43),
                Width = Application.GetRealWidth(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            contentView.AddChidren(btnBottomLine);
            Button btnConfirm = new Button()
            {
                X = btnBottomLine.Right,
                Y = btnLine.Bottom,
                Width = Application.GetRealWidth(135),
                Height = Application.GetRealHeight(43),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Confirm,
            };
            contentView.AddChidren(btnConfirm);
            dialog.Show();
            btnCancel.MouseDownEventHandler += (sender, e) =>
            {
                btnCancel.IsSelected = true;
            };
            btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                btnCancel.IsSelected = false;
                dialog.Close();
            };
            btnConfirm.MouseDownEventHandler += (sender, e) =>
            {
                btnConfirm.IsSelected = true;
            };
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                btnConfirm.IsSelected = false;
                callBackAction();
                dialog.Close();
            };
        }
        /// <summary>
        /// 信息提示窗口,自动关闭
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isWhite"></param>
        public void TipMsgAutoClose(string msg,bool isWhite)
        {
            Dialog dialog = new Dialog()
            {
                X = Application.GetRealWidth(89),
                Y = Application.GetRealHeight(285),
                Width = Application.GetRealWidth(198),
                Height = Application.GetRealHeight(98),
            };
            FrameLayout frame = new FrameLayout()
            {
                BackgroundColor = isWhite ? 0xE6FFFFFF : CSS_Color.DialogTransparentColor1,
                Radius = (uint)Application.GetRealWidth(12),
            };
            dialog.AddChidren(frame);
            Button btnTipIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(15),
                Width = Application.GetRealWidth(32),
                Height = Application.GetRealWidth(32),
                UnSelectedImagePath = isWhite ? "Public/MsgIcon/TipIconBlack.png" : "Public/MsgIcon/TipIconWhite.png",
            };
            frame.AddChidren(btnTipIcon);
            Button btnTipMsg = new Button()
            {
                Y = Application.GetRealHeight(47),
                Height = Application.GetRealHeight(50),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = isWhite ? CSS_Color.FirstLevelTitleColor : CSS_Color.MainBackgroundColor,
                Text = msg,
            };
            frame.AddChidren(btnTipMsg);
            dialog.Show();
            new Thread(() => {
                Thread.Sleep(1500);
                Application.RunOnMainThread(() =>
                {
                    dialog.Close();
                });
            }) { IsBackground = true }.Start();
        }
        /// <summary>
        /// 加载提示弹窗
        /// </summary>
        /// <param name="titleId"></param>
        /// <param name="msgId"></param>
        public void TipMsg(int titleId, int msgId)
        {
            Dialog dialog = new Dialog()
            {
                BackgroundColor = CSS_Color.DialogTransparentColor1,
            };
            FrameLayout contentView = new FrameLayout()
            {
                Gravity = Gravity.Center,
                Width = Application.GetRealWidth(270),
                Height = Application.GetRealHeight(140),
                BackgroundColor = CSS.CSS_Color.MainBackgroundColor,
                BorderColor = 0x00000000,
                BorderWidth = 0,
                Radius = (uint)Application.GetMinRealAverage(10),
            };
            dialog.AddChidren(contentView);
            Button btnTitle = new Button()
            {
                Y = Application.GetRealHeight(16),
                Height = Application.GetRealHeight(30),
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = titleId,
            };
            contentView.AddChidren(btnTitle);
            Button btnMsg = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Height = Application.GetRealHeight(25),
                Y = btnTitle.Bottom,
                Width = Application.GetRealHeight(200),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = msgId,
            };
            contentView.AddChidren(btnMsg);
            Button btnLine = new Button()
            {
                Y = Application.GetRealHeight(96),
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS.CSS_Color.DividingLineColor,
            };
            contentView.AddChidren(btnLine);
            Button btnConfirm = new Button()
            {
                Y = btnLine.Bottom,
                Height = Application.GetRealHeight(43),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.TextualColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                SelectedTextColor = CSS_Color.MainBackgroundColor,
                SelectedBackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Confirm,
            };
            contentView.AddChidren(btnConfirm);
            dialog.Show();
            btnConfirm.MouseDownEventHandler += (sender, e) =>
            {
                btnConfirm.IsSelected = true;
            };
            btnConfirm.MouseUpEventHandler += (sender, e) =>
            {
                btnConfirm.IsSelected = false;
                dialog.Close();
            };
        }
        /// <summary>
        /// 加载等待界面
        /// </summary>
        public void LoadPage_WaitPage(Thread thread, FrameLayout bodyView, Loading waitPage)
        {
            bodyView.AddChidren(waitPage);
            waitPage.Start(Language.StringByID(StringId.PleaseWait));
            var showedTime = DateTime.Now;
            //如果等待事件过长,可以允许用户取消当前操作
            waitPage.MouseUpEventHandler += (sender, e) =>
            {
                if (showedTime.AddSeconds(30) > DateTime.Now)
                {
                    thread.Abort();
                    waitPage.RemoveFromParent();
                }
            };
            thread.Start();
        }