old mode 100755
new mode 100644
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter
|
| | | {
|
| | | /// <summary>
|
| | | /// 房间组合或者设备组合的菜单控件(完成初始化后,会根据默认选择调用回调函数)
|
| | | /// </summary>
|
| | | public class RoomDeviceGroupMenuControl : FrameLayout
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 房间选择事件
|
| | | /// </summary>
|
| | | public Action<Common.Room> SelectRoomEvent = null;
|
| | | /// <summary>
|
| | | /// 设备选择事件
|
| | | /// </summary>
|
| | | public Action<List<CommonDevice>> SelectDeviceEvent = null;
|
| | | /// <summary>
|
| | | /// 当前选择的主键(房间类型时:房间ID 设备类型时:文本信息)
|
| | | /// </summary>
|
| | | public string nowSelectKeys
|
| | | {
|
| | | get
|
| | | {
|
| | | if (dicDevice != null)
|
| | | {
|
| | | int index = 0;
|
| | | foreach (var rId in dicDevice.Keys)
|
| | | {
|
| | | if (index == oldSelectIndex)
|
| | | {
|
| | | return rId.ToString();
|
| | | }
|
| | | index++;
|
| | | }
|
| | | return string.Empty;
|
| | | }
|
| | | return listRoom[oldSelectIndex].Id;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 当前选择的索引(内部使用)
|
| | | /// </summary>
|
| | | private int oldSelectIndex = -1;
|
| | | /// <summary>
|
| | | /// 房间对象
|
| | | /// </summary>
|
| | | private List<Common.Room> listRoom = null;
|
| | | /// <summary>
|
| | | /// 设备对象
|
| | | /// </summary>
|
| | | private Dictionary<string, List<CommonDevice>> dicDevice = null;
|
| | | /// <summary>
|
| | | /// 前回选择的控件
|
| | | /// </summary>
|
| | | private FrameLayoutStatuControl oldFrameBack = null;
|
| | | /// <summary>
|
| | | /// 前回选择的控件
|
| | | /// </summary>
|
| | | private NormalViewControl oldBtnText = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 房间组合的菜单控件(完成初始化后,会根据默认选择调用回调函数)
|
| | | /// </summary>
|
| | | /// <param name="i_listRoom">房间列表</param>
|
| | | public RoomDeviceGroupMenuControl(List<Common.Room> i_listRoom)
|
| | | {
|
| | | this.listRoom = i_listRoom;
|
| | | this.Height = Application.GetRealHeight(204);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 设备组合的菜单控件
|
| | | /// </summary>
|
| | | /// <param name="i_dicDevice">设备列表,keys:文本</param>
|
| | | public RoomDeviceGroupMenuControl(Dictionary<string, List<CommonDevice>> i_dicDevice)
|
| | | {
|
| | | this.dicDevice = i_dicDevice;
|
| | | this.Height = Application.GetRealHeight(204);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件(事件要至于它之前)
|
| | | /// </summary>
|
| | | public void InitControl()
|
| | | {
|
| | | var scrolContr = new HorizontalScrolViewLayout();
|
| | | scrolContr.Gravity = Gravity.CenterVertical;
|
| | | scrolContr.Height = this.Height;
|
| | | this.AddChidren(scrolContr);
|
| | |
|
| | | //弄个空的进去占位置
|
| | | var frameTemp = new FrameLayout();
|
| | | frameTemp.Height = this.Height;
|
| | | frameTemp.Width = ControlCommonResourse.XXLeft / 2;
|
| | | scrolContr.AddChidren(frameTemp);
|
| | |
|
| | | var btnTempWidth = new ButtonBase();
|
| | | btnTempWidth.TextSize = 12;
|
| | | if (this.listRoom != null)
|
| | | {
|
| | | //初始化房间模式的控件
|
| | | for (int i = 0; i < listRoom.Count; i++)
|
| | | {
|
| | | if (oldSelectIndex == -1)
|
| | | {
|
| | | //初始值
|
| | | oldSelectIndex = i;
|
| | | }
|
| | |
|
| | | //计算字符的真实宽度
|
| | | btnTempWidth.Text = listRoom[i].Name;
|
| | | this.DoInitControl(scrolContr, i.ToString(), i, listRoom[i].Name, btnTempWidth.GetRealWidthByText());
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | //初始化设备模式的控件
|
| | | int index = 0;
|
| | | foreach (string strKeys in dicDevice.Keys)
|
| | | {
|
| | | if (oldSelectIndex == -1)
|
| | | {
|
| | | //初始值
|
| | | oldSelectIndex = index;
|
| | | }
|
| | | //计算字符的真实宽度
|
| | | btnTempWidth.Text = strKeys;
|
| | | this.DoInitControl(scrolContr, strKeys, index, btnTempWidth.Text, btnTempWidth.GetRealWidthByText());
|
| | | index++;
|
| | | }
|
| | | }
|
| | | //让控件滑动到指定的索引位置
|
| | | scrolContr.ScrollToViewIndex(oldSelectIndex + 1);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件
|
| | | /// </summary>
|
| | | /// <param name="scrolContr">列表控件</param>
|
| | | /// <param name="strKey">字典的主键</param>
|
| | | /// <param name="index">索引</param>
|
| | | /// <param name="text">显示文本</param>
|
| | | /// <param name="textWidth">文本真实宽度</param>
|
| | | private void DoInitControl(HorizontalScrolViewLayout scrolContr, string strKey, int index, string text, int textWidth)
|
| | | {
|
| | | //带底图控件的最小宽度
|
| | | int minWidth = Application.GetRealWidth(255);
|
| | | //带底图控件的真实宽度 <文字的宽度的计算 frameBack.Width - (int)(frameBack.Height * 0.47)>
|
| | | int realWidth = textWidth + (int)(Application.GetRealHeight(159) * 0.47);
|
| | | if (realWidth < minWidth)
|
| | | {
|
| | | realWidth = minWidth;
|
| | | }
|
| | |
|
| | | //带图片的
|
| | | var frameBack = new FrameLayoutStatuControl();
|
| | | frameBack.UseClickStatu = false;
|
| | | frameBack.Gravity = Gravity.Center;
|
| | | frameBack.Height = Application.GetRealHeight(159);
|
| | | frameBack.Width = realWidth;
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
| | | oldFrameBack = frameBack;
|
| | | }
|
| | | else
|
| | | {
|
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackground.png";
|
| | | }
|
| | | scrolContr.AddChidren(frameBack);
|
| | | //文字
|
| | | var btnText = new NormalViewControl(textWidth, frameBack.Height, false);
|
| | | btnText.Gravity = Gravity.CenterHorizontal;
|
| | | btnText.Text = text;
|
| | | btnText.TextSize = 12;
|
| | | btnText.TextAlignment = TextAlignment.Center;
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | btnText.TextColor = UserCenterColor.Current.White;
|
| | | oldBtnText = btnText;
|
| | | }
|
| | | else
|
| | | {
|
| | | btnText.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | }
|
| | | frameBack.AddChidren(btnText, ChidrenBindMode.BindEvent);
|
| | |
|
| | | frameBack.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | //同一个东西
|
| | | return;
|
| | | }
|
| | | oldSelectIndex = index;
|
| | |
|
| | | //状态变更
|
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
| | | btnText.TextColor = UserCenterColor.Current.White;
|
| | |
|
| | | oldFrameBack.BackgroundImagePath = "Item/RoomIconBackground.png";
|
| | | oldBtnText.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | oldFrameBack = frameBack;
|
| | | oldBtnText = btnText;
|
| | | //调用回调函数
|
| | | if (this.dicDevice != null)
|
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[strKey]);
|
| | | }
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[Convert.ToInt32(strKey)]);
|
| | | }
|
| | | };
|
| | |
|
| | | //调用回调函数
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | if (this.dicDevice != null)
|
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[strKey]);
|
| | | }
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[Convert.ToInt32(strKey)]);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 控件摧毁___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 控件摧毁
|
| | | /// </summary>
|
| | | public override void RemoveFromParent()
|
| | | {
|
| | | this.SelectDeviceEvent = null;
|
| | | this.SelectRoomEvent = null;
|
| | |
|
| | | base.RemoveFromParent();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 一般方法___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 设置初始选择(请在初始化完成之前调用)
|
| | | /// </summary>
|
| | | /// <param name="strKey">房间ID 或者 文本信息</param>
|
| | | public void SetDefultIndex(string strKey)
|
| | | {
|
| | | if (listRoom != null)
|
| | | {
|
| | | for (int index = 0; index < listRoom.Count; index++)
|
| | | {
|
| | | if (listRoom[index].Id == strKey)
|
| | | {
|
| | | oldSelectIndex = index;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | else if (strKey != string.Empty)
|
| | | {
|
| | | int i = 0;
|
| | | foreach (string rId in dicDevice.Keys)
|
| | | {
|
| | | if (rId == strKey)
|
| | | {
|
| | | oldSelectIndex = i;
|
| | | break;
|
| | | }
|
| | | i++;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 房间组合或者设备组合的菜单控件(完成初始化后,会根据默认选择调用回调函数) |
| | | /// </summary> |
| | | public class RoomDeviceGroupMenuControl : FrameLayout |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 房间选择事件 |
| | | /// </summary> |
| | | public Action<Common.Room> SelectRoomEvent = null; |
| | | /// <summary> |
| | | /// 设备选择事件 |
| | | /// </summary> |
| | | public Action<List<CommonDevice>> SelectDeviceEvent = null; |
| | | /// <summary> |
| | | /// 当前选择的主键(房间类型时:房间ID 设备类型时:文本信息) |
| | | /// </summary> |
| | | public string nowSelectKeys |
| | | { |
| | | get |
| | | { |
| | | if (dicDevice != null) |
| | | { |
| | | int index = 0; |
| | | foreach (var rId in dicDevice.Keys) |
| | | { |
| | | if (index == oldSelectIndex) |
| | | { |
| | | return rId.ToString(); |
| | | } |
| | | index++; |
| | | } |
| | | return string.Empty; |
| | | } |
| | | return listRoom[oldSelectIndex].Id; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 当前选择的索引(内部使用) |
| | | /// </summary> |
| | | private int oldSelectIndex = -1; |
| | | /// <summary> |
| | | /// 房间对象 |
| | | /// </summary> |
| | | private List<Common.Room> listRoom = null; |
| | | /// <summary> |
| | | /// 设备对象 |
| | | /// </summary> |
| | | private Dictionary<string, List<CommonDevice>> dicDevice = null; |
| | | /// <summary> |
| | | /// 前回选择的控件 |
| | | /// </summary> |
| | | private FrameLayoutStatuControl oldFrameBack = null; |
| | | /// <summary> |
| | | /// 前回选择的控件 |
| | | /// </summary> |
| | | private NormalViewControl oldBtnText = null; |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化_____________________________ |
| | | |
| | | /// <summary> |
| | | /// 房间组合的菜单控件(完成初始化后,会根据默认选择调用回调函数) |
| | | /// </summary> |
| | | /// <param name="i_listRoom">房间列表</param> |
| | | public RoomDeviceGroupMenuControl(List<Common.Room> i_listRoom) |
| | | { |
| | | this.listRoom = i_listRoom; |
| | | this.Height = Application.GetRealHeight(204); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设备组合的菜单控件 |
| | | /// </summary> |
| | | /// <param name="i_dicDevice">设备列表,keys:文本</param> |
| | | public RoomDeviceGroupMenuControl(Dictionary<string, List<CommonDevice>> i_dicDevice) |
| | | { |
| | | this.dicDevice = i_dicDevice; |
| | | this.Height = Application.GetRealHeight(204); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化控件(事件要至于它之前) |
| | | /// </summary> |
| | | public void InitControl() |
| | | { |
| | | var scrolContr = new HorizontalScrolViewLayout(); |
| | | scrolContr.Gravity = Gravity.CenterVertical; |
| | | scrolContr.Height = this.Height; |
| | | this.AddChidren(scrolContr); |
| | | |
| | | //弄个空的进去占位置 |
| | | var frameTemp = new FrameLayout(); |
| | | frameTemp.Height = this.Height; |
| | | frameTemp.Width = ControlCommonResourse.XXLeft / 2; |
| | | scrolContr.AddChidren(frameTemp); |
| | | |
| | | var btnTempWidth = new ButtonBase(); |
| | | btnTempWidth.TextSize = 12; |
| | | if (this.listRoom != null) |
| | | { |
| | | //初始化房间模式的控件 |
| | | for (int i = 0; i < listRoom.Count; i++) |
| | | { |
| | | if (oldSelectIndex == -1) |
| | | { |
| | | //初始值 |
| | | oldSelectIndex = i; |
| | | } |
| | | |
| | | //计算字符的真实宽度 |
| | | btnTempWidth.Text = listRoom[i].Name; |
| | | this.DoInitControl(scrolContr, i.ToString(), i, listRoom[i].Name, btnTempWidth.GetRealWidthByText()); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | //初始化设备模式的控件 |
| | | int index = 0; |
| | | foreach (string strKeys in dicDevice.Keys) |
| | | { |
| | | if (oldSelectIndex == -1) |
| | | { |
| | | //初始值 |
| | | oldSelectIndex = index; |
| | | } |
| | | //计算字符的真实宽度 |
| | | btnTempWidth.Text = strKeys; |
| | | this.DoInitControl(scrolContr, strKeys, index, btnTempWidth.Text, btnTempWidth.GetRealWidthByText()); |
| | | index++; |
| | | } |
| | | } |
| | | //让控件滑动到指定的索引位置 |
| | | scrolContr.ScrollToViewIndex(oldSelectIndex + 1); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化控件 |
| | | /// </summary> |
| | | /// <param name="scrolContr">列表控件</param> |
| | | /// <param name="strKey">字典的主键</param> |
| | | /// <param name="index">索引</param> |
| | | /// <param name="text">显示文本</param> |
| | | /// <param name="textWidth">文本真实宽度</param> |
| | | private void DoInitControl(HorizontalScrolViewLayout scrolContr, string strKey, int index, string text, int textWidth) |
| | | { |
| | | //带底图控件的最小宽度 |
| | | int minWidth = Application.GetRealWidth(255); |
| | | //带底图控件的真实宽度 <文字的宽度的计算 frameBack.Width - (int)(frameBack.Height * 0.47)> |
| | | int realWidth = textWidth + (int)(Application.GetRealHeight(159) * 0.47); |
| | | if (realWidth < minWidth) |
| | | { |
| | | realWidth = minWidth; |
| | | } |
| | | |
| | | //带图片的 |
| | | var frameBack = new FrameLayoutStatuControl(); |
| | | frameBack.UseClickStatu = false; |
| | | frameBack.Gravity = Gravity.Center; |
| | | frameBack.Height = Application.GetRealHeight(159); |
| | | frameBack.Width = realWidth; |
| | | if (oldSelectIndex == index) |
| | | { |
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; |
| | | oldFrameBack = frameBack; |
| | | } |
| | | else |
| | | { |
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackground.png"; |
| | | } |
| | | scrolContr.AddChidren(frameBack); |
| | | //文字 |
| | | var btnText = new NormalViewControl(textWidth, frameBack.Height, false); |
| | | btnText.Gravity = Gravity.CenterHorizontal; |
| | | btnText.Text = text; |
| | | btnText.TextSize = 12; |
| | | btnText.TextAlignment = TextAlignment.Center; |
| | | if (oldSelectIndex == index) |
| | | { |
| | | btnText.TextColor = UserCenterColor.Current.White; |
| | | oldBtnText = btnText; |
| | | } |
| | | else |
| | | { |
| | | btnText.TextColor = UserCenterColor.Current.TextGrayColor1; |
| | | } |
| | | frameBack.AddChidren(btnText, ChidrenBindMode.BindEvent); |
| | | |
| | | frameBack.ButtonClickEvent += (sender, e) => |
| | | { |
| | | if (oldSelectIndex == index) |
| | | { |
| | | //同一个东西 |
| | | return; |
| | | } |
| | | oldSelectIndex = index; |
| | | |
| | | //状态变更 |
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png"; |
| | | btnText.TextColor = UserCenterColor.Current.White; |
| | | |
| | | oldFrameBack.BackgroundImagePath = "Item/RoomIconBackground.png"; |
| | | oldBtnText.TextColor = UserCenterColor.Current.TextGrayColor1; |
| | | oldFrameBack = frameBack; |
| | | oldBtnText = btnText; |
| | | //调用回调函数 |
| | | if (this.dicDevice != null) |
| | | { |
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[strKey]); |
| | | } |
| | | else if (this.listRoom != null) |
| | | { |
| | | this.SelectRoomEvent?.Invoke(this.listRoom[Convert.ToInt32(strKey)]); |
| | | } |
| | | }; |
| | | |
| | | //调用回调函数 |
| | | if (oldSelectIndex == index) |
| | | { |
| | | if (this.dicDevice != null) |
| | | { |
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[strKey]); |
| | | } |
| | | else if (this.listRoom != null) |
| | | { |
| | | this.SelectRoomEvent?.Invoke(this.listRoom[Convert.ToInt32(strKey)]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 控件摧毁___________________________ |
| | | |
| | | /// <summary> |
| | | /// 控件摧毁 |
| | | /// </summary> |
| | | public override void RemoveFromParent() |
| | | { |
| | | this.SelectDeviceEvent = null; |
| | | this.SelectRoomEvent = null; |
| | | |
| | | base.RemoveFromParent(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 一般方法___________________________ |
| | | |
| | | /// <summary> |
| | | /// 设置初始选择(请在初始化完成之前调用) |
| | | /// </summary> |
| | | /// <param name="strKey">房间ID 或者 文本信息</param> |
| | | public void SetDefultIndex(string strKey) |
| | | { |
| | | if (listRoom != null) |
| | | { |
| | | for (int index = 0; index < listRoom.Count; index++) |
| | | { |
| | | if (listRoom[index].Id == strKey) |
| | | { |
| | | oldSelectIndex = index; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | else if (strKey != string.Empty) |
| | | { |
| | | int i = 0; |
| | | foreach (string rId in dicDevice.Keys) |
| | | { |
| | | if (rId == strKey) |
| | | { |
| | | oldSelectIndex = i; |
| | | break; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |