New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.DevicePanel
|
| | | {
|
| | | /// <summary>
|
| | | /// 按键面板的颜色选择界面
|
| | | /// </summary>
|
| | | public class PanelColorSelectForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 颜色选择结束的事件(R,G,B)
|
| | | /// </summary>
|
| | | public Action<int, int, int> FinishSelectColorEvent;
|
| | | /// <summary>
|
| | | /// 选择的RGB
|
| | | /// </summary>
|
| | | private List<int> listRGB = null;
|
| | | /// <summary>
|
| | | /// 当前选择的控件(外框)
|
| | | /// </summary>
|
| | | private FrameLayoutControl nowSelectIcon1 = null;
|
| | | /// <summary>
|
| | | /// 圆盘选择的颜色显示控件(外框)
|
| | | /// </summary>
|
| | | private FrameLayoutControl wheelSelectIcon1 = null;
|
| | | /// <summary>
|
| | | /// 圆盘选择的颜色显示控件(内框)
|
| | | /// </summary>
|
| | | private IconViewControl wheelSelectIcon2 = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | /// <param name="i_R">R</param>
|
| | | /// <param name="i_G">G</param>
|
| | | /// <param name="i_B">B</param>
|
| | | public void ShowForm(int i_R,int i_G,int i_B)
|
| | | {
|
| | | //设置头部信息
|
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uSelectColor));
|
| | |
|
| | | //初始化中部信息
|
| | | this.InitMiddleFrame(i_R, i_G, i_B);
|
| | |
|
| | | //确定
|
| | | var btnfinish = new BottomClickButton();
|
| | | btnfinish.TextID = R.MyInternationalizationString.Confrim;
|
| | | bodyFrameLayout.AddChidren(btnfinish);
|
| | | btnfinish.MouseUpEventHandler += (sender, e) =>
|
| | | {
|
| | | if (listRGB == null || FinishSelectColorEvent == null)
|
| | | {
|
| | | this.CloseForm();
|
| | | return;
|
| | | }
|
| | | //回调函数
|
| | | this.FinishSelectColorEvent(listRGB[0], listRGB[1], listRGB[2]);
|
| | | this.CloseForm();
|
| | | };
|
| | |
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化中部信息
|
| | | /// </summary>
|
| | | /// <param name="i_R">R</param>
|
| | | /// <param name="i_G">G</param>
|
| | | /// <param name="i_B">B</param>
|
| | | private void InitMiddleFrame(int i_R, int i_G, int i_B)
|
| | | {
|
| | | bodyFrameLayout.BackgroundColor = UserCenterColor.Current.White;
|
| | | //清空bodyFrame
|
| | | this.ClearBodyFrame();
|
| | | //初始化颜色圆盘控件
|
| | | this.InitColorPictrueControl();
|
| | | //初始化备用颜色的控件
|
| | | this.InitSpareColorControl(i_R, i_G, i_B);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化颜色圆盘_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化颜色圆盘控件
|
| | | /// </summary>
|
| | | private void InitColorPictrueControl()
|
| | | {
|
| | | //圆盘控件的FrameLayout
|
| | | var frameBack = new FrameLayout();
|
| | | frameBack.Y = Application.GetRealHeight(66);
|
| | | frameBack.Height = Application.GetRealHeight(1204);
|
| | | bodyFrameLayout.AddChidren(frameBack);
|
| | |
|
| | | var framePic = new FrameLayout();
|
| | | framePic.Width = Application.GetMinRealAverage(588);
|
| | | framePic.Height = Application.GetMinRealAverage(588);
|
| | | framePic.Gravity = Gravity.Center;
|
| | | frameBack.AddChidren(framePic);
|
| | |
|
| | | //圆盘控件
|
| | | var colorPic = new ColorPicker();
|
| | | colorPic.ColorImagePath = "Item/PickerColorWheel.png";
|
| | | framePic.AddChidren(colorPic);
|
| | |
|
| | | //白点控件
|
| | | var btnWhiteView = new IconViewControl(30);
|
| | | btnWhiteView.Visible = false;
|
| | | btnWhiteView.BackgroundColor = UserCenterColor.Current.White;
|
| | | btnWhiteView.Radius = (uint)Application.GetMinRealAverage(30) / 2;
|
| | | framePic.AddChidren(btnWhiteView);
|
| | |
|
| | | colorPic.ColorChaged += (sender, eColor) =>
|
| | | {
|
| | | listRGB = new List<int>();
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[0])));
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[1])));
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[2])));
|
| | |
|
| | | //显示选择颜色的控件
|
| | | if (nowSelectIcon1 != null)
|
| | | {
|
| | | nowSelectIcon1.BorderColor = UserCenterColor.Current.White;
|
| | | }
|
| | | wheelSelectIcon2.BackgroundColor = this.GetColorByRGB(eColor[0], eColor[1], eColor[2]);
|
| | | wheelSelectIcon1.BorderColor = 0xffcccccc;
|
| | | wheelSelectIcon1.Name = listRGB[0] + "-" + listRGB[1] + "-" + listRGB[2];
|
| | | nowSelectIcon1 = wheelSelectIcon1;
|
| | | };
|
| | | colorPic.MouseDownEventHandler += (sender, e) =>
|
| | | {
|
| | | //显示白点
|
| | | btnWhiteView.X = (int)e.X;
|
| | | btnWhiteView.Y = (int)e.Y;
|
| | | if (btnWhiteView.Visible == false)
|
| | | {
|
| | | btnWhiteView.Visible = true;
|
| | | }
|
| | | };
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化预选颜色_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化备用颜色的控件
|
| | | /// </summary>
|
| | | /// <param name="i_R">R</param>
|
| | | /// <param name="i_G">G</param>
|
| | | /// <param name="i_B">B</param>
|
| | | private void InitSpareColorControl(int i_R, int i_G, int i_B)
|
| | | {
|
| | | //控件数
|
| | | var listColor = this.InitSpareDefultColor();
|
| | | //X轴初始坐标
|
| | | int Xdefult = (bodyFrameLayout.Width - Application.GetMinRealAverage(80 + 24) * (listColor.Count - 1) - Application.GetMinRealAverage(80)) / 2;
|
| | | for (int i = 0; i < listColor.Count; i++)
|
| | | {
|
| | | var dataColor = listColor[i];
|
| | |
|
| | | var btnFrame = new FrameLayoutControl();
|
| | | btnFrame.Height = Application.GetMinRealAverage(80);
|
| | | btnFrame.Width = Application.GetMinRealAverage(80);
|
| | | btnFrame.Radius = (uint)Application.GetMinRealAverage(80) / 2;
|
| | | btnFrame.X = Xdefult + i * Application.GetMinRealAverage(80 + 24);
|
| | | btnFrame.Y = Application.GetRealHeight(1054);
|
| | | btnFrame.BackgroundColor = UserCenterColor.Current.White;
|
| | | btnFrame.BorderWidth = 1;
|
| | | btnFrame.BorderColor = UserCenterColor.Current.White;
|
| | | bodyFrameLayout.AddChidren(btnFrame);
|
| | |
|
| | | //分两步计算,不然有可能它得出的结果有误差导致不居中
|
| | | int iconWidth = btnFrame.Height - Application.GetMinRealAverage(10) - Application.GetMinRealAverage(10);
|
| | | var btnIcon = new IconViewControl(iconWidth, false);
|
| | | btnIcon.Gravity = Gravity.Center;
|
| | | btnIcon.Radius = (uint)btnIcon.IconSize / 2;
|
| | | btnFrame.AddChidren(btnIcon, ChidrenBindMode.BindEventOnly);
|
| | |
|
| | | if (dataColor != null)
|
| | | {
|
| | | //预设置的颜色
|
| | | btnFrame.Name = dataColor[0] + "-" + dataColor[1] + "-" + dataColor[2];
|
| | | btnIcon.BackgroundColor = this.GetColorByRGB((byte)dataColor[0], (byte)dataColor[1], (byte)dataColor[2]);
|
| | | }
|
| | | else
|
| | | {
|
| | | //原来的颜色
|
| | | btnFrame.BorderColor = 0xffcccccc;
|
| | | btnIcon.BackgroundColor = this.GetColorByRGB((byte)i_R, (byte)i_G, (byte)i_B);
|
| | | wheelSelectIcon1 = btnFrame;
|
| | | wheelSelectIcon2 = btnIcon;
|
| | | nowSelectIcon1 = btnFrame;
|
| | | }
|
| | |
|
| | | btnFrame.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //显示选择颜色的控件
|
| | | if (nowSelectIcon1 != null)
|
| | | {
|
| | | nowSelectIcon1.BorderColor = UserCenterColor.Current.White;
|
| | | }
|
| | | btnFrame.BorderColor = 0xffcccccc;
|
| | | nowSelectIcon1 = btnFrame;
|
| | |
|
| | | if (btnFrame.Name != null)
|
| | | {
|
| | | listRGB = new List<int>();
|
| | | string[] Arry = btnFrame.Name.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[0])));
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[1])));
|
| | | listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[2])));
|
| | | }
|
| | | };
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化备用颜色的默认值
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private List<List<int>> InitSpareDefultColor()
|
| | | {
|
| | | var list = new List<List<int>>();
|
| | |
|
| | | list.Add(new List<int>() { 253, 226, 39 });
|
| | | list.Add(new List<int>() { 121, 255, 197 });
|
| | | list.Add(null);
|
| | | list.Add(new List<int>() { 198, 85, 250 });
|
| | | list.Add(new List<int>() { 255, 117, 67 });
|
| | |
|
| | | return list;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将RGB转换为颜色
|
| | | /// </summary>
|
| | | /// <param name="R"></param>
|
| | | /// <param name="G"></param>
|
| | | /// <param name="B"></param>
|
| | | /// <returns></returns>
|
| | | private uint GetColorByRGB(byte R, byte G, byte B)
|
| | | {
|
| | | return (uint)(0xFF000000 + R * 256 * 256 + G * 256 + B);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 界面关闭___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 界面关闭
|
| | | /// </summary>
|
| | | public override void CloseFormBefore()
|
| | | {
|
| | | this.FinishSelectColorEvent = null;
|
| | |
|
| | | base.CloseFormBefore();
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|