using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
namespace HDL_ON.UI
{
public partial class SceneEditPage : FrameLayout
{
FrameLayout bodyView;
///
/// 场景背景显示区域
///
ImageView addSceneImageView;
///
/// 场景功能列表显示区域
///
VerticalScrolViewLayout functionListView;
///
/// 场景名称显示文本
///
EditText etSceneName;
Button btnZoneName;
Button btnAddFunctionTitle;
///
/// 底部完成按钮
///
Button btnComplete;
#region 图标选择部分图标
///
/// 背景图选项区域
///
FrameLayout pictureOptionView;
///
/// 背景图选项选择区域
///
VerticalScrolViewLayout optionView;
///
/// 默认图库按钮
///
Button btnDefaultGallery;
///
/// 拍照按钮
///
Button btnTakePicture;
///
/// 相册按钮
///
Button btnAlbum;
///
/// 取消按钮
///
Button btnCancel;
#endregion
Scene scene;
int pageTitleId;
///
/// 更新功能row
///
Action refreshFunctionRowAction;
///
/// 回掉更新
///
Action backAction;
public SceneEditPage(Scene s,Action act)
{
bodyView = this;
scene = s;
backAction = act;
}
public void LoadPage(int titleId)
{
refreshFunctionRowAction = () => {
LoadFunctionRow(functionListView);
};
bodyView.BackgroundColor = CSS_Color.MainBackgroundColor;
pageTitleId = titleId;
new TopViewDiv(bodyView, Language.StringByID(pageTitleId)).LoadTopView();
VerticalScrolViewLayout contentView = new VerticalScrolViewLayout()
{
Y = Application.GetRealHeight(64),
Height = Application.GetRealHeight(603-50),
};
bodyView.AddChidren(contentView);
Button btnBaseInfoText = new Button()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealWidth(46),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextID = StringId.BaseInfo,
TextSize = CSS_FontSize.SubheadingFontSize,
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(btnBaseInfoText);
FrameLayout sceneBgView = new FrameLayout()
{
Gravity = Gravity.CenterHorizontal,
Y = btnBaseInfoText.Bottom,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(184),
Radius = (uint)Application.GetRealWidth(12),
BackgroundColor = CSS_Color.MainBackgroundColor,
};
contentView.AddChidren(sceneBgView);
addSceneImageView = new ImageView()
{
Gravity = Gravity.CenterHorizontal,
Height = Application.GetRealWidth(184),
Radius = (uint)Application.GetRealWidth(12),
ImagePath = scene.ImagePath
};
sceneBgView.AddChidren(addSceneImageView);
contentView.AddChidren(new Button() { Height = Application.GetRealWidth(16) ,BackgroundColor = CSS_Color.MainBackgroundColor});
#region 场景名称row
FrameLayout sceneNameView = new FrameLayout()
{
Height = Application.GetRealWidth(50),
};
contentView.AddChidren(sceneNameView);
Button btnSceneTitle = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.SceneName,
};
sceneNameView.AddChidren(btnSceneTitle);
etSceneName = new EditText()
{
X = btnSceneTitle.Right,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.TextualColor,
TextSize = CSS_FontSize.TextFontSize,
Text = scene.name
};
sceneNameView.AddChidren(etSceneName);
Button btnSceneNameLine = new Button()
{
Y = Application.GetRealWidth(49),
Gravity = Gravity.CenterHorizontal,
Height = Application.GetRealHeight(1),
Width = Application.GetRealWidth(343),
BackgroundColor = CSS_Color.DividingLineColor,
};
sceneNameView.AddChidren(btnSceneNameLine);
#endregion
#region 所属区域row
FrameLayout belongToZoneRow = new FrameLayout()
{
Y = sceneNameView.Bottom,
Height = Application.GetRealWidth(50),
};
contentView.AddChidren(belongToZoneRow);
Button btnBelongToTitle = new Button()
{
X = Application.GetRealWidth(16),
Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.BelongToZone,
};
belongToZoneRow.AddChidren(btnBelongToTitle);
Button btnBelongToZoneRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
belongToZoneRow.AddChidren(btnBelongToZoneRight);
btnZoneName = new Button()
{
X = btnSceneTitle.Right,
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.TextualColor,
TextSize = CSS_FontSize.TextFontSize,
Text = scene.GetRoomListName() == "" ? Language.StringByID(StringId.WholeHouseScene) : scene.GetRoomListName()
};
belongToZoneRow.AddChidren(btnZoneName);
contentView.AddChidren(new Button()
{
Y = belongToZoneRow.Bottom,
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.DividingLineColor,
});
#endregion
#region 场景延时row
FrameLayout sceneDelayRow = new FrameLayout()
{
Y = sceneNameView.Bottom,
Height = Application.GetRealWidth(50),
};
contentView.AddChidren(sceneDelayRow);
Button btnSceneDelayRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
sceneDelayRow.AddChidren(btnSceneDelayRight);
var btnSceneDelayInfo = new Button()
{
Width = Application.GetRealWidth(327),
TextAlignment = TextAlignment.CenterRight,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = scene.delayText
};
sceneDelayRow.AddChidren(btnSceneDelayInfo);
Button btnSceneDelayTitle = new Button()
{
X = Application.GetRealWidth(16),
//Width = Application.GetRealWidth(90),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
TextID = StringId.SceneDelay,
};
sceneDelayRow.AddChidren(btnSceneDelayTitle);
btnSceneDelayTitle.MouseUpEventHandler = (sender, e) => {
new PublicAssmebly().SetSceneDelayDialog(scene, btnSceneDelayInfo);
};
contentView.AddChidren(new Button()
{
Y = sceneDelayRow.Bottom,
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.DividingLineColor,
});
#endregion
#region 添加功能row
FrameLayout addFunctionRow = new FrameLayout()
{
Height = Application.GetRealWidth(44),
};
contentView.AddChidren(addFunctionRow);
Button btnAddIcon = new Button()
{
X = Application.GetRealWidth(333),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(28),
Height = Application.GetMinRealAverage(28),
UnSelectedImagePath = "Public/AddIcon.png",
};
addFunctionRow.AddChidren(btnAddIcon);
btnAddFunctionTitle = new Button()
{
X = Application.GetRealWidth(16),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.AddFunction,
IsBold = true,
};
addFunctionRow.AddChidren(btnAddFunctionTitle);
functionListView = new VerticalScrolViewLayout() {
Height = 0,
};
contentView.AddChidren(functionListView);
LoadFunctionRow(functionListView);
Button btnLine1 = new Button()
{
Y = sceneDelayRow.Bottom,
Height = Application.GetRealHeight(8),
BackgroundColor = CSS_Color.DividingLineColor,
};
contentView.AddChidren(btnLine1);
Button btnLine2 = new Button()
{
Y = sceneDelayRow.Bottom,
Height = Application.GetRealHeight(228),
BackgroundColor = CSS_Color.DividingLineColor,
};
contentView.AddChidren(btnLine2);
#endregion
Button btnBottomLine = new Button()
{
Y = Application.GetRealHeight(667-50)-1,
Height = 1,
BackgroundColor = CSS_Color.DividingLineColor,
};
bodyView.AddChidren(btnBottomLine);
btnComplete = new Button()
{
Y = Application.GetRealHeight(667-50),
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.Complete,
BackgroundColor = CSS_Color.MainBackgroundColor,
IsBold = true
};
bodyView.AddChidren(btnComplete);
LoadEventList();
}
///
/// 加载功能列表
///
void LoadFunctionRow(VerticalScrolViewLayout functionListView)
{
functionListView.RemoveAll();
functionListView.Height = Application.GetRealWidth(65 * scene.sceneFunctionList.Count);
foreach (var function in scene.sceneFunctionList)
{
var row = new RowLayout()
{
Height = Application.GetRealWidth(65),
BackgroundColor = CSS_Color.MainBackgroundColor,
LineColor = 0x00000000
};
functionListView.AddChidren(row);
row.AddChidren(new Button()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealWidth(1),
BackgroundColor = CSS_Color.DividingLineColor,
});
Button btnRight = new Button()
{
X = Application.GetRealWidth(339),
Gravity = Gravity.CenterVertical,
Width = Application.GetMinRealAverage(16),
Height = Application.GetMinRealAverage(16),
UnSelectedImagePath = "Public/Right.png",
};
row.AddChidren(btnRight);
var btnFunctionInfo = new Button()
{
Width = Application.GetRealWidth(327),
Height = Application.GetRealWidth(32),
TextAlignment = TextAlignment.BottomRight,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
Text = GetFunctionScnenInfo(function),
};
row.AddChidren(btnFunctionInfo);
var btnFunctionDelayInfo = new Button()
{
Width = Application.GetRealWidth(327),
Y = Application.GetRealWidth(35),
Height = Application.GetRealWidth(32),
TextAlignment = TextAlignment.TopRight,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
};
row.AddChidren(btnFunctionDelayInfo);
if (function.delay > 0)
{
btnFunctionDelayInfo.Text = Language.StringByID(StringId.Delay) + " " + function.delayText;
}
else
{
btnFunctionDelayInfo.Text = Language.StringByID(StringId.NoDelay);
}
var btnFunctionName = new Button()
{
X = Application.GetRealWidth(16),
Height = Application.GetRealWidth(44),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.FirstLevelTitleColor,
TextSize = CSS_FontSize.TextFontSize,
Text = function.name,
};
row.AddChidren(btnFunctionName);
var btnFunctionFloorAndRoom = new Button()
{
X = Application.GetRealWidth(16),
Y = Application.GetRealWidth(24),
Height = Application.GetRealWidth(41),
TextAlignment = TextAlignment.CenterLeft,
TextColor = CSS_Color.PromptingColor1,
TextSize = CSS_FontSize.TextFontSize,
Text = function.GetRoomListName(),
};
row.AddChidren(btnFunctionFloorAndRoom);
btnFunctionName.MouseUpEventHandler = (sender, e) =>
{
var ssf = new SceneFunctionInfoEditPage(scene, function, refreshFunctionRowAction);
MainPage.BasePageView.AddChidren(ssf);
ssf.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
btnFunctionFloorAndRoom.MouseUpEventHandler = (sender, e) =>
{
var ssf = new SceneFunctionInfoEditPage(scene, function, refreshFunctionRowAction);
MainPage.BasePageView.AddChidren(ssf);
ssf.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
}
}
///
/// 解析场景功能数据
///
///
string GetFunctionScnenInfo(Function sceneFunction)
{
string sceneFunctionInfo = Language.StringByID(StringId.Close);
if (sceneFunction.trait_on_off.value.ToString() == "off")
return sceneFunctionInfo;
sceneFunctionInfo = "";
switch(sceneFunction.functionType)
{
case FunctionType.AC:
var addAC = sceneFunction as AC;
sceneFunctionInfo += addAC.trait_mode.GetCurValueText();
sceneFunctionInfo += " " + addAC.trait_temp.value.ToString() + addAC.tempUnitString;
sceneFunctionInfo += " " + addAC.trait_fan.GetCurValueText();
break;
case FunctionType.FloorHeating:
sceneFunctionInfo += sceneFunction.function.Find((obj) => obj.name == "mode").GetCurValueText();
sceneFunctionInfo += " " + sceneFunction.function.Find((obj) => obj.name == "temperature").value.ToString() +
sceneFunction.function.Find((obj) => obj.name == "temperature").uintString;
break;
case FunctionType.Dimmer:
sceneFunctionInfo += Language.StringByID(StringId.Brightness) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
break;
case FunctionType.Relay:
sceneFunctionInfo += Language.StringByID(StringId.Open);
break;
case FunctionType.RGB:
sceneFunctionInfo += Language.StringByID(StringId.Brightness) + " " + sceneFunction.function.Find((obj) => obj.name == "brightness").value.ToString() + "%";
break;
case FunctionType.Curtain:
sceneFunctionInfo += Language.StringByID(StringId.Open);
break;
case FunctionType.MotorCurtain:
sceneFunctionInfo += Language.StringByID(StringId.Open) + " " + sceneFunction.function.Find((obj) => obj.name == "percent").value.ToString() + "%";
break;
}
return sceneFunctionInfo;
}
///
/// 加载图标选择选项
///
void LoadPictureOptionView()
{
var pView = new FrameLayout()
{
BackgroundColor = CSS_Color.DialogTransparentColor1,
};
bodyView.AddChidren(pView);
pictureOptionView = new FrameLayout()
{
Y = Application.GetRealHeight(445),
Height = Application.GetRealHeight(250),
AnimateSpeed = 0.3f,
Animate = Animate.DownToUp,
};
pView.AddChidren(pictureOptionView);
optionView = new VerticalScrolViewLayout()
{
Gravity = Gravity.CenterHorizontal,
Width = Application.GetRealWidth(343),
Height = Application.GetRealHeight(150),
BackgroundColor = CSS_Color.MainBackgroundColor,
Radius = (uint)Application.GetRealWidth(12),
};
pictureOptionView.AddChidren(optionView);
btnDefaultGallery = new Button()
{
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.TextualColor,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.DefaultGallery,
};
optionView.AddChidren(btnDefaultGallery);
optionView.AddChidren(new Button() { X = Application.GetRealWidth(16), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
btnTakePicture = new Button()
{
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.TextualColor,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.TakePicture,
};
optionView.AddChidren(btnTakePicture);
optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
btnAlbum = new Button()
{
Height = Application.GetRealHeight(50),
TextAlignment = TextAlignment.Center,
TextColor = CSS_Color.TextualColor,
SelectedTextColor = CSS_Color.MainColor,
TextSize = CSS_FontSize.SubheadingFontSize,
TextID = StringId.Album,
};
optionView.AddChidren(btnAlbum);
optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
btnCancel = new Button()
{
Gravity = Gravity.CenterHorizontal,
Y = Application.GetRealHeight(8) + optionView.Bottom,
Width = Application.GetRealWidth(343),
Height = Application.GetRealHeight(50),
BackgroundColor = CSS_Color.MainBackgroundColor,
Radius = (uint)Application.GetRealWidth(12),
TextID = StringId.Cancel,
TextColor = CSS_Color.WarningColor,
TextSize = CSS_FontSize.SubheadingFontSize,
};
pictureOptionView.AddChidren(btnCancel);
LoadEvent_PictureOptionViewEventList( pView);
}
}
//--------------------------------------
public partial class SceneEditPage
{
void LoadEventList()
{
LoadEvent_ChangeSceneImage();
LoadEvent_ChangeSceneZone();
LoadEvent_ChangeFunctionList();
LoadEvent_CompleteEvent();
}
///
/// 修改场景所属区域
///
void LoadEvent_ChangeSceneZone()
{
btnZoneName.MouseUpEventHandler = (sender, e) =>
{
Action backAction = () => {
btnZoneName.Text = scene.GetRoomListName();
};
var ssl = new SetSceneLocationPage(scene, backAction);
MainPage.BasePageView.AddChidren(ssl);
ssl.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
}
///
/// 修改场景的功能列表
///
void LoadEvent_ChangeFunctionList()
{
btnAddFunctionTitle.MouseUpEventHandler = (sender, e) => {
var sefp =new SceneFunctionListEditPage(scene,refreshFunctionRowAction);
MainPage.BasePageView.AddChidren(sefp);
sefp.LoadPage();
MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
};
}
///
/// 修改场景背景事件
///
void LoadEvent_ChangeSceneImage()
{
addSceneImageView.MouseUpEventHandler = (sender, e) => {
LoadPictureOptionView();
};
}
///
/// 加载背景图选择区域事件列表
///
void LoadEvent_PictureOptionViewEventList(FrameLayout pView)
{
pictureOptionView.MouseUpEventHandler = (sender, e) =>
{
pictureOptionView.Parent.RemoveFromParent();
};
pView.MouseUpEventHandler = (sender, e) =>
{
pictureOptionView.Parent.RemoveFromParent();
};
btnCancel.MouseUpEventHandler = (sender, e) =>
{
pictureOptionView.Parent.RemoveFromParent();
};
btnTakePicture.MouseDownEventHandler = (sender, e) => {
btnTakePicture.IsSelected = true;
};
btnTakePicture.MouseUpEventHandler = (sender, e) =>
{
btnTakePicture.IsSelected = false;
var pid = Guid.NewGuid();
CropImage.TakePicture((imagePath) =>
{
if (imagePath != null)
{
addSceneImageView.ImagePath = imagePath.ToString();
scene.ImagePath = addSceneImageView.ImagePath;
MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath);
}
}, pid.ToString(), 16, 9);
scene.SaveFunctionData();
pictureOptionView.Parent.RemoveFromParent();
};
btnAlbum.MouseDownEventHandler = (sender, e) => {
btnAlbum.IsSelected = true;
};
btnAlbum.MouseUpEventHandler = (sender, e) =>
{
btnAlbum.IsSelected = false;
var pid = Guid.NewGuid();
CropImage.SelectPicture((imagePath) =>
{
if (imagePath != null)
{
addSceneImageView.ImagePath = imagePath.ToString();
scene.ImagePath = addSceneImageView.ImagePath;
MainPage.Log("SelectPicture 裁剪图片返回路径: " + imagePath);
}
}, pid.ToString(), 16, 9);
scene.SaveFunctionData();
pictureOptionView.Parent.RemoveFromParent();
};
}
///
/// 按钮按钮点击事件
///
void LoadEvent_CompleteEvent()
{
btnComplete.MouseUpEventHandler = (sender, e) =>
{
scene.SaveFunctionData();
DB_ResidenceData.functionList.scenes.Add(scene);
this.RemoveFromParent();
backAction();
};
}
}
}