using System;
|
using System.Collections.Generic;
|
using System.Text;
|
|
namespace Shared.Phone.UserCenter
|
{
|
/// <summary>
|
/// 做成一个点击后能够显示点击状态的控件(基层控件)
|
/// </summary>
|
public class FrameLayoutControl : FrameLayout
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 单击弹起事件
|
/// </summary>
|
public Action<object, MouseEventArgs> ButtonClickEvent;
|
/// <summary>
|
/// 状态设置的事件(会重载底层效果)
|
/// </summary>
|
public Action<bool> SelectStatuEvent;
|
/// <summary>
|
/// 是否启用点亮功能(默认启用)
|
/// </summary>
|
public bool UseClickStatu = true;
|
/// <summary>
|
/// 原来的背景色
|
/// </summary>
|
private uint oldBackColor = 0;
|
/// <summary>
|
/// 当前是否已经处于选择状态
|
/// </summary>
|
private bool IsSelectStatu = false;
|
/// <summary>
|
/// 子控件Y轴偏移量(共通定义而已)
|
/// </summary>
|
public int chidrenYaxis = 0;
|
|
/// <summary>
|
/// 圆角度(安卓和IOS或许需要预编译)
|
/// </summary>
|
public uint RadiusEx
|
{
|
set
|
{
|
this.Radius = value;
|
}
|
}
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 做成一个点击后能够显示点击状态的控件
|
/// </summary>
|
/// <param name="i_ChidrenYaxis">子控件Y轴偏移量(真实值,有些界面需要这种特殊操作)</param>
|
public FrameLayoutControl(int i_ChidrenYaxis = 0)
|
{
|
this.chidrenYaxis = i_ChidrenYaxis;
|
|
this.MouseUpEventHandler += ChildrenUpEvent;
|
this.MouseDownEventHandler += ChildrenDownEvent;
|
}
|
|
/// <summary>
|
/// 做成一个普通的FrameLayout控件
|
/// </summary>
|
/// <param name="flage">没啥用的东西</param>
|
public FrameLayoutControl(bool flage)
|
{
|
}
|
|
#endregion
|
|
#region ■ 绑定事件___________________________
|
|
/// <summary>
|
/// 变更子控件的绑定模式
|
/// </summary>
|
/// <param name="view">子控件</param>
|
/// <param name="chidrenBindMode">变更的绑定模式</param>
|
public void ChangedChidrenBindMode(View view, ChidrenBindMode chidrenBindMode)
|
{
|
if (view is ButtonBase)
|
{
|
//子控件移除事件
|
ButtonBase button = (ButtonBase)view;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.MouseDownEventHandler -= ChildrenDownEvent;
|
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
else if (view is ViewGroup)
|
{
|
ViewGroup groupContr = (ViewGroup)view;
|
for (int i = 0; i < groupContr.ChildrenCount; i++)
|
{
|
var myView = groupContr.GetChildren(i);
|
if (myView == null)
|
{
|
break;
|
}
|
if (myView is ButtonBase)
|
{
|
//子控件移除事件
|
ButtonBase button = (ButtonBase)myView;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.MouseDownEventHandler -= ChildrenDownEvent;
|
}
|
}
|
//自身移除事件
|
groupContr.MouseUpEventHandler -= ChildrenUpEvent;
|
groupContr.MouseDownEventHandler -= ChildrenDownEvent;
|
|
this.BindChidrenEvent(view, chidrenBindMode);
|
}
|
}
|
|
/// <summary>
|
/// 绑定子控件事件(如果是复合控件,在初始化完成后,调用ChangedChidrenBindMode)
|
/// </summary>
|
/// <param name="view"></param>
|
/// <param name="chidrenBindMode"></param>
|
private void BindChidrenEvent(View view, ChidrenBindMode chidrenBindMode)
|
{
|
if (view is ButtonBase && chidrenBindMode != ChidrenBindMode.NotBind)
|
{
|
//为子控件添加事件
|
ButtonBase button = (ButtonBase)view;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.MouseDownEventHandler -= ChildrenDownEvent;
|
|
button.ButtonClickEvent += ChildrenUpEvent;
|
button.MouseDownEventHandler += ChildrenDownEvent;
|
}
|
else if (view is ViewGroup && chidrenBindMode != ChidrenBindMode.NotBind)
|
{
|
//为子控件添加事件
|
ViewGroup groupContr = (ViewGroup)view;
|
for (int i = 0; i < groupContr.ChildrenCount; i++)
|
{
|
var myView = groupContr.GetChildren(i);
|
if (myView == null)
|
{
|
break;
|
}
|
if (myView is ButtonBase)
|
{
|
//为子控件添加事件
|
ButtonBase button = (ButtonBase)myView;
|
button.ButtonClickEvent -= ChildrenUpEvent;
|
button.MouseDownEventHandler -= ChildrenDownEvent;
|
|
button.ButtonClickEvent += ChildrenUpEvent;
|
button.MouseDownEventHandler += ChildrenDownEvent;
|
}
|
}
|
//自身也添加事件
|
groupContr.MouseUpEventHandler -= ChildrenUpEvent;
|
groupContr.MouseDownEventHandler -= ChildrenDownEvent;
|
|
groupContr.MouseUpEventHandler += ChildrenUpEvent;
|
groupContr.MouseDownEventHandler += ChildrenDownEvent;
|
}
|
}
|
|
#endregion
|
|
#region ■ 添加子控件_________________________
|
|
/// <summary>
|
/// 添加子控件
|
/// </summary>
|
/// <param name="view">子控件</param>
|
/// <param name="chidrenBindMode">绑定模式</param>
|
public void AddChidren(View view, ChidrenBindMode chidrenBindMode = ChidrenBindMode.BindAll)
|
{
|
this.oldBackColor = this.BackgroundColor;
|
|
base.AddChidren(view);
|
|
//绑定子控件事件
|
this.BindChidrenEvent(view, chidrenBindMode);
|
|
}
|
|
#endregion
|
|
#region ■ 控件事件___________________________
|
|
/// <summary>
|
/// 点击按下事件(点亮)
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="e">E.</param>
|
private void ChildrenDownEvent(object sender, MouseEventArgs e)
|
{
|
if (this.UseClickStatu == false)
|
{
|
return;
|
}
|
this.StartSelectStatuAppeal(ControlCommonResourse.StatuChangedWaitTime);
|
}
|
|
/// <summary>
|
/// 点击松开事件
|
/// </summary>
|
/// <param name="sender">Sender.</param>
|
/// <param name="e">E.</param>
|
private void ChildrenUpEvent(object sender, MouseEventArgs e)
|
{
|
if (sender is FrameLayoutControl)
|
{
|
//LOG出力
|
this.WriteLog();
|
}
|
//调用委托
|
ButtonClickEvent?.Invoke(sender, e);
|
}
|
|
#endregion
|
|
#region ■ 单击状态显示_______________________
|
|
/// <summary>
|
/// 设置单击后结束的状态
|
/// </summary>
|
public void SetClickNotSelectStatu()
|
{
|
this.IsSelectStatu = false;
|
if (this.SelectStatuEvent != null)
|
{
|
this.SelectStatuEvent(false);
|
return;
|
}
|
|
this.BackgroundColor = this.oldBackColor;
|
}
|
|
/// <summary>
|
/// 设置单击时的状态
|
/// </summary>
|
public void SetClickSelectStatu()
|
{
|
this.IsSelectStatu = true;
|
if (this.SelectStatuEvent != null)
|
{
|
this.SelectStatuEvent(true);
|
return;
|
}
|
|
this.BackgroundColor = UserCenterColor.Current.RowSelectBackColor;
|
}
|
|
#endregion
|
|
#region ■ 一般方法___________________________
|
|
/// <summary>
|
/// 强制实施控件选中状态的特效
|
/// </summary>
|
/// <param name="waiTime"></param>
|
public void StartSelectStatuAppeal(int waiTime)
|
{
|
if (this.IsSelectStatu == true)
|
{
|
return;
|
}
|
this.IsSelectStatu = true;
|
|
//设置选择状态
|
this.SetClickSelectStatu();
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
System.Threading.Thread.Sleep(waiTime);
|
Application.RunOnMainThread(() =>
|
{
|
//设置不选择状态
|
this.SetClickNotSelectStatu();
|
});
|
});
|
}
|
|
/// <summary>
|
/// 移除底层控件自身的单击事件
|
/// </summary>
|
public void RemoveBaseClickEvent()
|
{
|
this.MouseUpEventHandler -= ChildrenUpEvent;
|
this.MouseDownEventHandler -= ChildrenDownEvent;
|
}
|
|
/// <summary>
|
/// 控件摧毁
|
/// </summary>
|
public override void RemoveFromParent()
|
{
|
this.ButtonClickEvent = null;
|
this.SelectStatuEvent = null;
|
|
base.RemoveFromParent();
|
}
|
|
#endregion
|
|
#region ■ Log出力____________________________
|
|
/// <summary>
|
/// 该控件所属的界面名字
|
/// </summary>
|
private string formName = null;
|
|
/// <summary>
|
/// Log出力
|
/// </summary>
|
private void WriteLog()
|
{
|
if (formName == null)
|
{
|
formName = string.Empty;
|
View myView = this.Parent;
|
for (; ; )
|
{
|
if (myView == null)
|
{
|
break;
|
}
|
else if (myView is CommonFormBase)
|
{
|
formName = ((CommonFormBase)myView).FormID;
|
break;
|
}
|
myView = myView.Parent;
|
}
|
}
|
HdlLogLogic.Current.WriteLog(1, formName + ".FrameLayoutControl 被点击");
|
}
|
|
#endregion
|
}
|
}
|