using System;
|
using System.Collections.Generic;
|
using HDL_ON.Entity;
|
using HDL_ON.UI.CSS;
|
using Shared;
|
|
namespace HDL_ON.UI
|
{
|
public partial class GroupControlPage_V2 : FrameLayout
|
{
|
FrameLayout bodyView;
|
GroupControl function;
|
|
FrameLayout controlView;
|
|
Button btnFunctionName;
|
Button btnFromFoorAndRoom;
|
Button btnCollection;
|
|
Button btnCollection_Out;
|
Button btnFunctionName_Out;
|
Button btnFromFloor_Out;
|
|
public GroupControlPage_V2(GroupControl groupControl)
|
{
|
bodyView = this;
|
function = groupControl;
|
if (function == null)
|
{
|
function = new GroupControl();
|
}
|
}
|
|
public override void RemoveFromParent()
|
{
|
base.RemoveFromParent();
|
}
|
|
public void LoadPage(Button btnCollectionIcon, Button btnFunctionNameOut, Button btnFromFloorOut)
|
{
|
bodyView.RemoveAll();
|
|
btnCollection_Out = btnCollectionIcon;
|
btnFunctionName_Out = btnFunctionNameOut;
|
btnFromFloor_Out = btnFromFloorOut;
|
bodyView.BackgroundColor = CSS_Color.BackgroundColor;
|
|
controlView = new FrameLayout()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(88 + 10),
|
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);
|
//btnCollection.MouseUpEventHandler += (sender, e) => {
|
// btnCollection.IsSelected = function.collect = btnCollection_Out.IsSelected = !btnCollection.IsSelected;
|
// function.CollectFunction();
|
//};
|
|
//回退刷新信息事件
|
new TopViewDiv(bodyView, Language.StringByID(StringId.GroupControl)).LoadTopView_SettingIcon( () => {
|
var page = new AddGroupControlPage(function,
|
(newGC) => {
|
try
|
{
|
Application.RunOnMainThread(() =>
|
{
|
if (newGC != null)
|
{
|
var localTemp = FunctionList.List.groupControls.Find((obj) => obj.deviceId == newGC.deviceId);
|
if(localTemp!= null)
|
{
|
try
|
{
|
localTemp.sids = newGC.sids;
|
localTemp.name = newGC.name;
|
localTemp.roomIds = newGC.roomIds;
|
localTemp.uids = newGC.uids;
|
}
|
catch { }
|
function = newGC;
|
btnFunctionName_Out.Text = function.name;
|
btnFromFloor_Out.Text = function.GetRoomListName();
|
LoadPage(btnCollection, btnFunctionName, btnFunctionName);
|
}
|
}
|
});
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"刷新群控房间信息异常:{ex.Message}");
|
}
|
},()=> {
|
try
|
{
|
this.RemoveFromParent();
|
UI.HomePage.RefreshGroupControlView();
|
UI.RoomPage.bodyView?.ReLoadPage();
|
UI.FunctionPage.bodyView?.ReLoadPage();
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"群控刷新界面异常:\r\n{ex.Message}");
|
}
|
});
|
MainPage.BasePageView.AddChidren(page);
|
page.LoadPage();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
|
});
|
|
ShowContentView();
|
}
|
|
private void ShowContentView()
|
{
|
var hadDimming = false;
|
var hadCCT = false;
|
var hadRGB = false;
|
var hadColorful = false;
|
|
foreach (var temp in function.sids)
|
{
|
if (temp.spk == SPK.LightRGB)
|
{
|
if (!hadColorful)
|
{
|
var lightGroupControl = FunctionList.List.GetLightList().Find((obj) => obj.sid == temp.sid);
|
if (lightGroupControl != null)
|
{
|
if (lightGroupControl.GetAttribute(FunctionAttributeKey.Colorful) != null)
|
{
|
hadColorful = true;
|
}
|
}
|
}
|
hadRGB = true;
|
hadDimming = true;
|
}
|
else if (temp.spk == SPK.LightCCT)
|
{
|
hadCCT = true;
|
hadDimming = true;
|
}
|
else if (temp.spk == SPK.LightDimming)
|
{
|
hadDimming = true;
|
}
|
|
if (hadDimming && hadCCT && hadRGB && hadColorful)
|
{
|
break;
|
}
|
}
|
|
//属性设置区域
|
VerticalScrolViewLayout attrView = new VerticalScrolViewLayout()
|
{
|
Y = Application.GetRealHeight(52),
|
Width = Application.GetRealWidth(343),
|
ScrollEnabled = false,
|
};
|
controlView.AddChidren(attrView);
|
|
attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) });
|
|
var btnOn = new Button()
|
{
|
X = Application.GetRealWidth(100),
|
Y = Application.GetRealHeight(466),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/Light/LightScene/gp_all_on.png",
|
};
|
controlView.AddChidren(btnOn);
|
var btnOnText = new Button()
|
{
|
X = Application.GetRealWidth(100-9),
|
Y = Application.GetRealHeight(495),
|
Width = Application.GetMinRealAverage(50),
|
Height = Application.GetMinRealAverage(32),
|
TextColor = CSS_Color.TextualColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.Center,
|
TextID = StringId.Open,
|
};
|
controlView.AddChidren(btnOnText);
|
|
|
var btnOff = new Button()
|
{
|
X = Application.GetRealWidth(180),
|
Y = Application.GetRealHeight(466),
|
Width = Application.GetMinRealAverage(32),
|
Height = Application.GetMinRealAverage(32),
|
UnSelectedImagePath = "FunctionIcon/Light/LightScene/gp_all_off.png",
|
};
|
controlView.AddChidren(btnOff);
|
var btnOffText = new Button()
|
{
|
X = Application.GetRealWidth(180 - 9),
|
Y = Application.GetRealHeight(495),
|
Width = Application.GetMinRealAverage(50),
|
Height = Application.GetMinRealAverage(32),
|
TextColor = CSS_Color.TextualColor,
|
TextSize = CSS_FontSize.TextFontSize,
|
TextAlignment = TextAlignment.Center,
|
TextID = StringId.Close,
|
};
|
controlView.AddChidren(btnOffText);
|
|
|
|
btnOn.MouseUpEventHandler = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "on");
|
function.Control(d);
|
};
|
|
btnOff.MouseUpEventHandler = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "off");
|
function.Control(d);
|
};
|
btnOnText.MouseUpEventHandler = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "on");
|
function.Control(d);
|
};
|
|
btnOffText.MouseUpEventHandler = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "off");
|
function.Control(d);
|
};
|
|
|
if (hadRGB)
|
{
|
LoadRgbAttrView(hadCCT,hadColorful,btnOn,btnOff);
|
}
|
else if (hadCCT)
|
{
|
LoadCctAttrView(attrView, btnOn, btnOff);
|
}
|
else if (hadDimming)
|
{
|
LoadDimmingAttrView(attrView, btnOn, btnOff);
|
}
|
else
|
{
|
attrView.AddChidren(new Button() { Height = Application.GetRealHeight(30) });
|
var btnSwitchIcon = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = Application.GetRealHeight(102),
|
Width = Application.GetRealWidth(168),
|
Height = Application.GetRealWidth(288),
|
UnSelectedImagePath = "FunctionIcon/Light/RelayBg.png",
|
SelectedImagePath = "FunctionIcon/Light/RelayOnBg.png",
|
IsSelected = function.trait_on_off.curValue.ToString() == "on"
|
};
|
attrView.AddChidren(btnSwitchIcon);
|
|
btnSwitchIcon.MouseUpEventHandler = (sender, e) => {
|
btnSwitchIcon.IsSelected = !btnSwitchIcon.IsSelected;
|
if (btnSwitchIcon.IsSelected)
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "on");
|
function.Control(d);
|
}
|
else
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.OnOff, "off");
|
function.Control(d);
|
}
|
};
|
|
btnOn.MouseUpEventHandler += (sender, e) => {
|
btnSwitchIcon.IsSelected = true;
|
};
|
btnOff.MouseUpEventHandler += (sender, e) => {
|
btnSwitchIcon.IsSelected = false;
|
};
|
}
|
|
|
|
|
}
|
|
/// <summary>
|
/// 加载调光属性设置控件
|
/// </summary>
|
/// <param name="attrView"></param>
|
void LoadDimmingAttrView(VerticalScrolViewLayout attrView,Button btnOn,Button btnOff)
|
{
|
|
|
|
attrView.AddChidren(new Button
|
{
|
Height = Application.GetRealHeight(50),
|
});
|
|
var dimmerView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(280)
|
};
|
attrView.AddChidren(dimmerView);
|
|
var dimmerBar = new WaveSeekBarOn()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(168 - 40),
|
Height = Application.GetRealHeight(288 - 16 - 16),
|
BorderColor = 0x00000000,
|
CornerRadius = Application.GetRealWidth(30),
|
BorderWidth = 0,
|
Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
|
IsProgressTextShow = false,
|
};
|
dimmerView.AddChidren(dimmerBar);
|
|
var btnBrightnessText = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = ((100 - Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100),
|
Width = Application.GetRealWidth(56),
|
Height = Application.GetRealWidth(46),
|
UnSelectedImagePath = "FunctionIcon/Light/BrightnessBg.png",
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
|
Text = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)) + "%",
|
};
|
dimmerView.AddChidren(btnBrightnessText);
|
|
dimmerBar.OnStopTrackingTouchEvent = (sender, e) => {
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
dimmerBar.OnProgressChangedEvent = (sender, e) =>
|
{
|
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
return;
|
if (e == 0 && lastBrightness != 0)
|
{
|
lastBrightness = 0;
|
}
|
else
|
{
|
if (lastBrightness == 0)
|
lastBrightness = e;
|
}
|
if (e == 0 || e == 100)
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
d.Add(FunctionAttributeKey.OnOff, e == 0 ? "off" : "on");
|
function.Control(d);
|
}
|
else
|
{
|
if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
|
{
|
function.refreshTime = DateTime.Now;
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
|
};
|
|
|
|
btnOn.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 100;
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
btnOff.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 0;
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
|
|
}
|
int lastBrightness = 0;
|
|
/// <summary>
|
/// 加载cct属性设置控件
|
/// </summary>
|
/// <param name="attrView"></param>
|
void LoadCctAttrView(VerticalScrolViewLayout attrView,Button btnOn,Button btnOff)
|
{
|
attrView.AddChidren(new Button
|
{
|
Height = Application.GetRealHeight(20),
|
});
|
|
var dimmerView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(280)
|
};
|
attrView.AddChidren(dimmerView);
|
|
var dimmerBar = new WaveSeekBarOn()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Width = Application.GetRealWidth(168 - 40),
|
Height = Application.GetRealHeight(288 - 16 - 16),
|
BorderColor = 0x00000000,
|
CornerRadius = Application.GetRealWidth(30),
|
BorderWidth = 0,
|
Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
|
IsProgressTextShow = false,
|
};
|
dimmerView.AddChidren(dimmerBar);
|
|
var btnBrightnessText = new Button()
|
{
|
Gravity = Gravity.CenterHorizontal,
|
Y = ((100 - Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness))) * Application.GetRealHeight(222 - 16) / 100),
|
Width = Application.GetRealWidth(56),
|
Height = Application.GetRealWidth(46),
|
UnSelectedImagePath = "FunctionIcon/Light/BrightnessBg.png",
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
|
Text = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)) + "%",
|
};
|
dimmerView.AddChidren(btnBrightnessText);
|
|
dimmerBar.OnStopTrackingTouchEvent = (sender, e) => {
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
dimmerBar.OnProgressChangedEvent = (sender, e) =>
|
{
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
return;
|
if (e == 0 && lastBrightness != 0)
|
{
|
lastBrightness = 0;
|
}
|
else
|
{
|
if (lastBrightness == 0)
|
lastBrightness = e;
|
}
|
|
if (e == 0 || e == 100)
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
d.Add(FunctionAttributeKey.OnOff, e == 0 ? "off" : "on");
|
function.Control(d);
|
}
|
else
|
{
|
if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
|
{
|
function.refreshTime = DateTime.Now;
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
|
|
};
|
|
|
//attrView.AddChidren(new Button() { Height = Application.GetRealHeight(10) });
|
|
#region 色温
|
var cctView = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(75 + 11)
|
};
|
attrView.AddChidren(cctView);
|
|
|
//色温
|
var btnTempClolor = new Button();
|
btnTempClolor.X = Application.GetRealWidth(35);
|
btnTempClolor.Y = Application.GetRealHeight(1);
|
btnTempClolor.Width = Application.GetRealWidth(224);
|
btnTempClolor.Height = Application.GetRealHeight(42);
|
btnTempClolor.TextAlignment = TextAlignment.CenterLeft;
|
btnTempClolor.TextColor = CSS_Color.FirstLevelTitleColor;
|
btnTempClolor.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
btnTempClolor.TextID = StringId.ColorTemperature;
|
cctView.AddChidren(btnTempClolor);
|
|
//2700K
|
var btnTempClolorMin = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = btnTempClolor.Bottom,
|
Width = Application.GetRealWidth(40),
|
Height = Application.GetRealHeight(21),
|
};
|
btnTempClolorMin.Width = Application.GetRealWidth(54);
|
btnTempClolorMin.Height = Application.GetRealHeight(21);
|
btnTempClolorMin.Text = "2700K";
|
btnTempClolorMin.TextAlignment = TextAlignment.CenterLeft;
|
btnTempClolorMin.TextColor = CSS_Color.PromptingColor1;
|
btnTempClolorMin.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
cctView.AddChidren(btnTempClolorMin);
|
|
//滑动条的背景图片
|
var btnColorTemplatrueBack = new Button()
|
{
|
X = Application.GetRealWidth(55 + 22 + 15),
|
Y = Application.GetRealHeight(11),
|
Width = Application.GetRealWidth(180),
|
Height = Application.GetRealHeight(54),
|
};
|
btnColorTemplatrueBack.UnSelectedImagePath = "FunctionIcon/Light/ColorTemperatureBar.png";
|
btnColorTemplatrueBack.Height = Application.GetRealHeight(8);
|
btnColorTemplatrueBack.Gravity = Gravity.CenterHorizontal;
|
cctView.AddChidren(btnColorTemplatrueBack);
|
//滑动条控件
|
var barColorTemplatrue = new CCTSeekBarControl()
|
{
|
X = Application.GetRealWidth(55 + 22),
|
Y = Application.GetRealHeight(11),
|
Width = Application.GetRealWidth(220),
|
Height = Application.GetRealHeight(54),
|
Progress = 38,
|
};
|
barColorTemplatrue.MinValue = 27;
|
barColorTemplatrue.MaxValue = 65;
|
barColorTemplatrue.ProgressBarColor = 0x00000000;//全部透明
|
barColorTemplatrue.ProgressBarUnEnableColor = 0x00000000;
|
barColorTemplatrue.SeekBarBackgroundColor = 0x00000000;
|
cctView.AddChidren(barColorTemplatrue);
|
barColorTemplatrue.Y = btnTempClolorMin.Y - (barColorTemplatrue.Height - btnTempClolorMin.Height) / 2;
|
//设置初始值
|
btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
|
barColorTemplatrue.OnProgressChangedEvent = (sender, e) =>
|
{
|
btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
|
};
|
barColorTemplatrue.OnStopTrackingTouchEvent = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.CCT, (barColorTemplatrue.Progress * 100).ToString());
|
function.Control(d);
|
};
|
//变更背景图的Y轴坐标
|
btnColorTemplatrueBack.Y = barColorTemplatrue.Y + (barColorTemplatrue.Height - btnColorTemplatrueBack.Height) / 2;
|
|
//6500K
|
var btnTempClolorMax = new Button();
|
btnTempClolorMax.Y = btnTempClolorMin.Y;
|
btnTempClolorMax.X = barColorTemplatrue.Right - Application.GetRealWidth(30);
|
btnTempClolorMax.Width = Application.GetRealWidth(54);
|
btnTempClolorMax.Height = Application.GetRealHeight(21);
|
btnTempClolorMax.Text = "6500K";
|
btnTempClolorMax.TextAlignment = TextAlignment.CenterRight;
|
btnTempClolorMax.TextColor = CSS_Color.PromptingColor1;
|
btnTempClolorMax.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
cctView.AddChidren(btnTempClolorMax);
|
|
#endregion
|
|
|
|
|
btnOn.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 100;
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
btnOff.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 0;
|
btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
|
|
}
|
|
/// <summary>
|
/// 加载rgb属性设置控件
|
/// </summary>
|
/// <param name="attrView"></param>
|
void LoadRgbAttrView(bool hadCCT,bool hadColorful,Button btnOn,Button btnOff)
|
{
|
Light lightTemp = new Light();
|
int magriHeight = 0;
|
if (hadCCT && hadColorful)
|
{
|
magriHeight = 80;
|
}
|
|
var btnCurColor = new Button()
|
{
|
X = Application.GetRealWidth(16),
|
Y = Application.GetRealHeight(74),
|
Width = Application.GetMinRealAverage(24),
|
Height = Application.GetMinRealAverage(24),
|
Radius = (uint)Application.GetMinRealAverage(8),
|
BorderColor = CSS_Color.PromptingColor2,
|
BorderWidth = 1,
|
BackgroundColor = (uint)(0xFF000000 + lightTemp.GetRGBcolor(function.GetAttrState(FunctionAttributeKey.RGB)))
|
};
|
controlView.AddChidren(btnCurColor);
|
|
|
//色盘的桌布控件(限制那个白色滑动球使用)
|
var framePickerBack = new FrameLayout();
|
framePickerBack.Gravity = Gravity.CenterHorizontal;
|
framePickerBack.Y = btnFromFoorAndRoom.Bottom + Application.GetRealHeight(1);
|
framePickerBack.Width = Application.GetMinRealAverage(216 - magriHeight);
|
framePickerBack.Height = Application.GetMinRealAverage(216 - magriHeight);
|
//framePickerBack.BackgroundColor = 0xFFFF0000;
|
controlView.AddChidren(framePickerBack);
|
|
var colorPicker = new ColorPicker()
|
{
|
Gravity = Gravity.Center,
|
ColorImagePath = "FunctionIcon/Light/ColorWheel.png",
|
};
|
framePickerBack.AddChidren(colorPicker);
|
//if (function.trait_on_off.curValue.ToString() == "off")
|
//{
|
// colorPicker.ColorImagePath = "FunctionIcon/Light/ColorWheelGray.png";
|
//}
|
//colorPicker.MouseDownEventHandler = (sender, e) => {
|
// MainPage.BasePageView.ScrollEnabled = false;
|
//};
|
//colorPicker.MouseUpEventHandler = (sender, e) => {
|
// MainPage.BasePageView.ScrollEnabled = true;
|
//};
|
|
//白点控件
|
var diameter = Application.GetRealWidth(12);
|
var btnWhiteRound = new Button()
|
{
|
Width = diameter,
|
Height = diameter,
|
Radius = (uint)Application.GetRealWidth(6),
|
BorderWidth = (uint)Application.GetRealWidth(1),
|
BorderColor = CSS_Color.MainBackgroundColor,
|
Enable = false,
|
};
|
btnWhiteRound.Visible = false;
|
framePickerBack.AddChidren(btnWhiteRound);
|
|
|
//当前点击的【点】是否正确
|
bool pointIsRight = false;
|
//圆的半径(考虑边界,需要设置它的半径比较小一点)
|
int circleR = colorPicker.Width / 2 - Application.GetRealWidth(12);
|
string rgbString = "255,255,255";
|
var rgbTemp = new Light();
|
colorPicker.MouseUpEventHandler = (sender2, e2) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.RGB, rgbString);
|
function.Control(d);
|
};
|
colorPicker.ColorChaged += (sender2, e2) =>
|
{
|
if ( pointIsRight == false)
|
{
|
return;
|
}
|
//if (colorPicker.ColorImagePath == "FunctionIcon/Light/ColorWheelGray.png")
|
//{
|
// return;
|
//}
|
if (function.refreshTime.AddMilliseconds(350) > DateTime.Now)
|
{
|
MainPage.Log("频繁控制,退出");
|
return;
|
}
|
function.refreshTime = DateTime.Now;
|
rgbString = (e2[0] + "," + e2[1] + "," + e2[2]).ToString();
|
|
btnCurColor.BackgroundColor = (uint)(0xFF000000 + rgbTemp.GetRGBcolor(rgbString));
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.RGB, rgbString);
|
function.Control(d);
|
};
|
colorPicker.MouseDownEventHandler += (sender, e) =>
|
{
|
pointIsRight = this.CheckPoint(circleR, colorPicker.Width / 2, colorPicker.Height / 2, (int)e.X, (int)e.Y);
|
if (pointIsRight == false)
|
{
|
//pointIsRight:点的区域不是圆盘内
|
return;
|
}
|
//if (colorPicker.ColorImagePath == "FunctionIcon/Light/ColorWheelGray.png")
|
//{
|
// return;
|
//}
|
//显示白点
|
btnWhiteRound.X = (int)e.X - btnWhiteRound.Width / 2;
|
btnWhiteRound.Y = (int)e.Y - btnWhiteRound.Height / 2;
|
if (btnWhiteRound.Visible == false)
|
{
|
btnWhiteRound.Visible = true;
|
}
|
};
|
|
colorPicker.MouseMoveEventHandler += (sender, e) =>
|
{
|
//当鼠标点下事件处理
|
colorPicker.MouseDownEventHandler(sender, e);
|
};
|
|
#region 亮度调节
|
var btnBrightnessText = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = Application.GetRealHeight(308 - magriHeight),
|
Width = Application.GetRealWidth(224),
|
Height = Application.GetRealHeight(21),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.Brightness,
|
};
|
controlView.AddChidren(btnBrightnessText);
|
|
var btnMinValuesText = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = btnBrightnessText.Bottom,
|
Width = Application.GetRealWidth(30),
|
Height = Application.GetRealHeight(21),
|
Text = "0%",
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
};
|
controlView.AddChidren(btnMinValuesText);
|
|
var dimmerBar = new DiyImageSeekBar()
|
{
|
X = Application.GetRealWidth(35 + 22),
|
Y = Application.GetRealHeight(312 - magriHeight),
|
Width = Application.GetRealWidth(210),
|
Height = Application.GetRealHeight(54),
|
SeekBarViewHeight = Application.GetRealHeight(8),
|
ThumbImagePath = "Public/ThumbImage.png",
|
ThumbImageHeight = Application.GetRealHeight(54),
|
ProgressTextColor = CSS_Color.FirstLevelTitleColor,
|
ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
ProgressBarColor = CSS_Color.AuxiliaryColor1,
|
MaxValue = 100,
|
Progress = Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.Brightness)),
|
SeekBarPadding = Application.GetRealWidth(20),
|
};
|
controlView.AddChidren(dimmerBar);
|
|
dimmerBar.OnStopTrackingTouchEvent = (sender, e) => {
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
dimmerBar.OnProgressChangedEvent = (sender, e) =>
|
{
|
//btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
//btnBrightnessText.Text = dimmerBar.Progress + "%";
|
return;
|
if (e == 0 && lastBrightness != 0)
|
{
|
lastBrightness = 0;
|
}
|
else
|
{
|
if (lastBrightness == 0)
|
lastBrightness = e;
|
}
|
if (e == 0 || e == 100)
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
d.Add(FunctionAttributeKey.OnOff, e == 0 ? "off" : "on");
|
function.Control(d);
|
}
|
else
|
{
|
if (350 < (DateTime.Now - function.refreshTime).TotalMilliseconds)
|
{
|
function.refreshTime = DateTime.Now;
|
new System.Threading.Thread(() =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Brightness, e.ToString());
|
function.Control(d);
|
})
|
{ IsBackground = true }.Start();
|
}
|
}
|
//if (e == 0)
|
//{
|
// if (colorPicker.ColorImagePath != "FunctionIcon/Light/ColorWheelGray.png")
|
// {
|
// colorPicker.ColorImagePath = "FunctionIcon/Light/ColorWheelGray.png";
|
// }
|
//}
|
//else
|
//{
|
// if (colorPicker.ColorImagePath != "FunctionIcon/Light/ColorWheel.png")
|
// {
|
// colorPicker.ColorImagePath = "FunctionIcon/Light/ColorWheel.png";
|
// }
|
//}
|
};
|
|
|
|
var btnMaxValuesText = new Button()
|
{
|
X = dimmerBar.Right,
|
Y = btnBrightnessText.Bottom,
|
Width = Application.GetRealWidth(45),
|
Height = Application.GetRealHeight(21),
|
Text = "100%",
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.PromptingColor1,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
};
|
controlView.AddChidren(btnMaxValuesText);
|
|
#endregion
|
|
int heightMore = 375 - magriHeight-20;
|
|
if (hadCCT)
|
{
|
#region 色温
|
var cctView = new FrameLayout()
|
{
|
Y = Application.GetRealHeight(heightMore),
|
Height = Application.GetRealHeight(75 + 11)
|
};
|
controlView.AddChidren(cctView);
|
|
|
//色温
|
var btnTempClolor = new Button();
|
btnTempClolor.X = Application.GetRealWidth(35);
|
btnTempClolor.Y = Application.GetRealHeight(1);
|
btnTempClolor.Width = Application.GetRealWidth(224);
|
btnTempClolor.Height = Application.GetRealHeight(42);
|
btnTempClolor.TextAlignment = TextAlignment.CenterLeft;
|
btnTempClolor.TextColor = CSS_Color.FirstLevelTitleColor;
|
btnTempClolor.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
btnTempClolor.TextID = StringId.ColorTemperature;
|
cctView.AddChidren(btnTempClolor);
|
|
//2700K
|
var btnTempClolorMin = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = btnTempClolor.Bottom,
|
Width = Application.GetRealWidth(40),
|
Height = Application.GetRealHeight(21),
|
};
|
btnTempClolorMin.Width = Application.GetRealWidth(54);
|
btnTempClolorMin.Height = Application.GetRealHeight(21);
|
btnTempClolorMin.Text = "2700K";
|
btnTempClolorMin.TextAlignment = TextAlignment.CenterLeft;
|
btnTempClolorMin.TextColor = CSS_Color.PromptingColor1;
|
btnTempClolorMin.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
cctView.AddChidren(btnTempClolorMin);
|
|
//滑动条的背景图片
|
var btnColorTemplatrueBack = new Button()
|
{
|
X = Application.GetRealWidth(55 + 22 + 15+5),
|
Y = Application.GetRealHeight(11),
|
Width = Application.GetRealWidth(170),
|
Height = Application.GetRealHeight(54),
|
};
|
btnColorTemplatrueBack.UnSelectedImagePath = "FunctionIcon/Light/ColorTemperatureBar.png";
|
btnColorTemplatrueBack.Height = Application.GetRealHeight(8);
|
btnColorTemplatrueBack.Gravity = Gravity.CenterHorizontal;
|
cctView.AddChidren(btnColorTemplatrueBack);
|
//滑动条控件
|
var barColorTemplatrue = new CCTSeekBarControl()
|
{
|
X = Application.GetRealWidth(55 + 25),
|
Y = Application.GetRealHeight(11),
|
Width = Application.GetRealWidth(215),
|
Height = Application.GetRealHeight(52),
|
};
|
barColorTemplatrue.MinValue = 27;
|
barColorTemplatrue.MaxValue = 65;
|
barColorTemplatrue.Progress = 38;
|
barColorTemplatrue.ProgressBarColor = 0x00000000;//全部透明
|
barColorTemplatrue.ProgressBarUnEnableColor = 0x00000000;
|
barColorTemplatrue.SeekBarBackgroundColor = 0x00000000;
|
cctView.AddChidren(barColorTemplatrue);
|
barColorTemplatrue.Y = btnTempClolorMin.Y - (barColorTemplatrue.Height - btnTempClolorMin.Height) / 2;
|
//设置初始值
|
btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
|
barColorTemplatrue.OnProgressChangedEvent = (sender, e) =>
|
{
|
btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K");
|
};
|
barColorTemplatrue.OnStopTrackingTouchEvent = (sender, e) =>
|
{
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.CCT, (barColorTemplatrue.Progress * 100).ToString());
|
function.Control(d);
|
};
|
//变更背景图的Y轴坐标
|
btnColorTemplatrueBack.Y = barColorTemplatrue.Y + (barColorTemplatrue.Height - btnColorTemplatrueBack.Height) / 2;
|
|
//6500K
|
var btnTempClolorMax = new Button();
|
btnTempClolorMax.Y = btnTempClolorMin.Y;
|
btnTempClolorMax.X = barColorTemplatrue.Right - Application.GetRealWidth(15);
|
btnTempClolorMax.Width = Application.GetRealWidth(54);
|
btnTempClolorMax.Height = Application.GetRealHeight(21);
|
btnTempClolorMax.Text = "6500K";
|
btnTempClolorMax.TextAlignment = TextAlignment.CenterRight;
|
btnTempClolorMax.TextColor = CSS_Color.PromptingColor1;
|
btnTempClolorMax.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
|
cctView.AddChidren(btnTempClolorMax);
|
|
#endregion
|
|
heightMore = 70;
|
}
|
|
if (hadColorful)
|
{
|
#region 炫彩功能
|
|
var btnGradualChangeText = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = hadCCT ? Application.GetRealHeight(375 + heightMore - magriHeight) : Application.GetRealHeight(heightMore+10),
|
Width = Application.GetRealWidth(224),
|
Height = Application.GetRealHeight(21),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = CSS_Color.FirstLevelTitleColor,
|
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
|
TextID = StringId.ColorfulFunction,
|
};
|
controlView.AddChidren(btnGradualChangeText);
|
|
var btnColorfulEdit = new Button()
|
{
|
X = Application.GetRealWidth(35),
|
Y = btnGradualChangeText.Bottom + Application.GetRealHeight(10),
|
Width = Application.GetRealWidth(22),
|
Height = Application.GetRealHeight(21),
|
UnSelectedImagePath = "Public/Edit.png",
|
Visible = false,
|
};
|
controlView.AddChidren(btnColorfulEdit);
|
btnColorfulEdit.MouseUpEventHandler = (sender, e) => {
|
var rgbView = new ColorfulInfoPage(function);
|
MainPage.BasePageView.AddChidren(rgbView);
|
rgbView.LoadPage();
|
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
|
};
|
|
var barColorful = new FrameLayout()
|
{
|
X = btnColorfulEdit.Right + Application.GetRealWidth(15 + 5),
|
Width = Application.GetRealWidth(170),
|
//X = Application.GetRealWidth(35),
|
//Width = Application.GetRealWidth(170 + 41),
|
Y = hadCCT ? Application.GetRealHeight(412 + heightMore - magriHeight) : Application.GetRealHeight(heightMore + 50),
|
Height = Application.GetRealHeight(8),
|
BackgroundImagePath = "FunctionIcon/Light/ColorfulBar.png",
|
};
|
controlView.AddChidren(barColorful);
|
|
var btnColorfulSwitch = new Button()
|
{
|
X = barColorful.Right + Application.GetRealWidth(8),
|
Y = btnGradualChangeText.Bottom + Application.GetRealHeight(10),
|
Width = Application.GetRealWidth(38),
|
Height = Application.GetRealHeight(24),
|
UnSelectedImagePath = "Public/Switch.png",
|
SelectedImagePath = "Public/SwitchOn.png"
|
};
|
controlView.AddChidren(btnColorfulSwitch);
|
|
|
btnColorfulSwitch.MouseUpEventHandler = (sender, e) => {
|
btnColorfulSwitch.IsSelected = !btnColorfulSwitch.IsSelected;
|
new System.Threading.Thread(() =>
|
{
|
try
|
{
|
var controlColorfulState = btnColorfulSwitch.IsSelected ? "on" : "off";
|
function.SetAttrState(FunctionAttributeKey.Colorful, controlColorfulState);
|
var d = new Dictionary<string, string>();
|
d.Add(FunctionAttributeKey.Colorful, controlColorfulState);
|
function.Control(d);
|
}
|
catch (Exception ex)
|
{
|
MainPage.Log($"控制炫彩开关异常:{ex.Message}");
|
}
|
})
|
{ IsBackground = true }.Start();
|
};
|
|
#endregion
|
}
|
|
btnOn.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 100;
|
//btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
//btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
btnOff.MouseUpEventHandler += (sender, e) => {
|
dimmerBar.Progress = 0;
|
//btnBrightnessText.Y = ((100 - dimmerBar.Progress) * Application.GetRealHeight(222 - 16) / 100);
|
//btnBrightnessText.Text = dimmerBar.Progress + "%";
|
};
|
|
|
|
}
|
|
|
/// <summary>
|
/// 检测点击点
|
/// </summary>
|
/// <param name="circleR">圆的半径</param>
|
/// <param name="circleX">圆心X轴</param>
|
/// <param name="circleY">圆心Y轴</param>
|
/// <param name="pointX">点击点的X轴</param>
|
/// <param name="pointY">点击点的Y轴</param>
|
/// <returns></returns>
|
private bool CheckPoint(int circleR, int circleX, int circleY, int pointX, int pointY)
|
{
|
int dwidth = circleX - pointX;
|
if (dwidth < 0) { dwidth *= -1; }
|
|
int dHeight = circleY - pointY;
|
if (dHeight < 0) { dHeight *= -1; }
|
|
//根据三角函数,求三角形的斜边长
|
int dlength = dwidth * dwidth + dHeight * dHeight;
|
//半径长度(不开方,所以是按平方算)
|
circleR *= circleR;
|
if (dlength < circleR)
|
{
|
//如果组成的三角形并没有长过半径,则代表还在圆内(不允许点边界)
|
return true;
|
}
|
return false;
|
}
|
|
|
|
|
|
}
|
}
|