| | |
| | | /// </summary>
|
| | | public Action<List<CommonDevice>> SelectDeviceEvent = null;
|
| | | /// <summary>
|
| | | /// 当前选择的主键
|
| | | /// 当前选择的主键(房间类型时:房间ID 设备类型时:R文件里面的ID)
|
| | | /// </summary>
|
| | | public string nowSelectKeys
|
| | | {
|
| | |
| | | {
|
| | | if (dicDevice != null)
|
| | | {
|
| | | return oldSelectKeys.ToString();
|
| | | int index = 0;
|
| | | foreach (var rId in dicDevice.Keys)
|
| | | {
|
| | | if (index == oldSelectIndex)
|
| | | {
|
| | | return rId.ToString();
|
| | | }
|
| | | }
|
| | | return string.Empty;
|
| | | }
|
| | | return dicRoom[oldSelectKeys].Id;
|
| | | return listRoom[oldSelectIndex].Id;
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 当前选择的主键(内部使用)
|
| | | /// 当前选择的索引(内部使用)
|
| | | /// </summary>
|
| | | private int oldSelectKeys = -1;
|
| | | private int oldSelectIndex = -1;
|
| | | /// <summary>
|
| | | /// 房间对象
|
| | | /// </summary>
|
| | | private Dictionary<int, Common.Room> dicRoom = null;
|
| | | private List<Common.Room> listRoom = null;
|
| | | /// <summary>
|
| | | /// 设备对象
|
| | | /// </summary>
|
| | |
| | | /// <param name="i_listRoom">房间列表</param>
|
| | | public RoomDeviceGroupMenuControl(List<Common.Room> i_listRoom)
|
| | | {
|
| | | this.dicRoom = new Dictionary<int, Common.Room>();
|
| | | for (int i = 0; i < i_listRoom.Count; i++)
|
| | | {
|
| | | this.dicRoom[i] = i_listRoom[i];
|
| | | }
|
| | | this.listRoom = i_listRoom;
|
| | | this.Height = Application.GetRealHeight(204);
|
| | | }
|
| | |
|
| | |
| | |
|
| | | var btnTempWidth = new ButtonBase();
|
| | | btnTempWidth.TextSize = 12;
|
| | | if (this.dicRoom != null)
|
| | | if (this.listRoom != null)
|
| | | {
|
| | | //初始化房间模式的控件
|
| | | foreach (int keys in dicRoom.Keys)
|
| | | for (int i = 0; i < listRoom.Count; i++)
|
| | | {
|
| | | if (oldSelectKeys == -1)
|
| | | if (oldSelectIndex == -1)
|
| | | {
|
| | | //初始值
|
| | | oldSelectKeys = keys;
|
| | | oldSelectIndex = i;
|
| | | }
|
| | |
|
| | | //计算字符的真实宽度
|
| | | btnTempWidth.Text = dicRoom[keys].Name;
|
| | | this.DoInitControl(scrolContr, keys, dicRoom[keys].Name, btnTempWidth.GetRealWidthByText());
|
| | | btnTempWidth.Text = listRoom[i].Name;
|
| | | this.DoInitControl(scrolContr, i, i, listRoom[i].Name, btnTempWidth.GetRealWidthByText());
|
| | | }
|
| | | }
|
| | | else
|
| | |
| | | int index = 0;
|
| | | foreach (int keys in dicDevice.Keys)
|
| | | {
|
| | | if (oldSelectKeys == -1)
|
| | | if (oldSelectIndex == -1)
|
| | | {
|
| | | //初始值
|
| | | oldSelectKeys = keys;
|
| | | oldSelectIndex = index;
|
| | | }
|
| | | //计算字符的真实宽度
|
| | | btnTempWidth.Text = Language.StringByID(keys);
|
| | | this.DoInitControl(scrolContr, keys, btnTempWidth.Text, btnTempWidth.GetRealWidthByText());
|
| | | this.DoInitControl(scrolContr, keys, index, btnTempWidth.Text, btnTempWidth.GetRealWidthByText());
|
| | | index++;
|
| | | }
|
| | | }
|
| | | //让控件滑动到指定的索引位置
|
| | | scrolContr.ScrollToViewIndex(oldSelectKeys + 1);
|
| | | scrolContr.ScrollToViewIndex(oldSelectIndex + 1);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// </summary>
|
| | | /// <param name="scrolContr">列表控件</param>
|
| | | /// <param name="keys">字典的主键</param>
|
| | | /// <param name="index">索引</param>
|
| | | /// <param name="text">显示文本</param>
|
| | | /// <param name="textWidth">文本真实宽度</param>
|
| | | private void DoInitControl(HorizontalScrolViewLayout scrolContr, int keys, string text, int textWidth)
|
| | | private void DoInitControl(HorizontalScrolViewLayout scrolContr, int keys, int index, string text, int textWidth)
|
| | | {
|
| | | //带底图控件的最小宽度
|
| | | int minWidth = Application.GetRealWidth(255);
|
| | |
| | | frameBack.Gravity = Gravity.Center;
|
| | | frameBack.Height = Application.GetRealHeight(159);
|
| | | frameBack.Width = realWidth;
|
| | | if (oldSelectKeys == keys)
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
| | | oldFrameBack = frameBack;
|
| | |
| | | btnText.Text = text;
|
| | | btnText.TextSize = 12;
|
| | | btnText.TextAlignment = TextAlignment.Center;
|
| | | if (oldSelectKeys == keys)
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | btnText.TextColor = UserCenterColor.Current.White;
|
| | | oldBtnText = btnText;
|
| | |
| | |
|
| | | frameBack.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | if (oldSelectKeys == keys)
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | //同一个东西
|
| | | return;
|
| | | }
|
| | | oldSelectKeys = keys;
|
| | | oldSelectIndex = index;
|
| | |
|
| | | //状态变更
|
| | | frameBack.BackgroundImagePath = "Item/RoomIconBackgroundSelected.png";
|
| | |
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[keys]);
|
| | | }
|
| | | else if (this.dicRoom != null)
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.dicRoom[keys]);
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[keys]);
|
| | | }
|
| | | };
|
| | |
|
| | | //调用回调函数
|
| | | if (oldSelectKeys == keys)
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | if (this.dicDevice != null)
|
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[keys]);
|
| | | }
|
| | | else if (this.dicRoom != null)
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.dicRoom[keys]);
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[keys]);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件
|
| | | /// </summary>
|
| | | /// <param name="scrolContr">列表控件</param>
|
| | | /// <param name="keys">字典的主键</param>
|
| | | /// <param name="index">索引</param>
|
| | | /// <param name="text">显示文本</param>
|
| | | /// <param name="textWidth">文本真实宽度</param>
|
| | | private void DoInitControl2(HorizontalScrolViewLayout scrolContr, int keys, 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 FrameLayoutControl();
|
| | | frameBack.UseClickStatu = false;
|
| | | frameBack.Gravity = Gravity.Center;
|
| | | frameBack.Height = Application.GetRealHeight(159);
|
| | | frameBack.Width = realWidth;
|
| | | frameBack.BorderWidth = 1;
|
| | | frameBack.BorderColor = UserCenterColor.Current.TextColor1;
|
| | | scrolContr.AddChidren(frameBack);
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | frameBack.SetViewShadow(true);
|
| | | frameBack.BackgroundColor = UserCenterColor.Current.TextColor1;
|
| | | oldFrameBack = 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.BindEventOnly);
|
| | |
|
| | | frameBack.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | //同一个东西
|
| | | return;
|
| | | }
|
| | | oldSelectIndex = index;
|
| | |
|
| | | //状态变更
|
| | | frameBack.SetViewShadow(true);
|
| | | frameBack.BackgroundColor = UserCenterColor.Current.TextColor1;
|
| | | btnText.TextColor = UserCenterColor.Current.White;
|
| | |
|
| | | oldFrameBack.SetViewShadow(false);
|
| | | oldFrameBack.BackgroundColor = UserCenterColor.Current.Transparent;
|
| | | oldBtnText.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | oldFrameBack = frameBack;
|
| | | oldBtnText = btnText;
|
| | | //调用回调函数
|
| | | if (this.dicDevice != null)
|
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[keys]);
|
| | | }
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[keys]);
|
| | | }
|
| | | };
|
| | |
|
| | | //调用回调函数
|
| | | if (oldSelectIndex == index)
|
| | | {
|
| | | if (this.dicDevice != null)
|
| | | {
|
| | | this.SelectDeviceEvent?.Invoke(this.dicDevice[keys]);
|
| | | }
|
| | | else if (this.listRoom != null)
|
| | | {
|
| | | this.SelectRoomEvent?.Invoke(this.listRoom[keys]);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | /// <param name="keys">房间ID 或者 R文件里面的数值编号(转为字符串类型)</param>
|
| | | public void SetDefultIndex(string keys)
|
| | | {
|
| | | if (dicRoom != null)
|
| | | if (listRoom != null)
|
| | | {
|
| | | foreach (int index in dicRoom.Keys)
|
| | | for (int index = 0; index < listRoom.Count; index++)
|
| | | {
|
| | | if (dicRoom[index].Id == keys)
|
| | | if (listRoom[index].Id == keys)
|
| | | {
|
| | | oldSelectKeys = index;
|
| | | oldSelectIndex = index;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
| | | {
|
| | | if (rId == textId)
|
| | | {
|
| | | oldSelectKeys = i;
|
| | | oldSelectIndex = i;
|
| | | break;
|
| | | }
|
| | | i++;
|