黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.Login.Controls
{
    /// <summary>
    /// 登陆界面的手机号和邮箱来回切换的控件
    /// </summary>
    public class PhoneEmailSelectControl : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 菜单选择事件 1:手机号 2:邮箱
        /// </summary>
        public Action<int> SelectMenuEvent = null;
        /// <summary>
        /// 手机分支是否能用
        /// </summary>
        public bool PhoneEnable
        {
            set { if (btnPhone != null) { btnPhone.CanClick = false; } }
        }
        /// <summary>
        /// 邮箱分支是否能用
        /// </summary>
        public bool EmailEnable
        {
            set { if (btnEmail != null) { btnEmail.CanClick = false; } }
        }
        /// <summary>
        /// 手机号控件
        /// </summary>
        private NormalViewControl btnPhone = null;
        /// <summary>
        /// 邮箱控件
        /// </summary>
        private NormalViewControl btnEmail = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 登陆界面的手机号和邮箱来回切换的控件
        /// </summary>
        public PhoneEmailSelectControl()
        {
            this.Width = HdlControlLogic.Current.GetPictrueRealSize(905);
            this.Height = HdlControlLogic.Current.GetPictrueRealSize(170);
            this.Gravity = Gravity.CenterHorizontal;
            this.BackgroundImagePath = "Account/PhoneEmail_White.png";
        }
 
        /// <summary>
        /// 初始化控件(索引会触发回调事件,SelectMenuEvent需要在它之前实现)
        /// </summary>
        /// <param name="selectBackColor">选择时的背景颜色</param>
        /// <param name="selectIndex">默认选择的索引 1:手机号  2:邮箱</param>
        public void InitControl(uint selectBackColor,int selectIndex)
        {
            //手机号
            this.btnPhone = new NormalViewControl(HdlControlLogic.Current.GetPictrueRealSize(467), HdlControlLogic.Current.GetPictrueRealSize(127), false);
            btnPhone.X = HdlControlLogic.Current.GetPictrueRealSize(10);
            btnPhone.SelectedBackgroundColor = selectBackColor;
            btnPhone.TextID = R.MyInternationalizationString.PhoneNum;
            btnPhone.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnPhone.SelectedTextColor = UserCenterColor.Current.White;
            btnPhone.TextAlignment = TextAlignment.Center;
            btnPhone.Radius = (uint)HdlControlLogic.Current.GetPictrueRealSize(127) / 2;
            this.AddChidren(btnPhone);
            btnPhone.ButtonClickEvent += (sender, e) =>
            {
                if (btnPhone.IsSelected == false)
                {
                    btnPhone.IsBold = true;
                    btnPhone.IsSelected = true;
 
                    btnEmail.IsBold = false;
                    btnEmail.IsSelected = false;
                    //调用回调函数
                    this.SelectMenuEvent?.Invoke(1);
                }
            };
 
            //邮箱
            this.btnEmail = new NormalViewControl(this.btnPhone.Width, this.btnPhone.Height, false);
            btnEmail.X = this.Width - this.btnPhone.Width - HdlControlLogic.Current.GetPictrueRealSize(10);
            btnEmail.SelectedBackgroundColor = selectBackColor;
            btnEmail.TextID = R.MyInternationalizationString.Email;
            btnEmail.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnEmail.SelectedTextColor = UserCenterColor.Current.White;
            btnEmail.TextAlignment = TextAlignment.Center;
            btnEmail.Radius = (uint)HdlControlLogic.Current.GetPictrueRealSize(127) / 2;
            this.AddChidren(btnEmail);
            btnEmail.ButtonClickEvent += (sender, e) =>
            {
                if (btnEmail.IsSelected == false)
                {
                    btnPhone.IsBold = false;
                    btnPhone.IsSelected = false;
 
                    btnEmail.IsBold = true;
                    btnEmail.IsSelected = true;
                    //调用回调函数
                    this.SelectMenuEvent?.Invoke(2);
                }
            };
 
            //设置选择状态
            this.SetSelectIndex(selectIndex);
        }
 
        #endregion
 
        #region ■ 设置选择状态_______________________
 
        /// <summary>
        /// 设置选择状态(1:手机号 2:邮箱)
        /// </summary>
        /// <param name="i_index">1:手机号 2:邮箱</param>
        public void SetSelectIndex(int i_index)
        {
            //设置初始值
            if (i_index == 1)
            {
                btnPhone.IsBold = true;
                btnPhone.IsSelected = true;
                if (btnEmail.IsSelected == true)
                {
                    btnEmail.IsBold = false;
                    btnEmail.IsSelected = false;
                }
                //调用回调函数
                this.SelectMenuEvent?.Invoke(1);
            }
            else if (i_index == 2)
            {
                btnEmail.IsBold = true;
                btnEmail.IsSelected = true;
                if (btnPhone.IsSelected == true)
                {
                    btnPhone.IsBold = false;
                    btnPhone.IsSelected = false;
                }
                //调用回调函数
                this.SelectMenuEvent?.Invoke(2);
            }
        }
 
        #endregion
 
        #region ■ 控件摧毁___________________________
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.SelectMenuEvent = null;
 
            base.RemoveFromParent();
        }
 
        #endregion
    }
}