2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using System.Threading.Tasks;
21 namespace ElmSharp.Accessible
24 /// Enumeration for the ReadingStatus.
26 /// <since_tizen> preview </since_tizen>
27 public enum ReadingStatus
48 /// AccessibleUtil provides a method to set the reading information.
50 /// <since_tizen> preview </since_tizen>
51 public static class AccessibleUtil
54 static void AtspiSignalCallback(IntPtr data, string say_signal)
56 GCHandle gch = GCHandle.FromIntPtr(data);
57 TaskCompletionSource<ReadingStatus> tcs = (TaskCompletionSource<ReadingStatus>) gch.Target;
58 if (say_signal.Equals("ReadingCancelled"))
60 tcs.SetResult(ReadingStatus.Cancelled);
62 else if (say_signal.Equals("ReadingStopped"))
64 tcs.SetResult(ReadingStatus.Stoppped);
66 else if (say_signal.Equals("ReadingSkipped"))
68 tcs.SetResult(ReadingStatus.Skipped);
72 tcs.SetException(new InvalidOperationException("unknown signal : " + say_signal));
79 /// Reads the given text by a screen reader.
81 /// <param name="text">The reading text.</param>
82 /// <param name="discardable">If true, reading can be discarded by subsequent reading requests. If false, reading must be finished before the next reading request can be started.</param>
83 /// <returns>Return a task with the reading status.</returns>
84 /// <since_tizen> preview </since_tizen>
85 public static Task<ReadingStatus> Say(string text, bool discardable)
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));