diff options
author | Kangho Hur <kangho.hur@samsung.com> | 2016-12-16 11:00:07 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 13:18:57 +0900 |
commit | 4f0149dae93bf80770664d74a33f27c8f0821310 (patch) | |
tree | f42aa298fe8ab04e5e898d84a337bbcfcf44229e /Xamarin.Forms.Platform.Tizen/FormsApplication.cs | |
parent | 4cf32c94986e6541f67c4909ac5428c92a221bce (diff) | |
download | xamarin-forms-4f0149dae93bf80770664d74a33f27c8f0821310.tar.gz xamarin-forms-4f0149dae93bf80770664d74a33f27c8f0821310.tar.bz2 xamarin-forms-4f0149dae93bf80770664d74a33f27c8f0821310.zip |
Add Tizen backend renderer
- Xamarin.Forms.Platform.Tizen has been added
- Xamarin.Forms.Maps.Tizen has been added
- RPM build spec has been added
Change-Id: I0021e0f040d97345affc87512ee0f6ce437f4e6d
Diffstat (limited to 'Xamarin.Forms.Platform.Tizen/FormsApplication.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Tizen/FormsApplication.cs | 344 |
1 files changed, 344 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/FormsApplication.cs b/Xamarin.Forms.Platform.Tizen/FormsApplication.cs new file mode 100644 index 00000000..32ef3c38 --- /dev/null +++ b/Xamarin.Forms.Platform.Tizen/FormsApplication.cs @@ -0,0 +1,344 @@ +using System; +using System.ComponentModel; +using System.Diagnostics; +using Tizen.Applications; +using ElmSharp; +using EProgressBar = ElmSharp.ProgressBar; +using EColor = ElmSharp.Color; +using ELabel = ElmSharp.Label; + +namespace Xamarin.Forms.Platform.Tizen +{ + public class FormsApplication : CoreUIApplication + { + Platform _platform; + Application _application; + bool _isInitialStart; + int _pageBusyCount; + Native.Dialog _pageBusyDialog; + Native.Window _window; + + protected FormsApplication() + { + _isInitialStart = true; + _pageBusyCount = 0; + } + + /// <summary> + /// Gets the main window or <c>null</c> if it's not set. + /// </summary> + /// <value>The main window or <c>null</c>.</value> + public Native.Window MainWindow + { + get + { + return _window; + } + + private set + { + _window = value; + } + } + + protected override void OnCreate() + { + base.OnCreate(); + Application.ClearCurrent(); + CreateWindow(); + } + + protected override void OnTerminate() + { + base.OnTerminate(); + MessagingCenter.Unsubscribe<Page, AlertArguments>(this, "Xamarin.SendAlert"); + MessagingCenter.Unsubscribe<Page, bool>(this, "Xamarin.BusySet"); + MessagingCenter.Unsubscribe<Page, ActionSheetArguments>(this, "Xamarin.ShowActionSheet"); + if (_platform != null) + { + _platform.Dispose(); + } + } + + protected override void OnAppControlReceived(AppControlReceivedEventArgs e) + { + base.OnAppControlReceived(e); + + if (!_isInitialStart && _application != null) + { + _application.SendResume(); + } + _isInitialStart = false; + } + + protected override void OnPause() + { + base.OnPause(); + if (_application != null) + { + _application.SendSleepAsync(); + } + } + + protected override void OnResume() + { + base.OnResume(); + if (_application != null) + { + _application.SendResume(); + } + } + + public void LoadApplication(Application application) + { + if (null == MainWindow) + { + throw new NullReferenceException("Call base OnCreate() method before loading the application."); + } + if (null == application) + { + throw new ArgumentNullException("application"); + } + _application = application; + Application.Current = application; + application.SendStart(); + application.PropertyChanged += new PropertyChangedEventHandler(this.AppOnPropertyChanged); + SetPage(_application.MainPage); + } + + void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args) + { + if ("MainPage" == args.PropertyName) + { + SetPage(_application.MainPage); + } + } + + void ShowActivityIndicatorDialog(bool enabled) + { + if (null == _pageBusyDialog) + { + _pageBusyDialog = new Native.Dialog(Forms.Context.MainWindow) + { + Orientation = PopupOrientation.Top, + }; + + var activity = new EProgressBar(_pageBusyDialog) + { + Style = "process_large", + IsPulseMode = true, + }; + activity.PlayPulse(); + activity.Show(); + + _pageBusyDialog.Content = activity; + + } + _pageBusyCount = Math.Max(0, enabled ? _pageBusyCount + 1 : _pageBusyCount - 1); + if (_pageBusyCount > 0) + { + _pageBusyDialog.Show(); + } + else + { + _pageBusyDialog.Dismiss(); + _pageBusyDialog = null; + } + } + + void SetPage(Page page) + { + if (!Forms.IsInitialized) + { + throw new InvalidOperationException("Call Forms.Init (UIApplication) before this"); + } + if (_platform != null) + { + _platform.SetPage(page); + return; + } + MessagingCenter.Subscribe<Page, bool>(this, Page.BusySetSignalName, delegate (Page sender, bool enabled) + { + ShowActivityIndicatorDialog(enabled); + }, null); + + MessagingCenter.Subscribe<Page, AlertArguments>(this, Page.AlertSignalName, delegate (Page sender, AlertArguments arguments) + { + Native.Dialog alert = new Native.Dialog(Forms.Context.MainWindow); + + alert.Title = arguments.Title; + var label = new ELabel(alert) + { + Text = "<span font_size=30 >" + arguments.Message + "<\\span>", + }; + label.Show(); + + var box = new Box(alert); + box.PackEnd(label); + box.Show(); + alert.Content = box; + + Native.Button cancel = new Native.Button(alert) { Text = arguments.Cancel }; + alert.NegativeButton = cancel; + cancel.Clicked += (s, evt) => + { + arguments.SetResult(false); + alert.Dismiss(); + }; + + if (arguments.Accept != null) + { + Native.Button ok = new Native.Button(alert) { Text = arguments.Accept }; + alert.PositiveButton = ok; + ok.Clicked += (s, evt) => + { + arguments.SetResult(true); + alert.Dismiss(); + }; + } + + alert.BackButtonPressed += (s, evt) => + { + arguments.SetResult(false); + alert.Dismiss(); + }; + + alert.Show(); + }, null); + + MessagingCenter.Subscribe<Page, ActionSheetArguments>(this, Page.ActionSheetSignalName, delegate (Page sender, ActionSheetArguments arguments) + { + Native.Dialog alert = new Native.Dialog(Forms.Context.MainWindow); + + alert.Title = arguments.Title; + Box box = new Box(alert); + + if (null != arguments.Destruction) + { + Native.Button destruction = new Native.Button(alert) + { + Text = arguments.Destruction, + TextColor = EColor.Red, + AlignmentX = -1 + }; + destruction.Clicked += (s, evt) => + { + arguments.SetResult(arguments.Destruction); + alert.Dismiss(); + }; + destruction.Show(); + box.PackEnd(destruction); + } + + foreach (string buttonName in arguments.Buttons) + { + Native.Button button = new Native.Button(alert) + { + Text = buttonName, + AlignmentX = -1 + }; + button.Clicked += (s, evt) => + { + arguments.SetResult(buttonName); + alert.Dismiss(); + }; + button.Show(); + box.PackEnd(button); + } + + box.Show(); + alert.Content = box; + + if (null != arguments.Cancel) + { + Native.Button cancel = new Native.Button(Forms.Context.MainWindow) { Text = arguments.Cancel }; + alert.NegativeButton = cancel; + cancel.Clicked += (s, evt) => + { + alert.Dismiss(); + }; + } + + alert.BackButtonPressed += (s, evt) => + { + alert.Dismiss(); + }; + + alert.Show(); + }, null); + + _platform = new Platform(this); + if (_application != null) + { + _application.Platform = _platform; + } + _platform.SetPage(page); + } + + void CreateWindow() + { + Debug.Assert(null == MainWindow); + + var window = new Native.Window(); + window.Closed += (s, e) => + { + Exit(); + }; + window.RotationChanged += (sender, e) => + { + switch (_window.CurrentOrientation) + { + case Native.DisplayOrientations.None: + Device.Info.CurrentOrientation = DeviceOrientation.Other; + break; + + case Native.DisplayOrientations.Portrait: + Device.Info.CurrentOrientation = DeviceOrientation.PortraitUp; + break; + + case Native.DisplayOrientations.Landscape: + Device.Info.CurrentOrientation = DeviceOrientation.LandscapeLeft; + break; + + case Native.DisplayOrientations.PortraitFlipped: + Device.Info.CurrentOrientation = DeviceOrientation.PortraitDown; + break; + + case Native.DisplayOrientations.LandscapeFlipped: + Device.Info.CurrentOrientation = DeviceOrientation.LandscapeRight; + break; + } + }; + + MainWindow = window; + } + public void Run() + { + Run(System.Environment.GetCommandLineArgs()); + } + + /// <summary> + /// Exits the application's main loop, which initiates the process of its termination + /// </summary> + public override void Exit() + { + if (_platform == null) + { + Log.Warn("Exit was already called or FormsApplication is not initialized yet."); + return; + } + // before everything is closed, inform the MainPage that it is disappearing + try + { + (_platform?.Page as IPageController)?.SendDisappearing(); + _platform = null; + } + catch (Exception e) + { + Log.Error("Exception thrown from SendDisappearing: {0}", e.Message); + } + + base.Exit(); + } + } +} |