using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 底部弹窗项目选择界面(列表数尽可能别弄那么多)
///
public class BottomItemSelectForm : DialogCommonForm
{
#region ■ 变量声明___________________________
///
/// 完成选择的事件(参数为选择的是列表的第几行,从0开始)
///
public Action FinishSelectEvent = null;
///
/// 前回选择的控件
///
private NormalSelectControl oldSelectContr = null;
///
/// 选择取消(不是左下角),并且按下确定键时,是否调用回调函数(调用时传递的参数是 -1,默认不回调)
///
public bool CancelCallEvent = false;
///
/// 选择的行能否取消
///
public bool SelectRowCanCancel = true;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 头部标题
/// 需要显示的列表信息(列表数尽可能别弄那么多)
/// 设置哪个文本为默认选择(不设置填-1)
public void ShowForm(string i_topText, List i_listText, int i_selectNo)
{
//初始化中部信息
this.InitMiddleFrame(i_topText, i_listText, i_selectNo);
}
///
/// 初始化中部信息
///
/// 头部标题
/// 需要显示的列表信息
/// 默认选择
private void InitMiddleFrame(string i_topText, List i_listText, int i_selectNo)
{
//弧度的圆的一半的高度(固定)
int halfRoundHeigth = Application.GetRealHeight(116) / 2;
//头部高度
int topHeight = Application.GetRealHeight(195);
//底部高度
int bottomHeight = Application.GetRealHeight(57);
//明细高度
int detailHeight = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(12)) * i_listText.Count;
//搞一个透明的框
var frameTransparent = new FrameLayout();
frameTransparent.Y = bodyFrameLayout.Height - topHeight - bottomHeight - detailHeight;
frameTransparent.Height = topHeight + bottomHeight + detailHeight + halfRoundHeigth * 2;//高度就是要它超过,随便搞的
frameTransparent.BackgroundColor = UserCenterColor.Current.Transparent;
bodyFrameLayout.AddChidren(frameTransparent);
//明细列表的桌布,白色背景(它与实际高度小了半个弧度的圆)
var detailBackFrame = new FrameLayout();
detailBackFrame.Y = halfRoundHeigth;
detailBackFrame.Height = frameTransparent.Height;
detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
frameTransparent.AddChidren(detailBackFrame);
//弧度的圆
var rowRound = new FrameLayout();
rowRound.Width = bodyFrameLayout.Width;
rowRound.Height = halfRoundHeigth * 2;
rowRound.BackgroundColor = UserCenterColor.Current.White;
rowRound.Radius = (uint)halfRoundHeigth;
frameTransparent.AddChidren(rowRound);
//头部信息
var btnTitle = new NormalViewControl(detailBackFrame.Width, Application.GetRealHeight(63), false);
btnTitle.Y = Application.GetRealHeight(35);
btnTitle.Text = i_topText;
btnTitle.TextColor = UserCenterColor.Current.TextColor4;
btnTitle.TextSize = 16;
btnTitle.TextAlignment = TextAlignment.Center;
rowRound.AddChidren(btnTitle);
//取消
var btnCancel = new NormalViewControl(200, 58, true);
btnCancel.X = Application.GetRealWidth(81);
btnCancel.Y = Application.GetRealHeight(40);
btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
btnCancel.TextID = R.MyInternationalizationString.uCancel;
rowRound.AddChidren(btnCancel);
btnCancel.ButtonClickEvent += (sender, e) =>
{
this.CloseForm();
};
//完成
var btnFinish = new NormalViewControl(200, 58, true);
btnFinish.X = Application.GetRealWidth(800);
btnFinish.Y = Application.GetRealHeight(40);
btnFinish.TextAlignment = TextAlignment.CenterRight;
btnFinish.TextColor = 0xfffb744a;
btnFinish.TextID = R.MyInternationalizationString.uFinish;
rowRound.AddChidren(btnFinish);
btnFinish.ButtonClickEvent += (sender, e) =>
{
if (FinishSelectEvent != null && oldSelectContr != null)
{
//回调函数
FinishSelectEvent.Invoke(Convert.ToInt32(oldSelectContr.MainKeys));
}
else if (FinishSelectEvent != null && this.CancelCallEvent == true)
{
//回调函数
FinishSelectEvent.Invoke(-1);
}
this.CloseForm();
};
//线
var btnLine = new NormalViewControl(detailBackFrame.Width, ControlCommonResourse.BottomLineHeight, false);
btnLine.Y = Application.GetRealHeight(138) - ControlCommonResourse.BottomLineHeight - halfRoundHeigth;
btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
detailBackFrame.AddChidren(btnLine);
//列表控件
var listView = new FrameListControl(12);
listView.Height = detailHeight + bottomHeight;
listView.Y = topHeight - halfRoundHeigth;
detailBackFrame.AddChidren(listView);
for (int i = 0; i < i_listText.Count; i++)
{
var btnRow = new NormalSelectControl(i_listText[i], listView.rowSpace / 2);
btnRow.LeftOffset = Application.GetRealWidth(81) - ControlCommonResourse.XXLeft;//向右偏移
btnRow.RightOffset = ControlCommonResourse.XXLeft - Application.GetRealWidth(81);//向左偏移
listView.AddChidren(btnRow);
btnRow.InitControl();
btnRow.MainKeys = i.ToString();
btnRow.ButtonClickEvent += (sender, e) =>
{
//取消选择
if (btnRow.IsSelected == true)
{
//允许取消的时候,才能取消
if (this.SelectRowCanCancel == true)
{
btnRow.IsSelected = false;
oldSelectContr = null;
}
return;
}
if (oldSelectContr != null)
{
oldSelectContr.IsSelected = false;
}
btnRow.IsSelected = true;
oldSelectContr = btnRow;
};
//默认选择
if (i == i_selectNo)
{
btnRow.IsSelected = true;
oldSelectContr = btnRow;
}
if (i != i_listText.Count - 1)
{
//底线
btnRow.AddBottomLine();
}
}
}
#endregion
}
}