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;
22 using System.Diagnostics.CodeAnalysis;
24 using tlog = Tizen.Log;
27 namespace Tizen.NUI.Accessibility
30 /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility
32 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
33 [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
34 [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public class Accessibility
38 #region Constructor, Distructor, Dispose
39 private Accessibility()
42 dummy.Name = "dali-atspi-singleton";
45 /// destructor. This is HiddenAPI. recommended not to use in public.
49 Tizen.Log.Debug("NUI",$"Accessibility is destroyed\n");
51 #endregion Constructor, Distructor, Dispose
56 /// Instance for singleton
58 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public static Accessibility Instance
62 get => _accessibility;
69 /// Get the current status
71 /// <returns>Current enabled status</returns>
72 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 static public bool GetStatus()
82 /// <param name="sentence">Content to be spoken</param>
83 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
84 /// <returns></returns>
85 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public bool Say(string sentence, bool discardable)
89 IntPtr callbackIntPtr = IntPtr.Zero;
90 if (_sayFinishedEventHandler != null)
92 callback = _sayFinishedEventCallback;
93 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
95 bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
96 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101 /// To make Say be paused or resumed
103 /// <param name="pause">true to be paused, false to be resumed</param>
104 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public void PauseResume(bool pause)
108 Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 #region Event, Enum, Struct, ETC
116 /// Say Finished event arguments
118 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
119 [EditorBrowsable(EditorBrowsableState.Never)]
120 public class SayFinishedEventArgs : EventArgs
123 /// The state of Say finished
125 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
126 [EditorBrowsable(EditorBrowsableState.Never)]
127 public SayFinishedState State
133 internal SayFinishedEventArgs(int result)
135 State = (SayFinishedState)(result);
136 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
141 /// Enum of Say finished event argument status
143 [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState instead!")]
144 [EditorBrowsable(EditorBrowsableState.Never)]
145 public enum SayFinishedStates
150 [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
151 [EditorBrowsable(EditorBrowsableState.Never)]
156 [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
157 [EditorBrowsable(EditorBrowsableState.Never)]
162 [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
163 [EditorBrowsable(EditorBrowsableState.Never)]
168 [Obsolete("Please do not use! This will be removed. Please use Accessibility.SayFinishedState.Invalid instead!")]
169 [EditorBrowsable(EditorBrowsableState.Never)]
174 /// Enum of Say finished event argument status
176 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 public enum SayFinishedState
183 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
184 [EditorBrowsable(EditorBrowsableState.Never)]
189 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
190 [EditorBrowsable(EditorBrowsableState.Never)]
195 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196 [EditorBrowsable(EditorBrowsableState.Never)]
201 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
202 [EditorBrowsable(EditorBrowsableState.Never)]
207 /// When Say is finished, this event is triggered
209 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public event EventHandler<SayFinishedEventArgs> SayFinished
213 add => _sayFinishedEventHandler += value;
214 remove => _sayFinishedEventHandler -= value;
216 #endregion Event, Enum, Struct, ETC
220 internal void PauseResume(View target, bool pause)
222 Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
223 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226 internal bool Say(View target, string sentence, bool discardable)
228 IntPtr callbackIntPtr = IntPtr.Zero;
229 if (_sayFinishedEventHandler != null)
231 callback = _sayFinishedEventCallback;
232 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
234 bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
235 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 private static readonly Accessibility _accessibility = new Accessibility();
244 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
246 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
247 private delegate void _sayFinishedEventCallbackType(int result);
249 private _sayFinishedEventCallbackType callback = null;
251 private void _sayFinishedEventCallback(int result)
253 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
254 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
259 private static string tag = "NUITEST";