New file |
| | |
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | | using ZigBee.Device;
|
| | |
|
| | | namespace Shared.Phone.UserCenter.GatewayUpdate
|
| | | {
|
| | | /// <summary>
|
| | | /// 固件升级画面
|
| | | /// </summary>
|
| | | public class GatewayFirmwareUpdateForm : DialogCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 要升级的网关
|
| | | /// </summary>
|
| | | private ZbGateway upDatezbGateway = null;
|
| | | /// <summary>
|
| | | /// 虚拟设备的固件信息
|
| | | /// </summary>
|
| | | private FirmwareVersionInfo virtualFirmware = null;
|
| | | /// <summary>
|
| | | /// 协调器新版本的固件信息
|
| | | /// </summary>
|
| | | private FirmwareVersionInfo coordinatorFirmware = null;
|
| | | /// <summary>
|
| | | /// 网关新版本的固件信息
|
| | | /// </summary>
|
| | | private FirmwareVersionInfo gatewayFirmware = null;
|
| | | /// <summary>
|
| | | /// 虚拟驱动号
|
| | | /// </summary>
|
| | | private List<ZbGatewayData.DriveCodeObj> listVode = null;
|
| | | /// <summary>
|
| | | /// 设备成功升级完成的回调函数
|
| | | /// </summary>
|
| | | public Action FinishUpdateEvent = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 初始化_____________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建)
|
| | | /// </summary>
|
| | | /// <param name="i_zbGateway">网关</param>
|
| | | /// <param name="i_virtualFirmware">虚拟设备的固件信息</param>
|
| | | /// <param name="i_coordinatorFirmware">协调器新版本的固件信息</param>
|
| | | /// <param name="i_gatewayFirmware">网关新版本的固件信息</param>
|
| | | /// <param name="i_listVode">虚拟驱动</param> |
| | | public void ShowForm(ZbGateway i_zbGateway, FirmwareVersionInfo i_virtualFirmware, FirmwareVersionInfo i_coordinatorFirmware, |
| | | FirmwareVersionInfo i_gatewayFirmware, List<ZbGatewayData.DriveCodeObj> i_listVode) |
| | | { |
| | | this.upDatezbGateway = i_zbGateway;
|
| | | this.virtualFirmware = i_virtualFirmware;
|
| | | this.coordinatorFirmware = i_coordinatorFirmware;
|
| | | this.gatewayFirmware = i_gatewayFirmware;
|
| | | this.listVode = i_listVode; |
| | | |
| | | //初始化中部信息 |
| | | this.InitMiddleFrame(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化中部信息 |
| | | /// </summary> |
| | | private void InitMiddleFrame() |
| | | {
|
| | | var frameBack = new FrameLayout(); |
| | | frameBack.Width = Application.GetRealWidth(674); |
| | | frameBack.Height = Application.GetRealHeight(386); |
| | | frameBack.BackgroundColor = UserCenterColor.Current.White; |
| | | frameBack.Gravity = Gravity.CenterHorizontal; |
| | | frameBack.Y = Application.GetRealHeight(683); |
| | | frameBack.Radius = 6; |
| | | bodyFrameLayout.AddChidren(frameBack); |
| | | |
| | | //进度显示文本 |
| | | var btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(58), false); |
| | | btnText.Y = Application.GetRealHeight(248); |
| | | btnText.TextColor = UserCenterColor.Current.TextGrayColor1; |
| | | btnText.TextAlignment = TextAlignment.Center; |
| | | //btnText.Text = "升级中"; |
| | | frameBack.AddChidren(btnText);
|
| | |
|
| | | //进度条
|
| | | var btnProRow = new FrameLayout(); |
| | | btnProRow.Gravity = Gravity.CenterHorizontal; |
| | | btnProRow.Y = Application.GetRealHeight(161); |
| | | btnProRow.Width = Application.GetRealWidth(559); |
| | | btnProRow.Height = Application.GetRealHeight(29); |
| | | btnProRow.BackgroundColor = 0xfff5f5f5;
|
| | | btnProRow.Radius = (uint)Application.GetRealHeight(29) / 2;
|
| | | frameBack.AddChidren(btnProRow); |
| | | var btnProgressBar = new FrameLayout(); |
| | | btnProgressBar.Width = 0; |
| | | btnProgressBar.Height = btnProRow.Height; |
| | | btnProgressBar.Radius = btnProRow.Radius;
|
| | | btnProgressBar.BackgroundColor = 0xfffb744a;
|
| | | btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2;
|
| | | btnProRow.AddChidren(btnProgressBar);
|
| | |
|
| | | //进度值文本
|
| | | var frameProgress = new FrameLayout();
|
| | | frameProgress.Width = Application.GetRealWidth(84);
|
| | | frameProgress.Height = Application.GetRealHeight(60);
|
| | | frameProgress.Y = Application.GetRealHeight(86);
|
| | | frameBack.AddChidren(frameProgress);
|
| | | frameProgress.X = btnProRow.X + btnProgressBar.Right - frameProgress.Width / 2;
|
| | | var btnProgressPic = new PicViewControl(84, 60);
|
| | | btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png";
|
| | | frameProgress.AddChidren(btnProgressPic);
|
| | | var btnProgressView = new NormalViewControl(84, 32, true);
|
| | | btnProgressView.TextSize = 10;
|
| | | btnProgressView.TextAlignment = TextAlignment.Center;
|
| | | btnProgressView.Text = "0%";
|
| | | frameProgress.AddChidren(btnProgressView);
|
| | |
|
| | | //设备升级
|
| | | this.GatewayUpdateMethod(btnText, btnProgressView, frameProgress, btnProgressBar, btnProRow.Width);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 设备升级___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 网关升级
|
| | | /// </summary>
|
| | | /// <param name="btnText">标题控件</param>
|
| | | /// <param name="btnProgressView">进度值文本的显示控件</param>
|
| | | /// <param name="frameProgress">进度值能够移动的那个框控件</param>
|
| | | /// <param name="btnProgressBar">进度条</param>
|
| | | /// <param name="ProRowWidth">进度条容器的最大宽度</param>
|
| | | private void GatewayUpdateMethod(NormalViewControl btnText, NormalViewControl btnProgressView,
|
| | | FrameLayout frameProgress, FrameLayout btnProgressBar, int ProRowWidth)
|
| | | {
|
| | | //设备升级
|
| | | var updateLogic = new HdlGatewayUpdateLogic(this.upDatezbGateway, virtualFirmware, coordinatorFirmware, gatewayFirmware);
|
| | | //更新状态变化的事件
|
| | | updateLogic.UpdateStatuChangedEvent += (div, msg) =>
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | if (div == -1)
|
| | | {
|
| | | //异常
|
| | | this.ShowMassage(ShowMsgType.Tip, msg);
|
| | | this.CloseForm();
|
| | | }
|
| | | else if (div == 0)
|
| | | {
|
| | | //一般信息
|
| | | btnText.Text = msg;
|
| | | }
|
| | | else if (div == 1)
|
| | | {
|
| | | //升级完成
|
| | | btnText.Text = msg;
|
| | | this.ShowMassage(ShowMsgType.Tip, msg);
|
| | | //调用回调函数
|
| | | this.FinishUpdateEvent?.Invoke();
|
| | | this.CloseForm();
|
| | | }
|
| | | });
|
| | | };
|
| | | //进度值改变事件
|
| | | updateLogic.ProgressEvent += (value) =>
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | //进度条
|
| | | int width = (int)(value * ProRowWidth);
|
| | | btnProgressBar.Width = width;
|
| | |
|
| | | //文本显示
|
| | | int persent = (int)(value * 100);
|
| | | btnProgressView.Text = persent + "%";
|
| | | //文本显示的那个图片框移动
|
| | | frameProgress.X = ControlCommonResourse.XXLeft + btnProgressBar.Right - frameProgress.Width / 2;
|
| | | });
|
| | |
|
| | | };
|
| | | //网关升级开始
|
| | | updateLogic.StartUpdateReady();
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 界面关闭___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 画面关闭
|
| | | /// </summary>
|
| | | public override void CloseForm()
|
| | | {
|
| | | //安卓可以点击系统的返回键
|
| | | UserView.HomePage.Instance.ScrollEnabled = true;
|
| | | Shared.Common.CommonPage.BackKeyCanClick = true;
|
| | |
|
| | | //升级对象
|
| | | string gwId = HdlGatewayLogic.Current.GetGatewayId(upDatezbGateway);
|
| | | if (FirmwareUpdateResourse.dicGatewayUpdateList.ContainsKey(gwId) == true
|
| | | && FirmwareUpdateResourse.dicGatewayUpdateList[gwId].IsFinishUpdate == true)
|
| | | {
|
| | | //如果网关已经升级完成,界面关闭时,则移除内存
|
| | | FirmwareUpdateResourse.dicGatewayUpdateList[gwId].Dispose();
|
| | | FirmwareUpdateResourse.dicGatewayUpdateList.Remove(gwId);
|
| | | }
|
| | | this.FinishUpdateEvent = null;
|
| | |
|
| | | base.CloseForm();
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|
| | | }
|