using Shared;
|
using HDL_ON.UI.CSS;
|
using System;
|
using System.Text;
|
|
namespace HDL_ON.Stan
|
{
|
/// <summary>
|
/// 显示一个信息框(请使用HdlMessageLogic调用)
|
/// </summary>
|
public class ShowMsgControl
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 点击确认的事件
|
/// </summary>
|
public Action ConfirmClickEvent = null;
|
/// <summary>
|
/// 点击取消的事件
|
/// </summary>
|
public Action CancelClickEvent = null;
|
/// <summary>
|
/// 信息类型
|
/// </summary>
|
private ShowMsgType msgType = ShowMsgType.Confirm;
|
/// <summary>
|
/// 消息
|
/// </summary>
|
private string msgText = string.Empty;
|
/// <summary>
|
/// 确认按钮的文本
|
/// </summary>
|
private string buttonOkText = null;
|
/// <summary>
|
/// 取消按钮的文本
|
/// </summary>
|
private string buttonCancelText = null;
|
/// <summary>
|
/// 提示控件
|
/// </summary>
|
private Tip myTip = null;
|
/// <summary>
|
/// 等待时间
|
/// </summary>
|
private int WaitTime = -1;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 显示一个需要确认的信息框
|
/// </summary>
|
/// <param name="i_msgType">信息类型</param>
|
/// <param name="i_msg">信息</param>
|
/// <param name="i_buttonOkText">确认按钮的文本</param>
|
/// <param name="i_buttonCancelText">取消按钮的文本</param>
|
/// <param name="i_waitTime">等待时间,单位为秒,设置确认按钮在多长时间后才能够点击</param>
|
public ShowMsgControl(ShowMsgType i_msgType, string i_msg, string i_buttonOkText = null, string i_buttonCancelText = null, int i_waitTime = -1)
|
{
|
//确认按钮文本
|
this.buttonOkText = i_buttonOkText == null ? Language.StringByID(StringId.Confirm) : i_buttonOkText;
|
this.buttonCancelText = i_buttonCancelText == null ? Language.StringByID(StringId.Cancel) : i_buttonCancelText;
|
this.msgType = i_msgType;
|
this.msgText = i_msg;
|
this.WaitTime = i_waitTime;
|
|
if (i_msgType == ShowMsgType.Tip)
|
{
|
myTip = new Tip();
|
myTip.Direction = AMPopTipDirection.None;
|
myTip.CloseTime = 2;
|
myTip.Text = i_msg;
|
}
|
}
|
|
#endregion
|
|
#region ■ 显示消息___________________________
|
|
/// <summary>
|
/// 显示
|
/// </summary>
|
public void Show()
|
{
|
try
|
{
|
if (myTip != null)
|
{
|
myTip.Show(MainPage.BasePageView);
|
myTip = null;
|
return;
|
}
|
//初始化控件
|
this.InitMsgControl();
|
}
|
catch { }
|
}
|
|
#endregion
|
|
#region ■ 初始化控件_________________________
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
private void InitMsgControl()
|
{
|
var dialogForm = new Dialog();
|
dialogForm.BackgroundColor = CSS_Color.DialogTransparentColor1;
|
//主控件
|
var frameMain = new NormalFrameLayout();
|
dialogForm.AddChidren(frameMain);
|
dialogForm.Show();
|
|
//计算用
|
var btnTemp = new ButtonCtrBase();
|
btnTemp.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
btnTemp.Text = msgText.Replace("\r\n", string.Empty);
|
//获取这个显示的内容的高度
|
int rowCount = btnTemp.GetRealRowCountByText();
|
int contentHeight = rowCount * Application.GetRealHeight(18);
|
if (rowCount <= 2)
|
{
|
//它有一个最小高度
|
contentHeight = Application.GetRealHeight(51);
|
}
|
|
//这个区域的高度比例为:显示内容到上部的距离(50)+显示内容的高度+显示内容到底部的距离(70)
|
|
//中间区域
|
var frameCenter = new NormalFrameLayout();
|
frameCenter.Gravity = Gravity.Center;
|
frameCenter.Width = Application.GetRealWidth(270);
|
frameCenter.Height = Application.GetRealHeight(50) + contentHeight + Application.GetRealHeight(70);
|
frameCenter.BackgroundColor = CSS_Color.MainBackgroundColor;
|
frameCenter.BorderColor = 0x00000000;
|
frameCenter.BorderWidth = 0;
|
frameCenter.Radius = (uint)Application.GetMinRealAverage(10);
|
frameMain.AddChidren(frameCenter);
|
|
//标题
|
var btnTitle = new NormalViewControl(frameCenter.Width, Application.GetRealHeight(22), false);
|
btnTitle.Y = Application.GetRealHeight(20);
|
btnTitle.TextColor = CSS_Color.MainColor;
|
btnTitle.TextSize = CSS_FontSize.SubheadingFontSize;
|
btnTitle.TextAlignment = TextAlignment.Center;
|
btnTitle.IsBold = true;
|
btnTitle.Text = Language.StringByID(StringId.Tip);
|
frameCenter.AddChidren(btnTitle);
|
//提示内容按钮
|
var btnMsg = new NormalViewControl(Application.GetRealWidth(258), contentHeight, false);
|
btnMsg.Y = btnTitle.Bottom + Application.GetRealHeight(8);
|
btnMsg.Gravity = Gravity.CenterHorizontal;
|
btnMsg.TextAlignment = TextAlignment.Center;
|
btnMsg.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
btnMsg.Text = msgText;
|
btnMsg.IsMoreLines = true;
|
frameCenter.AddChidren(btnMsg);
|
|
if (msgType == ShowMsgType.Confirm)
|
{
|
//初始化确认类型的底部按钮
|
this.InitBottomConfirmButton(dialogForm, frameCenter);
|
}
|
else
|
{
|
//初始化普通类型的底部按钮
|
this.InitBottomNormalButton(dialogForm, frameCenter);
|
}
|
}
|
|
/// <summary>
|
/// 初始化确认类型的底部按钮
|
/// </summary>
|
/// <param name="frameCenter"></param>
|
private void InitBottomConfirmButton(Dialog dialogForm, NormalFrameLayout frameCenter)
|
{
|
//取消
|
var btnCancel = new NormalViewControl(frameCenter.Width / 2, Application.GetRealHeight(43), false);
|
btnCancel.Gravity = Gravity.BottomLeft;
|
btnCancel.TextAlignment = TextAlignment.Center;
|
btnCancel.TextSize = CSS_FontSize.SubheadingFontSize;
|
btnCancel.Text = this.buttonCancelText;
|
//btnCancel.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomLeft);
|
frameCenter.AddChidren(btnCancel);
|
btnCancel.ButtonClickEvent += (sender, e) =>
|
{
|
//关闭界面
|
dialogForm.Close();
|
//回调函数
|
this.CancelClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
this.CancelClickEvent = null;
|
};
|
//线
|
var btnLine = new NormalViewControl(frameCenter.Width / 2, HdlControlResourse.BottomLineHeight, false);
|
btnLine.Y = btnCancel.Y - HdlControlResourse.BottomLineHeight;
|
btnLine.BackgroundColor = CSS_Color.DividingLineColor;
|
frameCenter.AddChidren(btnLine);
|
|
//确认
|
var btnConfirm = new NormalViewControl(frameCenter.Width - btnCancel.Width, Application.GetRealHeight(45), false);
|
btnConfirm.X = btnCancel.Right;
|
btnConfirm.Y = btnLine.Y;
|
btnConfirm.TextAlignment = TextAlignment.Center;
|
btnConfirm.TextSize = CSS_FontSize.SubheadingFontSize;
|
btnConfirm.TextColor = CSS_Color.MainBackgroundColor;
|
btnConfirm.BackgroundColor = CSS_Color.MainColor;
|
btnConfirm.Text = this.buttonOkText;
|
frameCenter.AddChidren(btnConfirm);
|
btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomRight);
|
btnConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//关闭界面
|
dialogForm.Close();
|
//回调函数
|
this.ConfirmClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
this.CancelClickEvent = null;
|
};
|
|
//开启等待时间
|
this.StartWaitTime(btnConfirm);
|
}
|
|
/// <summary>
|
/// 初始化普通类型的底部按钮
|
/// </summary>
|
/// <param name="dialogForm"></param>
|
/// <param name="frameCenter"></param>
|
private void InitBottomNormalButton(Dialog dialogForm, NormalFrameLayout frameCenter)
|
{
|
//确认
|
var btnConfirm = new NormalViewControl(frameCenter.Width, Application.GetRealHeight(45), false);
|
btnConfirm.Gravity = Gravity.BottomCenter;
|
btnConfirm.TextAlignment = TextAlignment.Center;
|
btnConfirm.TextSize = CSS_FontSize.SubheadingFontSize;
|
btnConfirm.TextColor = CSS_Color.MainBackgroundColor;
|
btnConfirm.BackgroundColor = CSS_Color.MainColor;
|
btnConfirm.Text = this.buttonOkText;
|
frameCenter.AddChidren(btnConfirm);
|
btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
|
btnConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//关闭界面
|
dialogForm.Close();
|
//回调函数
|
this.ConfirmClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
this.CancelClickEvent = null;
|
};
|
|
//开启等待时间
|
this.StartWaitTime(btnConfirm);
|
}
|
|
#endregion
|
|
#region ■ 开启等待时间_______________________
|
|
/// <summary>
|
/// 开启等待时间(此函数只用于安卓)
|
/// </summary>
|
/// <param name="btnConfirm">确认按钮</param>
|
private void StartWaitTime(NormalViewControl btnConfirm)
|
{
|
if (this.WaitTime <= 0)
|
{
|
return;
|
}
|
|
btnConfirm.CanClick = false;
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//显示剩余等待时间
|
while (btnConfirm.Parent != null && this.WaitTime >= 0)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
btnConfirm.Text = this.buttonOkText + "(" + this.WaitTime + ")";
|
|
}, ShowErrorMode.NO);
|
System.Threading.Thread.Sleep(1000);
|
this.WaitTime--;
|
}
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//可以点击
|
btnConfirm.Text = this.buttonOkText;
|
btnConfirm.CanClick = true;
|
|
}, ShowErrorMode.NO);
|
});
|
}
|
|
/// <summary>
|
/// 开启等待时间
|
/// </summary>
|
/// <param name="btnConfirm">确认按钮</param>
|
private void StartWaitTime(ButtonCtrBase btnConfirm)
|
{
|
if (this.WaitTime <= 0)
|
{
|
return;
|
}
|
//不能点击
|
btnConfirm.CanClick = false;
|
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
//显示剩余等待时间
|
while (btnConfirm.Parent != null && this.WaitTime >= 0)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
btnConfirm.Text = this.buttonOkText + "(" + this.WaitTime + ")";
|
}, ShowErrorMode.NO);
|
System.Threading.Thread.Sleep(1000);
|
this.WaitTime--;
|
}
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//可以点击
|
btnConfirm.Text = this.buttonOkText;
|
btnConfirm.CanClick = true;
|
|
}, ShowErrorMode.NO);
|
});
|
}
|
|
#endregion
|
}
|
}
|