2 * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using Xamarin.Forms.Platform.Tizen;
20 using XForms = Xamarin.Forms.Forms;
22 [assembly: Dependency(typeof(Tizen.Wearable.CircularUI.Forms.Renderer.InformationPopupImplementation))]
24 namespace Tizen.Wearable.CircularUI.Forms.Renderer
26 public class InformationPopupImplementation : IInformationPopup, IDisposable
28 MenuItem _bottomMenuItem;
31 ElmSharp.Popup _popUp;
32 ElmSharp.ProgressBar _progress;
33 ElmSharp.Layout _layout;
34 ElmSharp.Button _bottomButton;
36 ElmSharp.Label _progressLabel;
40 bool _isProgressRunning;
43 public event EventHandler BackButtonPressed;
45 public InformationPopupImplementation()
47 _popUp = new ElmSharp.Popup(XForms.NativeParent);
48 _popUp.Style = "circle";
50 _layout = new ElmSharp.Layout(_popUp);
51 _layout.SetTheme("layout", "popup", "content/circle");
52 _popUp.SetContent(_layout);
54 _popUp.BackButtonPressed += BackButtonPressedHandler;
55 _popUp.Dismissed += OnDismissed;
58 ~InformationPopupImplementation()
66 GC.SuppressFinalize(this);
69 protected virtual void Dispose(bool disposing)
76 if (_bottomButton != null)
78 _bottomButton.Unrealize();
88 if (_progress != null)
90 _progress.Unrealize();
94 if (_progressLabel != null)
96 _progressLabel.Unrealize();
97 _progressLabel = null;
104 _popUp.BackButtonPressed -= BackButtonPressedHandler;
113 void BackButtonPressedHandler(object sender, EventArgs e)
115 BackButtonPressed?.Invoke(this, EventArgs.Empty);
118 public bool IsProgressRunning
122 return _isProgressRunning;
126 _isProgressRunning = value;
127 UpdateProcessVisibility();
131 public MenuItem BottomButton
135 return _bottomMenuItem;
139 if (_bottomMenuItem == value) return;
141 if (value is ColorMenuItem)
143 _buttonBgColor = ((ColorMenuItem)value).BackgroundColor;
147 _buttonBgColor = Color.Default;
149 _bottomMenuItem = value;
162 if (_title == value) return;
176 if (_text == value) return;
182 void UpdateProcessVisibility()
184 if (!XForms.IsInitialized)
186 Log.Debug(FormsCircularUI.Tag, "Tizen Forms is not initialized");
190 if (_isProgressRunning)
192 _box = new ElmSharp.Box(XForms.NativeParent);
195 _progress = new ElmSharp.ProgressBar(XForms.NativeParent)
197 Style = "process/popup/small",
200 _progress.PlayPulse();
201 _box.PackEnd(_progress);
203 _layout.SetPartContent("elm.swallow.content", _box, true);
209 if (_progress != null)
211 _progress.Unrealize();
215 if (_progressLabel != null)
217 _progressLabel.Unrealize();
218 _progressLabel = null;
224 _layout.SetPartContent("elm.swallow.content", null, true);
233 _bottomButton?.Hide();
235 if (BottomButton != null)
237 _bottomButton = new ElmSharp.Button(_popUp)
244 if (!string.IsNullOrEmpty(BottomButton.Text)) _bottomButton.Text = BottomButton.Text;
246 if (!BottomButton.IconImageSource.IsNullOrEmpty())
248 var iconSource = BottomButton.IconImageSource as FileImageSource;
249 var buttonImage = new ElmSharp.Image(_bottomButton);
250 buttonImage.LoadAsync(ResourcePath.GetPath(iconSource));
252 _bottomButton.SetPartContent("elm.swallow.content", buttonImage);
255 _bottomButton.Clicked += (s, e) =>
257 ((IMenuItemController)BottomButton).Activate();
260 if (_buttonBgColor != Color.Default)
262 Log.Debug(FormsCircularUI.Tag, $"InformationPopup set button background color:{_buttonBgColor.ToNative()}");
263 _bottomButton.BackgroundColor = _buttonBgColor.ToNative();
268 _bottomButton.Unrealize();
269 _bottomButton = null;
272 _popUp.SetPartContent("button1", _bottomButton);
277 string title = _title?.Replace("&", "&")
278 .Replace("<", "<")
279 .Replace(">", ">")
280 .Replace(Environment.NewLine, "<br>");
282 if (!_isProgressRunning)
284 _layout.SetPartText("elm.text.title", title);
288 _layout.SetPartText("elm.text.title", null);
294 string text = _text?.Replace("&", "&")
295 .Replace("<", "<")
296 .Replace(">", ">")
297 .Replace(Environment.NewLine, "<br>");
299 if (!_isProgressRunning)
301 _layout.SetPartText("elm.text", text);
305 _layout.SetPartText("elm.text", null);
306 if (!string.IsNullOrEmpty(text))
308 if (_progressLabel == null)
310 _progressLabel = new ElmSharp.Label(XForms.NativeParent)
312 TextStyle = "DEFAULT ='font=Tizen:style=Light color=#F9F9F9FF font_size=32 align=center valign=top wrap=word'",
315 _progressLabel.Text = text;
316 _progressLabel.Show();
319 _box.PackEnd(_progressLabel);
327 if (!XForms.IsInitialized)
329 throw new InvalidOperationException("When the Application's Platform is not initialized, it can not show the Dialog.");
338 public void Dismiss()
342 if (_bottomButton != null)
344 _bottomButton.Unrealize();
345 _bottomButton = null;
346 _popUp.SetPartContent("button1", null);
355 if (_progress != null)
357 _progress.Unrealize();
361 if (_progressLabel != null)
363 _progressLabel.Unrealize();
364 _progressLabel = null;
371 _popUp.BackButtonPressed -= BackButtonPressedHandler;
377 void OnDismissed(object sender, EventArgs e)
379 Log.Debug(FormsCircularUI.Tag, $"OnDismissed called");