[ElmSharp] Mark ElmSharp API as API Level: preview
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / AccessibleUtil.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 using System;
18 using System.Runtime.InteropServices;
19 using System.Threading.Tasks;
20
21 namespace ElmSharp.Accessible
22 {
23     /// <summary>
24     /// Enumeration for ReadingStatus.
25     /// </summary>
26     /// <since_tizen> preview </since_tizen>
27     public enum ReadingStatus
28     {
29         /// <summary>
30         /// Unknown status
31         /// </summary>
32         Unknown,
33         /// <summary>
34         /// Cancelled status
35         /// </summary>
36         Cancelled,
37         /// <summary>
38         /// Stopped status
39         /// </summary>
40         Stoppped,
41         /// <summary>
42         /// Skipped status
43         /// </summary>
44         Skipped
45     }
46
47     /// <summary>
48     /// AccessibleUtil provides a method to set the reading information.
49     /// </summary>
50     /// <since_tizen> preview </since_tizen>
51     public static class AccessibleUtil
52     {
53
54         static void AtspiSignalCallback(IntPtr data, string say_signal)
55         {
56             GCHandle gch = GCHandle.FromIntPtr(data);
57             TaskCompletionSource<ReadingStatus> tcs = (TaskCompletionSource<ReadingStatus>) gch.Target;
58             if (say_signal.Equals("ReadingCancelled"))
59             {
60                 tcs.SetResult(ReadingStatus.Cancelled);
61             }
62             else if (say_signal.Equals("ReadingStopped"))
63             {
64                 tcs.SetResult(ReadingStatus.Stoppped);
65             }
66             else if (say_signal.Equals("ReadingSkipped"))
67             {
68                 tcs.SetResult(ReadingStatus.Skipped);
69             }
70             else
71             {
72                 tcs.SetException(new InvalidOperationException("unknown signal : " + say_signal));
73             }
74
75             gch.Free();
76         }
77
78         /// <summary>
79         /// Reads given text by screen reader.
80         /// </summary>
81         /// <param name="text">The reading text.</param>
82         /// <param name="discardable">If true, reading can be discarded by subsequent reading requests, if false the reading must finish before next reading request can be started.</param>
83         /// <returns>Return a task with reading status.</returns>
84         /// <since_tizen> preview </since_tizen>
85         public static Task<ReadingStatus> Say(string text, bool discardable)
86         {
87             var tcs = new TaskCompletionSource<ReadingStatus>();
88             GCHandle gch = GCHandle.Alloc(tcs);
89             Interop.Elementary.elm_atspi_bridge_utils_say(text, discardable, AtspiSignalCallback, GCHandle.ToIntPtr(gch));
90             return tcs.Task;
91         }
92     }
93 }