using Shared.Common;
|
using Shared.Phone.UserCenter;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using ZigBee.Device;
|
|
namespace Shared.Phone.MainPage.ControlForm
|
{
|
/// <summary>
|
/// 彩灯(调光器)类型的深度卡片界面
|
/// </summary>
|
public class DeviceColorLightDetailCardForm : DeviceDetailCardCommonForm
|
{
|
#region ■ 变量声明___________________________
|
|
/// <summary>
|
/// 界面上可以操作的控件
|
/// </summary>
|
private List<ButtonBase> listControl = new List<ButtonBase>();
|
/// <summary>
|
/// MaxLevel
|
/// </summary>
|
private const int MaxLevel = 254;
|
/// <summary>
|
/// 彩灯控件
|
/// </summary>
|
private WaveSeekBar waveSeekBar = null;
|
/// <summary>
|
/// 进度值是否在改变中
|
/// </summary>
|
private bool isProgressing = false;
|
/// <summary>
|
/// 是否已经初始化了控件(因为底层有可能会刷新整个界面)
|
/// </summary>
|
private bool hadInitControl = false;
|
/// <summary>
|
/// 彩灯是否是打开状态(不能用控件的Select来判断,太坑)
|
/// </summary>
|
private bool IsLightOpen = false;
|
|
#endregion
|
|
#region ■ 初始化_____________________________
|
|
/// <summary>
|
/// 底层初始化中部控件完成之后
|
/// </summary>
|
/// <param name="frameWhiteBack"></param>
|
public override void InitMiddleFrameAfter(FrameLayout frameWhiteBack)
|
{
|
//左滑不能
|
this.ScrollEnabled = false;
|
//先清空
|
this.listControl = new List<ButtonBase>();
|
//设置状态文字
|
if (((LightBase)this.device).OnOffStatus == 1)
|
{
|
//亮度 XX
|
this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(this.device));
|
}
|
else
|
{
|
//关闭
|
this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
|
}
|
|
//彩灯控件
|
this.waveSeekBar = new WaveSeekBar();
|
waveSeekBar.Y = Application.GetRealHeight(377);
|
waveSeekBar.Width = this.GetPictrueRealSize(271);
|
waveSeekBar.Height = this.GetPictrueRealSize(533);
|
waveSeekBar.Gravity = Gravity.CenterHorizontal;
|
waveSeekBar.WavePadding = Application.GetRealWidth(8);
|
waveSeekBar.MaxValue = 100;
|
waveSeekBar.Progress = (int)(((DimmableLight)this.device).Level * 1.0 / MaxLevel * 100);
|
waveSeekBar.CornerRadius = Application.GetRealHeight(58);
|
waveSeekBar.SetProgressBarColors(ZigbeeColor.Current.GXCWaveSeekBarColor_Start, ZigbeeColor.Current.GXCWaveSeekBarColor_End);
|
frameWhiteBack.AddChidren(waveSeekBar);
|
|
//开关
|
var btnSwitch = new IconViewControl(81);
|
btnSwitch.UnSelectedImagePath = "Item/Switch.png";
|
btnSwitch.SelectedImagePath = "Item/SwitchSelected.png";
|
btnSwitch.Y = waveSeekBar.Bottom + Application.GetRealHeight(84);
|
btnSwitch.Gravity = Gravity.CenterHorizontal;
|
frameWhiteBack.AddChidren(btnSwitch);
|
listControl.Add(btnSwitch);
|
btnSwitch.ButtonClickEvent += (sender, e) =>
|
{
|
//发送开关命令
|
this.SetSwitchCommand(!btnSwitch.IsSelected);
|
};
|
|
//设置初始状态
|
this.IsLightOpen = ((LightBase)this.device).OnOffStatus == 1;
|
if (IsLightOpen == true)
|
{
|
btnSwitch.IsSelected = true;
|
}
|
|
//彩灯控件里面的那个显示百分比的控件
|
int progressY = waveSeekBar.Y - Application.GetMinReal(154);
|
var btnProgress = new NormalViewControl(Application.GetMinReal(135), Application.GetMinReal(104), false);
|
btnProgress.Y = progressY;
|
btnProgress.UnSelectedImagePath = "Item/ProgressBubbles.png";
|
btnProgress.IsBold = true;
|
btnProgress.TextColor = UserCenterColor.Current.White;
|
btnProgress.Gravity = Gravity.CenterHorizontal;
|
btnProgress.TextAlignment = TextAlignment.Center;
|
frameWhiteBack.AddChidren(btnProgress);
|
btnProgress.Visible = false;
|
|
//开始滑动的事件
|
waveSeekBar.OnStartTrackingTouchEvent += (sender, e) =>
|
{
|
//进度值开始变更
|
this.isProgressing = true;
|
//变更进度百分比的显示
|
btnProgress.Y = progressY + waveSeekBar.NowProgressY;
|
btnProgress.Text = waveSeekBar.Progress + "%";
|
waveSeekBar.IsProgressTextShow = false;
|
if (btnProgress.Visible == false)
|
{
|
btnProgress.Visible = true;
|
}
|
};
|
|
//结束滑动的事件
|
waveSeekBar.OnStopTrackingTouchEvent += (sender, e) =>
|
{
|
//进度值开始结束
|
this.isProgressing = false;
|
btnProgress.Visible = false;
|
waveSeekBar.IsProgressTextShow = true;
|
};
|
|
//滑动过程中
|
int oldProgressValue = waveSeekBar.Progress;//之前的值
|
int nowProgressValue = oldProgressValue;//变更的值
|
waveSeekBar.OnProgressChangedEvent += (sender, value) =>
|
{
|
//变更进度百分比的显示
|
btnProgress.Y = progressY + waveSeekBar.NowProgressY;
|
btnProgress.Text = value + "%";
|
if (Common.Config.Instance.Home.IsVirtually == false)
|
{
|
nowProgressValue = value;
|
}
|
else
|
{
|
//如果住宅为虚拟住宅,直接改缓存
|
((DimmableLight)this.device).Level = value * MaxLevel / 100;
|
//亮度 XX
|
this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(this.device));
|
}
|
};
|
|
if (this.hadInitControl == true)
|
{
|
//已经完成初始化
|
return;
|
}
|
this.hadInitControl = true;
|
|
if (Config.Instance.Home.IsVirtually == true)
|
{
|
//虚拟住宅
|
return;
|
}
|
|
//开一个线程,监视是否滑动的滑动条,每秒检测一次
|
HdlThreadLogic.Current.RunThread(() =>
|
{
|
while (this.Parent != null)
|
{
|
System.Threading.Thread.Sleep(1000);
|
if (nowProgressValue == oldProgressValue)
|
{
|
//值一样
|
continue;
|
}
|
oldProgressValue = nowProgressValue;
|
//发送进度值
|
((DimmableLight)this.device).SetLevel((int)(oldProgressValue * MaxLevel / 100.0));
|
}
|
});
|
}
|
|
#endregion
|
|
#region ■ 发送开关命令_______________________
|
|
/// <summary>
|
/// 发送开关命令
|
/// </summary>
|
/// <param name="isOpen"></param>
|
private void SetSwitchCommand(bool isOpen)
|
{
|
//获取当前亮度
|
int level = Convert.ToInt32(this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.GetField, null, this.device, null));
|
//如果住宅是虚拟住宅
|
if (Common.Config.Instance.Home.IsVirtually == true)
|
{
|
((LightBase)this.device).OnOffStatus = isOpen == true ? 1 : 0;
|
if (((LightBase)this.device).OnOffStatus == 1 && level == 0)
|
{
|
//如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
|
this.device.GetType().InvokeMember("Level", System.Reflection.BindingFlags.SetField, null, this.device, new object[] { 100 });
|
}
|
//刷新开关状态
|
this.RefreshSwitchStatu(isOpen);
|
return;
|
}
|
|
//检测是否获取网关反馈的结果,如果网关没有回复,则会弹出消息
|
this.StartCheckResponeResult(this.listControl, (result) =>
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
bool statu = ((LightBase)this.device).OnOffStatus == 1;
|
//接收到网关回复
|
if (result == true)
|
{
|
//刷新开关状态
|
this.RefreshSwitchStatu(statu);
|
//状态取反
|
listControl[0].IsSelected = statu;
|
}
|
});
|
});
|
if (isOpen == true)
|
{
|
//打开
|
if (level == 0)
|
{
|
//如果当前是打开状态,并且亮度为0的话,则需要变成100%亮度
|
this.device.GetType().InvokeMember("SetLevel", System.Reflection.BindingFlags.InvokeMethod, null, this.device, new object[] { 254 });
|
}
|
else
|
{
|
this.device.SwitchControl(1);
|
}
|
}
|
else
|
{
|
//关闭
|
this.device.SwitchControl(0);
|
}
|
}
|
|
#endregion
|
|
#region ■ 是否获取网关反馈的结果_____________
|
|
/// <summary>
|
/// 检测网关的反馈结果(属性上报的对象:device.DeviceStatusReport)
|
/// </summary>
|
/// <param name="comandDiv">命令区分</param>
|
/// <param name="report">上报数据</param>
|
/// <returns></returns>
|
public override bool CheckResponeResultStatu(ReceiveComandDiv comandDiv, CommonDevice report)
|
{
|
if (comandDiv == ReceiveComandDiv.A设备属性上报)
|
{
|
HdlThreadLogic.Current.RunMain(() =>
|
{
|
//刷新开关状态
|
this.RefreshSwitchStatu(((LightBase)this.device).OnOffStatus == 1);
|
});
|
return true;
|
}
|
return false;
|
}
|
|
#endregion
|
|
#region ■ 刷新开关状态_______________________
|
|
/// <summary>
|
/// 刷新开关状态
|
/// </summary>
|
/// <param name="isOpen">打开状态</param>
|
private void RefreshSwitchStatu(bool isOpen)
|
{
|
if (isOpen == true)
|
{
|
//亮度是必须要刷新的 亮度 XX
|
this.SetStatuText(Language.StringByID(R.MyInternationalizationString.uBrightness) + " " + HdlDeviceCommonLogic.Current.GetMainPageDeviceStatuText(this.device));
|
}
|
if (isOpen == false && this.IsLightOpen == true)
|
{
|
//状态不一样,才变更字样:关闭
|
this.SetStatuText(Language.StringByID(R.MyInternationalizationString.Close));
|
}
|
|
if (this.isProgressing == false)
|
{
|
//当进度值在手动变更中时,不接收推送
|
waveSeekBar.Progress = (int)(((DimmableLight)this.device).Level * 1.0 / MaxLevel * 100);
|
}
|
|
if (listControl[0].IsSelected != isOpen)
|
{
|
//开关状态变更
|
listControl[0].IsSelected = isOpen;
|
}
|
|
this.IsLightOpen = isOpen;
|
}
|
|
#endregion
|
}
|
}
|