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 0bba092..6e99333 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 48b1e0d..c2ea9da 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 c56dd58..527a50f 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 55e6220..efda5c0 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 dab15e3..0f66ed9 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,15 +621,24 @@ 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>
         private void NotifyMenuKeyPressed()
@@ -722,4 +721,4 @@ namespace TVMediaHub.Tizen.Views
             }
         }
     }
-}
\ No newline at end of file
+}
index 04fc744..a1bd13b 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 5111418..9baeea1 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 5ef3c01..caae1f8 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();
             }