[Inputmethod Manager][TCSACR-147] Add API to launch IME (#273)
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.InputMethodManager / Tizen.Uix.InputMethodManager / InputMethodManager.cs
1 /*
2 * Copyright (c) 2016 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
18 using static Interop.InputMethodManager;
19
20 namespace Tizen.Uix.InputMethodManager
21 {
22     /// <summary>
23     /// This class provides the function for launching the input method editor (IME) list and selector settings. A user can manage the installed IMEs in the system.
24     /// The input method editor (IME) is an input panel that lets users provide an input and the platform to receive the text data entered.
25     /// The manager is a module for managing the installed IMEs.
26     /// IME developers can use this module to open the installed IME list or the selector menu after their IME installation, and then guide to select the installed IME.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public static class Manager
30     {
31         /// <summary>
32         /// Requests to open the installed IME list menu.
33         /// This API provides the installed IME list menu for IME developers who might want to open it to enable their IME.
34         /// </summary>
35         /// <privilege>
36         /// http://tizen.org/privilege/imemanager
37         /// </privilege>
38         /// <exception cref="T:System.InvalidOperationException">
39         /// This exception can occur if:
40         /// 1) The application does not have the privilege to call this function.
41         /// 2) Operation failed.
42         /// </exception>
43         /// <since_tizen> 3 </since_tizen>
44         public static void ShowIMEList()
45         {
46             ErrorCode error = ImeManagerShowImeList();
47             if (error != ErrorCode.None)
48             {
49                 Log.Error(LogTag, "ShowIMEList Failed with error " + error);
50                 throw InputMethodManagerExceptionFactory.CreateException(error);
51             }
52         }
53
54         /// <summary>
55         /// Requests to open the IME selector menu.
56         /// This API provides the IME selector menu for the IME or other application developers who might want to change the default IME.
57         /// </summary>
58         /// <privilege>
59         /// http://tizen.org/privilege/imemanager
60         /// </privilege>
61         /// <exception cref="T:System.InvalidOperationException">
62         /// This exception can occur if:
63         /// 1) The application does not have the privilege to call this function.
64         /// 2) Operation failed.
65         /// </exception>
66         /// <since_tizen> 3 </since_tizen>
67         public static void ShowIMESelector()
68         {
69             ErrorCode error = ImeManagerShowImeSelector();
70             if (error != ErrorCode.None)
71             {
72                 Log.Error(LogTag, "ShowIMESelector Failed with error " + error);
73                 throw InputMethodManagerExceptionFactory.CreateException(error);
74             }
75         }
76
77         /// <summary>
78         /// Checks if the specific IME is enabled or disabled in the system keyboard setting.
79         /// The IME developers can use this property to check if their IME is enabled or not.
80         /// </summary>
81         /// <privilege>
82         /// http://tizen.org/privilege/imemanager
83         /// </privilege>
84         /// <param name="appId">The application ID of the IME.</param>
85         /// <returns>The On (enabled) and Off (disabled) state of the IME.</returns>
86         /// <exception cref="T:System.ArgumentException">
87         /// This exception can occur if an invalid parameter is provided.
88         /// </exception>
89         /// <exception cref="T:System.InvalidOperationException">
90         /// This exception can occur if:
91         /// 1) The application does not have the privilege to call this function.
92         /// 2) Operation failed.
93         /// </exception>
94         /// <since_tizen> 3 </since_tizen>
95         public static bool IsIMEEnabled(string appId)
96         {
97             bool isIMEEnabled;
98             ErrorCode error = ImeManagerIsImeEnabled(appId, out isIMEEnabled);
99             if (error != ErrorCode.None)
100             {
101                 Log.Error(LogTag, "IsIMEEnabled Failed with error " + error);
102                 throw InputMethodManagerExceptionFactory.CreateException(error);
103             }
104
105             return isIMEEnabled;
106         }
107
108         /// <summary>
109         /// Checks which IME is the current activated (selected) IME.
110         /// </summary>
111         /// <privilege>
112         /// http://tizen.org/privilege/imemanager
113         /// </privilege>
114         /// <returns>
115         /// The current activated (selected) IME.
116         /// </returns>
117         /// <exception cref="T:System.InvalidOperationException">
118         /// This exception can occur if:
119         /// 1) The application does not have the privilege to call this function.
120         /// 2) Operation failed.
121         /// </exception>
122         /// <since_tizen> 3 </since_tizen>
123         public static string GetActiveIME()
124         {
125             string activeIME;
126             ErrorCode error = ImeManagerGetActiveIme(out activeIME);
127             if (error != ErrorCode.None)
128             {
129                 Log.Error(LogTag, "GetActiveIME Failed with error " + error);
130                 throw InputMethodManagerExceptionFactory.CreateException(error);
131             }
132
133             return activeIME;
134         }
135
136         /// <summary>
137         /// Gets the number of IMEs that are enabled (usable).
138         /// </summary>
139         /// <privilege>
140         /// http://tizen.org/privilege/imemanager
141         /// </privilege>
142         /// <returns>
143         /// The number of enabled IMEs.
144         /// </returns>
145         /// <exception cref="T:System.InvalidOperationException">
146         /// This exception can occur if:
147         /// 1) The application does not have the privilege to call this function.
148         /// 2) Operation failed.
149         /// </exception>
150         /// <since_tizen> 3 </since_tizen>
151         public static int GetEnabledIMECount()
152         {
153             int activeIME = ImeManagerGetEnabledImeCount();
154             ErrorCode error = (ErrorCode)Tizen.Internals.Errors.ErrorFacts.GetLastResult();
155             if (error != ErrorCode.None)
156             {
157                 Log.Error(LogTag, "GetEnabledIMECount Failed with error " + error);
158                 throw InputMethodManagerExceptionFactory.CreateException(error);
159             }
160
161             return activeIME;
162         }
163
164         /// <summary>
165         /// Requests to pre-launch the IME.
166         /// The developers can use this function to launch IME in On-demand mode.
167         /// </summary>
168         /// <privilege>
169         /// http://tizen.org/privilege/imemanager
170         /// </privilege>
171         /// <exception cref="InvalidOperationException">
172         /// This exception can occur if:
173         /// 1) The application does not have the privilege to call this function.
174         /// 2) Operation failed.
175         /// </exception>
176         /// <since_tizen> 5 </since_tizen>
177         public static void PrelaunchIME()
178         {
179             ErrorCode error = ImeManagerPrelaunchIme();
180             if (error != ErrorCode.None)
181             {
182                 Log.Error(LogTag, "PrelaunchIME Failed with error " + error);
183                 throw InputMethodManagerExceptionFactory.CreateException(error);
184             }
185         }
186     }
187 }