HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-30 3dcbd186c42c598c0c08d1cd37034cf2baa09e54
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 场景和功能之间相互切换的Tab控件(完成初始化后,会根据默认选择调用回调函数)
    /// </summary>
    public class SceneFunctionSwitchControl : FrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 选择事件 1:场景  2:功能
        /// </summary>
        public Action<int> SelectTabEvent = null;
 
        private int m_nowSelectIndex = 1;
        /// <summary>
        /// 当前选择的分支 1:场景  2:功能
        /// </summary>
        public int nowSelectIndex
        {
            get { return m_nowSelectIndex; }
        }
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 场景和功能之间相互切换的Tab控件(完成初始化后,会根据默认选择调用回调函数)
        /// </summary>
        public SceneFunctionSwitchControl()
        {
            this.Height = Application.GetRealHeight(90);
        }
 
        /// <summary>
        /// 初始化控件(事件要至于它之前)
        /// </summary>
        public void InitControl()
        {
            var btnTemp = new NormalViewControl(10, 10, false);
            btnTemp.TextSize = 16;
            btnTemp.TextID = R.MyInternationalizationString.uScence;
 
            //场景框(点击范围有点小,需要扩大它的点击范围)
            var frameScene = new FrameLayoutControl();
            frameScene.UseClickStatu = false;
            frameScene.Height = Application.GetRealHeight(90);
            frameScene.Width = btnTemp.GetRealWidthByText();
            frameScene.X = ControlCommonResourse.XXLeft;
            this.AddChidren(frameScene);
            //场景
            var btnScene = new NormalViewControl(frameScene.Width, Application.GetRealHeight(63), false);
            btnScene.Text = btnTemp.Text;
            btnScene.TextSize = 16;
            btnScene.IsBold = true;
            btnScene.TextColor = UserCenterColor.Current.TextColor2;
            frameScene.AddChidren(btnScene, ChidrenBindMode.BindEventOnly);
            //底线
            var btnSceneLine = new NormalViewControl(40, 10, true);
            btnSceneLine.Y = btnScene.Bottom + Application.GetRealHeight(14);
            btnSceneLine.X = btnScene.X + btnScene.Width / 2 - Application.GetRealWidth(40) / 2;
            btnSceneLine.Radius = (uint)Application.GetRealHeight(10) / 2;
            btnSceneLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            frameScene.AddChidren(btnSceneLine, ChidrenBindMode.BindEventOnly);
 
            btnTemp.TextID = R.MyInternationalizationString.uFunction;
            //功能框(点击范围有点小,需要扩大它的点击范围)
            var frameFunc = new FrameLayoutControl();
            frameFunc.UseClickStatu = false;
            frameFunc.Height = Application.GetRealHeight(90);
            frameFunc.Width = btnTemp.GetRealWidthByText();
            frameFunc.X = frameScene.Right + Application.GetRealWidth(58);
            this.AddChidren(frameFunc);
            //功能
            var btnFunc = new NormalViewControl(frameFunc.Width, Application.GetRealHeight(63), false);
            btnFunc.Text = btnTemp.Text;
            btnFunc.TextColor = UserCenterColor.Current.TextGrayColor3;
            frameFunc.AddChidren(btnFunc, ChidrenBindMode.BindEventOnly);
            //底线
            var btnFuncLine = new NormalViewControl(40, 10, true);
            btnFuncLine.Y = btnFunc.Bottom + Application.GetRealHeight(14);
            btnFuncLine.X = btnFunc.X + btnFunc.Width / 2 - Application.GetRealWidth(40) / 2;
            btnFuncLine.Radius = (uint)Application.GetRealHeight(10) / 2;
            btnFuncLine.BackgroundColor = UserCenterColor.Current.TextOrangeColor;
            frameFunc.AddChidren(btnFuncLine, ChidrenBindMode.BindEventOnly);
            btnFuncLine.Visible = false;
 
            frameScene.ButtonClickEvent += (sender, e) =>
            {
                //场景分支选择
                if (this.m_nowSelectIndex == 1)
                {
                    return;
                }
                this.m_nowSelectIndex = 1;
 
                btnScene.TextSize = 16;
                btnScene.IsBold = true;
                btnScene.TextColor = UserCenterColor.Current.TextColor2;
                btnFunc.TextSize = 14;
                btnFunc.IsBold = false;
                btnFunc.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnSceneLine.Visible = true;
                btnFuncLine.Visible = false;
 
                this.SelectTabEvent?.Invoke(1);
            };
 
            frameFunc.ButtonClickEvent += (sender, e) =>
            {
                //功能分支选择
                if (this.m_nowSelectIndex == 2)
                {
                    return;
                }
                this.m_nowSelectIndex = 2;
 
                btnScene.TextSize = 14;
                btnScene.IsBold = false;
                btnScene.TextColor = UserCenterColor.Current.TextGrayColor3;
                btnFunc.TextSize = 16;
                btnFunc.IsBold = true;
                btnFunc.TextColor = UserCenterColor.Current.TextColor2;
                btnFuncLine.Visible = true;
                btnSceneLine.Visible = false;
 
                this.SelectTabEvent?.Invoke(2);
            };
            //回调方法
            if (this.m_nowSelectIndex == 1)
            {
                this.m_nowSelectIndex = 0;
                frameScene.ButtonClickEvent?.Invoke(null, null);
            }
            if (this.m_nowSelectIndex == 2)
            {
                this.m_nowSelectIndex = 0;
                frameFunc.ButtonClickEvent?.Invoke(null, null);
            }
        }
 
        #endregion
 
        #region ■ 控件摧毁___________________________
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.SelectTabEvent = null;
 
            base.RemoveFromParent();
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 设置初始选择(请在初始化完成之前调用)
        /// </summary>
        /// <param name="index">1:场景  2:功能</param>
        public void SetDefultIndex(int index)
        {
            this.m_nowSelectIndex = index;
        }
 
        #endregion
    }
}