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;
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";
45 #endregion Constructor, Distructor, Dispose
50 /// Instance for singleton
52 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
53 [EditorBrowsable(EditorBrowsableState.Never)]
54 public static Accessibility Instance
56 get => _accessibility;
63 /// Get the current status
65 /// <returns>Current enabled status</returns>
66 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
67 [EditorBrowsable(EditorBrowsableState.Never)]
68 static public bool GetStatus()
76 /// <param name="sentence">Content to be spoken</param>
77 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
78 /// <returns></returns>
79 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public bool Say(string sentence, bool discardable)
83 IntPtr callbackIntPtr = IntPtr.Zero;
84 if (_sayFinishedEventHandler != null)
86 callback = _sayFinishedEventCallback;
87 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
89 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
90 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
95 /// To make Say be paused or resumed
97 /// <param name="pause">true to be paused, false to be resumed</param>
98 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
99 [EditorBrowsable(EditorBrowsableState.Never)]
100 public void PauseResume(bool pause)
102 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(dummy), pause);
103 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 #region Event, Enum, Struct, ETC
110 /// Say Finished event arguments
112 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public class SayFinishedEventArgs : EventArgs
117 /// The state of Say finished
119 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
120 [EditorBrowsable(EditorBrowsableState.Never)]
121 public SayFinishedStates State
127 internal SayFinishedEventArgs(int result)
129 State = (SayFinishedStates)(result);
130 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
135 /// Enum of Say finished event argument status
137 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public enum SayFinishedStates
144 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
145 [EditorBrowsable(EditorBrowsableState.Never)]
150 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
151 [EditorBrowsable(EditorBrowsableState.Never)]
156 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
157 [EditorBrowsable(EditorBrowsableState.Never)]
162 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
163 [EditorBrowsable(EditorBrowsableState.Never)]
168 /// When Say is finished, this event is triggered
170 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public event EventHandler<SayFinishedEventArgs> SayFinished
174 add => _sayFinishedEventHandler += value;
175 remove => _sayFinishedEventHandler -= value;
177 #endregion Event, Enum, Struct, ETC
181 internal void PauseResume(View target, bool pause)
183 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(target), pause);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 internal bool Say(View target, string sentence, bool discardable)
189 IntPtr callbackIntPtr = IntPtr.Zero;
190 if (_sayFinishedEventHandler != null)
192 callback = _sayFinishedEventCallback;
193 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
195 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
196 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
203 private static readonly Accessibility _accessibility = new Accessibility();
205 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
207 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
208 private delegate void _sayFinishedEventCallbackType(int result);
210 private _sayFinishedEventCallbackType callback = null;
212 private void _sayFinishedEventCallback(int result)
214 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
215 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
220 private static string tag = "NUITEST";