gxc
2019-10-29 081ea8d273048fd03756718ac6fb48a3c09218e9
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 个人中心的共通基层画面,继承于此共通的画面,请使用AddForm()函数,
    /// 或者AddFromAndRemoveNowForm()函数实现添加画面,然后在各自的画面中,
    /// 实现一个ShowForm()的函数(参数由添加画面时,使用的函数的参数指定)
    /// </summary>
    public class EditorCommonForm : CommonFormBase
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// TopMenuFrameLayout
        /// </summary>
        public FrameLayout topMenuFrameLayout = null;
        /// <summary>
        /// TopFrameLayout
        /// </summary>
        public FrameLayout topFrameLayout = null;
        /// <summary>
        /// bodyFrameLayout
        /// </summary>
        public FrameLayout bodyFrameLayout = null;
        /// <summary>
        /// 缓存启动参数
        /// </summary>
        private object[] m_parameter = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化界面框架
        /// </summary>
        public override void InitForm()
        {
            base.InitForm();
 
            //初始化头部控件
            this.InitTopFrameLayout();
 
            //初始化中部控件
            this.InitBodyFrameLayout();
        }
 
        /// <summary>
        /// 执行ShowForm()方法
        /// </summary>
        /// <param name="parameter">启动参数</param>
        public override void LoadShowFormMethod(params object[] parameter)
        {
            this.m_parameter = parameter;
            base.LoadShowFormMethod(parameter);
        }
 
        #endregion
 
        #region ■ 初始化界面_________________________
 
        #region ■ Top________________________________
 
        /// <summary>
        /// 初始化头部控件
        /// </summary>
        public void InitTopFrameLayout()
        {
            if (topFrameLayout != null)
            {
                topFrameLayout.RemoveAll();
            }
 
            //TopMenuFrameLayout做成
            topMenuFrameLayout = new FrameLayout();
            topMenuFrameLayout.Height = ControlCommonResourse.TopMenuFrameHeight;
            topMenuFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
            topMenuFrameLayout.Name = "topMenuFrameLayout";
            this.AddChidren(topMenuFrameLayout);
 
            //TopFrameLayout做成
            topFrameLayout = new FrameLayout();
            topFrameLayout.Height = ControlCommonResourse.TopFrameHeight;
            topFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
            topFrameLayout.Y = topMenuFrameLayout.Bottom;
            topFrameLayout.Name = "topFrameLayout";
            this.AddChidren(topFrameLayout);
 
            //返回键
            var btnBack = new BackViewControl();
            topFrameLayout.AddChidren(btnBack);
            btnBack.InitControl();
            btnBack.ButtonClickEvent += (sender, e) =>
            {
                //画面关闭
                this.CloseForm();
            };
            topFrameLayout.AddTag("btnBack", btnBack);
 
            //标题
            var txttitle = new TopLayoutTitleControl();
            topFrameLayout.AddChidren(txttitle);
            topFrameLayout.AddTag("txtTitle", txttitle);
        }
 
        #endregion
 
        #region ■ Middle_____________________________
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        public void InitBodyFrameLayout()
        {
            if (bodyFrameLayout != null)
            {
                bodyFrameLayout.RemoveAll();
            }
            bodyFrameLayout = new FrameLayout();
            bodyFrameLayout.Height = ControlCommonResourse.BodyFrameHeight;
            bodyFrameLayout.Y = topFrameLayout.Bottom;
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            bodyFrameLayout.Name = "bodyFrameLayout";
            this.AddChidren(bodyFrameLayout);
        }
 
        #endregion
 
        #endregion
 
        #region ■ 添加界面___________________________
 
        /// <summary>
        /// 添加画面,启动参数由指定画面的ShowForm函数所指定
        /// </summary>
        /// <param name="parameter">启动参数:参数由指定画面的ShowForm函数所指定</param>
        public override void AddForm(params object[] parameter)
        {
            //检测能否追加画面
            if (UserCenterLogic.CheckCanAddForm(this) == false)
            {
                return;
            }
 
            UserView.HomePage.Instance.AddChidren(this);
            UserView.HomePage.Instance.PageIndex += 1;
 
            //初始化界面框架
            this.InitForm();
 
            //执行ShowForm()方法
            this.LoadShowFormMethod(parameter);
        }
 
        #endregion
 
        #region ■ 关闭界面___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        {
            this.m_parameter = null;
            //清空bodyFrame
            this.ClearBodyFrame();
 
            base.CloseForm();
        }
 
        #endregion
 
        #region ■ 显示重新加载_______________________
 
        /// <summary>
        /// 显示重新加载的界面(主要是用在界面加载错误时,再次加载)
        /// </summary>
        public override void ShowReLoadView()
        {
            Application.RunOnMainThread(() =>
            {
                if (bodyFrameLayout == null || bodyFrameLayout.Parent == null)
                {
                    return;
                }
                //切换为重新加载模式时的事件
                this.ReLoadModelEventMethod();
 
                var frame = new FrameLayout();
                frame.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frame);
 
                //重新加载
                var btnReLoad = new BottomClickButton();
                btnReLoad.Gravity = Gravity.Center;
                btnReLoad.TextID = R.MyInternationalizationString.uDoReload;
                frame.AddChidren(btnReLoad);
                btnReLoad.ButtonClickEvent += (sender, e) =>
                {
                    //清除全部控件
                    this.ClearBodyFrame();
 
                    //执行ShowForm()方法实现重新加载
                    this.LoadShowFormMethod(this.m_parameter);
                };
 
                //清除topFrameLayout的非默认的控件
                var list = new List<View>();
                for (int i = 0; i < topFrameLayout.ChildrenCount; i++)
                {
                    var view = topFrameLayout.GetChildren(i);
                    if (view.Name == "btnBack" || view.Name == "txtTitle")
                    {
                        //这里是默认的底层控件
                        continue;
                    }
                    list.Add(view);
                }
                foreach (var view in list)
                {
                    view?.RemoveFromParent();
                }
            });
        }
 
        /// <summary>
        /// 切换为【重新加载模式】时的事件函数,旨在关闭所有线程信息
        /// </summary>
        public virtual void ReLoadModelEventMethod()
        {
        }
 
        #endregion
 
        #region ■ 显示没有数据的图像显示特效_________
 
        /// <summary>
        /// 显示没有数据的图像显示特效
        /// </summary>
        /// <param name="frameTable">容器</param>
        /// <param name="i_Text">显示文字</param>
        /// <param name="Imagepath">图像地址</param>
        /// <param name="imageWith">图像宽度(非真实值)</param>
        /// <param name="imageHeight">图像高度(非真实值)</param>
        public void ShowNotDataImage(FrameLayout frameTable, string i_Text, string Imagepath = "Item/NoFunction.png", int imageWith = 683, int imageHeight = 392)
        {
            //还没有绑定网关哦
            var btnPic = new PicViewControl(imageWith, imageHeight);
            btnPic.UnSelectedImagePath = Imagepath;
            btnPic.Y = (int)(frameTable.Height * 0.382) - Application.GetRealHeight(imageHeight / 2);
            btnPic.Gravity = Gravity.CenterHorizontal;
            frameTable.AddChidren(btnPic);
 
            var btnView = new NormalViewControl(frameTable.Width, Application.GetRealHeight(50), false);
            btnView.Y = btnPic.Bottom + Application.GetRealHeight(32);
            btnView.Text = i_Text;
            btnView.TextAlignment = TextAlignment.Center;
            btnView.TextSize = 12;
            btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
            frameTable.AddChidren(btnView);
            return;
        }
        #endregion
 
        #region ■ 清空BodyFrame______________________
 
        /// <summary>
        /// 清空BodyFrame
        /// </summary>
        public void ClearBodyFrame()
        {
            if (this.Parent == null)
            {
                return;
            }
            bodyFrameLayout?.RemoveAll();
        }
 
        #endregion
 
        #region ■ 一般的方法_________________________
 
        /// <summary>
        /// 设置标题信息
        /// </summary>
        /// <param name="title">Title.</param>
        public void SetTitleText(string title)
        {
            //设置头部信息
            var btntitle = (Button)topFrameLayout.GetTagByKey("txtTitle");
            btntitle.Text = title;
        }
 
        /// <summary>
        /// 移除返回键
        /// </summary>
        public void RemoveBackButton()
        {
            //移除返回键
            var back = (BackViewControl)topFrameLayout.GetTagByKey("btnBack");
            back?.RemoveFromParent();
        }
 
        #endregion
    }
}