using System;
|
using System.Collections.Generic;
|
//using EZMonitor;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
/// <summary>
|
/// 用户场景界面
|
/// </summary>
|
public class UserScenePage : FrameLayout
|
{
|
public static readonly VerticalScrolViewLayout VerticalScrolView_InUserMiddleView = new VerticalScrolViewLayout ();
|
Button beforeClickButton = new Button ();
|
FrameLayout LongPressFrameLayout = new FrameLayout ();
|
|
/// <summary>
|
///构造函数
|
/// </summary>
|
public UserScenePage (UserDeviceToScene mView)
|
{
|
mUserDeviceToScene = mView;
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
UserDeviceToScene mUserDeviceToScene;
|
public override void RemoveFromParent ()
|
{
|
mUserDeviceToScene.InitView (UserConfig.Instance.SceneOfGloba);
|
base.RemoveFromParent ();
|
|
}
|
|
public void ShowUserScene (Room room)
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = Language.StringByID (R.MyInternationalizationString.Scenes),
|
TextSize = 19,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
topView.AddChidren (title);
|
|
var logo = new Button () {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
UnSelectedImagePath = MainPage.LogoString,
|
};
|
topView.AddChidren (logo);
|
var back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
};
|
#endregion
|
|
#region bodyView
|
FrameLayout bodyView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = LayoutParams.MatchParent,
|
Y = topView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
AddChidren (bodyView);
|
|
VerticalScrolViewLayout scenesBodyView = new VerticalScrolViewLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = LayoutParams.MatchParent,
|
};
|
bodyView.AddChidren (scenesBodyView);
|
|
|
FrameLayout scenesRowView = new FrameLayout () {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (254),
|
};
|
|
//显示每个房间有多少个场景
|
if (room != null) {
|
//所有场景
|
var sceneFileList = room.SceneFilePathList;
|
List<string> sceneFilePaths = new List<string> ();//存路径
|
sceneFilePaths = sceneFileList;
|
sceneFilePaths.Add ("");
|
|
for (int index = 0; index < sceneFilePaths.Count; index++) {
|
var sceneFilePath = sceneFilePaths [index];
|
var scene = Scene.GetSceneByFilePath (sceneFilePath);
|
// 当场景不存在时,可以NEW 一个场景,不然值一直是空的
|
|
if (scene == null) {
|
scene = new Scene ();
|
}
|
|
if (index % 2 == 0) {
|
scenesRowView = new FrameLayout () {
|
Height = Application.GetRealHeight (250),
|
};
|
scenesBodyView.AddChidren (scenesRowView);
|
}
|
|
var sceneView = new FrameLayout () {
|
Width = Application.GetRealWidth (320),
|
BackgroundImagePath = scene.BackgroundImagePath,
|
};
|
scenesRowView.AddChidren (sceneView);
|
|
if (index % 2 == 1) {
|
sceneView.X = Application.GetRealWidth (320);
|
}
|
|
if (index == sceneFilePaths.Count - 1) {
|
sceneView.BackgroundImagePath = "Item/SceneAdd.png";
|
sceneView.MouseUpEventHandler += (sender, e) => {
|
Action ShowUserSceneForFileName = () => {
|
ShowUserScene (Room.GetRoomByFilePath ( room.RoomFilePath));
|
};
|
new ScenePhoneMethod ().AddOrUpdataSceneBaseMassage (room.RoomFilePath,null, null, ShowUserSceneForFileName);
|
};
|
} else {
|
Button btnSceneName = new Button () {
|
Height = Application.GetRealHeight (40),
|
Y = Application.GetRealHeight (210),
|
BackgroundColor = SkinStyle.Current.Black50Transparent,
|
};
|
sceneView.AddChidren (btnSceneName);
|
|
var btnBGC = new Button () {
|
UnSelectedImagePath = "Item/Transparent.png",
|
SelectedImagePath = "Item/SceneSettingBackground.png",
|
TextAlignment = TextAlignment.BottomCenter,
|
Text = scene.Name,
|
TextColor = SkinStyle.Current.TextColor1,
|
TextSize = 15,
|
};
|
sceneView.AddChidren (btnBGC);
|
|
var btnSetSceneIcon = new Button () {
|
UnSelectedImagePath = "Item/More2.png",
|
SelectedImagePath = "Item/Transparent.png",
|
Height = Application.GetRealHeight (50),
|
Width = Application.GetRealWidth (60),
|
X = Application.GetRealWidth(240),
|
Y = Application.GetRealHeight(10),
|
};
|
|
|
sceneView.AddChidren (btnSetSceneIcon);
|
//btnBGC.MouseLongEventHandler += (sender, e) => {
|
btnSetSceneIcon.MouseUpEventHandler += (sender, e) => {
|
if (string.IsNullOrEmpty (scene.Name))
|
return;
|
btnSetSceneIcon.IsSelected = true;
|
LongPressFrameLayout = new FrameLayout () {
|
BackgroundColor = SkinStyle.Current.SceneTransparentBackColor,
|
};
|
LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => {
|
LongPressFrameLayout.RemoveFromParent ();
|
btnSetSceneIcon.IsSelected = false;
|
};
|
sceneView.AddChidren (LongPressFrameLayout);
|
|
var btnEditor = new Button () {
|
Width = Application.GetRealWidth (70),
|
Height = Application.GetRealHeight (76),
|
UnSelectedImagePath = "Item/UserSceneEditIcon.png",
|
X = Application.GetRealWidth (220),
|
Y = Application.GetRealHeight (13),
|
};
|
LongPressFrameLayout.AddChidren (btnEditor);
|
btnEditor.MouseUpEventHandler += (sender1, e1) => {
|
var userAddSceneDeviceView = new UserAddSceneDevice ( room.RoomFilePath, sceneFilePath);
|
UserMiddle.DevicePageView.AddChidren (userAddSceneDeviceView);
|
userAddSceneDeviceView.ShowScene ((newSceneFilePath) => {
|
sceneFilePath = newSceneFilePath;
|
scene = Scene.GetSceneByFilePath (sceneFilePath);
|
sceneView.BackgroundImagePath = scene.BackgroundImagePath;
|
ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath));
|
UserDeviceToScene.hasModify = true;
|
});
|
UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1;
|
LongPressFrameLayout.RemoveFromParent ();
|
};
|
|
var btnDel = new Button () {
|
Width = Application.GetRealWidth (70),
|
Height = Application.GetRealHeight (76),
|
UnSelectedImagePath = "Item/UserSceneDelIcon.png",
|
X = Application.GetRealWidth (40),
|
Y = Application.GetRealHeight (20),
|
};
|
LongPressFrameLayout.AddChidren (btnDel);
|
|
btnDel.MouseUpEventHandler += (senderDel, eDel) => {
|
Alert alert = new Alert ("", $"Are you sure to delete the scenario: {scene.Name}?", Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
|
alert.ResultEventHandler += (sender2, e2) => {
|
if (e2) {
|
IO.FileUtils.DeleteFile (sceneFilePath);
|
room.SceneFilePathList.Remove (sceneFilePath);
|
room.SceneFilePathList.Remove ("");
|
room.Save (room.RoomFilePath);
|
ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath));
|
UserDeviceToScene.hasModify = true;
|
}
|
};
|
alert.Show ();
|
|
|
|
//if (CommonList.MonitorScenePathList.Count > 0) {
|
// foreach (var monitorData in CommonList.MonitorScenePathList) {
|
// if (sceneFilePath == monitorData.FileName) {
|
// CommonList.MonitorScenePathList.Remove (monitorData);
|
// CommonList.Save ();
|
// }
|
// }
|
//}
|
};
|
};
|
|
btnBGC.MouseUpEventHandler += (sender, e) => {
|
LongPressFrameLayout.RemoveFromParent ();
|
beforeClickButton.IsSelected = false;
|
beforeClickButton = btnBGC;
|
btnBGC.IsSelected = true;
|
new ScenePhoneMethod ().ControlScene (sceneFilePath);
|
};
|
}
|
}
|
sceneFileList.Remove ("");
|
}
|
#endregion
|
}
|
}
|
}
|