2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
23 using tlog = Tizen.Log;
26 namespace Tizen.NUI.Accessibility
29 /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility
31 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public class Accessibility
35 #region Constructor, Distructor, Dispose
36 private Accessibility()
39 dummy.Name = "dali-atspi-singleton";
42 /// destructor. This is HiddenAPI. recommended not to use in public.
47 #endregion Constructor, Distructor, Dispose
52 /// Instance for singleton
54 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
55 [EditorBrowsable(EditorBrowsableState.Never)]
56 public static Accessibility Instance
58 get => _accessibility;
65 /// Get the current status
67 /// <returns>Current enabled status</returns>
68 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
69 [EditorBrowsable(EditorBrowsableState.Never)]
70 static public bool GetStatus()
78 /// <param name="sentence">Content to be spoken</param>
79 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
80 /// <returns></returns>
81 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
82 [EditorBrowsable(EditorBrowsableState.Never)]
83 public bool Say(string sentence, bool discardable)
85 IntPtr callbackIntPtr = IntPtr.Zero;
86 if (_sayFinishedEventHandler != null)
88 callback = _sayFinishedEventCallback;
89 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
91 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// To make Say be paused or resumed
99 /// <param name="pause">true to be paused, false to be resumed</param>
100 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
101 [EditorBrowsable(EditorBrowsableState.Never)]
102 public void PauseResume(bool pause)
104 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(dummy), pause);
105 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110 #region Event, Enum, Struct, ETC
112 /// Say Finished event arguments
114 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public class SayFinishedEventArgs : EventArgs
119 /// The state of Say finished
121 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
122 [EditorBrowsable(EditorBrowsableState.Never)]
123 public SayFinishedStates State
129 internal SayFinishedEventArgs(int result)
131 State = (SayFinishedStates)(result);
132 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
137 /// Enum of Say finished event argument status
139 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
140 [EditorBrowsable(EditorBrowsableState.Never)]
141 public enum SayFinishedStates
146 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
147 [EditorBrowsable(EditorBrowsableState.Never)]
152 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153 [EditorBrowsable(EditorBrowsableState.Never)]
158 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
159 [EditorBrowsable(EditorBrowsableState.Never)]
164 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
165 [EditorBrowsable(EditorBrowsableState.Never)]
170 /// When Say is finished, this event is triggered
172 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public event EventHandler<SayFinishedEventArgs> SayFinished
176 add => _sayFinishedEventHandler += value;
177 remove => _sayFinishedEventHandler -= value;
179 #endregion Event, Enum, Struct, ETC
183 internal void PauseResume(View target, bool pause)
185 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(target), pause);
186 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 internal bool Say(View target, string sentence, bool discardable)
191 IntPtr callbackIntPtr = IntPtr.Zero;
192 if (_sayFinishedEventHandler != null)
194 callback = _sayFinishedEventCallback;
195 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
197 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
198 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
205 private static readonly Accessibility _accessibility = new Accessibility();
207 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
209 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
210 private delegate void _sayFinishedEventCallbackType(int result);
212 private _sayFinishedEventCallbackType callback = null;
214 private void _sayFinishedEventCallback(int result)
216 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
217 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
222 private static string tag = "NUITEST";