Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.RemoteView / Tizen.Applications / RemoteView.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 using System.Runtime.InteropServices;
20
21 namespace Tizen.Applications
22 {
23     /// <summary>
24     /// Represents the proxy class for the widget application.
25     /// </summary>
26     public class RemoteView
27     {
28         /// <summary>
29         /// The event types to send.
30         /// </summary>
31         public enum Event
32         {
33             /// <summary>
34             /// Type for feeding the mouse-up event to the widget application.
35             /// </summary>
36             FeedMouseUp,
37
38             /// <summary>
39             /// Type for canceling the click event procedure.
40             /// </summary>
41             CancelClick
42         }
43
44         /// <summary>
45         /// Layout object including preview image, overlay text, loading text, and remote screen image.
46         /// </summary>
47         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
48         public Layout Layout { get; internal set; }
49
50         /// <summary>
51         /// The widget ID.
52         /// </summary>
53         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
54         public string Id
55         {
56             get
57             {
58                 IntPtr ptr = Interop.WidgetViewerEvas.GetWidgetId(Layout);
59
60                 return Marshal.PtrToStringAnsi(ptr);
61             }
62         }
63
64         /// <summary>
65         /// The update period.
66         /// </summary>
67         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
68         public double Period
69         {
70             get
71             {
72                 return Interop.WidgetViewerEvas.GetPeriod(Layout);
73             }
74         }
75
76         /// <summary>
77         /// Contents of the widget.
78         /// </summary>
79         /// <remarks>
80         /// This string can be used for creating contents of the widget again after rebooting a device or it can be recovered from a crash (abnormal status).
81         /// </remarks>
82         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
83         public string Content
84         {
85             get
86             {
87                 IntPtr ptr = Interop.WidgetViewerEvas.GetContentInfo(Layout);
88
89                 return Marshal.PtrToStringAnsi(ptr);
90             }
91         }
92
93         /// <summary>
94         /// Summarized string of the widget content for accessibility.
95         /// </summary>
96         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
97         public string Title
98         {
99             get
100             {
101                 IntPtr ptr = Interop.WidgetViewerEvas.GetTitleString(Layout);
102
103                 return Marshal.PtrToStringAnsi(ptr);
104             }
105         }
106
107         internal RemoteView()
108         {
109         }
110
111         internal static void CheckException(Interop.WidgetViewerEvas.ErrorCode err)
112         {
113             switch (err)
114             {
115                 case Interop.WidgetViewerEvas.ErrorCode.Fault:
116                     throw new InvalidOperationException("Fault at unmanaged code");
117
118                 case Interop.WidgetViewerEvas.ErrorCode.PermissionDenied:
119                     throw new UnauthorizedAccessException();
120
121                 case Interop.WidgetViewerEvas.ErrorCode.NotSupported:
122                     throw new NotSupportedException();
123
124                 case Interop.WidgetViewerEvas.ErrorCode.InvalidParameter:
125                     throw new InvalidOperationException("Invalid parameter error at unmanaged code");
126
127                 case Interop.WidgetViewerEvas.ErrorCode.AlreadyExist:
128                     throw new InvalidOperationException("Already exist");
129
130                 case Interop.WidgetViewerEvas.ErrorCode.MaxExceeded:
131                     throw new InvalidOperationException("Max exceeded");
132             }
133         }
134
135         /// <summary>
136         /// Pauses all the connected widget applications.
137         /// </summary>
138         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
139         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
140         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
141         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
142         public static void PauseAll()
143         {
144             CheckException(Interop.WidgetViewerEvas.NotifyPausedStatusOfViewer());
145         }
146
147         /// <summary>
148         /// Resumes all the connected widget applications.
149         /// </summary>
150         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
151         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
152         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
153         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device<./exception>
154         public static void ResumeAll()
155         {
156             CheckException(Interop.WidgetViewerEvas.NotifyResumedStatusOfViewer());
157         }
158
159         /// <summary>
160         /// Pauses the widget application which is connected on this proxy.
161         /// </summary>
162         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
163         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
164         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
165         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
166         public void Pause()
167         {
168             CheckException(Interop.WidgetViewerEvas.PauseWidget(Layout));
169         }
170
171         /// <summary>
172         /// Resumes the widget application which is connected on this proxy.
173         /// </summary>
174         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
175         /// <exception cref="InvalidOperationException">Thrown when this operation failed.</exception>
176         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
177         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
178         public void Resume()
179         {
180             CheckException(Interop.WidgetViewerEvas.ResumeWidget(Layout));
181         }
182
183         /// <summary>
184         /// Sends the event to the widget application which is connected on this proxy.
185         /// </summary>
186         /// <privilege>http://tizen.org/privilege/widget.viewer</privilege>
187         /// <exception cref="UnauthorizedAccessException">Thrown when this operation is denied.</exception>
188         /// <exception cref="NotSupportedException">Thrown when this operation is not supported for this device.</exception>
189         public void SendEvent(Event ev)
190         {
191             switch (ev)
192             {
193                 case Event.FeedMouseUp:
194                     Interop.WidgetViewerEvas.FeedMouseUpEvent(Layout);
195                     break;
196
197                 case Event.CancelClick:
198                     Interop.WidgetViewerEvas.CancelClickEvent(Layout);
199                     break;
200
201                 default:
202                     throw new NotSupportedException("Not supported event type");
203             }
204
205             int err = Internals.Errors.ErrorFacts.GetLastResult();
206             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
207         }
208
209         internal void HideLoadingMessage()
210         {
211             Interop.WidgetViewerEvas.DisableLoading(Layout);
212             int err = Internals.Errors.ErrorFacts.GetLastResult();
213             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
214         }
215
216         internal void HidePreviewImage()
217         {
218             Interop.WidgetViewerEvas.DisablePreview(Layout);
219             int err = Internals.Errors.ErrorFacts.GetLastResult();
220             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
221         }
222
223         internal void HideOverlayText()
224         {
225             Interop.WidgetViewerEvas.DisableOverlayText(Layout);
226             int err = Internals.Errors.ErrorFacts.GetLastResult();
227             CheckException((Interop.WidgetViewerEvas.ErrorCode)err);
228         }
229
230     }
231 }