Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.RemoteView / Tizen.Applications / RemoteViewFactory.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using ElmSharp;
18 using System;
19
20 namespace Tizen.Applications
21 {
22     /// <summary>
23     /// Represents a factory class for making the RemoteView objects.
24     /// </summary>
25     public static class RemoteViewFactory
26     {
27         private static bool _ready;
28
29         /// <summary>
30         /// Initializes RemoteViewFactory.
31         /// </summary>
32         /// <param name="win">Window object that will contain RemoteViews that are generated by RemoteViewFactory.
33         /// All the remote views will be located in the specified window object.
34         /// </param>
35         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
36         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
37         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
38         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
39         public static void Init(EvasObject win)
40         {
41             if (_ready)
42                 throw new InvalidOperationException("Already initialized");
43             RemoteView.CheckException(Interop.WidgetViewerEvas.Init(win));
44             _ready = true;
45         }
46
47         /// <summary>
48         /// Creates a RemoteView object.
49         /// </summary>
50         /// <param name="parent">Parent object.</param>
51         /// <param name="widgetId">Widget ID.</param>
52         /// <param name="content">Contents that will be given to the widget instance.</param>
53         /// <param name="period">Update period.</param>
54         /// <param name="previewImage">True if you want to show the preview image.</param>
55         /// <param name="overlayText">True if you want to show the overlay text.</param>
56         /// <param name="loadingMessage">True if you want to show the loading message.</param>
57         /// <returns>RemoteView object.</returns>
58         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
59         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
60         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
61         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
62         public static RemoteView Create(EvasObject parent, string widgetId, string content, double period,
63             bool previewImage = true, bool overlayText = true, bool loadingMessage = true)
64         {
65             if (!_ready)
66                 throw new InvalidOperationException("Not initialized");
67
68             var obj = new RemoteView()
69             {
70                 Layout = new RemoteWindow(parent, widgetId, content, period)
71             };
72
73             if (!previewImage)
74                 obj.HidePreviewImage();
75
76             if (!overlayText)
77                 obj.HideOverlayText();
78
79             if (!loadingMessage)
80                 obj.HideLoadingMessage();
81
82             return obj;
83         }
84
85         /// <summary>
86         /// Finalizes the RemoteViewFactory.
87         /// </summary>
88         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
89         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
90         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
91         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
92         public static void Shutdown()
93         {
94             if (!_ready)
95                 throw new InvalidOperationException("Not initialized");
96             RemoteView.CheckException(Interop.WidgetViewerEvas.Fini());
97             _ready = false;
98         }
99
100     }
101 }