using System;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 显示一个信息框
|
/// </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;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 显示一个需要确认的信息框
|
/// </summary>
|
/// <param name="i_msgType">信息类型</param>
|
/// <param name="i_msg">信息</param>
|
/// <param name="i_buttonOkText">确认按钮的文本</param>
|
/// <param name="i_buttonCancelText">取消按钮的文本</param>
|
public ShowMsgControl(ShowMsgType i_msgType, string i_msg, string i_buttonOkText = null, string i_buttonCancelText = null)
|
{
|
//确认按钮文本
|
this.buttonOkText = i_buttonOkText == null ? Language.StringByID(R.MyInternationalizationString.OkMsg) : i_buttonOkText;
|
this.buttonCancelText = i_buttonCancelText == null ? Language.StringByID(R.MyInternationalizationString.uCancel) : i_buttonCancelText;
|
this.msgType = i_msgType;
|
this.msgText = i_msg;
|
|
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(Common.CommonPage.Instance);
|
myTip = null;
|
return;
|
}
|
//初始化控件
|
this.InitMsgControl();
|
}
|
catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
|
}
|
|
#endregion
|
|
#region ■ 初始化控件_________________________
|
|
/// <summary>
|
/// 初始化控件
|
/// </summary>
|
private void InitMsgControl()
|
{
|
//主控件
|
var frameMain = new FrameLayout();
|
frameMain.BackgroundColor = UserCenterColor.Current.DialogBackColor;
|
Common.CommonPage.Instance.AddChidren(frameMain);
|
frameMain.MouseUpEventHandler += (sender, e) =>
|
{
|
//移除界面
|
frameMain.RemoveFromParent();
|
this.ConfirmClickEvent = null;
|
};
|
|
//白色背景框
|
var frameBack = new FrameLayout();
|
frameBack.Height = Application.GetRealHeight(478);
|
frameBack.Width = Application.GetRealWidth(792);
|
frameBack.BackgroundColor = UserCenterColor.Current.White;
|
frameBack.Y = Application.GetRealHeight(706);
|
frameBack.Gravity = Gravity.CenterHorizontal;
|
frameBack.Radius = (uint)Application.GetRealHeight(17);
|
frameMain.AddChidren(frameBack);
|
//标题
|
var btnTitle = new NormalViewControl(frameBack.Width, Application.GetRealHeight(65), false);
|
btnTitle.Y = Application.GetRealHeight(68);
|
btnTitle.TextColor = 0xff333443;
|
btnTitle.TextAlignment = TextAlignment.Center;
|
btnTitle.TextSize = 16;
|
frameBack.AddChidren(btnTitle);
|
if (msgType == ShowMsgType.Normal)
|
{
|
btnTitle.TextID = R.MyInternationalizationString.NormalTip;
|
}
|
else if (msgType == ShowMsgType.Error)
|
{
|
btnTitle.TextID = R.MyInternationalizationString.ErrorTip;
|
}
|
else if (msgType == ShowMsgType.Confirm)
|
{
|
btnTitle.TextID = R.MyInternationalizationString.NormalTip;
|
}
|
else if (msgType == ShowMsgType.Remind)
|
{
|
btnTitle.TextID = R.MyInternationalizationString.uRemind;
|
}
|
|
//消息
|
var btnMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(180), false);
|
btnMsg.Y = Application.GetRealHeight(141);
|
btnMsg.IsMoreLines = true;
|
btnMsg.TextAlignment = TextAlignment.Center;
|
btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
|
btnMsg.Gravity = Gravity.CenterHorizontal;
|
btnMsg.Text = msgText;
|
frameBack.AddChidren(btnMsg);
|
|
if (msgType == ShowMsgType.Confirm)
|
{
|
//初始化确认类型的底部按钮
|
this.InitBottomConfirmButton(frameMain, frameBack);
|
}
|
else
|
{
|
//初始化普通类型的底部按钮
|
this.InitBottomNormalButton(frameMain, frameBack);
|
}
|
}
|
|
/// <summary>
|
/// 初始化确认类型的底部按钮
|
/// </summary>
|
/// <param name="frameMain"></param>
|
/// <param name="frameBack"></param>
|
private void InitBottomConfirmButton(FrameLayout frameMain, FrameLayout frameBack)
|
{
|
//取消按钮
|
var btnCancel = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127));
|
frameBack.AddChidren(btnCancel);
|
btnCancel.InitControl(this.buttonCancelText);
|
btnCancel.ButtonClickEvent += (sender, e) =>
|
{
|
//移除界面
|
frameMain.RemoveFromParent();
|
//回调函数
|
this.CancelClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
this.CancelClickEvent = null;
|
};
|
|
//确定按钮
|
var btnConfirm = new BottomRightClickButton(frameBack.Width - btnCancel.Width, btnCancel.Height);
|
frameBack.AddChidren(btnConfirm);
|
btnConfirm.InitControl(this.buttonOkText);
|
btnConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//移除界面
|
frameMain.RemoveFromParent();
|
//回调函数
|
this.ConfirmClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
this.CancelClickEvent = null;
|
};
|
}
|
|
/// <summary>
|
/// 初始化普通类型的底部按钮
|
/// </summary>
|
/// <param name="frameMain"></param>
|
/// <param name="frameBack"></param>
|
private void InitBottomNormalButton(FrameLayout frameMain, FrameLayout frameBack)
|
{
|
#if Android
|
//确认
|
var frameConfirm = new FrameLayoutStatuControl();
|
frameConfirm.Height = Application.GetRealHeight(127);
|
frameConfirm.Width = frameBack.Width;
|
frameConfirm.Gravity = Gravity.BottomCenter;
|
frameConfirm.RadiusEx = 17;
|
frameConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
frameBack.AddChidren(frameConfirm);
|
//把上圆角覆盖为方角
|
var btnTopTemp2 = new NormalViewControl(frameConfirm.Width, Application.GetRealHeight(35), false);
|
btnTopTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
frameConfirm.AddChidren(btnTopTemp2, ChidrenBindMode.BindEvent);
|
//确认按钮
|
var btnConfirm = new NormalViewControl(frameConfirm.Width - Application.GetRealWidth(10), Application.GetRealHeight(60), false);
|
btnConfirm.Gravity = Gravity.Center;
|
btnConfirm.TextColor = UserCenterColor.Current.White;
|
btnConfirm.Text = buttonOkText;
|
btnConfirm.TextAlignment = TextAlignment.Center;
|
frameConfirm.AddChidren(btnConfirm, ChidrenBindMode.BindEvent);
|
frameConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//移除界面
|
frameMain.RemoveFromParent();
|
//回调函数
|
this.ConfirmClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
};
|
//重写控件点击状态
|
frameConfirm.SelectStatuEvent += (statu) =>
|
{
|
if (statu == true)
|
{
|
frameConfirm.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
|
btnTopTemp2.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
|
btnConfirm.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
|
}
|
else
|
{
|
frameConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
btnTopTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
btnConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
}
|
};
|
#endif
|
#if iOS
|
//确认按钮
|
var btnConfirm = new NormalClickButton(frameBack.Width, Application.GetRealHeight(127), false);
|
btnConfirm.Gravity = Gravity.BottomCenter;
|
btnConfirm.TextColor = UserCenterColor.Current.White;
|
btnConfirm.Text = buttonOkText;
|
btnConfirm.TextAlignment = TextAlignment.Center;
|
btnConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
btnConfirm.oldBackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
|
frameBack.AddChidren(btnConfirm);
|
btnConfirm.ButtonClickEvent += (sender, e) =>
|
{
|
//移除界面
|
frameMain.RemoveFromParent();
|
//回调函数
|
this.ConfirmClickEvent?.Invoke();
|
this.ConfirmClickEvent = null;
|
};
|
#endif
|
}
|
|
#endregion
|
}
|
}
|