[Tts][TCSACR-449] Add new method for checking screen reader status (#3475)
authorSuyeon Hwang <35016426+stom-hwang@users.noreply.github.com>
Thu, 9 Sep 2021 08:22:38 +0000 (17:22 +0900)
committerGitHub <noreply@github.com>
Thu, 9 Sep 2021 08:22:38 +0000 (17:22 +0900)
This commit includes these changes.
* Add new method for screen reader status checking
* Remove white space to match the indentation
* Remove invalid symbol from interop
* Add feature tag on doxygen for 'IsScreenReaderOn' property
* Fix log to make easy for specifying error

Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
src/Tizen.Uix.Tts/Interop/Interop.Tts.cs
src/Tizen.Uix.Tts/Tizen.Uix.Tts/ScreenReaderChangedEventArgs.cs [new file with mode: 0644]
src/Tizen.Uix.Tts/Tizen.Uix.Tts/TtsClient.cs

index b3b787a..00407eb 100755 (executable)
@@ -45,11 +45,12 @@ internal static partial class Interop
             NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,           /* STT NOT supported */
             InvalidState = ErrorTts | 0x01,                                         /* Invalid state */
             InvalidVoice = ErrorTts | 0x02,                                         /* Invalid language */
-            EngineNotFound = ErrorTts | 0x03,                                       /* No available engine  */
-            OperationFailed = ErrorTts | 0x04,                                      /* Operation failed  */
+            EngineNotFound = ErrorTts | 0x03,                                       /* No available engine */
+            OperationFailed = ErrorTts | 0x04,                                      /* Operation failed */
             AudioPolicyBlocked = ErrorTts | 0x05,                                   /* Audio policy blocked */
-            NotSupportedFeature = ErrorTts | 0x06,                                  /* Not supported feature of current engine*/
-            ServiceReset = ErrorTts | 0x07                                          /* Service reset*/
+            NotSupportedFeature = ErrorTts | 0x06,                                  /* Not supported feature of current engine */
+            ServiceReset = ErrorTts | 0x07,                                         /* Service reset*/
+            ScreenReaderOff = ErrorTts | 0x08                                       /* Screen reader off */
         };
 
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@@ -73,6 +74,9 @@ internal static partial class Interop
         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         internal delegate void TtsEngineChangedCB(IntPtr handle, IntPtr engine_id, IntPtr language, int voice_type, bool need_credential, IntPtr userData);
 
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void TtsScreenReaderChangedCB(IntPtr handle, bool is_on, IntPtr userData);
+
         [DllImport(Libraries.Tts, EntryPoint = "tts_create", CallingConvention = CallingConvention.Cdecl)]
         internal static extern TtsError TtsCreate(out IntPtr handle);
 
@@ -118,8 +122,8 @@ internal static partial class Interop
         [DllImport(Libraries.Tts, EntryPoint = "tts_get_error_message", CallingConvention = CallingConvention.Cdecl)]
         internal static extern TtsError TtsGetErrorMessage(IntPtr handle, out string err_msg);
 
-        [DllImport(Libraries.Tts, EntryPoint = "tts_is_recognition_type_supported", CallingConvention = CallingConvention.Cdecl)]
-        internal static extern TtsError TtsIsRecognitionTypeSupported(IntPtr handle, string type, out bool support);
+        [DllImport(Libraries.Tts, EntryPoint = "tts_check_screen_reader_on", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern TtsError TtsCheckScreenReaderOn(IntPtr handle, out bool isOn);
 
         [DllImport(Libraries.Tts, EntryPoint = "tts_add_text", CallingConvention = CallingConvention.Cdecl)]
         internal static extern TtsError TtsAddText(IntPtr handle, string text, string language, int voice_type, int speed, out int uttId);
@@ -168,5 +172,11 @@ internal static partial class Interop
 
         [DllImport(Libraries.Tts, EntryPoint = "tts_unset_engine_changed_cb", CallingConvention = CallingConvention.Cdecl)]
         internal static extern TtsError TtsUnsetEngineChangedCB(IntPtr handle);
+
+        [DllImport(Libraries.Tts, EntryPoint = "tts_set_screen_reader_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern TtsError TtsSetScreenReaderChangedCB(IntPtr handle, TtsScreenReaderChangedCB callback, IntPtr userData);
+
+        [DllImport(Libraries.Tts, EntryPoint = "tts_unset_screen_reader_changed_cb", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern TtsError TtsUnsetScreenReaderChangedCB(IntPtr handle);
     }
 }
diff --git a/src/Tizen.Uix.Tts/Tizen.Uix.Tts/ScreenReaderChangedEventArgs.cs b/src/Tizen.Uix.Tts/Tizen.Uix.Tts/ScreenReaderChangedEventArgs.cs
new file mode 100644 (file)
index 0000000..ea1a9c8
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* 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.
+*/
+
+
+namespace Tizen.Uix.Tts
+{
+    /// <summary>
+    /// This class holds information related to the ScreenReaderChanged event.
+    /// </summary>
+    /// <since_tizen> 9 </since_tizen>
+    public class ScreenReaderChangedEventArgs
+    {
+        internal ScreenReaderChangedEventArgs(bool isOn)
+        {
+            IsOn = isOn;
+        }
+
+        /// <summary>
+        /// The status of screen reader
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public bool IsOn
+        {
+            get;
+            internal set;
+        }
+    }
+}
index 02dc78a..41130f2 100644 (file)
@@ -202,6 +202,7 @@ namespace Tizen.Uix.Tts
         private event EventHandler<ErrorOccurredEventArgs> _errorOccurred;
         private event EventHandler<DefaultVoiceChangedEventArgs> _defaultVoiceChanged;
         private event EventHandler<EngineChangedEventArgs> _engineChanged;
+        private event EventHandler<ScreenReaderChangedEventArgs> _screenReaderChanged;
         private bool disposedValue = false;
         private readonly Object _stateChangedLock = new Object();
         private readonly Object _utteranceStartedLock = new Object();
@@ -209,12 +210,14 @@ namespace Tizen.Uix.Tts
         private readonly Object _errorOccurredLock = new Object();
         private readonly Object _defaultVoiceChangedLock = new Object();
         private readonly Object _engineChangedLock = new Object();
+        private readonly Object _screenReaderChangedLock = new Object();
         private TtsStateChangedCB _stateDelegate;
         private TtsUtteranceStartedCB _utteranceStartedResultDelegate;
         private TtsUtteranceCompletedCB _utteranceCompletedResultDelegate;
         private TtsErrorCB _errorDelegate;
         private TtsDefaultVoiceChangedCB _voiceChangedDelegate;
         private TtsEngineChangedCB _engineDelegate;
+        private TtsScreenReaderChangedCB _screenReaderDelegate;
         private TtsSupportedVoiceCB _supportedvoiceDelegate;
 
         /// <summary>
@@ -528,6 +531,50 @@ namespace Tizen.Uix.Tts
         }
 
         /// <summary>
+        /// Event to be invoked to detect screen reader status change.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        public event EventHandler<ScreenReaderChangedEventArgs> ScreenReaderChanged
+        {
+            add
+            {
+                lock (_screenReaderChangedLock)
+                {
+                    if (_screenReaderChanged == null)
+                    {
+                        _screenReaderDelegate = (IntPtr handle, bool isOn, IntPtr userData) =>
+                        {
+                            ScreenReaderChangedEventArgs args = new ScreenReaderChangedEventArgs(isOn);
+                            _screenReaderChanged?.Invoke(this, args);
+                        };
+                        TtsError error = TtsSetScreenReaderChangedCB(_handle, _screenReaderDelegate, IntPtr.Zero);
+                        if (error != TtsError.None)
+                        {
+                            Log.Error(LogTag, "Add ScreenReaderChanged Failed with error " + error);
+                        }
+                    }
+                    _screenReaderChanged += value;
+                }
+            }
+
+            remove
+            {
+                lock (_screenReaderChangedLock)
+                {
+                    _screenReaderChanged -= value;
+                    if (_screenReaderChanged == null)
+                    {
+                        TtsError error = TtsUnsetScreenReaderChangedCB(_handle);
+                        if (error != TtsError.None)
+                        {
+                            Log.Error(LogTag, "Remove ScreenReaderChanged Failed with error " + error);
+                        }
+                    }
+                }
+            }
+        }
+
+        /// <summary>
         /// Gets the default voice set by the user.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
@@ -659,6 +706,37 @@ namespace Tizen.Uix.Tts
         }
 
         /// <summary>
+        /// Gets the current status of screen reader.
+        /// </summary>
+        /// <since_tizen> 9 </since_tizen>
+        /// <value>
+        /// The current status of screen reader.
+        /// </value>
+        /// <returns>
+        /// Boolean value whether screen reader is on or off.
+        /// </returns>
+        /// <feature>
+        /// http://tizen.org/feature/speech.synthesis
+        /// </feature>
+        /// <exception cref="InvalidOperationException">This exception can be due to operation failed.</exception>
+        /// <exception cref="NotSupportedException">This exception can be due to TTS not supported.</exception>
+        public bool IsScreenReaderOn
+        {
+            get
+            {
+                bool isOn = true;
+                TtsError error = TtsCheckScreenReaderOn(_handle, out isOn);
+                if (error != TtsError.None)
+                {
+                    Log.Error(LogTag, "Fail to check screen reader on with error " + error);
+                    return false;
+                }
+
+                return isOn;
+            }
+        }
+
+        /// <summary>
         /// Sets the application credential.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>