using System;
|
using HDL_ON.UI.Music;
|
using Shared;
|
using System.Collections.Generic;
|
using HDL_ON.UI.UI2.FuntionControlView.Aks.Entity;
|
|
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
|
{
|
/// <summary>
|
/// 自定义圆角容器
|
/// </summary>
|
public class CornerFramLayout : BaseFramLayout
|
{
|
private int topMargin;
|
private int leftMargin;
|
private int bottomMargin;
|
private int rightMargin;
|
private int mWidth;
|
private int mHeight;
|
/// <summary>
|
/// 一行几个元素
|
/// </summary>
|
private int mRowNumber;
|
/// <summary>
|
/// 列表最大值
|
/// </summary>
|
private int mListCount;
|
/// <summary>
|
/// 按键回调
|
/// </summary>
|
public Action<KeypadEntity> selectKeyAction = null;
|
/// <summary>
|
/// 影片回调
|
/// </summary>
|
public Action<MovieLibrary> selectImageAction = null;
|
|
|
/// <summary>
|
///
|
/// </summary>
|
/// <param name="width">容器宽度</param>
|
/// <param name="height">容器高度</param>
|
///<param name="rowNumber">圆角值</param>
|
public CornerFramLayout(int width, int height, int radius = 0)
|
{
|
this.BackgroundColor = MusicColor.WhiteColor;
|
this.Width = Application.GetRealWidth(width);
|
this.Height = Application.GetRealHeight(height);
|
this.Radius = (uint)Application.GetRealHeight(radius);
|
this.mWidth = this.Width;
|
this.mHeight = this.Height;
|
|
|
}
|
/// <summary>
|
/// 设置内边距
|
/// </summary>
|
/// <param name="top">上边距</param>
|
/// <param name="bottom">下边距</param>
|
/// <param name="left">左边距</param>
|
/// <param name="right">右边距</param>
|
public void SetMargin(int top, int bottom, int left, int right)
|
{
|
this.topMargin = top;
|
this.bottomMargin = bottom;
|
this.leftMargin = left;
|
this.rightMargin = right;
|
}
|
|
|
|
/// <summary>
|
/// 获取测试列表数据
|
/// </summary>
|
public List<KeypadEntity> GetTestList()
|
{
|
return AksCommonMethod.Current.GetTYYKeypadList(null);
|
}
|
|
/// <summary>
|
/// 动态加载按键界面
|
/// </summary>
|
/// <param name="mList">列表</param>
|
/// <param name="mRowNumber">一行多少个元素</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadButtonPage(List<KeypadEntity> mList, int mRowNumber, int defaultIndex = -1)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
if (mRowNumber == 0)
|
{
|
return;
|
}
|
this.mRowNumber = mRowNumber;
|
this.mListCount = mList.Count;
|
int line = 0;
|
int xCount = 0;
|
for (int i = 1; i <= mList.Count; i++)
|
{
|
var keypad = mList[i - 1];
|
ButtonFramLayout buttonFram = new ButtonFramLayout();
|
this.AddChidren(buttonFram);
|
buttonFram.Tag = keypad;
|
buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(ButtonFramLayout.heightFrameLayout * line);
|
buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(ButtonFramLayout.widthFrameLayout * xCount);
|
buttonFram.AddImageView();
|
buttonFram.AddNameView();
|
if (!IsLastRight(i))
|
{
|
buttonFram.AddRightLine();
|
}
|
if (!IsLastColumn(i))
|
{
|
buttonFram.AddBottomLine();
|
}
|
buttonFram.GetImageButton().UnSelectedImagePath = keypad.localIconAddress;
|
buttonFram.GetNameButton().Text = keypad.name;
|
|
xCount++;
|
if (i % this.mRowNumber == 0)
|
{
|
|
line++;
|
xCount = 0;
|
}
|
//不支持按键点击背景颜色
|
if (!keypad.isClicked)
|
{
|
buttonFram.Enable = false;
|
buttonFram.GetImageButton().Alpha =0.5f;
|
buttonFram.GetImageButton().Enable = false;
|
buttonFram.GetNameButton().Enable = false;
|
buttonFram.GetNameButton().TextColor = AksCommonMethod.unBackgroundColor;
|
//buttonFram.BackgroundColor =AksCommonMethod.unParentBackgroundColor;
|
|
}
|
buttonFram.SetClickListener((fl, btnIcon, btnName) =>
|
{
|
if (buttonFram.Tag != null && buttonFram.Tag is KeypadEntity)
|
{
|
selectKeyAction?.Invoke((KeypadEntity)buttonFram.Tag);
|
}
|
});
|
|
//if (defaultIndex != -1 && defaultIndex == i)
|
//{
|
// if (buttonFram.Tag != null && buttonFram.Tag is KeypadEntity)
|
// {
|
// selectAction?.Invoke((KeypadEntity)buttonFram.Tag);
|
// }
|
//}
|
|
|
}
|
}
|
|
/// <summary>
|
/// 动态加载按键界面
|
/// </summary>
|
/// <param name="mList">列表</param>
|
/// <param name="list"> 列表中索引,表示某一条宽度加宽,没有默认(new List<int>)</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadButtonPage(List<KeypadEntity> mList, List<int> list,int defaultIndex=-1)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
int currnetheightValue = 0;
|
int currnetWidthValue = 0;
|
//获取相对一个纬度值
|
int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(ButtonFramLayout.heightFrameLayout / 2);
|
int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(ButtonFramLayout.widthFrameLayout / 2);
|
for (int i = 1; i <= mList.Count; i++)
|
{
|
var keypad = mList[i - 1];
|
ButtonFramLayout buttonFram = null;
|
if (list.Contains(i))
|
{
|
buttonFram = new ButtonFramLayout(ButtonFramLayout.widthFrameLayout * 2);
|
buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
|
buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue);
|
currnetWidthValue += ButtonFramLayout.widthFrameLayout * 2;
|
}
|
else
|
{
|
buttonFram = new ButtonFramLayout();
|
buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
|
buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue);
|
currnetWidthValue += ButtonFramLayout.widthFrameLayout;
|
|
}
|
|
this.AddChidren(buttonFram);
|
buttonFram.AddImageView();
|
buttonFram.AddNameView();
|
buttonFram.Tag = keypad;//标记数据
|
buttonFram.GetImageButton().UnSelectedImagePath = keypad.localIconAddress;
|
buttonFram.GetNameButton().Text = keypad.name;
|
if (widthDimensionValue > Application.GetRealWidth(currnetWidthValue))
|
{
|
//加右线
|
buttonFram.AddRightLine();
|
}
|
|
if (heightDimensionValue > buttonFram.Bottom)
|
{
|
//加底线
|
buttonFram.AddBottomLine();
|
}
|
|
if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
|
{
|
currnetheightValue += ButtonFramLayout.heightFrameLayout;
|
currnetWidthValue = 0;
|
}
|
//不支持按键点击背景颜色
|
if (!keypad.isClicked)
|
{
|
buttonFram.Enable = false;
|
buttonFram.GetImageButton().Enable = false;
|
buttonFram.GetNameButton().Enable = false;
|
buttonFram.GetNameButton().TextColor = AksCommonMethod.unBackgroundColor;
|
}
|
buttonFram.SetClickListener((fl, btnIcon, btnName) =>
|
{
|
if (buttonFram.Tag != null&& buttonFram.Tag is KeypadEntity)
|
{
|
selectKeyAction?.Invoke((KeypadEntity)buttonFram.Tag);
|
}
|
});
|
|
//if (defaultIndex != -1 && defaultIndex == i)
|
//{
|
// if (buttonFram.Tag != null && buttonFram.Tag is KeypadEntity)
|
// {
|
// selectAction?.Invoke((KeypadEntity)buttonFram.Tag);
|
// }
|
//}
|
}
|
}
|
|
/// <summary>
|
///动态加载数字按键界面
|
/// </summary>
|
/// <param name="mList">列表</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadNumberButtonPage(List<KeypadEntity> mList)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
int currnetheightValue = 0;
|
int currnetWidthValue = 0;
|
int heightMaxValue = 84-6;
|
int widthMaxValue = 78;
|
//获取相对一个纬度值
|
int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(heightMaxValue / 2);
|
int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(widthMaxValue / 2);
|
for (int i = 0; i <mList.Count; i++)
|
{
|
var keypad = mList[i];
|
Button button = new Button
|
{
|
Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue),
|
X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue),
|
Width = Application.GetRealWidth(widthMaxValue),
|
Height = Application.GetRealHeight(heightMaxValue),
|
Text = keypad.name,
|
TextSize = TextSize.Text20,
|
TextColor = MusicColor.TextColor,
|
TextAlignment = TextAlignment.Center,
|
IsBold = true,
|
Tag = keypad,
|
BackgroundColor = MusicColor.WhiteColor,
|
SelectedBackgroundColor = 0xFFF2F3F7,
|
Radius = (uint)Application.GetRealHeight(8),
|
SelectedTextColor = MusicColor.TextColor,
|
};
|
this.AddChidren(button);
|
|
currnetWidthValue += widthMaxValue;
|
if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
|
{
|
currnetheightValue += heightMaxValue;
|
currnetWidthValue = 0;
|
}
|
//不支持按键点击背景颜色
|
if (!keypad.isClicked)
|
{
|
button.Enable = false;
|
button.TextColor = AksCommonMethod.unBackgroundColor;
|
}
|
button.MouseDownEventHandler += (sen, e) =>
|
{
|
|
button.IsSelected = true;
|
|
};
|
button.MouseUpOutsideEventHandler += (sen, e) =>
|
{
|
|
button.IsSelected = true;
|
|
};
|
button.MouseUpEventHandler += (sen, e) =>
|
{
|
if (button.Tag == null || ((KeypadEntity)button.Tag).keypad == "none")
|
{
|
return;
|
}
|
selectKeyAction?.Invoke((KeypadEntity)button.Tag);
|
button.IsSelected = false;
|
};
|
|
//if (defaultIndex != -1 && defaultIndex == i)
|
//{
|
// selectAction?.Invoke((int)buttonFram.Tag);
|
//}
|
}
|
}
|
|
/// <summary>
|
/// 动态加载图片界面
|
/// 影片布局
|
/// </summary>
|
/// <param name="mList">列表</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadImagePage(List<MovieLibrary> mList)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
int currnetheightValue = 0;
|
int currnetWidthValue = 0;
|
int heightMaxValue = ImageFramlayout.heightFrameLayout;
|
int widthMaxValue = ImageFramlayout.widthFrameLayout;
|
//获取相对一个纬度值
|
int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(heightMaxValue / 2);
|
int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(widthMaxValue / 2);
|
for (int i = 0; i < mList.Count; i++)
|
{
|
var movieLibrary = mList[i];
|
ImageFramlayout imageFram = new ImageFramlayout();
|
imageFram.AddView(this);
|
imageFram.Tag = movieLibrary;
|
imageFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
|
imageFram.X = Application.GetRealWidth(currnetWidthValue);
|
imageFram.btnName.Text = movieLibrary.name;
|
imageFram.btnImage.ImageBytes = movieLibrary.imageBytes;
|
imageFram.btnScore.Text = movieLibrary.rating;
|
currnetWidthValue += (widthMaxValue + 8);//8是隔间值
|
if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
|
{
|
currnetheightValue += (heightMaxValue + 20);//20是隔间值
|
currnetWidthValue = 0;
|
}
|
|
imageFram.SetClickListener((fl) =>
|
{
|
if (imageFram.Tag != null&& imageFram.Tag is MovieLibrary)
|
{
|
selectImageAction?.Invoke((MovieLibrary)imageFram.Tag);
|
}
|
});
|
//if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
|
//{
|
// selectImageAction?.Invoke((int)imageFram.Tag);
|
//}
|
}
|
}
|
/// <summary>
|
/// 动态加载图片界面
|
/// 影片布局
|
/// </summary>
|
/// <param name="mRowNumber">一行多少个元素</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadImagePage(List<MovieLibrary> mList, int mRowNumber)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
if (mRowNumber == 0)
|
{
|
return;
|
}
|
this.mListCount = mList.Count;
|
this.mRowNumber = mRowNumber;
|
int line = 0;
|
int xCount = 0;
|
for (int i = 1; i <= mList.Count; i++)
|
{
|
var keypad = mList[i - 1];
|
ImageFramlayout imageFram = new ImageFramlayout();
|
imageFram.AddView(this);
|
imageFram.Tag = keypad;
|
imageFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight((ImageFramlayout.heightFrameLayout + 20) * line);
|
imageFram.X = Application.GetRealWidth((ImageFramlayout.widthFrameLayout + 8) * xCount);
|
imageFram.btnName.Text = keypad.name;
|
|
xCount++;
|
if (i % this.mRowNumber == 0)
|
{
|
|
line++;
|
xCount = 0;
|
}
|
imageFram.SetClickListener((fl) =>
|
{
|
if (imageFram.Tag != null && imageFram.Tag is MovieLibrary)
|
{
|
selectImageAction?.Invoke((MovieLibrary)imageFram.Tag);
|
}
|
});
|
|
//if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
|
//{
|
// selectImageAction?.Invoke((MovieLibrary)imageFram.Tag);
|
//}
|
|
|
}
|
}
|
|
private int currnetheightValue1 = 0;
|
private int currnetWidthValue1 = 0;
|
private int heightMaxValue1 = ImageFramlayout.heightFrameLayout;
|
private int widthMaxValue1 = ImageFramlayout.widthFrameLayout;
|
//获取相对一个纬度值
|
private int widthDimensionValue1 = Application.GetRealWidth(343) - Application.GetRealHeight(ImageFramlayout.widthFrameLayout / 2);
|
/// <summary>
|
/// 加载影片列表布局
|
/// (特殊布局)
|
/// </summary>
|
/// <param name="mList">列表</param>
|
public void LoadImagePage(List<ImageFramlayout> imageFramlayoutList)
|
{
|
|
if (imageFramlayoutList==null||imageFramlayoutList.Count == 0)
|
{
|
return;
|
}
|
//int currnetheightValue = 0;
|
//int currnetWidthValue = 0;
|
//int heightMaxValue = ImageFramlayout.heightFrameLayout;
|
//int widthMaxValue = ImageFramlayout.widthFrameLayout;
|
////获取相对一个纬度值
|
//int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(heightMaxValue / 2);
|
//int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(widthMaxValue / 2);
|
for (int i = 0; i < imageFramlayoutList.Count; i++)
|
{
|
var imageFram = imageFramlayoutList[i];
|
if (imageFram == null)
|
{
|
continue;
|
}
|
imageFram.AddView(this);
|
imageFram.Y =Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue1);
|
imageFram.X = Application.GetRealWidth(currnetWidthValue1);
|
currnetWidthValue1 += (widthMaxValue1 + 8);//8是隔间值
|
if (widthDimensionValue1 < Application.GetRealWidth(currnetWidthValue1))
|
{
|
currnetheightValue1 += (heightMaxValue1 + 20);//20是隔间值
|
currnetWidthValue1 = 0;
|
}
|
|
imageFram.SetClickListener((fl) =>
|
{
|
if (imageFram.Tag != null && imageFram.Tag is MovieLibrary)
|
{
|
selectImageAction?.Invoke((MovieLibrary)imageFram.Tag);
|
}
|
});
|
}
|
}
|
/// <summary>
|
/// 水平滑动布局
|
/// </summary>
|
/// <param name="mList">列表</param>
|
/// <param name="defaultIndex">默认值索引范围[0,mList.count-1],值超出范围视为无效</param>
|
public void LoadHorizontalPage(List<FilterCategoryEntity> mList, int defaultIndex = -1)
|
{
|
if (mList == null || mList.Count == 0)
|
{
|
return;
|
}
|
for (int i = 0; i < mList.Count; i++)
|
{
|
var filterCategory = mList[i];
|
BaseFramLayout horizontalFL = new BaseFramLayout
|
{
|
Y = Application.GetRealHeight(i * 75),
|
Height = Application.GetRealHeight(75),
|
Width = this.Width,
|
};
|
this.AddChidren(horizontalFL);
|
Button btnTitleType = new Button
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(16),
|
Height = Application.GetRealHeight(22),
|
Width = Application.GetRealWidth(200),
|
Text = filterCategory.name,
|
TextSize = TextSize.Text16,
|
TextColor = MusicColor.TextColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
IsBold = true,
|
Tag = filterCategory,
|
};
|
horizontalFL.AddChidren(btnTitleType);
|
|
HorizontalFramLayout horizontal = new HorizontalFramLayout(375 - 16, 28);
|
horizontalFL.AddChidren(horizontal);
|
horizontal.Y = btnTitleType.Bottom + Application.GetRealHeight(8);
|
horizontal.X = Application.GetRealWidth(16);
|
horizontal.SelectTypeEvent += (filters) =>
|
{
|
KeypadEntity keypad = new KeypadEntity();
|
keypad.category = filters.category;
|
keypad.filterValue = filters.filterValue;
|
keypad.filterName = filters.filterName;
|
selectKeyAction?.Invoke(keypad);
|
};
|
horizontal.InitControl(filterCategory.filters, defaultIndex);
|
|
|
}
|
|
}
|
|
/// <summary>
|
/// 最后一行
|
/// </summary>
|
/// <param name="index">当前索引值</param>
|
/// <returns></returns>
|
private bool IsLastColumn(int index)
|
{
|
if (this.mRowNumber == 0 || mListCount == 0)
|
{
|
return false;
|
}
|
int lineCount = mListCount / this.mRowNumber;//得出行数
|
int number = mListCount % this.mRowNumber;
|
if (number != 0)
|
{
|
if (index > lineCount * this.mRowNumber)
|
{
|
return true;
|
}
|
}
|
else
|
{
|
int value = --lineCount * this.mRowNumber;
|
if (index > value)
|
{
|
return true;
|
}
|
|
}
|
return false;
|
}
|
/// <summary>
|
/// 最后右边那一个
|
/// </summary>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
private bool IsLastRight(int value)
|
{
|
if (this.mRowNumber == 0)
|
{
|
return false;
|
}
|
if (value % this.mRowNumber == 0)
|
{
|
return true;
|
};
|
return false;
|
}
|
|
|
/// <summary>
|
/// 重新计算button宽度
|
/// </summary>
|
/// <param name="button">控件</param>
|
/// <param name="widthMax">宽度最大最</param>
|
/// <param name="padding">内边距</param>
|
private void AdjustRealWidth(Button button, int widthMax = 0, int padding = 0)
|
{
|
if (button == null)
|
{
|
return;
|
}
|
int width;
|
if (widthMax == 0)
|
{
|
//内边距
|
width = button.GetTextWidth() + Application.GetRealWidth(padding * 2);
|
}
|
else
|
{
|
if (button.GetTextWidth() > Application.GetRealWidth(widthMax))
|
{
|
|
button.TextSize = 10;//控件高度不变,改变字体大小,准备换行;
|
width = Application.GetRealWidth(widthMax);
|
}
|
else
|
{
|
width = button.GetTextWidth();
|
}
|
|
}
|
|
button.Width = width;
|
}
|
|
|
|
|
}
|
}
|