Removed key grab/ungrab 39/152439/3
authorSung-jae Park <nicesj@nicesj.com>
Tue, 26 Sep 2017 06:51:53 +0000 (15:51 +0900)
committerHeonjae Jang <heonjae.jang@samsung.com>
Tue, 26 Sep 2017 09:00:36 +0000 (09:00 +0000)
The H/W key should not be grabbed by the application if it doesn't have any specific purpose of grabbing.
This patch will remove them all and replace grab and ungrab code with EcoreEvent handlers.

Change-Id: I01b00e63307285e354b737baa87598b45ec984a5
Signed-off-by: Sung-jae Park <nicesj@nicesj.com>
TVMediaHub/TVMediaHub.Tizen/TVMediaHub.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/ImageViewerZoom.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/MusicTab.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoTab.xaml.cs

index 0bba0924a90fc7d56a37d714093b905d191366e6..6e99333713e645bde08b2cc081abeb57e2705f23 100755 (executable)
@@ -35,6 +35,11 @@ namespace TVMediaHub
         /// Gets or sets the NavigationPage of TV MediaHub
         /// </summary>
         public static NavigationPage AppMainPage { get; private set; }
+
+        public static ElmSharp.EcoreEvent<ElmSharp.EcoreKeyEventArgs> KeyDownEvent;
+
+        public static ElmSharp.EcoreEvent<ElmSharp.EcoreKeyEventArgs> KeyUpEvent;
+
         /// <summary>
         /// A constructor
         /// Sets main page to MainPage instance
@@ -66,6 +71,17 @@ namespace TVMediaHub
             }
 
             MainWindow = window;
+
+            KeyDownEvent = new ElmSharp.EcoreEvent<ElmSharp.EcoreKeyEventArgs>(ElmSharp.EcoreEventType.KeyDown, (s, e, t) =>
+            {
+                return ElmSharp.EcoreKeyEventArgs.Create(s, e, t);
+            });
+
+            KeyUpEvent = new ElmSharp.EcoreEvent<ElmSharp.EcoreKeyEventArgs>(ElmSharp.EcoreEventType.KeyUp, (s, e, t) =>
+            {
+                return ElmSharp.EcoreKeyEventArgs.Create(s, e, t);
+            });
+
             TransitionToMain();
         }
 
index 48b1e0deec872257bda6c5df78e6264c6e73fac0..c2ea9da528a3f577047f40443d4c4aac130f46c9 100755 (executable)
@@ -693,21 +693,21 @@ namespace TVMediaHub.Tizen.Views
         {
             base.OnAppearing();
             // add Listener
-            App.MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, false);
-            App.MainWindow.KeyUp += MenuKeyListener;
+
+            App.KeyUpEvent.On += MenuKeyListener;
         }
 
         protected override void OnDisappearing()
         {
             base.OnDisappearing();
             // remove listener
-            App.MainWindow.KeyUp -= MenuKeyListener;
-            App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
+            App.KeyUpEvent.On -= MenuKeyListener;
         }
 
-        private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void MenuKeyListener(object sender, EventArgs e)
         {
-            if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
+            ElmSharp.EcoreKeyEventArgs args = e as ElmSharp.EcoreKeyEventArgs;
+            if (args.KeyName.Contains(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
             {
                 NotifyMenuKeyPressed();
             }
index c56dd58d57706647bdf21aa4ff47fa542f4fd42f..527a50fd0c7555d6f021ece97c5e0e1dae53ea94 100755 (executable)
@@ -270,12 +270,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void GrabRemoteKeys()
         {
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyGrab(key, false);
-            }
-
-            App.MainWindow.KeyDown += RemoteKeyDownListener;
+            App.KeyDownEvent.On += RemoteKeyDownListener;
         }
 
         /// <summary>
@@ -283,12 +278,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void UngrabRemoteKeys()
         {
-            App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyUngrab(key);
-            }
+            App.KeyDownEvent.On -= RemoteKeyDownListener;
         }
 
         /// <summary>
@@ -296,7 +286,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The object that raised the event</param>
         /// <param name="e">The information about the event</param>
-        private void RemoteKeyDownListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void RemoteKeyDownListener(object sender, EventArgs e)
         {
             SetControlAreaState(ControlAreaState.AUTO);
         }
index 55e622086150ca512f11542eb8d09d722030ae13..efda5c0ba42a54b4271c8d5276269aa31e401912 100755 (executable)
@@ -141,6 +141,7 @@ namespace TVMediaHub.Tizen.Views
         {
             /// Grabs the hardware keys to move the given image
             GrabMoveKeys();
+
         }
 
         /// <summary>
@@ -190,31 +191,24 @@ namespace TVMediaHub.Tizen.Views
         }
 
         /// <summary>
-        /// Grabs move keys of the remote controller to move the given image
+        /// KeyDown will be triggered when key is pressed down
         /// </summary>
-        private void GrabMoveKeys()
+        /// <param name="sender">The object that raised the event</param>
+        /// <param name="e">The information about the event</param>
+        private void EvtDownOn(object sender, EventArgs e)
         {
-            foreach (string direction in MoveDirection)
-            {
-                App.MainWindow.KeyGrab(direction, false);
-            }
+            ElmSharp.EcoreKeyEventArgs args = e as ElmSharp.EcoreKeyEventArgs;
 
-            App.MainWindow.KeyUp += MoveKeyUpListener;
-            App.MainWindow.KeyDown += MoveKeyDownListener;
-        }
+            DbgPort.D("[ZoomMode] key down : " + args.KeyName);
 
-        /// <summary>
-        /// Ungrabs move keys of the remote controller
-        /// </summary>
-        private void UngrabMoveKeys()
-        {
-            App.MainWindow.KeyUp -= MoveKeyUpListener;
-            App.MainWindow.KeyDown -= MoveKeyDownListener;
-
-            foreach (string direction in MoveDirection)
+            if (!MoveDirection.Contains(args.KeyName))
             {
-                App.MainWindow.KeyUngrab(direction);
+                return;
             }
+
+            int direction = MoveDirection.FindIndex(x => x.Equals(args.KeyName));
+            object[] buttons = new object[4] { UpButton, DownButton, LeftButton, RightButton };
+            (buttons[direction] as ZoomNaviButton).OnButtonPressed();
         }
 
         /// <summary>
@@ -222,37 +216,38 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The object that raised the event</param>
         /// <param name="e">The information about the event</param>
-        private void MoveKeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void EvtUpOn(object sender, EventArgs e)
         {
-            DbgPort.D("[ZoomMode] key up : " + e.KeyName);
+            ElmSharp.EcoreKeyEventArgs args = e as ElmSharp.EcoreKeyEventArgs;
 
-            if (!MoveDirection.Contains(e.KeyName))
+            DbgPort.D("[ZoomMode] key up : " + args.KeyName);
+
+            if (!MoveDirection.Contains(args.KeyName))
             {
                 return;
             }
 
-            int direction = MoveDirection.FindIndex(x => x.Equals(e.KeyName));
+            int direction = MoveDirection.FindIndex(x => x.Equals(args.KeyName));
             object[] buttons = new object[4] { UpButton, DownButton, LeftButton, RightButton };
             (buttons[direction] as ZoomNaviButton).OnButtonReleased();
         }
 
         /// <summary>
-        /// KeyDown will be triggered when key is pressed down
+        /// Grabs move keys of the remote controller to move the given image
         /// </summary>
-        /// <param name="sender">The object that raised the event</param>
-        /// <param name="e">The information about the event</param>
-        private void MoveKeyDownListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void GrabMoveKeys()
         {
-            DbgPort.D("[ZoomMode] key down : " + e.KeyName);
-
-            if (!MoveDirection.Contains(e.KeyName))
-            {
-                return;
-            }
+            App.KeyDownEvent.On += EvtDownOn;
+            App.KeyUpEvent.On += EvtUpOn;
+        }
 
-            int direction = MoveDirection.FindIndex(x => x.Equals(e.KeyName));
-            object[] buttons = new object[4] { UpButton, DownButton, LeftButton, RightButton };
-            (buttons[direction] as ZoomNaviButton).OnButtonPressed();
+        /// <summary>
+        /// Ungrabs move keys of the remote controller
+        /// </summary>
+        private void UngrabMoveKeys()
+        {
+            App.KeyDownEvent.On -= EvtDownOn;
+            App.KeyUpEvent.On -= EvtUpOn;
         }
 
         /// <summary>
index dab15e373b2a2f251cf971f317a88a2412f3372b..0f66ed910571383360ddb2d3690e7ecd58cc8cc5 100755 (executable)
@@ -612,18 +612,8 @@ namespace TVMediaHub.Tizen.Views
         protected override void OnAppearing()
         {
             base.OnAppearing();
-            App.MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, false);
-            App.MainWindow.KeyUp += MenuKeyListener;
-        }
 
-        /// <summary>
-        /// this method is for customizing behavior when the Page becoming invisible
-        /// </summary>
-        protected override void OnDisappearing()
-        {
-            base.OnDisappearing();
-            App.MainWindow.KeyUp -= MenuKeyListener;
-            App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
+            App.KeyUpEvent.On += KeyUpEventOn;
         }
 
         /// <summary>
@@ -631,14 +621,23 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The object that raised the event</param>
         /// <param name="e">The information about the event</param>
-        private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void KeyUpEventOn(object sender, ElmSharp.EcoreKeyEventArgs e)
         {
-            if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
+            if (e.KeyName.Contains(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
             {
                 NotifyMenuKeyPressed();
             }
         }
 
+        /// <summary>
+        /// this method is for customizing behavior when the Page becoming invisible
+        /// </summary>
+        protected override void OnDisappearing()
+        {
+            base.OnDisappearing();
+            App.KeyUpEvent.On -= KeyUpEventOn;
+        }
+
         /// <summary>
         /// A method notifies menu key pressed event
         /// </summary>
@@ -722,4 +721,4 @@ namespace TVMediaHub.Tizen.Views
             }
         }
     }
-}
\ No newline at end of file
+}
index 04fc7444e265bcc5ea91f45557c31fbf6fd68b01..a1bd13bc70577052f51f26d804a22c4fa4f3e717 100755 (executable)
@@ -226,12 +226,12 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void GrabRemoteKeys()
         {
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyGrab(key, false);
-            }
+            App.KeyDownEvent.On += EvtDownOn;
+        }
 
-            App.MainWindow.KeyDown += RemoteKeyDownListener;
+        private void EvtDownOn(object sender, ElmSharp.EcoreKeyEventArgs e)
+        {
+            SetControlAreaState(ControlAreaState.AUTO);
         }
 
         /// <summary>
@@ -239,12 +239,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void UngrabRemoteKeys()
         {
-            App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyUngrab(key);
-            }
+            App.KeyDownEvent.On -= EvtDownOn;
         }
 
         /// <summary>
index 51114180c9c98f1b99bebf5c2d79defe0656d310..9baeea1bfb6b2c4beca40fc4987da3fbeb22f123 100755 (executable)
@@ -281,12 +281,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void GrabRemoteKeys()
         {
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyGrab(key, false);
-            }
-
-            App.MainWindow.KeyDown += RemoteKeyDownListener;
+            App.KeyDownEvent.On += RemoteKeyDownListener;
         }
 
         /// <summary>
@@ -294,12 +289,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         private void UngrabRemoteKeys()
         {
-            App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
-            foreach (var key in remoteKeys)
-            {
-                App.MainWindow.KeyUngrab(key);
-            }
+            App.KeyDownEvent.On -= RemoteKeyDownListener;
         }
 
         /// <summary>
@@ -307,7 +297,7 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         /// <param name="sender">The object that raised the event</param>
         /// <param name="e">The information about the event</param>
-        private void RemoteKeyDownListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void RemoteKeyDownListener(object sender, EventArgs e)
         {
             SetControlAreaState(ControlAreaState.AUTO);
         }
index 5ef3c012b70edd8bc104ed9e6957aac4c5044a63..caae1f8dc83109e700ea881e80b2ca87c7836d77 100755 (executable)
@@ -677,21 +677,21 @@ namespace TVMediaHub.Tizen.Views
         {
             base.OnAppearing();
             // add Listener
-            App.MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, false);
-            App.MainWindow.KeyUp += MenuKeyListener;
+            App.KeyUpEvent.On += MenuKeyListener;
         }
 
         protected override void OnDisappearing()
         {
             base.OnDisappearing();
             // remove listener
-            App.MainWindow.KeyUp -= MenuKeyListener;
-            App.MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
+            App.KeyUpEvent.On -= MenuKeyListener;
         }
 
-        private void MenuKeyListener(object sender, ElmSharp.EvasKeyEventArgs e)
+        private void MenuKeyListener(object sender, EventArgs e)
         {
-            if (e.KeyName.Equals(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
+            ElmSharp.EcoreKeyEventArgs args = e as ElmSharp.EcoreKeyEventArgs;
+
+            if (args.KeyName.Contains(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName))
             {
                 NotifyMenuKeyPressed();
             }