黄学彪
2019-11-25 160785587667cc0d927f85e44c139ec9dde13a9e
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// <para>做成一个弹窗型,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件</para>
    /// <para>New的时候,就已经加入到了界面</para>
    /// </summary>
    public class DialogInputControl : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 确认按钮事件
        /// </summary>
        public Action<string> ComfirmClickEvent;
        /// <summary>
        /// 输入框的文本信息
        /// </summary>
        public string Text
        {
            get { return txtInput.Text.Trim(); }
            set { this.txtInput.Text = value; }
        }
 
        /// <summary>
        /// 输入框控件
        /// </summary>
        private TextInputControl txtInput = null;
        /// <summary>
        /// 标题控件
        /// </summary>
        private NormalViewControl btnTitle = null;
        /// <summary>
        /// 取消按钮
        /// </summary>
        private NormalViewControl btnCancel = null;
        /// <summary>
        /// 确认按钮
        /// </summary>
        private NormalViewControl btnConfirm = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// <para>做成一个弹窗型,左下角是【取消按钮】,右下角是【确认按钮】的弹窗控件</para>
        /// <para>New的时候,就已经加入到了界面</para>
        /// </summary>
        public DialogInputControl()
        {
            //添加界面
            var nowForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1);
            if (nowForm == null || (nowForm is ViewGroup) == false)
            {
                return;
            }
            this.BackgroundColor = UserCenterColor.Current.DialogBackColor;
            ((ViewGroup)nowForm).AddChidren(this);
 
            //白色背景框
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(507);
            frameBack.Width = Application.GetRealWidth(792);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Y = Application.GetRealHeight(691);
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Radius = 8;
            this.AddChidren(frameBack);
            //标题信息
            this.btnTitle = new NormalViewControl(frameBack.Width, Application.GetRealHeight(65), false);
            btnTitle.Y = Application.GetRealHeight(68);
            btnTitle.TextColor = UserCenterColor.Current.TextColor1;
            btnTitle.TextSize = 16;
            btnTitle.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnTitle);
 
            //初始化边框
            var frameText = new FrameLayout();
            frameText.Width = Application.GetRealWidth(677);
            frameText.Height = Application.GetRealHeight(100);
            frameText.Y = Application.GetRealHeight(198);
            frameText.Gravity = Gravity.CenterHorizontal;
            frameText.BorderColor = 0xff676767;
            frameText.BorderWidth = 1;
            frameText.Radius = 8;
            frameBack.AddChidren(frameText);
            //输入框
            this.txtInput = new TextInputControl(frameText.Width - Application.GetRealWidth(20), frameText.Height, false);
            txtInput.TextAlignment = TextAlignment.Center;
            txtInput.Gravity = Gravity.CenterHorizontal;
            frameText.AddChidren(txtInput);
 
            //取消
            var frameCancel = new FrameLayoutControl();
            frameCancel.Height = Application.GetRealHeight(127);
            frameCancel.Width = Application.GetRealWidth(396);
            frameCancel.Gravity = Gravity.BottomLeft;
            frameCancel.Radius = 8;
            frameCancel.BackgroundColor = 0xfff5f6fa;
            frameBack.AddChidren(frameCancel);
            //把上圆角覆盖为方角
            var btnTopTemp1 = new NormalViewControl(frameCancel.Width, Application.GetRealHeight(40), false);
            btnTopTemp1.BackgroundColor = 0xfff5f6fa;
            frameCancel.AddChidren(btnTopTemp1, ChidrenBindMode.BindEventOnly);
            //把右下圆角覆盖为方角
            var btnBomTemp1 = new NormalViewControl(frameCancel.Width / 2, Application.GetRealHeight(40), false);
            btnBomTemp1.BackgroundColor = 0xfff5f6fa;
            btnBomTemp1.Gravity = Gravity.BottomRight;
            frameCancel.AddChidren(btnBomTemp1, ChidrenBindMode.BindEventOnly);
            //取消按钮
            this.btnCancel = new NormalViewControl(frameCancel.Width - Application.GetRealWidth(10), Application.GetRealHeight(60), false);
            btnCancel.Gravity = Gravity.Center;
            btnCancel.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnCancel.TextID = R.MyInternationalizationString.uCancel;
            btnCancel.TextAlignment = TextAlignment.Center;
            btnCancel.BackgroundColor = 0xfff5f6fa;
            frameCancel.AddChidren(btnCancel, ChidrenBindMode.BindEventOnly);
            frameCancel.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                this.CloseDialog();
            };
            //重写控件点击状态
            frameCancel.SelectStatuEvent += (statu) =>
            {
                if (statu == true)
                {
                    frameCancel.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnTopTemp1.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnBomTemp1.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnCancel.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                }
                else
                {
                    frameCancel.BackgroundColor = 0xfff5f6fa;
                    btnTopTemp1.BackgroundColor = 0xfff5f6fa;
                    btnBomTemp1.BackgroundColor = 0xfff5f6fa;
                    btnCancel.BackgroundColor = 0xfff5f6fa;
                }
            };
 
            //确认
            var frameConfirm = new FrameLayoutControl();
            frameConfirm.Height = Application.GetRealHeight(127);
            frameConfirm.Width = Application.GetRealWidth(396);
            frameConfirm.Gravity = Gravity.BottomRight;
            frameConfirm.Radius = 8;
            frameConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            frameBack.AddChidren(frameConfirm);
            //把上圆角覆盖为方角
            var btnTopTemp2 = new NormalViewControl(frameConfirm.Width, Application.GetRealHeight(40), false);
            btnTopTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            frameConfirm.AddChidren(btnTopTemp2, ChidrenBindMode.BindEventOnly);
            //把左下圆角覆盖为方角
            var btnBomTemp2 = new NormalViewControl(frameConfirm.Width / 2, Application.GetRealHeight(40), false);
            btnBomTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
            btnBomTemp2.Gravity = Gravity.BottomLeft;
            frameConfirm.AddChidren(btnBomTemp2, ChidrenBindMode.BindEventOnly);
            //确认按钮
            this.btnConfirm = new NormalViewControl(frameConfirm.Width - Application.GetRealWidth(10), Application.GetRealHeight(60), false);
            btnConfirm.Gravity = Gravity.Center;
            btnConfirm.TextColor = UserCenterColor.Current.White;
            btnConfirm.TextID = R.MyInternationalizationString.OkMsg;
            btnConfirm.TextAlignment = TextAlignment.Center;
            frameConfirm.AddChidren(btnConfirm, ChidrenBindMode.BindEventOnly);
            frameConfirm.ButtonClickEvent += (sender, e) =>
            {
                if (this.Text == string.Empty && string.IsNullOrEmpty(this.txtInput.PlaceholderText) == false)
                {
                    var alert = new ShowMsgControl(ShowMsgType.Tip, this.txtInput.PlaceholderText);
                    alert.Show();
                    return;
                }
                //回调函数
                this.ComfirmClickEvent?.Invoke(this.Text);
            };
            //重写控件点击状态
            frameConfirm.SelectStatuEvent += (statu) =>
            {
                if (statu == true)
                {
                    frameConfirm.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnTopTemp2.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnBomTemp2.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                    btnConfirm.BackgroundColor = UserCenterColor.Current.ButtonClickStatuColor;
                }
                else
                {
                    frameConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
                    btnTopTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
                    btnBomTemp2.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
                    btnConfirm.BackgroundColor = UserCenterColor.Current.ClickButtonDefultColor;
                }
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public void CloseDialog()
        {
            this.ComfirmClickEvent = null;
            this.RemoveFromParent();
        }
 
        #endregion
 
        #region ■ 设置信息___________________________
 
        /// <summary>
        /// 设置标题信息
        /// </summary>
        /// <param name="txtValue"></param>
        public void SetTitleText(string txtValue)
        {
            this.btnTitle.Text = txtValue;
        }
        /// <summary>
        /// 设置取消按钮的文本信息
        /// </summary>
        /// <param name="txtValue"></param>
        public void SetCancelButtonText(string txtValue)
        {
            this.btnCancel.Text = txtValue;
        }
 
        /// <summary>
        /// 设置确定按钮的文本信息
        /// </summary>
        /// <param name="txtValue"></param>
        public void SetOkButtonText(string txtValue)
        {
            this.btnConfirm.Text = txtValue;
        }
 
        /// <summary>
        /// 设置输入框灰色字体说明
        /// </summary>
        /// <param name="txtValue"></param>
        public void SetTipText(string txtValue)
        {
            if (this.txtInput != null)
            {
                this.txtInput.PlaceholderText = txtValue;
            }
        }
 
        #endregion
    }
}