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 [EditorBrowsable(EditorBrowsableState.Never)]
35 public class Accessibility
37 #region Constructor, Distructor, Dispose
38 private Accessibility()
41 dummy.Name = "dali-atspi-singleton";
44 /// destructor. This is HiddenAPI. recommended not to use in public.
48 Tizen.Log.Debug("NUI",$"Accessibility is destroyed\n");
50 #endregion Constructor, Distructor, Dispose
55 /// Instance for singleton
57 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
58 [EditorBrowsable(EditorBrowsableState.Never)]
59 public static Accessibility Instance
61 get => _accessibility;
68 /// Get the current status
70 /// <returns>Current enabled status</returns>
71 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 static public bool GetStatus()
81 /// <param name="sentence">Content to be spoken</param>
82 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
83 /// <returns></returns>
84 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public bool Say(string sentence, bool discardable)
88 IntPtr callbackIntPtr = IntPtr.Zero;
89 if (_sayFinishedEventHandler != null)
91 callback = _sayFinishedEventCallback;
92 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
94 bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100 /// To make Say be paused or resumed
102 /// <param name="pause">true to be paused, false to be resumed</param>
103 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 public void PauseResume(bool pause)
107 Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 #region Event, Enum, Struct, ETC
115 /// Say Finished event arguments
117 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public class SayFinishedEventArgs : EventArgs
122 /// The state of Say finished
124 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public SayFinishedStates State
132 internal SayFinishedEventArgs(int result)
134 State = (SayFinishedStates)(result);
135 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
140 /// Enum of Say finished event argument status
142 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public enum SayFinishedStates
149 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
150 [EditorBrowsable(EditorBrowsableState.Never)]
155 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
156 [EditorBrowsable(EditorBrowsableState.Never)]
161 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
162 [EditorBrowsable(EditorBrowsableState.Never)]
167 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
168 [EditorBrowsable(EditorBrowsableState.Never)]
173 /// When Say is finished, this event is triggered
175 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
176 [EditorBrowsable(EditorBrowsableState.Never)]
177 public event EventHandler<SayFinishedEventArgs> SayFinished
179 add => _sayFinishedEventHandler += value;
180 remove => _sayFinishedEventHandler -= value;
182 #endregion Event, Enum, Struct, ETC
186 internal void PauseResume(View target, bool pause)
188 Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192 internal bool Say(View target, string sentence, bool discardable)
194 IntPtr callbackIntPtr = IntPtr.Zero;
195 if (_sayFinishedEventHandler != null)
197 callback = _sayFinishedEventCallback;
198 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
200 bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208 private static readonly Accessibility _accessibility = new Accessibility();
210 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
212 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
213 private delegate void _sayFinishedEventCallbackType(int result);
215 private _sayFinishedEventCallbackType callback = null;
217 private void _sayFinishedEventCallback(int result)
219 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
220 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
225 private static string tag = "NUITEST";