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>
/// 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
}
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();
}
{
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();
}
/// </summary>
private void GrabRemoteKeys()
{
- foreach (var key in remoteKeys)
- {
- App.MainWindow.KeyGrab(key, false);
- }
-
- App.MainWindow.KeyDown += RemoteKeyDownListener;
+ App.KeyDownEvent.On += RemoteKeyDownListener;
}
/// <summary>
/// </summary>
private void UngrabRemoteKeys()
{
- App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
- foreach (var key in remoteKeys)
- {
- App.MainWindow.KeyUngrab(key);
- }
+ App.KeyDownEvent.On -= RemoteKeyDownListener;
}
/// <summary>
/// </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);
}
{
/// Grabs the hardware keys to move the given image
GrabMoveKeys();
+
}
/// <summary>
}
/// <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>
/// </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>
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>
/// </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()
}
}
}
-}
\ No newline at end of file
+}
/// </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>
/// </summary>
private void UngrabRemoteKeys()
{
- App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
- foreach (var key in remoteKeys)
- {
- App.MainWindow.KeyUngrab(key);
- }
+ App.KeyDownEvent.On -= EvtDownOn;
}
/// <summary>
/// </summary>
private void GrabRemoteKeys()
{
- foreach (var key in remoteKeys)
- {
- App.MainWindow.KeyGrab(key, false);
- }
-
- App.MainWindow.KeyDown += RemoteKeyDownListener;
+ App.KeyDownEvent.On += RemoteKeyDownListener;
}
/// <summary>
/// </summary>
private void UngrabRemoteKeys()
{
- App.MainWindow.KeyDown -= RemoteKeyDownListener;
-
- foreach (var key in remoteKeys)
- {
- App.MainWindow.KeyUngrab(key);
- }
+ App.KeyDownEvent.On -= RemoteKeyDownListener;
}
/// <summary>
/// </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);
}
{
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();
}