黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 底部弹窗项目选择界面(列表数尽可能别弄那么多)
    /// </summary>
    public class BottomItemSelectForm : DialogCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 完成选择的事件(参数为选择的是列表的第几行,从0开始)
        /// </summary>
        public Action<int> FinishSelectEvent = null;
        /// <summary>
        /// 前回选择的控件
        /// </summary>
        private NormalSelectControl oldSelectContr = null;
        /// <summary>
        /// 选择取消(不是左下角),并且按下确定键时,是否调用回调函数(调用时传递的参数是 -1,默认不回调)
        /// </summary>
        public bool CancelCallEvent = false;
        /// <summary>
        /// 选择的行能否取消
        /// </summary>
        public bool SelectRowCanCancel = true;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_topText">头部标题</param>
        /// <param name="i_listText">需要显示的列表信息(列表数尽可能别弄那么多)</param>
        /// <param name="i_selectNo">设置哪个文本为默认选择(不设置填-1)</param>
        public void ShowForm(string i_topText, List<string> i_listText, int i_selectNo)
        {
            //初始化中部信息
            this.InitMiddleFrame(i_topText, i_listText, i_selectNo);
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        /// <param name="i_topText">头部标题</param>
        /// <param name="i_listText">需要显示的列表信息</param>
        /// <param name="i_selectNo">默认选择</param>
        private void InitMiddleFrame(string i_topText, List<string> 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
    }
}