2 * Copyright(c) 2020 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 : Disposable
35 #region Constructor, Distructor, Dispose
36 private Accessibility()
39 dummy.Name = "dali-atspi-singleton";
43 /// destructor. This is HiddenAPI. recommended not to use in public.
49 #endregion Constructor, Distructor, Dispose
53 /// Instance for singleton
55 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
56 [EditorBrowsable(EditorBrowsableState.Never)]
57 public static Accessibility Instance
59 get => _accessibility;
66 /// Get the current status
68 /// <returns>Current enabled status</returns>
69 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
70 [EditorBrowsable(EditorBrowsableState.Never)]
71 static public bool GetStatus()
79 /// <param name="sentence">Content to be spoken</param>
80 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
81 /// <returns></returns>
82 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
83 [EditorBrowsable(EditorBrowsableState.Never)]
84 public bool Say(string sentence, bool discardable)
86 IntPtr callbackIntPtr = IntPtr.Zero;
87 if (_sayFinishedEventHandler != null)
89 callback = _sayFinishedEventCallback;
90 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
92 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
93 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
98 /// To make Say be paused or resumed
100 /// <param name="pause">true to be paused, false to be resumed</param>
101 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public void PauseResume(bool pause)
105 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(dummy), pause);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 #region Event, Enum, Struct, ETC
113 /// Say Finished event arguments
115 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
116 [EditorBrowsable(EditorBrowsableState.Never)]
117 public class SayFinishedEventArgs : EventArgs
120 /// The state of Say finished
122 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
123 [EditorBrowsable(EditorBrowsableState.Never)]
124 public SayFinishedStates State
130 internal SayFinishedEventArgs(int result)
132 State = (SayFinishedStates)(result);
133 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
138 /// Enum of Say finished event argument status
140 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
141 [EditorBrowsable(EditorBrowsableState.Never)]
142 public enum SayFinishedStates
147 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
148 [EditorBrowsable(EditorBrowsableState.Never)]
153 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
154 [EditorBrowsable(EditorBrowsableState.Never)]
159 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
160 [EditorBrowsable(EditorBrowsableState.Never)]
165 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
166 [EditorBrowsable(EditorBrowsableState.Never)]
171 /// When Say is finished, this event is triggered
173 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
174 [EditorBrowsable(EditorBrowsableState.Never)]
175 public event EventHandler<SayFinishedEventArgs> SayFinished
177 add => _sayFinishedEventHandler += value;
178 remove => _sayFinishedEventHandler -= value;
180 #endregion Event, Enum, Struct, ETC
184 internal void PauseResume(View target, bool pause)
186 Interop.Accessibility.accessibility_pause_resume(View.getCPtr(target), pause);
187 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190 internal bool Say(View target, string sentence, bool discardable)
192 IntPtr callbackIntPtr = IntPtr.Zero;
193 if (_sayFinishedEventHandler != null)
195 callback = _sayFinishedEventCallback;
196 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
198 bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
199 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 private static readonly Accessibility _accessibility = new Accessibility();
208 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
210 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
211 private delegate void _sayFinishedEventCallbackType(int result);
213 private _sayFinishedEventCallbackType callback = null;
215 private void _sayFinishedEventCallback(int result)
217 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
218 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
223 /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
225 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
226 [EditorBrowsable(EditorBrowsableState.Never)]
227 protected override void Dispose(DisposeTypes type)
241 private static string tag = "NUITEST";