using System;
|
using HDL_ON.Entity;
|
using Shared;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using System.Collections.Generic;
|
using HDL_ON.DriverLayer;
|
|
namespace HDL_ON.UI
|
{
|
public class CurtainDreamPage : FrameLayout
|
{
|
|
#region 控件集合
|
static CurtainDreamPage bodyView;
|
/// <summary>
|
/// 功能名称按钮
|
/// </summary>
|
Button btnFunctionName;
|
/// <summary>
|
/// 房间楼层信息按钮
|
/// </summary>
|
Button btnFromFoorAndRoom;
|
/// <summary>
|
/// 收藏按钮
|
/// </summary>
|
Button btnCollection;
|
/// <summary>
|
/// 窗帘动态控件
|
/// </summary>
|
CurtainSeekBarOn curtainSeekBar;
|
/// <summary>
|
/// 进度值
|
/// </summary>
|
Button btnProgress;
|
/// <summary>
|
/// 角度控件集
|
/// </summary>
|
List<Button> buttons;
|
/// <summary>
|
/// 角度文本按钮
|
/// </summary>
|
Button btnAngle;
|
/// <summary>
|
/// 角度滑动控件
|
/// </summary>
|
DiyImageSeekBar angleBar;
|
|
|
/// <summary>
|
/// 窗帘关闭按钮
|
/// </summary>
|
Button btnCurtainClose;
|
/// <summary>
|
/// 窗帘停止按钮
|
/// </summary>
|
Button btnCurtainStop;
|
/// <summary>
|
/// 窗帘打开按钮
|
/// </summary>
|
Button btnCurtainOpen;
|
#endregion
|
|
#region 区域变量
|
Entity.Curtain curtainTemp = new Entity.Curtain();
|
|
Function function;
|
Button btnCollection_Out;
|
Button btnFunctionName_Out;
|
Button btnFromFloor_Out;
|
/// <summary>
|
/// 刷新显示信息
|
/// </summary>
|
Action actionRefresh;
|
#endregion
|
/// <summary>
|
/// 正在控制
|
/// </summary>
|
bool onControl = false;
|
|
public CurtainDreamPage(Function func)
|
{
|
bodyView = this;
|
function = func;
|
}
|
|
public void LoadPage(Button btnCollectionIcon, Button btnFunctionNameOut, Button btnFromFloorOut)
|
{
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
btnCollection_Out = btnCollectionIcon;
|
btnFunctionName_Out = btnFunctionNameOut;
|
btnFromFloor_Out = btnFromFloorOut;
|
|
|
FrameLayout controlView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(88),
|
Width = Application.GetRealWidth(327),
|
Height = Application.GetRealHeight(526),
|
BackgroundImagePath = "Public/Fragmentbg.png",
|
};
|
bodyView.AddChidren(controlView);
|
|
btnFunctionName = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(14),
|
Width = Application.GetRealWidth(270),
|
Height = Application.GetRealHeight(37),
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel,
|
Text = function.name,
|
};
|
controlView.AddChidren(btnFunctionName);
|
|
btnFromFoorAndRoom = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Y = btnFunctionName.Bottom,
|
Width = Application.GetRealWidth(270),
|
Height = Application.GetRealHeight(21),
|
TextColor = CSS_Color.PromptingColor1,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
Text = function.GetRoomListName()
|
};
|
controlView.AddChidren(btnFromFoorAndRoom);
|
|
btnCollection = new Button()
|
{
|
X = Application.GetRealWidth(273),
|
Y = Application.GetRealHeight(14),
|
Width = Application.GetMinRealAverage(40),
|
Height = Application.GetMinRealAverage(40),
|
SelectedImagePath = "Collection/CollectionIcon.png",
|
UnSelectedImagePath = "Collection/CollectionGrayIcon.png",
|
IsSelected = function.collect
|
};
|
controlView.AddChidren(btnCollection);
|
//2020-12-16 如果是成员隐藏收藏功能
|
//if (!DB_ResidenceData.Instance.CurrentRegion.isOtherShare)
|
//{
|
// controlView.AddChidren(btnCollection);
|
//}
|
|
|
btnProgress = new Button()
|
{
|
Y = Application.GetRealHeight(80),
|
Height = Application.GetRealHeight(50),
|
TextSize = CSS_FontSize.TextFontSize,
|
TextColor = CSS_Color.PromptingColor1,
|
Text = curtainTemp.GetPercent(function).ToString() + "%",
|
};
|
controlView.AddChidren(btnProgress);
|
|
|
curtainSeekBar = new CurtainSeekBarOn()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(130),
|
Width = Application.GetRealWidth(250),
|
Height = Application.GetRealWidth(177),
|
Progress = curtainTemp.GetPercent(function),
|
ProgressTextColor = 0x00000000,
|
//IsInvertedProgress = true,
|
};
|
controlView.AddChidren(curtainSeekBar);
|
|
|
int angleValut = Convert.ToInt32(function.GetAttrState("angle")) - 90;
|
var angleView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(300),//414,设计数据
|
Width = Application.GetRealWidth(250),
|
Height = Application.GetRealWidth(30),
|
BackgroundColor = 0x00ff0000
|
};
|
controlView.AddChidren(angleView);
|
|
buttons = new List<Button>();
|
for (int i = 0; i < 18; i++)
|
{
|
var btn = new Button()
|
{
|
X = Application.GetRealWidth(12 * i + 4),
|
Y = Application.GetRealHeight(5),
|
Width = Application.GetRealWidth(4),
|
Height = Application.GetRealHeight(20),
|
BackgroundColor = 0xFFDFE1E6,
|
};
|
btn.SetRotation(angleValut);
|
angleView.AddChidren(btn);
|
buttons.Add(btn);
|
};
|
|
btnAngle = new Button()
|
{
|
TextAlignment = TextAlignment.CenterRight,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextColor = CSS_Color.PromptingColor1,
|
Text = function.GetAttrState("angle") + "°"
|
};
|
angleView.AddChidren(btnAngle);
|
|
angleBar = new DiyImageSeekBar()
|
{
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealHeight(30),
|
SeekBarViewHeight = Application.GetRealHeight(20),
|
SeekBarBackgroundColor = 0x00000000,
|
ThumbImagePath = "Public/ThumbImage2.png",
|
ThumbImageHeight = Application.GetRealHeight(40),
|
ProgressBarColor = 0x00000000,
|
ProgressTextColor = 0x00000000,
|
ProgressTextSize = 0,
|
MaxValue = 180,
|
Progress = 90,
|
ProgressChangeDelayTime = 0
|
};
|
angleView.AddChidren(angleBar);
|
angleBar.OnProgressChangedEvent = (sender, e) =>
|
{
|
float angle = (e - 90);
|
btnAngle.Text = e + "°";
|
foreach (var btn in buttons)
|
{
|
btn.SetRotation(angle);
|
}
|
};
|
angleBar.OnStopTrackingTouchEvent = (sende, e) =>
|
{
|
function.refreshTime = DateTime.Now;
|
new System.Threading.Thread(() =>
|
{
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
dic.Add("angle", e.ToString());
|
Control.Ins.SendWriteCommand(function, dic);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
|
btnCurtainClose = new Button()
|
{
|
X = Application.GetRealWidth(84),
|
Y = Application.GetRealHeight(466),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/Curtain/CurtainCloseIcon.png",
|
SelectedImagePath = "FunctionIcon/Curtain/CurtainCloseOnIcon.png",
|
};
|
controlView.AddChidren(btnCurtainClose);
|
|
btnCurtainStop = new Button()
|
{
|
X = Application.GetRealWidth(148),
|
Y = Application.GetRealHeight(466),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/Curtain/CurtainStopIcon.png",
|
SelectedImagePath = "FunctionIcon/Curtain/CurtainStopOnIcon.png",
|
};
|
controlView.AddChidren(btnCurtainStop);
|
|
btnCurtainOpen = new Button()
|
{
|
X = Application.GetRealWidth(212),
|
Y = Application.GetRealHeight(466),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/Curtain/CurtainOpenIcon.png",
|
SelectedImagePath = "FunctionIcon/Curtain/CurtainOpenOnIcon.png",
|
};
|
controlView.AddChidren(btnCurtainOpen);
|
|
LoadEventList();
|
new TopViewDiv(bodyView, Language.StringByID(StringId.Curtain)).LoadTopView_FunctionTop(function, actionRefresh);
|
new System.Threading.Thread(() =>
|
{
|
Control.Ins.SendReadCommand(function);
|
})
|
{ IsBackground = true }.Start();
|
}
|
|
/// <summary>
|
/// 更新窗帘
|
/// </summary>
|
/// <param name="updateTemp"></param>
|
public static void UpdataState(Function updateTemp)
|
{
|
Application.RunOnMainThread((Action)(() =>
|
{
|
if (bodyView == null)
|
return;
|
if (bodyView.onControl)
|
return;
|
if (updateTemp.spk == bodyView.function.spk && updateTemp.sid == bodyView.function.sid)
|
{
|
try
|
{
|
if (!bodyView.onCurtainAnimation)
|
{
|
var percent = Convert.ToInt32(updateTemp.GetAttrState(FunctionAttributeKey.Percent));
|
bodyView.CurtainAnimation(percent);
|
bodyView.btnProgress.Text = percent + "%";
|
|
var e = Convert.ToInt32( updateTemp.GetAttrState(FunctionAttributeKey.Angle));
|
bodyView.angleBar.Progress = e;
|
float angle = e - 90;
|
bodyView.btnAngle.Text = (e - 0) + "°";
|
foreach (var btn in bodyView.buttons)
|
{
|
btn.SetRotation(angle);
|
}
|
|
|
}
|
}
|
catch { }
|
}
|
}));
|
}
|
|
/// <summary>
|
/// 正在执行窗帘动画
|
/// </summary>
|
bool onCurtainAnimation = false;
|
/// <summary>
|
/// 窗帘动画
|
/// </summary>
|
/// <param name="progress"></param>
|
void CurtainAnimation(int progress)
|
{
|
onCurtainAnimation = true;
|
//运行方向 打开(加进度):关闭(减进度)
|
bool runningDirection = progress > curtainSeekBar.Progress;
|
int curBarProgress = curtainSeekBar.Progress;
|
btnProgress.Text = progress + "%";
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
while (progress != curBarProgress && onCurtainAnimation)
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (runningDirection)
|
{
|
if (curtainSeekBar.Progress + 5 > progress)
|
{
|
curtainSeekBar.Progress = progress;
|
}
|
else
|
{
|
curtainSeekBar.Progress = curtainSeekBar.Progress + 5;
|
}
|
}
|
else
|
{
|
if (curtainSeekBar.Progress - 5 < progress)
|
{
|
curtainSeekBar.Progress = progress;
|
}
|
else
|
{
|
curtainSeekBar.Progress = curtainSeekBar.Progress - 5;
|
}
|
}
|
curBarProgress = curtainSeekBar.Progress;
|
});
|
System.Threading.Thread.Sleep(100);
|
}
|
}
|
catch { }
|
finally
|
{
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(3000);
|
onCurtainAnimation = false;
|
})
|
{ IsBackground = true, Priority = System.Threading.ThreadPriority.Lowest }.Start();
|
}
|
}).Start();
|
}
|
|
|
/// <summary>
|
/// 加载事件列表
|
/// </summary>
|
void LoadEventList()
|
{
|
LoadEvent_ControlEvent();
|
LoadCollectionEvent();
|
|
//回退刷新信息事件
|
actionRefresh = () =>
|
{
|
btnFunctionName.Text = btnFunctionName_Out.Text = function.name;
|
btnFromFloor_Out.Text = btnFromFoorAndRoom.Text = function.GetRoomListName();
|
//function.SaveFunctionData(true);
|
};
|
}
|
/// <summary>
|
/// 收藏功能按钮事件
|
/// </summary>
|
void LoadCollectionEvent()
|
{
|
btnCollection.MouseUpEventHandler += (sender, e) =>
|
{
|
btnCollection.IsSelected = function.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
|
function.CollectFunction();
|
};
|
}
|
|
/// <summary>
|
/// 加载窗帘控制事件
|
/// </summary>
|
void LoadEvent_ControlEvent()
|
{
|
btnCurtainClose.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(2000);
|
Application.RunOnMainThread(() =>
|
{
|
btnCurtainClose.IsSelected = false;
|
});
|
})
|
{ IsBackground = true }.Start();
|
function.trait_on_off.curValue = "off";
|
function.SetAttrState(FunctionAttributeKey.Percent, 0);
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
DriverLayer.Control.Ins.SendWriteCommand(function, d);
|
CurtainAnimation(0);
|
};
|
|
btnCurtainStop.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
onCurtainAnimation = false;
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(2000);
|
Application.RunOnMainThread(() =>
|
{
|
btnCurtainStop.IsSelected = false;
|
});
|
})
|
{ IsBackground = true }.Start();
|
function.trait_on_off.curValue = "stop";
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
DriverLayer.Control.Ins.SendWriteCommand(function, d);
|
};
|
|
btnCurtainOpen.MouseUpEventHandler = (sender, e) =>
|
{
|
//if (!function.online)
|
//{
|
// new Tip()
|
// {
|
// CloseTime = 1,
|
// Text = Language.StringByID(StringId.DeviceOfflineCannotOption),
|
// Direction = AMPopTipDirection.None,
|
// }.Show(MainPage.BaseView);
|
// return;
|
//}
|
new System.Threading.Thread(() =>
|
{
|
System.Threading.Thread.Sleep(2000);
|
Application.RunOnMainThread(() =>
|
{
|
btnCurtainOpen.IsSelected = false;
|
});
|
})
|
{ IsBackground = true }.Start();
|
function.trait_on_off.curValue = "on";
|
function.SetAttrState(FunctionAttributeKey.Percent, 100);
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, function.trait_on_off.curValue.ToString());
|
DriverLayer.Control.Ins.SendWriteCommand(function, d);
|
CurtainAnimation(100);
|
};
|
|
//if (function.online)
|
{
|
btnCurtainStop.MouseDownEventHandler = (sender, e) =>
|
{
|
btnCurtainStop.IsSelected = true;
|
btnCurtainClose.IsSelected = false;
|
btnCurtainOpen.IsSelected = false;
|
};
|
btnCurtainOpen.MouseDownEventHandler = (sender, e) =>
|
{
|
btnCurtainOpen.IsSelected = true;
|
btnCurtainClose.IsSelected = false;
|
btnCurtainStop.IsSelected = false;
|
};
|
btnCurtainClose.MouseDownEventHandler = (sender, e) =>
|
{
|
btnCurtainClose.IsSelected = true;
|
btnCurtainOpen.IsSelected = false;
|
btnCurtainStop.IsSelected = false;
|
};
|
|
curtainSeekBar.OnProgressChangedEvent = (sender, e) =>
|
{
|
btnProgress.Text = curtainSeekBar.Progress + "%";
|
};
|
curtainSeekBar.OnStopTrackingTouchEvent = (sender, e) =>
|
{
|
btnProgress.Text = curtainSeekBar.Progress + "%";
|
//controlBar.Progress = curtainSeekBar.Progress;
|
new System.Threading.Thread(() =>
|
{
|
function.SetAttrState(FunctionAttributeKey.Percent, e);
|
function.refreshTime = DateTime.Now;
|
System.Collections.Generic.Dictionary<string, string> d = new System.Collections.Generic.Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Percent, e.ToString());
|
DriverLayer.Control.Ins.SendWriteCommand(function, d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
}
|
}
|
|
}
|
}
|