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.
22 using System.ComponentModel;
23 using System.Runtime.InteropServices;
24 using Tizen.NUI.BaseComponents;
26 using tlog = Tizen.Log;
32 /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility
34 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public class Accessibility
38 #region Constructor, Distructor, Dispose
39 private Accessibility()
42 dummy.Name = "dali-atspi-singleton";
48 #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 _sayFinishedEventCallbackType 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 _sayFinishedEventCallbackType 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 void _sayFinishedEventCallback(int result)
215 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
216 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
221 private static string tag = "NUITEST";