using System;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// Button的共通,共有的方法写在里面,
|
/// 初始值:标准字体和颜色,文字向左靠齐
|
/// </summary>
|
public class ButtonCommon : Button
|
{
|
/// <summary>
|
/// 单击弹起事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
public delegate void _MouseUpEvent(object sender, MouseEventArgs e);
|
/// <summary>
|
/// 单击弹起事件(这事件封装有可单击的时间间隔的功能:5秒)
|
/// </summary>
|
public _MouseUpEvent MouseUpEvent;
|
/// <summary>
|
/// 能否触发单击弹起事件
|
/// </summary>
|
public bool isCanClickUp = true;
|
/// <summary>
|
/// 显示可执行单击弹起的倒计时
|
/// </summary>
|
public bool IsShowMouseUpTime = false;
|
/// <summary>
|
/// 弹起间隔2秒(设置为0时,无间隔)
|
/// </summary>
|
public int MouseUpTime = 2;
|
/// <summary>
|
/// 向上的偏差值
|
/// </summary>
|
public int DeviationValue = Application.GetRealHeight(10);
|
/// <summary>
|
/// 初始化(初始值:标准字体颜色,文字向左靠齐)
|
/// </summary>
|
public ButtonCommon()
|
{
|
this.TextColor = UserCenterColor.Current.TextColor;
|
this.TextAlignment = TextAlignment.CenterLeft;
|
|
//测试,全体字体为14号字
|
this.TextSize = 14;
|
|
this.MouseUpEventHandler += this.Button_MouseUpEvent;
|
}
|
|
/// <summary>
|
/// 初始化控件大小(不以平均值进行真实数值计算)
|
/// </summary>
|
/// <param name="i_Width">宽度</param>
|
/// <param name="i_Height">高度</param>
|
/// <param name="real">是否计算真实值</param>
|
public void InitSize(int i_Width, int i_Height, bool real = true)
|
{
|
if (real == true)
|
{
|
i_Width = Application.GetRealWidth(i_Width);
|
i_Height = Application.GetRealHeight(i_Height);
|
}
|
|
this.Height = i_Height;
|
this.Width = i_Width;
|
}
|
|
/// <summary>
|
/// 初始化控件大小(不以平均值进行真实数值计算)
|
/// </summary>
|
/// <param name="i_Width">宽度</param>
|
/// <param name="real">是否计算真实值</param>
|
public void InitSize(int i_Width, bool real = false)
|
{
|
if (real == true)
|
{
|
i_Width = Application.GetRealWidth(i_Width);
|
}
|
|
this.Height = ControlCommonResourse.NormalControlHeight;
|
this.Width = i_Width;
|
}
|
|
/// <summary>
|
/// 初始化控件大小
|
/// </summary>
|
public void InitSize()
|
{
|
this.Height = ControlCommonResourse.NormalControlHeight;
|
this.Width = Application.CurrentWidth - ControlCommonResourse.XXLeft;
|
}
|
|
/// <summary>
|
/// 初始化控件大小(以平均值进行真实数值计算)
|
/// </summary>
|
/// <param name="i_Width">宽度</param>
|
/// <param name="i_Height">高度</param>
|
/// <param name="real">是否计算真实值</param>
|
public void InitAvgSize(int i_Width, int i_Height, bool real = true)
|
{
|
if (real == true)
|
{
|
i_Width = Application.GetMinRealAverage(i_Width);
|
i_Height = Application.GetMinRealAverage(i_Height);
|
}
|
|
this.Height = i_Height;
|
this.Width = i_Width;
|
}
|
|
/// <summary>
|
/// Y轴重置(真实数值,没有父容器无效)
|
/// </summary>
|
/// <param name="alignment">上下对齐方式</param>
|
/// <param name="Space">上下两部分的间距</param>
|
public void ReSetYaxis(UViewAlignment alignment, int Space = 0)
|
{
|
if (this.Parent == null)
|
{
|
return;
|
}
|
//Y轴重置
|
int YY = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
|
if (alignment == UViewAlignment.Top)
|
{
|
YY = YY + this.DeviationValue;
|
}
|
else if (alignment == UViewAlignment.Bottom)
|
{
|
YY = YY - this.DeviationValue;
|
}
|
this.Y = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
|
}
|
|
/// <summary>
|
/// 单击弹起事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Button_MouseUpEvent(object sender, MouseEventArgs e)
|
{
|
if (this.MouseUpEvent == null)
|
{
|
//永久移除事件
|
this.MouseUpEventHandler -= this.Button_MouseUpEvent;
|
return;
|
}
|
if (this.isCanClickUp == false)
|
{
|
return;
|
}
|
|
if (this.MouseUpTime > 0)
|
{
|
this.isCanClickUp = false;
|
string text = this.Text;
|
|
new System.Threading.Thread(() =>
|
{
|
//不能够连续狂点
|
int myTime = this.MouseUpTime;
|
while (myTime >= 0)
|
{
|
if (this.IsShowMouseUpTime == true)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
this.Text = text + "(" + myTime + ")";
|
});
|
}
|
System.Threading.Thread.Sleep(1000);
|
myTime--;
|
}
|
this.isCanClickUp = true;
|
|
if (this.IsShowMouseUpTime == true)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
this.Text = text;
|
});
|
}
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
//执行自定义的事件
|
this.MouseUpEvent(sender, e);
|
}
|
}
|
|
/// <summary>
|
/// Icon类的共通
|
/// </summary>
|
public class ButtonIconCommon : ButtonCommon
|
{
|
/// <summary>
|
/// 是否启用点亮功能(默认不启用)
|
/// </summary>
|
public bool UseClickStatu = false;
|
|
/// <summary>
|
/// Icon类的共通
|
/// </summary>
|
public ButtonIconCommon()
|
{
|
//这个事件是搞点亮特效的
|
this.MouseDownEventHandler += this.Button_MouseDownEvent;
|
}
|
/// <summary>
|
/// 单击按下事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Button_MouseDownEvent(object sender, MouseEventArgs e)
|
{
|
if (this.UseClickStatu == false)
|
{
|
//永久移除
|
this.MouseDownEventHandler -= this.Button_MouseDownEvent;
|
return;
|
}
|
|
if (string.IsNullOrEmpty(this.SelectedImagePath) == false)
|
{
|
//设置选择的状态
|
this.SetSelectStatu();
|
|
if (string.IsNullOrEmpty(this.UnSelectedImagePath) == false)
|
{
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
|
Application.RunOnMainThread(() =>
|
{
|
//设置不选择状态
|
this.SetNotSelectStatu();
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
else if (string.IsNullOrEmpty(this.Text) == false)
|
{
|
uint oldColor = this.TextColor;
|
//设置选择状态
|
this.TextColor = UserCenterColor.Current.SelectTextColor;
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
|
Application.RunOnMainThread(() =>
|
{
|
//设置不选择状态
|
this.TextColor = oldColor;
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
|
/// <summary>
|
/// 设置选择的状态
|
/// </summary>
|
public void SetSelectStatu()
|
{
|
this.IsSelected = true;
|
}
|
|
/// <summary>
|
/// 设置非选择的状态
|
/// </summary>
|
public void SetNotSelectStatu()
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//设置不选择状态
|
this.IsSelected = false;
|
});
|
}
|
}
|
|
/// <summary>
|
/// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中)
|
/// </summary>
|
public class ClickButtonCommon : ButtonCommon
|
{
|
/// <summary>
|
/// 是否启用点亮功能(默认不启用)
|
/// </summary>
|
public bool UseClickStatu = false;
|
/// <summary>
|
/// 原来的背景色
|
/// </summary>
|
private uint oldBackgroundColor = 0;
|
|
/// <summary>
|
/// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中)
|
/// </summary>
|
public ClickButtonCommon()
|
{
|
this.TextColor = UserCenterColor.Current.White;
|
this.BackgroundColor = UserCenterColor.Current.ClickButtonColor;
|
this.TextAlignment = TextAlignment.Center;
|
|
this.MouseDownEventHandler += this.Button_MouseDownEvent;
|
}
|
/// <summary>
|
/// 单击按下事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Button_MouseDownEvent(object sender, MouseEventArgs e)
|
{
|
if (this.UseClickStatu == false)
|
{
|
//永久移除
|
this.MouseDownEventHandler -= this.Button_MouseDownEvent;
|
return;
|
}
|
|
//设置点击后的状态
|
this.SetClickStatu();
|
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
|
//设置非点击后的状态
|
this.SetNotClickStatu();
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 设置点击后的状态
|
/// </summary>
|
public void SetClickStatu()
|
{
|
if (this.oldBackgroundColor == 0)
|
{
|
this.oldBackgroundColor = this.BackgroundColor;
|
}
|
this.BackgroundColor = UserCenterColor.Current.ButtonClickColor;
|
}
|
|
/// <summary>
|
/// 设置非点击后的状态
|
/// </summary>
|
public void SetNotClickStatu()
|
{
|
Application.RunOnMainThread(() =>
|
{
|
//设置不选择状态
|
this.BackgroundColor = oldBackgroundColor;
|
});
|
}
|
}
|
}
|