using System;
using System.Collections.Generic;
using HDL_ON.UI.CSS;
using Shared;
namespace HDL_ON
{
///
/// 通用PopupDialog 单选效果
/// 只回调Index
///
public class SelectPopupDialog : Dialog
{
/// bodyView
///
FrameLayout bodyView;
///
/// 底部View
/// 自己根据需要调整X、Y坐标
///
public FrameLayout BackView;
///
/// 一级滑动View
///
VerticalScrolViewLayout leftScrolView;
///
/// 二级滑动View
///
VerticalScrolViewLayout rightScrolView;
///
/// 选中回调事件
///
Action SelectAction;
///
/// 一级List
///
List mFirstList = new List();
///
/// 二级联动List
///
List> mSecondList = new List>();
///
/// SelectPopupDialog
///
///
public SelectPopupDialog()
{
bodyView = new FrameLayout();
}
///
/// 显示View
/// mFirstList、mSecondList不合法都不会显示View
/// mSecondList 不传为默认一级
///
///
///
public void ShowView(List mFirstList, List> mSecondList, Action SelectAction)
{
if (mFirstList == null)
{
Utlis.WriteLine("mFirstList null");
return;
}
//注册回调事件
this.SelectAction = SelectAction;
//二是否需要二级判断
if (mSecondList == null || mSecondList.Count == 0)
{
//一级
this.mFirstList = mFirstList;
//View显示
ShowOneBaseView();
//数据内容填充
RefreshOneBaseView();
}
else
{
if (mFirstList.Count != mSecondList.Count)
{
Utlis.WriteLine("数据 不联动异常");
return;
}
//二级联动
this.mFirstList = mFirstList;
this.mSecondList = mSecondList;
//View显示
ShowDoubleBaseView();
//数据内容填充
RefreshDoubleBaseView();
}
this.Show();
}
#region 二级联动选择效果
///
/// 显示二级view
///
void ShowDoubleBaseView()
{
bodyView.BackgroundColor = CSS_Color.DialogTransparentColor1;
this.AddChidren(bodyView);
bodyView.MouseUpEventHandler = (sender, e) =>
{
this.Close();
};
BackView = new FrameLayout()
{
X = Application.GetRealWidth(10),
Y = Application.GetRealHeight(104),
Width = Application.GetRealWidth(283),
Height = Application.GetRealWidth(242),
};
bodyView.AddChidren(BackView);
var backImageView = new ImageView(){
Width = BackView.Width,
Height = BackView.Height,
ImagePath = "Public/PopupDialog.png"
};
BackView.AddChidren(backImageView);
var leftAllButton = new Button()
{
Y = Application.GetRealWidth(14),
X = Application.GetRealWidth(24),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.CenterLeft,
TextID = StringId.All,
IsBold = true,
};
BackView.AddChidren(leftAllButton);
//分割线
var lineView1 = new FrameLayout()
{
Width = Application.GetRealWidth(112),
Height = Application.GetRealHeight(1),
Y = leftAllButton.Bottom,
X = leftAllButton.X,
BackgroundColor = CSS_Color.DividingLineColor,
};
BackView.AddChidren(lineView1);
leftScrolView = new VerticalScrolViewLayout()
{
X = Application.GetRealWidth(8),
Y = leftAllButton.Bottom,
Height = Application.GetRealWidth(176),
Width = Application.GetRealWidth(128),
VerticalScrollBarEnabled = false,
};
BackView.AddChidren(leftScrolView);
var rightAllButton = new Button()
{
Y = Application.GetRealWidth(58),
X = leftScrolView.Right + Application.GetRealWidth(12),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.CenterLeft,
TextID = StringId.All,
IsBold = true,
};
BackView.AddChidren(rightAllButton);
var lineView2 = new FrameLayout()
{
Width = Application.GetRealWidth(112),
Height = Application.GetRealHeight(1),
Y = rightAllButton.Y,
X = rightAllButton.X,
BackgroundColor = CSS_Color.DividingLineColor,
};
BackView.AddChidren(lineView2);
var lineView3 = new FrameLayout()
{
Width = Application.GetRealWidth(112),
Height = Application.GetRealHeight(1),
Y = rightAllButton.Bottom,
X = rightAllButton.X,
BackgroundColor = CSS_Color.DividingLineColor,
};
BackView.AddChidren(lineView3);
rightScrolView = new VerticalScrolViewLayout()
{
X = leftScrolView.Right + Application.GetRealWidth(12),
Y = Application.GetRealWidth(102),
Height = Application.GetRealWidth(132),
Width = Application.GetRealWidth(128),
VerticalScrollBarEnabled = false,
};
BackView.AddChidren(rightScrolView);
}
///
/// 刷新二级联动的VIEW
///
void RefreshDoubleBaseView()
{
leftScrolView.RemoveAll();
for (var i = 0; i < mFirstList.Count; i++)
{
AddSelectButton(leftScrolView, i, mFirstList[i], mSecondList[i]);
}
}
///
/// scrolView里面Button 选中效果互斥
///
void RefreshSelectButton(VerticalScrolViewLayout scrolView, string selectBtnTag)
{
try
{
if (scrolView != null)
{
for (int i = 0; i < scrolView.ChildrenCount; i++)
{
if (scrolView.GetChildren(i).GetType() == typeof(FrameLayout))
{
var cellView = (FrameLayout)scrolView.GetChildren(i);
for (int j = 0; j < cellView.ChildrenCount; j++)
{
if (cellView.GetChildren(j).GetType() == typeof(Button))
{
var titleButton = (Button)cellView.GetChildren(j);
var o = titleButton.GetTagByKey("BtnKey");
if (o != null && o.ToString() == selectBtnTag)
{
titleButton.IsSelected = true;
}
else
{
titleButton.IsSelected = false;
}
}
}
}
}
}
}
catch
{
}
}
///
/// 添加一级楼层选择CellView
///
///
void AddSelectButton(VerticalScrolViewLayout scrolView, int firstIndex, string firstText, List rightList)
{
var cellView = new FrameLayout()
{
Height = Application.GetRealWidth(44),
Tag = "cell"
};
scrolView.AddChidren(cellView);
var titleButton = new Button()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.FirstLevelTitleColor,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.TextFontSize,
TextAlignment = TextAlignment.CenterLeft,
Text = firstText,
};
cellView.AddChidren(titleButton);
titleButton.AddTag("BtnKey", firstIndex.ToString());
//顶部分割线
var lineView = new FrameLayout()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealHeight(1),
Width = Application.GetRealWidth(112),
BackgroundColor = CSS_Color.DividingLineColor,
Y = cellView.Height - Application.GetRealHeight(1),
};
cellView.AddChidren(lineView);
EventHandler eventHandler = (sender, e) =>
{
//cellView.BackgroundColor = CSS_Color.viewTranslucence;
RefreshSelectButton(scrolView, firstIndex.ToString());
LoadRightScrolView(firstIndex, rightList);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
//EventHandler mousDownEventHandler = (sender, e) =>
//{
// cellView.BackgroundColor = CSS_Color.TopViewColor;
//};
//titleButton.MouseDownEventHandler = mousDownEventHandler;
//cellView.MouseDownEventHandler = mousDownEventHandler;
}
///
/// 加载二级滑动View
///
/// 一级的索引
/// 二级对应一级的List
void LoadRightScrolView(int firstIndex, List rightList)
{
rightScrolView.RemoveAll();
for (var i = 0; i < rightList.Count; i++)
{
AddRightSelectButton(rightScrolView, firstIndex, rightList[i], i);
}
}
///
/// 添加二级选择CellView
///
///
///
///
///
void AddRightSelectButton(VerticalScrolViewLayout scrolView, int firstIndex, string secondText, int secondIndex)
{
var cellView = new FrameLayout()
{
Height = Application.GetRealWidth(44),
};
scrolView.AddChidren(cellView);
var titleButton = new Button()
{
//X = Application.GetRealWidth(16),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextAlignment = TextAlignment.CenterLeft,
Text = secondText,
};
cellView.AddChidren(titleButton);
var lineView = new FrameLayout()
{
Width = Application.GetRealWidth(112),
Height = Application.GetRealHeight(1),
Y = cellView.Height - Application.GetRealHeight(1),
BackgroundColor = CSS_Color.DividingLineColor,
};
cellView.AddChidren(lineView);
EventHandler eventHandler = (sender, e) =>
{
this.Close();
//回调选中索引
SelectAction?.Invoke(firstIndex, secondIndex);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
//EventHandler mousDownEventHandler = (sender, e) =>
//{
// cellView.BackgroundColor = CSS_Color.TopViewColor;
//};
//titleButton.MouseDownEventHandler = mousDownEventHandler;
//cellView.MouseDownEventHandler = mousDownEventHandler;
}
#endregion
#region 只有一级的联动
///
/// 都显示一级的
///
void ShowOneBaseView()
{
bodyView.BackgroundColor = CSS_Color.DialogTransparentColor1;
this.AddChidren(bodyView);
bodyView.MouseUpEventHandler = (sender, e) =>
{
this.Close();
};
BackView = new FrameLayout()
{
X = Application.GetRealWidth(10),
Y = Application.GetRealHeight(104),
Width = Application.GetRealWidth(160),
Height = Application.GetRealWidth(198),
};
bodyView.AddChidren(BackView);
var backImageView = new ImageView()
{
Width = BackView.Width,
Height = BackView.Height,
ImagePath = "PersonalCenter/HomeList3bg.png"
};
BackView.AddChidren(backImageView);
var leftAllButton = new Button()
{
Y = Application.GetRealWidth(14),
X = Application.GetRealWidth(24),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextAlignment = TextAlignment.CenterLeft,
TextID = StringId.All,
IsBold = true,
};
BackView.AddChidren(leftAllButton);
//分割线
var lineView1 = new FrameLayout()
{
Width = Application.GetRealWidth(112),
Height = Application.GetRealHeight(1),
Y = leftAllButton.Bottom,
X = leftAllButton.X,
BackgroundColor = CSS_Color.DividingLineColor,
};
BackView.AddChidren(lineView1);
leftScrolView = new VerticalScrolViewLayout()
{
X = Application.GetRealWidth(8),
Y = leftAllButton.Bottom,
Height = Application.GetRealWidth(132),
Width = Application.GetRealWidth(144),
VerticalScrollBarEnabled = false,
};
BackView.AddChidren(leftScrolView);
}
void RefreshOneBaseView()
{
leftScrolView.RemoveAll();
for (var i = 0; i < mFirstList.Count; i++)
{
AddOneSelectButton(leftScrolView, i, mFirstList[i]);
}
}
///
/// 添加一级楼层选择CellView
///
///
///
///
void AddOneSelectButton(VerticalScrolViewLayout scrolView, int firstIndex, string firstText)
{
var cellView = new FrameLayout()
{
Height = Application.GetRealWidth(44),
Tag = "cell"
};
scrolView.AddChidren(cellView);
var titleButton = new Button()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealWidth(44),
TextColor = CSS_Color.FirstLevelTitleColor,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.TextFontSize,
TextAlignment = TextAlignment.CenterLeft,
Text = firstText,
};
cellView.AddChidren(titleButton);
titleButton.AddTag("BtnKey", firstIndex.ToString());
//顶部分割线
var lineView = new FrameLayout()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealHeight(1),
Width = Application.GetRealWidth(112),
BackgroundColor = CSS_Color.DividingLineColor,
Y = cellView.Height - Application.GetRealHeight(1),
};
cellView.AddChidren(lineView);
EventHandler eventHandler = (sender, e) =>
{
this.Close();
//回调选中索引
SelectAction?.Invoke(firstIndex, 0);
};
titleButton.MouseUpEventHandler = eventHandler;
cellView.MouseUpEventHandler = eventHandler;
//EventHandler mousDownEventHandler = (sender, e) =>
//{
// cellView.BackgroundColor = CSS_Color.TopViewColor;
//};
//titleButton.MouseDownEventHandler = mousDownEventHandler;
//cellView.MouseDownEventHandler = mousDownEventHandler;
}
#endregion
#region 选择楼层和房间专用
#endregion
}
}