From 97a443275963a35c7b609f23f41dce1a12a52a78 Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Fri, 4 Aug 2017 12:06:00 +0900 Subject: Refactoring Native.Window to extend - Remove Native.Window - Remove hierarchy from ElmSharp.Window - We can easily change the window type with sub-class of Window Change-Id: I57a517e60b6e7c9acd2c32862a11db306e59a3d6 --- Xamarin.Forms.Platform.Tizen/FormsApplication.cs | 54 +++++--- .../Native/DisplayOrientations.cs | 36 ------ .../Native/MasterDetailPage.cs | 6 +- Xamarin.Forms.Platform.Tizen/Native/Window.cs | 140 --------------------- Xamarin.Forms.Platform.Tizen/Platform.cs | 2 +- 5 files changed, 38 insertions(+), 200 deletions(-) mode change 100755 => 100644 Xamarin.Forms.Platform.Tizen/FormsApplication.cs delete mode 100644 Xamarin.Forms.Platform.Tizen/Native/DisplayOrientations.cs mode change 100755 => 100644 Xamarin.Forms.Platform.Tizen/Native/MasterDetailPage.cs delete mode 100644 Xamarin.Forms.Platform.Tizen/Native/Window.cs diff --git a/Xamarin.Forms.Platform.Tizen/FormsApplication.cs b/Xamarin.Forms.Platform.Tizen/FormsApplication.cs old mode 100755 new mode 100644 index b725443f..ba01268d --- a/Xamarin.Forms.Platform.Tizen/FormsApplication.cs +++ b/Xamarin.Forms.Platform.Tizen/FormsApplication.cs @@ -7,6 +7,7 @@ using Tizen.Applications; using Xamarin.Forms.Internals; using EButton = ElmSharp.Button; using EColor = ElmSharp.Color; +using ELayout = ElmSharp.Layout; using EProgressBar = ElmSharp.ProgressBar; namespace Xamarin.Forms.Platform.Tizen @@ -19,7 +20,7 @@ namespace Xamarin.Forms.Platform.Tizen bool _isInitialStart; int _pageBusyCount; Native.Dialog _pageBusyDialog; - Native.Window _window; + Window _window; protected FormsApplication() { @@ -31,24 +32,29 @@ namespace Xamarin.Forms.Platform.Tizen /// Gets the main window or null if it's not set. /// /// The main window or null. - public Native.Window MainWindow + public Window MainWindow { get { return _window; } - protected set { _window = value; + InitializeWindow(); } } + public ELayout BaseLayout + { + get; protected set; + } + protected override void OnPreCreate() { base.OnPreCreate(); Application.ClearCurrent(); - CreateWindow(); + MainWindow = new Window("FormsWindow"); } protected override void OnTerminate() @@ -283,43 +289,51 @@ namespace Xamarin.Forms.Platform.Tizen _platform.SetPage(page); } - void CreateWindow() + void InitializeWindow() { - Debug.Assert(null == MainWindow); + Debug.Assert(MainWindow != null, "Window cannot be null"); + + MainWindow.Active(); + MainWindow.Show(); + var conformant = new Conformant(MainWindow); + conformant.Show(); + + // Create the base (default) layout for the application + var layout = new ELayout(conformant); + layout.SetTheme("layout", "application", "default"); + layout.Show(); - var window = new Native.Window(); - window.Closed += (s, e) => + conformant.SetContent(layout); + BaseLayout = layout; + MainWindow.AvailableRotations = DisplayRotation.Degree_0 | DisplayRotation.Degree_90 | DisplayRotation.Degree_180 | DisplayRotation.Degree_270; + + MainWindow.Deleted += (s, e) => { Exit(); }; - window.RotationChanged += (sender, e) => + MainWindow.RotationChanged += (sender, e) => { - switch (_window.CurrentOrientation) + switch (MainWindow.Rotation) { - case Native.DisplayOrientations.None: - Device.Info.CurrentOrientation = Internals.DeviceOrientation.Other; - break; - - case Native.DisplayOrientations.Portrait: + case 0: Device.Info.CurrentOrientation = Internals.DeviceOrientation.PortraitUp; break; - case Native.DisplayOrientations.Landscape: + case 90: Device.Info.CurrentOrientation = Internals.DeviceOrientation.LandscapeLeft; break; - case Native.DisplayOrientations.PortraitFlipped: + case 180: Device.Info.CurrentOrientation = Internals.DeviceOrientation.PortraitDown; break; - case Native.DisplayOrientations.LandscapeFlipped: + case 270: Device.Info.CurrentOrientation = Internals.DeviceOrientation.LandscapeRight; break; } }; - - MainWindow = window; } + public void Run() { Run(System.Environment.GetCommandLineArgs()); diff --git a/Xamarin.Forms.Platform.Tizen/Native/DisplayOrientations.cs b/Xamarin.Forms.Platform.Tizen/Native/DisplayOrientations.cs deleted file mode 100644 index efb09529..00000000 --- a/Xamarin.Forms.Platform.Tizen/Native/DisplayOrientations.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; - -namespace Xamarin.Forms.Platform.Tizen.Native -{ - /// - /// Enumeration for the orientation of a rectangular screen. - /// - [Flags] - public enum DisplayOrientations - { - /// - /// No display orientation is specified. - /// - None = 0, - - /// - /// The display is oriented in a natural position. - /// - Portrait = 1, - - /// - /// The display's left side is at the top. - /// - Landscape = 2, - - /// - /// The display is upside down. - /// - PortraitFlipped = 4, - - /// - /// The display's right side is at the top. - /// - LandscapeFlipped = 8 - } -} diff --git a/Xamarin.Forms.Platform.Tizen/Native/MasterDetailPage.cs b/Xamarin.Forms.Platform.Tizen/Native/MasterDetailPage.cs old mode 100755 new mode 100644 index e7e1f243..68260732 --- a/Xamarin.Forms.Platform.Tizen/Native/MasterDetailPage.cs +++ b/Xamarin.Forms.Platform.Tizen/Native/MasterDetailPage.cs @@ -295,10 +295,10 @@ namespace Xamarin.Forms.Platform.Tizen.Native if (behavior == MasterBehavior.SplitOnLandscape || behavior == MasterBehavior.SplitOnPortrait) { - var orientation = Forms.Context.MainWindow.CurrentOrientation; + var rotation = Forms.Context.MainWindow.Rotation; - if (((orientation == DisplayOrientations.Landscape || orientation == DisplayOrientations.LandscapeFlipped) && behavior == MasterBehavior.SplitOnLandscape) || - ((orientation == DisplayOrientations.Portrait || orientation == DisplayOrientations.PortraitFlipped) && behavior == MasterBehavior.SplitOnPortrait)) + if (((rotation == 90 || rotation == 270) && behavior == MasterBehavior.SplitOnLandscape) || + ((rotation == 0 || rotation == 90) && behavior == MasterBehavior.SplitOnPortrait)) { behavior = MasterBehavior.Split; } diff --git a/Xamarin.Forms.Platform.Tizen/Native/Window.cs b/Xamarin.Forms.Platform.Tizen/Native/Window.cs deleted file mode 100644 index 3e982ae5..00000000 --- a/Xamarin.Forms.Platform.Tizen/Native/Window.cs +++ /dev/null @@ -1,140 +0,0 @@ -using System; -using ElmSharp; -using EWindow = ElmSharp.Window; -using ELayout = ElmSharp.Layout; - -namespace Xamarin.Forms.Platform.Tizen.Native -{ - public class Window : EWindow - { - ELayout _layout; - Conformant _conformant; - - /// - /// Initializes a new instance of the Window class. - /// - public Window() : base("FormsWindow") - { - Initialize(); - } - - /// - /// Notifies that the window has been closed. - /// - public event EventHandler Closed; - - /// - /// Gets the current orientation. - /// - public DisplayOrientations CurrentOrientation - { - get - { - if (IsRotationSupported) - { - return GetDisplayOrientation(); - } - else - { - return DisplayOrientations.None; - } - } - } - - /// - /// Gets or sets the orientation of a rectangular screen. - /// - public DisplayOrientations AvailableOrientations - { - get - { - if (IsRotationSupported) - { - return (DisplayOrientations)AvailableRotations; - } - else - { - return DisplayOrientations.None; - } - } - set - { - if (IsRotationSupported) - { - AvailableRotations = (DisplayRotation)value; - } - } - } - - public ELayout BaseLayout - { - get - { - return _layout; - } - - private set - { - _layout = value; - } - } - - /// - /// Sets the main page of Window. - /// - /// ElmSharp.EvasObject type page to be set. - public void SetMainPage(EvasObject content) - { - _layout.SetContent(content); - } - - void Initialize() - { - // events - Deleted += (sender, e) => - { - Closed?.Invoke(this, EventArgs.Empty); - }; - CloseRequested += (sender, e) => - { - Unrealize(); - }; - - Active(); - AutoDeletion = false; - Show(); - - _conformant = new Conformant(this); - _conformant.Show(); - - // Create the base (default) layout for the application - _layout = new ELayout(_conformant); - _layout.SetTheme("layout", "application", "default"); - _layout.Show(); - - _conformant.SetContent(_layout); - BaseLayout = _layout; - AvailableOrientations = DisplayOrientations.Portrait | DisplayOrientations.Landscape | DisplayOrientations.PortraitFlipped | DisplayOrientations.LandscapeFlipped; - } - DisplayOrientations GetDisplayOrientation() - { - switch (Rotation) - { - case 0: - return Native.DisplayOrientations.Portrait; - - case 90: - return Native.DisplayOrientations.Landscape; - - case 180: - return Native.DisplayOrientations.PortraitFlipped; - - case 270: - return Native.DisplayOrientations.LandscapeFlipped; - - default: - return Native.DisplayOrientations.None; - } - } - } -} diff --git a/Xamarin.Forms.Platform.Tizen/Platform.cs b/Xamarin.Forms.Platform.Tizen/Platform.cs index 8111a832..b3cd88af 100644 --- a/Xamarin.Forms.Platform.Tizen/Platform.cs +++ b/Xamarin.Forms.Platform.Tizen/Platform.cs @@ -49,7 +49,7 @@ namespace Xamarin.Forms.Platform.Tizen _naviframe.SetWeight(1.0, 1.0); _naviframe.Show(); _naviframe.AnimationFinished += NaviAnimationFinished; - Forms.Context.MainWindow.SetMainPage(_naviframe); + Forms.Context.BaseLayout.SetContent(_naviframe); } ~Platform() -- cgit v1.2.3