HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-11-04 c7698e163e43cea9e7f8ee45f8e3f91c9265cca4
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 一个能够进行裁剪图片的控件
    /// </summary>
    public class CutPictureControl : ImageView
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 选择图片的事件
        /// </summary>
        public Action<string> SelectPictrueEvent = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 一个能够进行裁剪图片的控件
        /// </summary>
        /// <param name="saveFullFileName">保存裁剪图片的文件名(全路径)</param>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public CutPictureControl(string saveFullFileName, int i_Width, int i_Height, bool real = true)
        {
            if (real == true)
            {
                i_Width = Application.GetMinRealAverage(i_Width);
                i_Height = Application.GetMinRealAverage(i_Height);
            }
            this.Height = i_Height;
            this.Width = i_Width;
 
            this.MouseUpEventHandler += (sender, e) =>
            {
                //显示获取图片来源的方式
                this.ShowGetPictrueWayMenu(saveFullFileName);
            };
        }
 
        #endregion
 
        #region ■ 显示获取图片来源的方式_____________
 
        /// <summary>
        /// 显示获取图片来源的方式
        /// </summary>
        /// <param name="saveFullFileName">保存裁剪图片的文件名(全路径)</param>
        private void ShowGetPictrueWayMenu(string saveFullFileName)
        {
            //自定义菜单控件
            var form = new PictrueWayMenuControl();
            form.AddForm();
            form.SelectPictrueEvent += (selectPic) =>
            {
                try
                {
                    if (System.IO.File.Exists(saveFullFileName) == true)
                    {
                        System.IO.File.Delete(saveFullFileName);
                    }
                    //移动文件
                    System.IO.File.Move(selectPic, saveFullFileName);
 
                    //改变图片
                    this.ImagePath = saveFullFileName;
                    //调用回调函数
                    this.SelectPictrueEvent?.Invoke(saveFullFileName);
                }
                catch (Exception ex)
                {
                    //出现未知错误
                    var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                    alert.Show();
                    //Log
                    HdlLogLogic.Current.WriteLog(ex);
                }
            };
        }
 
        #endregion
 
        #region ■ 控件摧毁___________________________
 
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.SelectPictrueEvent = null;
 
            base.RemoveFromParent();
        }
 
        #endregion
 
        #region ■ 菜单控件___________________________
 
        /// <summary>
        /// 菜单控件
        /// </summary>
        private class PictrueWayMenuControl : DialogCommonForm
        {
            #region ■ 变量声明___________________________
 
            /// <summary>
            /// 选择图片的事件
            /// </summary>
            public Action<string> SelectPictrueEvent = null;
 
            #endregion
 
            #region ■ 初始化_____________________________
 
            /// <summary>
            /// 画面显示(底层会固定调用此方法,借以完成画面创建)
            /// </summary>
            public void ShowForm()
            {
                var frameBack1 = new FrameLayoutControl();
                frameBack1.UseClickStatu = false;
                frameBack1.Y = Application.GetRealHeight(1420);
                frameBack1.Gravity = Gravity.CenterHorizontal;
                frameBack1.RadiusEx = 12;
                frameBack1.Width = Application.GetRealWidth(1034);
                frameBack1.Height = Application.GetRealHeight(300);
                frameBack1.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frameBack1);
 
                //拍照
                var btnTakePhone = new NormalViewControl(900, 156, true);
                btnTakePhone.Gravity = Gravity.CenterHorizontal;
                btnTakePhone.TextAlignment = TextAlignment.Center;
                btnTakePhone.TextColor = 0xff0075ff;
                btnTakePhone.TextSize = 17;
                btnTakePhone.TextID = R.MyInternationalizationString.uTakePictrue;
                frameBack1.AddChidren(btnTakePhone, ChidrenBindMode.NotBind);
                btnTakePhone.ButtonClickEvent += (sender, e) =>
                {
                    //关闭界面
                    this.CloseForm();
                    //通过相机拍照裁剪
                    CropImage.TakePicture((imagePath) =>
                    {
                        if (string.IsNullOrEmpty(imagePath) == false)
                        {
                            //调用回调函数
                            this.SelectPictrueEvent(imagePath);
                        }
                        this.SelectPictrueEvent = null;
                    }, "HdlPicture");
                };
 
                //线
                var btnLine = new NormalViewControl(frameBack1.Width, ControlCommonResourse.BottomLineHeight, false);
                btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
                btnLine.Y = btnTakePhone.Bottom;
                frameBack1.AddChidren(btnLine, ChidrenBindMode.NotBind);
                //从相册中选择
                var btnAlbum = new NormalViewControl(900, 144, true);
                btnAlbum.Y = btnLine.Bottom;
                btnAlbum.Gravity = Gravity.CenterHorizontal;
                btnAlbum.TextAlignment = TextAlignment.Center;
                btnAlbum.TextColor = 0xff0075ff;
                btnAlbum.TextSize = 17;
                btnAlbum.TextID = R.MyInternationalizationString.uGetPictrueFromAlbum;
                frameBack1.AddChidren(btnAlbum, ChidrenBindMode.NotBind);
                btnAlbum.ButtonClickEvent += (sender, e) =>
                {
                    //关闭界面
                    this.CloseForm();
                    //从相册选择图片裁剪
                    CropImage.SelectPicture((imagePath) =>
                    {
                        if (string.IsNullOrEmpty(imagePath) == false)
                        {
                            //调用回调函数
                            this.SelectPictrueEvent(imagePath);
                        }
                        this.SelectPictrueEvent = null;
                    }, "HdlPicture");
                };
 
                var frameBack2 = new FrameLayoutControl();
                frameBack2.UseClickStatu = false;
                frameBack2.Y = frameBack1.Bottom + Application.GetRealHeight(23);
                frameBack2.Gravity = Gravity.CenterHorizontal;
                frameBack2.RadiusEx = 12;
                frameBack2.Width = Application.GetRealWidth(1034);
                frameBack2.Height = Application.GetRealHeight(156);
                frameBack2.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frameBack2);
                //取消
                var btnCancel = new NormalViewControl(900, 156, true);
                btnCancel.Gravity = Gravity.CenterHorizontal;
                btnCancel.TextAlignment = TextAlignment.Center;
                btnCancel.TextColor = 0xff0075ff;
                btnCancel.TextSize = 17;
                btnCancel.TextID = R.MyInternationalizationString.uCancel;
                frameBack2.AddChidren(btnCancel, ChidrenBindMode.NotBind);
                btnCancel.ButtonClickEvent += (sender, e) =>
                {
                    this.SelectPictrueEvent = null;
                    //关闭界面
                    this.CloseForm();
                };
            }
 
            #endregion
        }
 
        #endregion
    }
}