95cb240b6c09820da4f7e6a7387d90daddc6c063
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.WatchfaceComplication / Tizen.Applications / ComplicationProviderSetup.cs
1 /*
2  * Copyright (c) 2018 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 System;
18 using System.Collections.Generic;
19 using System.Text;
20
21 namespace Tizen.Applications.WatchfaceComplication
22 {
23     /// <summary>
24     /// Represents the ComplicationProviderSetup class for the complication provider setup application.
25     /// </summary>
26     /// <since_tizen> 6 </since_tizen>
27     public static class ComplicationProviderSetup
28     {
29         /// <summary>
30         /// Gets the received appctrl containing inforamtion about edit.
31         /// </summary>
32         /// <param name="recvAppCtrl">The appcontrol received event args.</param>
33         /// <exception cref="ArgumentException">Thrown when e is invalid.</exception>
34         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
35         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
36         /// <example>
37         /// <code>
38         /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
39         /// {
40         ///     if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl))
41         ///     {
42         ///         // do something
43         ///     }
44         ///     base.OnAppControlReceived(e);
45         /// }
46         /// </code>
47         /// </example>
48         /// <returns>The boolean value.</returns>
49         /// <since_tizen> 6 </since_tizen>
50         public static bool IsEditing(ReceivedAppControl recvAppCtrl)
51         {
52             bool isEditing = false;
53             ComplicationError err = Interop.WatchfaceComplication.IsSetupEditing(recvAppCtrl.SafeAppControlHandle, out isEditing);
54             if (err != ComplicationError.None)
55                 ErrorFactory.ThrowException(err, "fail to check editing");
56             return isEditing;
57         }
58
59         /// <summary>
60         /// Replies the setup context to the editor
61         /// </summary>
62         /// <param name="recvAppCtrl">The appcontrol received event args.</param>
63         /// <param name="context">The context created by complication setup app.</param>
64         /// <privilege>http://tizen.org/privilege/datasharing</privilege>
65         /// <exception cref="ArgumentException">Thrown when e is invalid.</exception>
66         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
67         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
68         /// <exception cref="UnauthorizedAccessException">Thrown when the application does not have privilege to access this method.</exception>
69         /// <example>
70         /// <code>
71         /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
72         /// {
73         ///     if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl))
74         ///     {
75         ///         Bundle context = ComplicationProviderSetup.GetContext(e.ReceivedAppControl);
76         ///         context.AddItem("TEST_KEY", "NEW CONTEXT");
77         ///         ComplicationProviderSetup.ReplyToEditor(e.ReceivedAppControl, context);
78         ///     }
79         ///     base.OnAppControlReceived(e);
80         /// }
81         /// </code>
82         /// </example>
83         /// <returns>Event target complication type</returns>
84         /// <since_tizen> 6 </since_tizen>
85         public static void ReplyToEditor(ReceivedAppControl recvAppCtrl, Bundle context)
86         {
87             ComplicationError err = Interop.WatchfaceComplication.SetupReplyToEditor(recvAppCtrl.SafeAppControlHandle, context.SafeBundleHandle);
88             if (err != ComplicationError.None)
89                 ErrorFactory.ThrowException(err, "fail to check editing");
90         }
91
92         /// <summary>
93         /// Gets complication's setup context.
94         /// </summary>
95         /// <param name="recvAppCtrl">The appcontrol received event args.</param>
96         /// <exception cref="ArgumentException">Thrown when e is invalid.</exception>
97         /// <exception cref="InvalidOperationException">Thrown when the method failed due to invalid operation.</exception>
98         /// <exception cref="NotSupportedException">Thrown when the watchface complication is not supported.</exception>
99         /// <example>
100         /// <code>
101         /// protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
102         /// {
103         ///     if (ComplicationProviderSetup.IsEditing(e.ReceivedAppControl))
104         ///     {
105         ///         Bundle context = ComplicationProviderSetup.GetContext(e.ReceivedAppControl);
106         ///         context.AddItem("TEST_KEY", "NEW CONTEXT");
107         ///         ComplicationProviderSetup.ReplyToEditor(e.ReceivedAppControl, context);
108         ///     }
109         ///     base.OnAppControlReceived(e);
110         /// }
111         /// </code>
112         /// </example>
113         /// <returns>The setup context.</returns>
114         /// <since_tizen> 6 </since_tizen>
115         public static Bundle GetContext(ReceivedAppControl recvAppCtrl)
116         {
117             SafeBundleHandle context;
118             ComplicationError err = Interop.WatchfaceComplication.GetSetupContext(recvAppCtrl.SafeAppControlHandle, out context);
119             if (err != ComplicationError.None)
120                 ErrorFactory.ThrowException(err, "fail to check editing");
121             if (context == null)
122                 return null;
123
124             return new Bundle(context);
125         }
126     }
127 }