New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// 安防记录控件 |
| | | /// </summary> |
| | | public class SafeguardLogControl : FrameLayout |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 今日无任何报警记录 的控件 |
| | | /// </summary> |
| | | private NormalViewControl btnMsg = null; |
| | | /// <summary> |
| | | /// 各防区的桌布控件 |
| | | /// </summary> |
| | | private Dictionary<int, FrameLayout> dicFrame = new Dictionary<int, FrameLayout>(); |
| | | /// <summary> |
| | | /// 各防区的行控件 |
| | | /// </summary> |
| | | private Dictionary<int, List<FrameLayout>> dicRowFrame = new Dictionary<int, List<FrameLayout>>(); |
| | | /// <summary> |
| | | /// 桌布控件 |
| | | /// </summary> |
| | | private FrameLayout frameTable = null; |
| | | /// <summary> |
| | | /// 开放这个控件出来,有点用 |
| | | /// </summary> |
| | | private NormalViewControl btnTime = null; |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化_____________________________ |
| | | |
| | | /// <summary> |
| | | /// 初始化 |
| | | /// </summary> |
| | | public SafeguardLogControl() |
| | | { |
| | | this.Height = Application.GetRealHeight(260 + 44); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化 |
| | | /// </summary> |
| | | /// <param name="dayText">日期</param> |
| | | /// <param name="dicInfo">防区报警信息</param> |
| | | public void InitControl(string dayText, Dictionary<int, List<SafeguardAlarmInfo>> dicInfo) |
| | | { |
| | | this.frameTable = new FrameLayout(); |
| | | frameTable.Gravity = Gravity.CenterHorizontal; |
| | | frameTable.Radius = (uint)Application.GetRealHeight(17); |
| | | frameTable.Height= Application.GetRealHeight(260); |
| | | frameTable.Width = Application.GetRealWidth(968); |
| | | frameTable.BackgroundColor = UserCenterColor.Current.White; |
| | | this.AddChidren(frameTable); |
| | | |
| | | //记录时间 |
| | | this.btnTime = new NormalViewControl(300, 58, true); |
| | | btnTime.X = Application.GetRealWidth(35); |
| | | btnTime.Y = Application.GetRealHeight(29); |
| | | btnTime.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnTime.TextID = R.MyInternationalizationString.uRecordTime; |
| | | this.frameTable.AddChidren(btnTime); |
| | | |
| | | //日期 |
| | | string month = dayText.Substring(4, 2); |
| | | string day = dayText.Substring(6, 2); |
| | | var btnDay = new NormalViewControl(300, 58, true); |
| | | btnDay.X = frameTable.Width - Application.GetRealWidth(300 + 35); |
| | | btnDay.Y = btnTime.Y; |
| | | btnDay.TextColor = UserCenterColor.Current.TextColor2; |
| | | btnDay.TextAlignment = TextAlignment.CenterRight; |
| | | btnDay.Text = month + Language.StringByID(R.MyInternationalizationString.Month) + day + Language.StringByID(R.MyInternationalizationString.Day); |
| | | this.frameTable.AddChidren(btnDay); |
| | | |
| | | //线 |
| | | var btnLine = new NormalViewControl(Application.GetRealWidth(904), ControlCommonResourse.BottomLineHeight, false); |
| | | btnLine.X = Application.GetRealWidth(29); |
| | | btnLine.Y = Application.GetRealHeight(98); |
| | | btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine; |
| | | this.frameTable.AddChidren(btnLine); |
| | | |
| | | //预创建五大防区的桌布 |
| | | var listId = new List<int>() { 1, 2, 4, 5, 3 }; |
| | | int tempY = 0; |
| | | for (int i = 0; i < listId.Count; i++) |
| | | { |
| | | var frame1 = new FrameLayout(); |
| | | frame1.Height = Application.GetRealHeight(10); |
| | | frame1.Y = tempY == 0 ? Application.GetRealHeight(98) : tempY; |
| | | this.frameTable.AddChidren(frame1); |
| | | dicFrame[listId[i]] = frame1; |
| | | dicRowFrame[listId[i]] = new List<FrameLayout>(); |
| | | |
| | | //初始化防区标题控件 |
| | | this.InitGarrisonTitleControl(listId[i]); |
| | | |
| | | if (dicInfo != null && dicInfo.ContainsKey(listId[i]) == true && dicInfo[listId[i]].Count > 0) |
| | | { |
| | | var listRow = dicRowFrame[listId[i]]; |
| | | foreach (var alarmInfo in dicInfo[listId[i]]) |
| | | { |
| | | //一条信息里面,它可能包含多个报警 |
| | | var listMsg = HdlAlarmsLogic.Current.GetSensorListAlarmMsg(alarmInfo); |
| | | foreach (var strMsg in listMsg) |
| | | { |
| | | //添加报警信息控件 |
| | | var contr = this.AddAlarmInfoControl(alarmInfo, strMsg); |
| | | if (listRow.Count != 0) |
| | | { |
| | | contr.Y = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(23); |
| | | } |
| | | listRow.Add(contr); |
| | | } |
| | | } |
| | | //变更高度 |
| | | frame1.Height = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(55); |
| | | this.frameTable.Height = frame1.Bottom; |
| | | this.Height = frame1.Bottom + Application.GetRealHeight(44); |
| | | tempY = frame1.Bottom; |
| | | } |
| | | else |
| | | { |
| | | frame1.Visible = false; |
| | | } |
| | | } |
| | | |
| | | if (dicInfo == null || dicInfo.Count == 0) |
| | | { |
| | | //今日无任何报警记录 |
| | | btnMsg = new NormalViewControl(frameTable.Width, Application.GetRealHeight(60), false); |
| | | btnMsg.Y = btnLine.Bottom + Application.GetRealHeight(28); |
| | | btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnMsg.TextID = R.MyInternationalizationString.uNowDayNotHadAlarmLog; |
| | | btnMsg.TextAlignment = TextAlignment.Center; |
| | | this.frameTable.AddChidren(btnMsg); |
| | | } |
| | | //添加底部阴影特效 |
| | | this.frameTable.SetViewShadow(true); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化防区标题控件_________________ |
| | | |
| | | /// <summary> |
| | | /// 初始化防区标题控件 |
| | | /// </summary> |
| | | /// <param name="zoneId"></param> |
| | | private void InitGarrisonTitleControl(int zoneId) |
| | | { |
| | | FrameLayout frame = dicFrame[zoneId]; |
| | | //图标 |
| | | var btnIcon = new IconViewControl(69); |
| | | btnIcon.X = Application.GetRealWidth(29); |
| | | btnIcon.Y = Application.GetRealHeight(23); |
| | | //只会是1~5 |
| | | if (zoneId == 1 || zoneId == 2) |
| | | { |
| | | btnIcon.UnSelectedImagePath = "Safeguard/ProtectionAtHome.png"; |
| | | } |
| | | else |
| | | { |
| | | btnIcon.UnSelectedImagePath = "Safeguard/ProtectionRemoveHome.png"; |
| | | } |
| | | frame.AddChidren(btnIcon); |
| | | //防区名 |
| | | var btnName = new NormalViewControl(400, 58, true); |
| | | btnName.X = Application.GetRealWidth(109); |
| | | btnName.Y = Application.GetRealHeight(35); |
| | | btnName.Text = HdlSafeguardLogic.Current.GetGarrisonText(zoneId); |
| | | frame.AddChidren(btnName); |
| | | //已启动 |
| | | var btnStatu = new NormalViewControl(300, 46, true); |
| | | btnStatu.X = frame.Width - Application.GetRealWidth(300 + 35); |
| | | btnStatu.Y = Application.GetRealHeight(35); |
| | | btnStatu.TextSize = 12; |
| | | btnStatu.TextColor = UserCenterColor.Current.TextGrayColor1; |
| | | btnStatu.TextAlignment = TextAlignment.CenterRight; |
| | | btnStatu.TextID = R.MyInternationalizationString.uHadStarted; |
| | | frame.AddChidren(btnStatu); |
| | | //空白行 |
| | | var btnSpace = new FrameLayout(); |
| | | btnSpace.Height = Application.GetRealHeight(46); |
| | | btnSpace.Y = btnIcon.Bottom; |
| | | frame.AddChidren(btnSpace); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加报警信息_______________________ |
| | | |
| | | /// <summary> |
| | | /// 添加报警信息 |
| | | /// </summary> |
| | | /// <param name="alarmInfo"></param> |
| | | /// <returns></returns> |
| | | public int AddSafeguardAlarmInfo(SafeguardAlarmInfo alarmInfo) |
| | | { |
| | | if (dicFrame.ContainsKey(alarmInfo.ZoneId) == false) |
| | | { |
| | | return -1; |
| | | } |
| | | //一条信息里面,它可能包含多个报警 |
| | | var listMsg = HdlAlarmsLogic.Current.GetSensorListAlarmMsg(alarmInfo); |
| | | int valueCount = 0; |
| | | foreach (var strMsg in listMsg) |
| | | { |
| | | //一个报警信息,一个控件 |
| | | int value = this.AddSafeguardAlarmInfo2(alarmInfo, strMsg); |
| | | //这个value是控件增加的高度值 |
| | | valueCount += value; |
| | | } |
| | | return valueCount; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加报警信息(一个报警信息,一个控件) |
| | | /// </summary> |
| | | /// <param name="alarmInfo"></param> |
| | | /// <param name="strMsg">针对一条数据里面包含多个报警的问题,追加的报警文本</param> |
| | | /// <returns></returns> |
| | | private int AddSafeguardAlarmInfo2(SafeguardAlarmInfo alarmInfo, string strMsg) |
| | | { |
| | | if (dicFrame.ContainsKey(alarmInfo.ZoneId) == false) |
| | | { |
| | | return -1; |
| | | } |
| | | if (btnMsg != null) |
| | | { |
| | | //移除信息提示控件 |
| | | btnMsg.RemoveFromParent(); |
| | | btnMsg = null; |
| | | } |
| | | var listRow = dicRowFrame[alarmInfo.ZoneId]; |
| | | if (listRow.Count == 0) |
| | | { |
| | | dicFrame[alarmInfo.ZoneId].Visible = true; |
| | | //重置桌布间的间距 |
| | | int tempY = 0; |
| | | foreach (var frame in dicFrame.Values) |
| | | { |
| | | if (frame.Visible == true) |
| | | { |
| | | frame.Y = tempY == 0 ? Application.GetRealHeight(98) : tempY; |
| | | tempY = frame.Bottom; |
| | | } |
| | | } |
| | | } |
| | | |
| | | //添加报警信息控件 |
| | | var frameRow = this.AddAlarmInfoControl(alarmInfo, strMsg); |
| | | if (listRow.Count >= 100) |
| | | { |
| | | //移除最后一个 |
| | | listRow[listRow.Count - 1].RemoveFromParent(); |
| | | listRow.RemoveAt(listRow.Count - 1); |
| | | } |
| | | //当前这个防区的全部行控件往下移动 |
| | | foreach (var row in listRow) |
| | | { |
| | | row.Y += frameRow.Height + Application.GetRealHeight(23); |
| | | } |
| | | listRow.Insert(0, frameRow); |
| | | |
| | | var value = listRow[listRow.Count - 1].Bottom + Application.GetRealHeight(55) - dicFrame[alarmInfo.ZoneId].Height; |
| | | if (value <= 0) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | //变更高度 |
| | | dicFrame[alarmInfo.ZoneId].Height += value; |
| | | //它之下的全部桌布全部往下移动 |
| | | bool canMove = false; |
| | | int realHeight = 0; |
| | | foreach (var id in dicFrame.Keys) |
| | | { |
| | | if (id == alarmInfo.ZoneId) |
| | | { |
| | | //当前的桌布 |
| | | canMove = true; |
| | | } |
| | | else if (canMove == true) |
| | | { |
| | | dicFrame[id].Y += value; |
| | | } |
| | | if (canMove == true && dicFrame[id].Visible == true) |
| | | { |
| | | //记录起最后一个FrameLayout的底部 |
| | | realHeight = dicFrame[id].Bottom; |
| | | } |
| | | } |
| | | if (realHeight > 0) |
| | | { |
| | | //变更整个控件的真实高度 |
| | | this.frameTable.Height = realHeight; |
| | | this.Height = realHeight + Application.GetRealHeight(44); |
| | | } |
| | | //添加底部阴影特效 |
| | | this.frameTable.SetViewShadow(true); |
| | | |
| | | return value; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加报警信息控件 |
| | | /// </summary> |
| | | /// <param name="alarmInfo"></param> |
| | | /// <returns></returns> |
| | | private FrameLayout AddAlarmInfoControl(SafeguardAlarmInfo alarmInfo, string strMsg) |
| | | { |
| | | var frame = dicFrame[alarmInfo.ZoneId]; |
| | | |
| | | var rowFrame = new FrameLayout(); |
| | | rowFrame.Y = Application.GetRealHeight(130); |
| | | rowFrame.Height = Application.GetRealHeight(58); |
| | | frame.AddChidren(rowFrame); |
| | | |
| | | //房间 |
| | | var btnRoom = new NormalViewControl(165, 58, true); |
| | | btnRoom.X = Application.GetRealWidth(35); |
| | | btnRoom.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnRoom.Text = alarmInfo.RoomName; |
| | | rowFrame.AddChidren(btnRoom); |
| | | //设备 |
| | | string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(alarmInfo.DeviceAddr, alarmInfo.DeviceEpoint); |
| | | var device = Common.LocalDevice.Current.GetDevice(mainkeys); |
| | | var btnDevice = new NormalViewControl(271, 58, true); |
| | | btnDevice.X = Application.GetRealWidth(199); |
| | | btnDevice.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnDevice.Text = device == null ? alarmInfo.DeviceName : Common.LocalDevice.Current.GetDeviceEpointName(device); |
| | | rowFrame.AddChidren(btnDevice); |
| | | //报警信息 |
| | | var btnMsg = new NormalViewControl(303, 58, true); |
| | | btnMsg.X = Application.GetRealWidth(469); |
| | | btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnMsg.Text = strMsg; |
| | | rowFrame.AddChidren(btnMsg); |
| | | //时间:时分秒 |
| | | var btnTime = new NormalViewControl(190, 58, true); |
| | | btnTime.X = Application.GetRealWidth(758); |
| | | btnTime.TextColor = UserCenterColor.Current.TextGrayColor3; |
| | | btnTime.TextAlignment = TextAlignment.CenterRight; |
| | | btnTime.Text = alarmInfo.Time; |
| | | rowFrame.AddChidren(btnTime); |
| | | |
| | | return rowFrame; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 控件销毁___________________________ |
| | | |
| | | /// <summary> |
| | | /// 控件销毁 |
| | | /// </summary> |
| | | public override void RemoveFromParent() |
| | | { |
| | | dicRowFrame.Clear(); |
| | | dicFrame.Clear(); |
| | | |
| | | base.RemoveFromParent(); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |