From 15d7ac86dd6b8a3aadbf4e5afc9a147c663d31a4 Mon Sep 17 00:00:00 2001 From: "sung-su.kim" Date: Fri, 17 Apr 2020 17:40:15 +0900 Subject: [PATCH 1/5] Add ContentPopup --- .../ContentPopupImplementation.cs | 143 ++++++++++++++++++ .../ContentPopup.cs | 88 +++++++++++ .../IContentPopup.cs | 52 +++++++ .../ITwoButtonPopup.cs | 2 +- .../WearableUIGallery/TC/TCContentPopup.xaml | 43 ++++++ .../TC/TCContentPopup.xaml.cs | 81 ++++++++++ .../WearableUIGallery/TCData.cs | 1 + 7 files changed, 409 insertions(+), 1 deletion(-) create mode 100644 src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupImplementation.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/ContentPopup.cs create mode 100644 src/Tizen.Wearable.CircularUI.Forms/IContentPopup.cs mode change 100755 => 100644 src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml create mode 100644 test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml.cs diff --git a/src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupImplementation.cs b/src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupImplementation.cs new file mode 100644 index 00000000..a3f88444 --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms.Renderer/ContentPopupImplementation.cs @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Xamarin.Forms; +using Xamarin.Forms.Platform.Tizen; +using XForms = Xamarin.Forms.Forms; + +[assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.ContentPopupImplementation))] + +namespace Tizen.Wearable.CircularUI.Forms.Renderer +{ + public class ContentPopupImplementation : IContentPopup, IDisposable + { + View _content; + ElmSharp.Popup _popUp; + bool _isDisposed; + + public event EventHandler BackButtonPressed; + + public ContentPopupImplementation() + { + _popUp = new ElmSharp.Popup(XForms.NativeParent); + _popUp.Style = "circle"; + + _popUp.BackButtonPressed += BackButtonPressedHandler; + _popUp.Dismissed += OnDismissed; + } + + ~ContentPopupImplementation() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (_isDisposed) + return; + + if (disposing) + { + if (Content != null) + Content = null; + + if (_popUp != null) + { + _popUp.BackButtonPressed -= BackButtonPressedHandler; + _popUp.Dismissed -= OnDismissed; + _popUp.Unrealize(); + _popUp = null; + } + } + + _isDisposed = true; + } + + public View Content + { + get + { + return _content; + } + set + { + _content = value; + UpdateContent(); + } + } + + void BackButtonPressedHandler(object sender, EventArgs e) + { + BackButtonPressed?.Invoke(this, EventArgs.Empty); + } + + void UpdateContent() + { + if (!XForms.IsInitialized) + { + Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized"); + return; + } + + if (Content != null) + { + var renderer = Platform.GetOrCreateRenderer(Content); + (renderer as LayoutRenderer)?.RegisterOnLayoutUpdated(); + var native = renderer.NativeView; + var sizeRequest = Content.Measure(XForms.NativeParent.Geometry.Width, XForms.NativeParent.Geometry.Height).Request.ToPixel(); + native.MinimumHeight = sizeRequest.Height; + _popUp.SetContent(native, false); + } + else + { + if (Content != null) + Content = null; + _popUp.SetContent(null, false); + } + } + + public void Show() + { + if (!XForms.IsInitialized) + { + throw new InvalidOperationException("When the Application's Platform is not initialized, it can not show the Dialog."); + } + + if (_popUp != null) + { + _popUp.Show(); + } + } + + public void Dismiss() + { + _popUp.Hide(); + _popUp.Dismiss(); + } + + void OnDismissed(object sender, EventArgs e) + { + Dispose(); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/ContentPopup.cs b/src/Tizen.Wearable.CircularUI.Forms/ContentPopup.cs new file mode 100644 index 00000000..a2143cb3 --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/ContentPopup.cs @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + /// + /// The ContentPopup is a Popup, which allows you to customize the View to be displayed. + /// + /// 4 + public class ContentPopup : BindableObject + { + /// + /// BindableProperty. Identifies the content bindable property. + /// + /// 4 + public static readonly BindableProperty ContentProperty = BindableProperty.Create(nameof(Content), typeof(View), typeof(ContentPopup), null); + + IContentPopup _popUp; + + /// + /// Occurs when the device's back button is pressed. + /// + /// 4 + public event EventHandler BackButtonPressed; + + /// + /// Creates and initializes a new instance of the ContentPopup class. + /// + /// 4 + public ContentPopup() + { + _popUp = DependencyService.Get(DependencyFetchTarget.NewInstance); + if (_popUp == null) + throw new InvalidOperationException("Object reference not set to an instance of a Popup."); + + _popUp.BackButtonPressed += (s, e) => + { + BackButtonPressed?.Invoke(this, EventArgs.Empty); + }; + + SetBinding(ContentProperty, new Binding(nameof(Content), mode: BindingMode.OneWayToSource, source: _popUp)); + } + + /// + /// Gets or sets content view of the Popup. + /// + /// 4 + public View Content + { + get { return (View)GetValue(ContentProperty); } + set { SetValue(ContentProperty, value); } + } + + /// + /// Shows the ContentPopup. + /// + /// 4 + public void Show() + { + _popUp.Show(); + } + + /// + /// Dismisses the ContentPopup. + /// + /// 4 + public void Dismiss(object result = null) + { + _popUp.Dismiss(); + } + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/IContentPopup.cs b/src/Tizen.Wearable.CircularUI.Forms/IContentPopup.cs new file mode 100644 index 00000000..1b4f0d4d --- /dev/null +++ b/src/Tizen.Wearable.CircularUI.Forms/IContentPopup.cs @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Xamarin.Forms; + +namespace Tizen.Wearable.CircularUI.Forms +{ + /// + /// The IContentPopup is an interface to describe confirmation pop-up which has content area + /// + /// 4 + internal interface IContentPopup + { + /// + /// Occurs when the Back button is pressed. + /// + /// 4 + event EventHandler BackButtonPressed; + + /// + /// Gets or sets content view of the Popup. + /// + /// 4 + View Content { get; set; } + + /// + /// Shows the Popup + /// + /// 4 + void Show(); + + /// + /// Dismisses the Popup + /// + /// 4 + void Dismiss(); + } +} diff --git a/src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs b/src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs old mode 100755 new mode 100644 index 913caca4..b4e1adc7 --- a/src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs +++ b/src/Tizen.Wearable.CircularUI.Forms/ITwoButtonPopup.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Flora License, Version 1.1 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml b/test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml new file mode 100644 index 00000000..f9fcdb94 --- /dev/null +++ b/test/WearableUIGallery/WearableUIGallery/TC/TCContentPopup.xaml @@ -0,0 +1,43 @@ + + + + + + + + +