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.
49 #endregion Constructor, Distructor, Dispose
54 /// Instance for singleton
56 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
57 [EditorBrowsable(EditorBrowsableState.Never)]
58 public static Accessibility Instance
60 get => _accessibility;
67 /// Get the current status
69 /// <returns>Current enabled status</returns>
70 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
71 [EditorBrowsable(EditorBrowsableState.Never)]
72 static public bool GetStatus()
80 /// <param name="sentence">Content to be spoken</param>
81 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
82 /// <returns></returns>
83 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public bool Say(string sentence, bool discardable)
87 IntPtr callbackIntPtr = IntPtr.Zero;
88 if (_sayFinishedEventHandler != null)
90 callback = _sayFinishedEventCallback;
91 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
93 bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
94 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 /// To make Say be paused or resumed
101 /// <param name="pause">true to be paused, false to be resumed</param>
102 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public void PauseResume(bool pause)
106 Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
107 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112 #region Event, Enum, Struct, ETC
114 /// Say Finished event arguments
116 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
117 [EditorBrowsable(EditorBrowsableState.Never)]
118 public class SayFinishedEventArgs : EventArgs
121 /// The state of Say finished
123 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 public SayFinishedStates State
131 internal SayFinishedEventArgs(int result)
133 State = (SayFinishedStates)(result);
134 tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}");
139 /// Enum of Say finished event argument status
141 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public enum SayFinishedStates
148 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
149 [EditorBrowsable(EditorBrowsableState.Never)]
154 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
155 [EditorBrowsable(EditorBrowsableState.Never)]
160 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
161 [EditorBrowsable(EditorBrowsableState.Never)]
166 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
167 [EditorBrowsable(EditorBrowsableState.Never)]
172 /// When Say is finished, this event is triggered
174 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
175 [EditorBrowsable(EditorBrowsableState.Never)]
176 public event EventHandler<SayFinishedEventArgs> SayFinished
178 add => _sayFinishedEventHandler += value;
179 remove => _sayFinishedEventHandler -= value;
181 #endregion Event, Enum, Struct, ETC
185 internal void PauseResume(View target, bool pause)
187 Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
188 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191 internal bool Say(View target, string sentence, bool discardable)
193 IntPtr callbackIntPtr = IntPtr.Zero;
194 if (_sayFinishedEventHandler != null)
196 callback = _sayFinishedEventCallback;
197 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
199 bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
200 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207 private static readonly Accessibility _accessibility = new Accessibility();
209 private event EventHandler<SayFinishedEventArgs> _sayFinishedEventHandler;
211 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
212 private delegate void _sayFinishedEventCallbackType(int result);
214 private _sayFinishedEventCallbackType callback = null;
216 private void _sayFinishedEventCallback(int result)
218 tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!");
219 _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
224 private static string tag = "NUITEST";