/* * Copyright(c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #if (NUI_DEBUG_ON) using global::System; using System.ComponentModel; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; #if (NUI_DEBUG_ON) using tlog = Tizen.Log; #endif namespace Tizen.NUI { /// /// Accessibility provides Dali-ATSPI interface which has funtionality of Screen-Reader and general accessibility /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public class Accessibility { #region Constructor, Distructor, Dispose private Accessibility() { dummy = new View(); dummy.Name = "dali-atspi-singleton"; } ~Accessibility() { } #endregion Constructor, Distructor, Dispose #region Property /// /// Instance for singleton /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public static Accessibility Instance { get => _accessibility; } #endregion Property #region Method /// /// Get the current status /// /// Current enabled status // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] static public bool GetStatus() { return true; } /// /// Start to speak /// /// Content to be spoken /// true to be stopped and discarded when other Say is triggered /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public bool Say(string sentence, bool discardable) { IntPtr callbackIntPtr = IntPtr.Zero; if (_sayFinishedEventHandler != null) { _sayFinishedEventCallbackType callback = _sayFinishedEventCallback; callbackIntPtr = Marshal.GetFunctionPointerForDelegate(callback); } bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// To make Say be paused or resumed /// /// true to be paused, false to be resumed // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public void PauseResume(bool pause) { Interop.Accessibility.accessibility_pause_resume(View.getCPtr(dummy), pause); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } #endregion Method #region Event, Enum, Struct, ETC /// /// Say Finished event arguments /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public class SayFinishedEventArgs : EventArgs { /// /// The state of Say finished /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public SayFinishedStates State { private set; get; } internal SayFinishedEventArgs(int result) { State = (SayFinishedStates)(result); tlog.Fatal(tag, $"SayFinishedEventArgs Constructor! State={State}"); } } /// /// Enum of Say finished event argument status /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public enum SayFinishedStates { /// /// Invalid /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] Invalid = -1, /// /// Cancelled /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] Cancelled = 1, /// /// Stopped /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] Stopped = 2, /// /// Skipped /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] Skipped = 3 } /// /// When Say is finished, this event is triggered /// // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API) [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler SayFinished { add => _sayFinishedEventHandler += value; remove => _sayFinishedEventHandler -= value; } #endregion Event, Enum, Struct, ETC #region Internal internal void PauseResume(View target, bool pause) { Interop.Accessibility.accessibility_pause_resume(View.getCPtr(target), pause); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal bool Say(View target, string sentence, bool discardable) { IntPtr callbackIntPtr = IntPtr.Zero; if (_sayFinishedEventHandler != null) { _sayFinishedEventCallbackType callback = _sayFinishedEventCallback; callbackIntPtr = Marshal.GetFunctionPointerForDelegate(callback); } bool ret = Interop.Accessibility.accessibility_say(View.getCPtr(target), sentence, discardable, callbackIntPtr); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } #endregion Internal #region Private private static readonly Accessibility _accessibility = new Accessibility(); private event EventHandler _sayFinishedEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void _sayFinishedEventCallbackType(int result); private void _sayFinishedEventCallback(int result) { tlog.Fatal(tag, $"_sayFinishedEventCallback(res={result}) called!"); _sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result)); } private View dummy; private static string tag = "NUITEST"; #endregion Private } } #endif