[NUI] Add sound feedback and fix scroll build errors
authorzhouleonlei <zhouleon.lei@samsung.com>
Mon, 14 Dec 2020 06:26:08 +0000 (14:26 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Mon, 14 Dec 2020 09:11:10 +0000 (18:11 +0900)
src/Tizen.NUI.Components/Controls/Control.cs
src/Tizen.NUI.Components/Tizen.NUI.Components.csproj
src/Tizen.NUI.Components/Tizen.NUI.Components.sln
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/ScrollableBaseOutOfBoundSample.cs
test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/SwitchSample.cs

index 8daafcf..06ba3c2 100755 (executable)
  * limitations under the License.
  *
  */
+
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
 using System.Windows.Input;
+using Tizen.System;
 
 namespace Tizen.NUI.Components
 {
@@ -33,15 +35,17 @@ namespace Tizen.NUI.Components
     {
         /// Internal used.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
+        public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(Control), null, propertyChanged: (bo, o, n) => ((Control)bo).OnCommandChanged());
 
         /// Internal used.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(Button), null,
+        public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(Button), null,
             propertyChanged: (bindable, oldvalue, newvalue) => ((Button)bindable).CommandCanExecuteChanged(bindable, EventArgs.Empty));
 
         private bool onThemeChangedEventOverrideChecker;
 
+        private Feedback feedback = new Feedback();
+
         private TapGestureDetector tapGestureDetector = new TapGestureDetector();
 
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -90,6 +94,13 @@ namespace Tizen.NUI.Components
             ThemeChangeSensitive = true;
         }
 
+        /// <summary>
+        /// The flag of sound feedback when tap gesture detected.
+        /// </summary>
+        /// This will be public opened in tizen_6.5 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public bool IsTapGestureFeedback { get; set; } = false;
+
         /// Internal used.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public ICommand Command
@@ -148,6 +159,12 @@ namespace Tizen.NUI.Components
             {
                 tapGestureDetector.Detected -= OnTapGestureDetected;
                 tapGestureDetector.Detach(this);
+
+                if (feedback != null)
+                {
+                    feedback.Stop();
+                    feedback = null;
+                }
             }
 
             base.Dispose(type);
@@ -213,7 +230,16 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 6 </since_tizen>
         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        protected virtual void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e) { }
+        protected virtual void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e)
+        {
+            if (IsTapGestureFeedback && e?.TapGesture?.State == Gesture.StateType.Started)
+            {
+                if (feedback != null && feedback.IsSupportedPattern(FeedbackType.Sound, "Tap"))
+                {
+                    feedback.Play(FeedbackType.Sound, "Tap");
+                }
+            }
+        }
 
         /// <summary>
         /// Update by style.
index cfc5d93..f4bd4d6 100755 (executable)
@@ -8,6 +8,7 @@
   <ItemGroup>
     <ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
     <ProjectReference Include="..\Tizen.NUI\Tizen.NUI.csproj" />
+    <ProjectReference Include="..\Tizen.System.Feedback\Tizen.System.Feedback.csproj" />
     <ProjectReference Include="..\Tizen.System.Information\Tizen.System.Information.csproj" />
   </ItemGroup>
 
index f3d1317..12c4174 100755 (executable)
@@ -19,6 +19,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.SystemSettings
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Information", "..\Tizen.System.Information\Tizen.System.Information.csproj", "{11CACB07-AF47-480E-AB25-88E3C3297631}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.System.Feedback", "..\Tizen.System.Feedback\Tizen.System.Feedback.csproj", "{675DA71D-4314-4F10-8632-C804A9F720D4}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
@@ -57,6 +59,10 @@ Global
                {11CACB07-AF47-480E-AB25-88E3C3297631}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {11CACB07-AF47-480E-AB25-88E3C3297631}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {11CACB07-AF47-480E-AB25-88E3C3297631}.Release|Any CPU.Build.0 = Release|Any CPU
+               {675DA71D-4314-4F10-8632-C804A9F720D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {675DA71D-4314-4F10-8632-C804A9F720D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {675DA71D-4314-4F10-8632-C804A9F720D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {675DA71D-4314-4F10-8632-C804A9F720D4}.Release|Any CPU.Build.0 = Release|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
index 390bbfd..bfce133 100755 (executable)
@@ -37,7 +37,7 @@ namespace Tizen.NUI.Samples
                 ScrollingDirection = Components.ScrollableBase.Direction.Vertical,
                 EnableOverShootingEffect = true,
             };
-            mScrollableBase.ScrollOutOfBound += OnScrollOutOfBound;
+            mScrollableBase.ScrollOutOfBoundWithDisplacement += OnScrollOutOfBound;
 
             items = new TextLabel[5];
             for (int i = 0; i < 5; i++)
@@ -62,18 +62,18 @@ namespace Tizen.NUI.Samples
             root.Add(mScrollableBase);
         }
 
-        private void OnScrollOutOfBound(object sender, Components.ScrollOutOfBoundEventArgs e)
+        private void OnScrollOutOfBound(object sender, Components.ScrollOutOfBoundWithDisplacementEventArgs e)
         {
             if (e.Displacement > 100)
             {
-                if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Down)
+                if (e.PanDirection == Components.ScrollOutOfBoundWithDisplacementEventArgs.Direction.Down)
                 {
                     items[0].Text = $"Reached at the top, panned displacement is {e.Displacement}.";
                 }
             }
             else if (0 - e.Displacement > 100)
             {
-                if (e.PanDirection == Components.ScrollOutOfBoundEventArgs.Direction.Up)
+                if (e.PanDirection == Components.ScrollOutOfBoundWithDisplacementEventArgs.Direction.Up)
                 {
                     items[4].Text = $"Reached at the bottom, panned displacement is {e.Displacement}.";
                 }
index 33c1502..50e152b 100755 (executable)
@@ -225,6 +225,7 @@ namespace Tizen.NUI.Samples
                 utilitySwitch[i].ApplyStyle(utilitySt);
                 utilitySwitch[i].Size = new Size(96, 60);
                 utilitySwitch[i].Margin = new Extents(100, 0, 20, 0);
+                utilitySwitch[i].IsTapGestureFeedback = true;
                 parentView[2].Add(utilitySwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -232,6 +233,7 @@ namespace Tizen.NUI.Samples
                 familySwitch[i] = new Switch();
                 familySwitch[i].ApplyStyle(familySt);
                 familySwitch[i].Size = new Size(96, 60);
+                familySwitch[i].IsTapGestureFeedback = true;
                 parentView[2].Add(familySwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -239,6 +241,7 @@ namespace Tizen.NUI.Samples
                 foodSwitch[i] = new Switch();
                 foodSwitch[i].ApplyStyle(foodSt);
                 foodSwitch[i].Size = new Size(96, 60);
+                foodSwitch[i].IsTapGestureFeedback = true;
                 parentView[2].Add(foodSwitch[i]);
             }
             for (i = 0; i < 4; i++)
@@ -246,6 +249,7 @@ namespace Tizen.NUI.Samples
                 kitchenSwitch[i] = new Switch();
                 kitchenSwitch[i].ApplyStyle(kitchenSt);
                 kitchenSwitch[i].Size = new Size(96, 60);
+                kitchenSwitch[i].IsTapGestureFeedback = true;
                 parentView[2].Add(kitchenSwitch[i]);
             }
 
@@ -255,6 +259,7 @@ namespace Tizen.NUI.Samples
                 utilitySwitch2[i] = new Switch();
                 utilitySwitch2[i].ApplyStyle(utilitySt);
                 utilitySwitch2[i].Size = new Size(96, 60);
+                utilitySwitch2[i].IsTapGestureFeedback = true;
                 parentView[2].Add(utilitySwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -262,6 +267,7 @@ namespace Tizen.NUI.Samples
                 familySwitch2[i] = new Switch();
                 familySwitch2[i].ApplyStyle(familySt);
                 familySwitch2[i].Size = new Size(96, 60);
+                familySwitch2[i].IsTapGestureFeedback = true;
                 parentView[2].Add(familySwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -269,6 +275,7 @@ namespace Tizen.NUI.Samples
                 foodSwitch2[i] = new Switch();
                 foodSwitch2[i].ApplyStyle(foodSt);
                 foodSwitch2[i].Size = new Size(96, 60);
+                foodSwitch2[i].IsTapGestureFeedback = true;
                 parentView[2].Add(foodSwitch2[i]);
             }
             for (i = 0; i < 4; i++)
@@ -276,6 +283,7 @@ namespace Tizen.NUI.Samples
                 kitchenSwitch2[i] = new Switch();
                 kitchenSwitch2[i].ApplyStyle(kitchenSt);
                 kitchenSwitch2[i].Size = new Size(96, 60);
+                kitchenSwitch2[i].IsTapGestureFeedback = true;
                 parentView[2].Add(kitchenSwitch2[i]);
             }