using System;
using HDL_ON.UI.Music;
using Shared;
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
///
/// 自定义按键容器
///
public class ButtonFramLayout : BaseFramLayout
{
public const int widthFrameLayout = 78;
public const int heightFrameLayout = 84-6;
public const int lineW = 1;
public const int cornerValue = 8;
public ButtonFramLayout(int width= widthFrameLayout, int height= heightFrameLayout)
{
this.Width = Application.GetRealWidth(width);
this.Height = Application.GetRealHeight(height);
//this.Radius = (uint)Application.GetRealHeight(cornerValue);
}
Button btnImage = new Button
{
Y = Application.GetRealHeight(12),
Width = Application.GetRealWidth(32),
Height = Application.GetRealWidth(32),
UnSelectedImagePath = "AksIcon/kai.png",
Gravity = Gravity.CenterHorizontal,
Name = "btnImage",
};
Button btnName = new Button
{
Y = Application.GetRealHeight(12 + 26 + 8),//(12 + 32 + 8)
Width = Application.GetRealWidth(widthFrameLayout),
Height = Application.GetRealHeight(20),
TextSize = TextSize.Text14,
TextColor = MusicColor.TextColor,
TextAlignment = TextAlignment.Center,
Gravity = Gravity.CenterHorizontal,
Padding = new Padding(0, 0, 0, 0),
Name = "btnName",
};
Button btnTopLine = new Button
{
Width = Application.GetRealWidth(widthFrameLayout),
Height = Application.GetRealHeight(lineW),
BackgroundColor = MusicColor.ViewColor,
Name = "btnTopLine",
};
Button btnBottomLine = new Button
{
Width = Application.GetRealWidth(widthFrameLayout),
Height = Application.GetRealHeight(lineW),
BackgroundColor = MusicColor.ViewColor,
Name = "btnBottomLine",
Y = Application.GetRealHeight(heightFrameLayout - 1),
};
Button btnLeftLine = new Button
{
Width = Application.GetRealWidth(lineW),
Height = Application.GetRealHeight(heightFrameLayout),
BackgroundColor = MusicColor.ViewColor,
Name = "btnLeftLine",
};
Button btnRightLine = new Button
{
Width = Application.GetRealWidth(lineW),
Height = Application.GetRealHeight(heightFrameLayout),
BackgroundColor = MusicColor.ViewColor,
X = Application.GetRealWidth(widthFrameLayout - 1),
Name = "btnRightLine",
};
///
/// 添加布局
///
///
public void AddView(FrameLayout parent)
{
parent.AddChidren(this);
this.AddChidren(btnImage);
this.AddChidren(btnName);
}
public void AddImageView()
{
this.AddChidren(btnImage);
}
public void AddNameView()
{
this.AddChidren(btnName);
}
///
/// 添加左边线
///
public void AddLeftLine()
{
btnLeftLine.Height = this.Height;
this.AddChidren(btnLeftLine);
}
///
/// 添加右边线
///
public void AddRightLine()
{
btnRightLine.Height = this.Height;
btnRightLine.X = this.Width - Application.GetRealWidth(1);
this.AddChidren(btnRightLine);
}
///
/// 添加顶部边线
///
public void AddTopLine()
{
btnTopLine.Width = this.Width;
this.AddChidren(btnTopLine);
}
///
/// 添加底部边线
///
public void AddBottomLine()
{
btnBottomLine.Y = this.Height - Application.GetRealHeight(1);
btnBottomLine.Width = this.Width;
this.AddChidren(btnBottomLine);
}
public Button GetImageButton()
{
return this.btnImage;
}
public Button GetNameButton()
{
return btnName;
}
///
/// 事件监听方法
///
/// 回调(第一个是父类对象;第二个是图标对象;第三个是状态对象
public void SetClickListener(Action action)
{
EventHandler UpClick = (sender, e) =>
{
if (!this.GetClick()) {
return;
}
action?.Invoke(this, btnImage, btnName);
SetHighlightColor(this);
//按下去改变背景颜色
//this.BackgroundColor = AksCommonMethod.seleBackgroundColor;
};
this.MouseUpEventHandler += UpClick;
btnImage.MouseUpEventHandler += UpClick;
btnName.MouseUpEventHandler += UpClick;
//EventHandler CancelClick = (sender, e) =>
//{
// this.BackgroundColor = 0x00000000;
// //弹起来还原背景颜色
//};
//this.MouseUpOutsideEventHandler += CancelClick;
//btnImage.MouseUpOutsideEventHandler += CancelClick;
//btnName.MouseUpOutsideEventHandler += CancelClick;
//EventHandler DownClick = (sender, e) =>
//{
// //按下去改变背景颜色
// this.BackgroundColor = AksCommonMethod.seleBackgroundColor;
//};
//this.MouseDownEventHandler += DownClick;
//btnImage.MouseDownEventHandler += DownClick;
//btnName.MouseDownEventHandler += DownClick;
}
///
/// 设置图标
///
///
public void SetButtonImage(int stringId)
{
switch (stringId)
{
case StringId.kai:
{
this.btnImage.UnSelectedImagePath = "AksIcon/kai.png";
}
break;
}
}
}
}