using System;
|
using Shared.Common;
|
|
namespace Shared.Phone.Device.CommonForm
|
{
|
public class SceneMainView : FrameLayout
|
{
|
/// <summary>
|
/// name
|
/// </summary>
|
public Button TimeButton;
|
/// <summary>
|
/// collect
|
/// </summary>
|
public Button CollectButton;
|
/// <summary>
|
/// SceneIcon
|
/// </summary>
|
public ImageView SceneIcon;
|
/// <summary>
|
/// statu
|
/// </summary>
|
public Button SceneNameButton;
|
/// <summary>
|
/// CardBG
|
/// </summary>
|
private Button CardBG;
|
/// <summary>
|
/// sceneBG
|
/// </summary>
|
public Button sceneBG;
|
/// <summary>
|
/// v_Selected
|
/// </summary>
|
private bool v_Selected;
|
/// <summary>
|
/// scene
|
/// </summary>
|
public SceneUI scene;
|
|
/// <summary>
|
/// IsSelected
|
/// </summary>
|
public bool IsSelected
|
{
|
set
|
{
|
try
|
{
|
v_Selected = value;
|
//SetStatu(v_Selected);
|
}
|
catch { };
|
}
|
get
|
{
|
return v_Selected;
|
}
|
}
|
|
/// <summary>
|
/// SceneMainView
|
/// </summary>
|
/// <param name="x"></param>
|
/// <param name="y"></param>
|
public SceneMainView(int x, int y)
|
{
|
X = Application.GetRealWidth(x);
|
Y = Application.GetRealHeight(y);
|
Width = Application.GetRealWidth(487);
|
Height = Application.GetRealHeight(358);
|
}
|
|
/// <summary>
|
/// init
|
/// </summary>
|
public void Init(SceneUI sceneUI)
|
{
|
this.scene = sceneUI;
|
|
InitFrame();
|
|
InitStatu();
|
}
|
|
/// <summary>
|
/// InitFrame
|
/// </summary>
|
private void InitFrame()
|
{
|
//CardBG = new Button
|
//{
|
// Width = Application.GetMinRealAverage(487),
|
// Height = Application.GetMinRealAverage(348),
|
// UnSelectedImagePath = "Item/FunctionCardView.png",
|
// Gravity = Gravity.CenterHorizontal
|
//};
|
//AddChidren(CardBG);
|
|
SceneIcon = new ImageView
|
{
|
X=Application.GetRealWidth(14),
|
Width = Application.GetMinRealAverage(458),
|
Height = Application.GetMinRealAverage(305),
|
Gravity = Gravity.CenterHorizontal,
|
Radius= (uint)Application.GetRealHeight(17)
|
};
|
AddChidren(SceneIcon);
|
//SceneIcon.SetViewShadow(true);
|
//SceneIcon.SetCornerWithSameRadius(Application.GetRealHeight(100), HDLUtils.RectCornerBottomRight);
|
|
sceneBG = new Button
|
{
|
Width = Application.GetMinRealAverage(487),
|
Height = Application.GetMinRealAverage(348),
|
UnSelectedImagePath = "Scene/Background.png",
|
Gravity = Gravity.CenterHorizontal
|
};
|
AddChidren(sceneBG);
|
|
TimeButton = new Button()
|
{
|
X = Application.GetMinRealAverage(30),
|
Y = Application.GetMinRealAverage(20),
|
Width = Application.GetMinRealAverage(63),
|
Height = Application.GetMinRealAverage(63),
|
TextColor = ZigbeeColor.Current.GXCTextSelectedColor3,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
AddChidren(TimeButton);
|
|
CollectButton = new Button
|
{
|
X = Application.GetMinRealAverage(340),
|
Y = Application.GetMinRealAverage(1),
|
Width = Application.GetMinRealAverage(107),
|
Height = Application.GetMinRealAverage(107),
|
UnSelectedImagePath = "Item/Collection1.png",
|
SelectedImagePath = "Item/CollectionSelected1.png"
|
};
|
AddChidren(CollectButton);
|
|
SceneNameButton = new Button()
|
{
|
X = Application.GetMinRealAverage(46),
|
Y = Application.GetMinRealAverage(239),
|
Width = Application.GetMinRealAverage(279),
|
Height = Application.GetMinRealAverage(60),
|
TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
|
SelectedTextColor = ZigbeeColor.Current.GXCTextSelectedColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
};
|
AddChidren(SceneNameButton);
|
}
|
|
/// <summary>
|
/// InitStatu
|
/// </summary>
|
private void InitStatu()
|
{
|
SetTimeByDelayTime(scene.SceneDelayTime);
|
SetSceneNameText(scene.Name);
|
SetIcon(scene.IconPath);
|
SetCollect(Common.Room.CurrentRoom.GetLoveRoom().SceneUIFilePathList.Contains(scene.FileName));
|
|
TimeButton.MouseUpEventHandler += SetTimeEvents;
|
CollectButton.MouseUpEventHandler += CollectionEvent;
|
SceneIcon.MouseUpEventHandler += SceneUpHandler;
|
SceneNameButton.MouseUpEventHandler += SceneUpHandler;
|
sceneBG.MouseUpEventHandler += SceneUpHandler;
|
}
|
|
/// <summary>
|
/// SetTimeText
|
/// </summary>
|
/// <param name="name"></param>
|
public void SetTimeText(string name)
|
{
|
TimeButton.Width = Application.GetMinRealAverage(280);
|
TimeButton.Height = Application.GetMinRealAverage(63);
|
TimeButton.UnSelectedImagePath = string.Empty;
|
TimeButton.Text = name;
|
}
|
|
/// <summary>
|
/// SetTimeImage
|
/// </summary>
|
public void SetTimeImage()
|
{
|
TimeButton.Width = Application.GetMinRealAverage(63);
|
TimeButton.Height = Application.GetMinRealAverage(63);
|
TimeButton.UnSelectedImagePath = "Item/Time.png";
|
TimeButton.Text = string.Empty;
|
}
|
|
/// <summary>
|
/// SetIimeByDelayTime
|
/// </summary>
|
/// <param name="time"></param>
|
public void SetTimeByDelayTime(int time)
|
{
|
if (time > 0)
|
{
|
SetTimeText(CommonFormResouce.GetTimeString(time));
|
}
|
else
|
{
|
SetTimeImage();
|
}
|
}
|
|
/// <summary>
|
/// SetStatu
|
/// </summary>
|
/// <param name="statu"></param>
|
public void SetSceneNameText(string statu)
|
{
|
SceneNameButton.Text = statu;
|
}
|
|
/// <summary>
|
/// SetIcon
|
/// </summary>
|
/// <param name="iconPath"></param>
|
public void SetIcon(string iconPath)
|
{
|
if (scene.IconPathType == 0)
|
{
|
SceneIcon.ImagePath = iconPath;
|
}
|
else
|
{
|
SceneIcon.ImagePath = System.IO.Path.Combine(Config.Instance.FullPath, iconPath);
|
}
|
}
|
|
/// <summary>
|
/// SetCollect
|
/// </summary>
|
/// <param name="collect"></param>
|
public void SetCollect(bool collect)
|
{
|
CollectButton.IsSelected = collect;
|
}
|
|
/// <summary>
|
/// 调用场景
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="args"></param>
|
private async void SceneUpHandler(object sender, MouseEventArgs args)
|
{
|
if (scene.RemainTime > 0 && scene.SceneDelayTime == 0)
|
{
|
CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneIsDelaying));
|
return;
|
}
|
//1成功 0失败
|
//后面补上相关提示
|
// Error参数含义
|
//<para>1:网关无法解析命令数据。</para>
|
//<para>2:协调器正在升级或备份/恢复数据
|
//<para>3:操作设备/组/场景不存在</para>
|
//<para>4:其他错误</para>
|
//<para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para>
|
var sceneOpenAllData = await ZigBee.Device.Scene.ControlSceneAsync(scene.Id, scene.SceneDelayTime);
|
|
if (sceneOpenAllData == null || sceneOpenAllData.sceneOpenData == null)
|
{
|
return;
|
}
|
if (sceneOpenAllData.sceneOpenData.Result == 0)
|
{
|
if (sceneOpenAllData.errorResponData == null)
|
{
|
return;
|
}
|
CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ControlSceneFail);
|
}
|
|
scene.RemainTime = scene.SceneDelayTime;
|
scene.SceneDelayTime = 0;
|
new System.Threading.Thread(() =>
|
{
|
while (scene.RemainTime > 0)
|
{
|
System.Threading.Thread.Sleep(1000);
|
Application.RunOnMainThread(() =>
|
{
|
SetTimeText(CommonFormResouce.GetTimeString(scene.RemainTime));
|
});
|
scene.RemainTime -= 1;
|
}
|
Application.RunOnMainThread(() =>
|
{
|
SetTimeImage();
|
});
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 收藏
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private void CollectionEvent(object sender,MouseEventArgs mouseEventArgs)
|
{
|
(sender as Button).IsSelected = !(sender as Button).IsSelected;
|
if ((sender as Button).IsSelected)
|
{
|
Shared.Common.Room.CurrentRoom.GetLoveRoom().AddScene(scene);
|
}
|
else
|
{
|
Shared.Common.Room.CurrentRoom.GetLoveRoom().RemoveScene(scene);
|
}
|
scene.Save();
|
}
|
|
/// <summary>
|
/// setTimeEvent
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="mouseEventArgs"></param>
|
private void SetTimeEvents(object sender, MouseEventArgs mouseEventArgs)
|
{
|
if (scene.RemainTime > 0)
|
{
|
CommonFormResouce.ShowTip(Language.StringByID(R.MyInternationalizationString.TheSceneIsDelaying));
|
return;
|
}
|
var timeSelect = new SelectTime();
|
CommonPage.Instance.AddChidren(timeSelect);
|
timeSelect.TempTime = scene.DelayTime;
|
timeSelect.Init();
|
timeSelect.TimeAction = (t) =>
|
{
|
scene.SceneDelayTime = t;
|
SetTimeByDelayTime(t);
|
};
|
}
|
|
}
|
}
|