Skip to content

Commit

Permalink
Added handling for Back/Escape key to exit all demos (dalihub#4)
Browse files Browse the repository at this point in the history
Change-Id: I6a69501f9d5e74f7e5024da9b4752bb4e653972e
  • Loading branch information
adeelkazmi authored and agnelovaz committed Sep 18, 2019
1 parent 579f520 commit af012cf
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 28 deletions.
19 changes: 18 additions & 1 deletion food-shopper/FoodShopper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,34 @@ private void WindowKeyEvent(object sender, Window.KeyEventArgs e)
switch( e.Key.KeyPressedName )
{
case "Left":
{
HorizontalOperation( false );

}
break;

case "Right" :
{
HorizontalOperation( true );
}
break;

case "Up" :
{
FocusSectionUp();
}
break;

case "Down" :
{
FocusSectionDown();
}
break;

case "Escape":
case "Back":
{
Exit();
}
break;
}

Expand Down
23 changes: 23 additions & 0 deletions hello-world/HelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ protected override void OnCreate()

// Add the text to the window
window.Add(title);

// Respond to key events
window.KeyEvent += OnKeyEvent;
}

/// <summary>
/// Called when any key event is received.
/// Will use this to exit the application if the Back or Escape key is pressed
/// </summary>
private void OnKeyEvent( object sender, Window.KeyEventArgs eventArgs )
{
if( eventArgs.Key.State == Key.StateType.Down )
{
switch( eventArgs.Key.KeyPressedName )
{
case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}

/// <summary>
Expand Down
23 changes: 23 additions & 0 deletions layout-demo/LayoutDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ private void Initialize()

// Set initial title
exampleTitle.Text = currentExampleLabel;

// Respond to key events
Window.Instance.KeyEvent += OnKeyEvent;
}

/// <summary>
/// Called when any key event is received.
/// Will use this to exit the application if the Back or Escape key is pressed
/// </summary>
private void OnKeyEvent( object sender, Window.KeyEventArgs eventArgs )
{
if( eventArgs.Key.State == Key.StateType.Down )
{
switch( eventArgs.Key.KeyPressedName )
{
case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}

/// <summary>
Expand Down
23 changes: 22 additions & 1 deletion multiple-window/MultipleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ protected override void OnCreate()
// Up call to the Base class first
base.OnCreate();

// Get the main window instance and change background color
// Get the main window instance, change background color & respond to key events
Window mainWindow = Window.Instance;
mainWindow.BackgroundColor = Color.Red;
mainWindow.KeyEvent += OnKeyEvent;

var layout = new LinearLayout()
{
Expand Down Expand Up @@ -141,6 +142,26 @@ protected override void OnCreate()
_focusManager.FocusIndicator = new View();
}

/// <summary>
/// Called when any key event is received.
/// Will use this to exit the application if the Back or Escape key is pressed
/// </summary>
private void OnKeyEvent( object sender, Window.KeyEventArgs eventArgs )
{
if( eventArgs.Key.State == Key.StateType.Down )
{
switch( eventArgs.Key.KeyPressedName )
{
case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}

private View OnPreFocusChange(object source, FocusManager.PreFocusChangeEventArgs e)
{
if (e.CurrentView != null && !e.ProposedView)
Expand Down
8 changes: 7 additions & 1 deletion silk-demo/SilkDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ private void WindowKeyEvent(object sender, Window.KeyEventArgs e)
EventAction(Action.ShowList);
}
break;
case "Escape" :
case "Back" :
{
Exit();
}
break;
}
}
}
Expand Down Expand Up @@ -600,4 +606,4 @@ static void Main(string[] args)
silkDemo.Run(args);
}
} // Class Demo
} // namespace Silk
} // namespace Silk
23 changes: 22 additions & 1 deletion simple-layout/SimpleLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ protected override void OnCreate()

private void Initialize()
{
// Change the background color of Window to White
// Change the background color of Window to White & respond to key events
Window window = Window.Instance;
window.BackgroundColor = Color.White;
window.KeyEvent += OnKeyEvent;

// Create a new view
View customLayoutView = new View();
Expand Down Expand Up @@ -75,6 +76,26 @@ ImageView CreateChildImageView( String url, Size2D size )
return imageView;
}

/// <summary>
/// Called when any key event is received.
/// Will use this to exit the application if the Back or Escape key is pressed
/// </summary>
private void OnKeyEvent( object sender, Window.KeyEventArgs eventArgs )
{
if( eventArgs.Key.State == Key.StateType.Down )
{
switch( eventArgs.Key.KeyPressedName )
{
case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}

static void Main(string[] args)
{
SimpleLayout simpleLayout = new SimpleLayout();
Expand Down
59 changes: 35 additions & 24 deletions simple-text/simple-text.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -232,37 +232,48 @@ public void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
{
keySubclassTest.Text = $"DeviceSubClass={e.Key.DeviceSubClass}, DeviceClass={e.Key.DeviceClass}, DeviceName={e.Key.DeviceName}, KeyCode={e.Key.KeyCode}";

if (e.Key.KeyPressedName == "Up")
switch( e.Key.KeyPressedName )
{
if (_animation)
case "Up":
{
_animation.Finished += AnimationFinished;
cnt++;
Tizen.Log.Fatal("NUI", "AnimationFinished added!");
if (_animation)
{
_animation.Finished += AnimationFinished;
cnt++;
Tizen.Log.Fatal("NUI", "AnimationFinished added!");
}

Tizen.Log.Fatal("NUI", $"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
}
//pointLabel.TextColorAnimatable = Color.Blue;
//pixelLabel.TextColorAnimatable = Color.Blue;
break;

Tizen.Log.Fatal("NUI", $"LineWrapMode 1st={ myTextLabel?.LineWrapMode} 2nd={ myTextLabel2?.LineWrapMode}");
}
else if (e.Key.KeyPressedName == "Down")
{
if (_animation)
case "Down":
{
_animation.Finished -= AnimationFinished;
cnt--;
Tizen.Log.Fatal("NUI", "AnimationFinished removed!");
if (_animation)
{
_animation.Finished -= AnimationFinished;
cnt--;
Tizen.Log.Fatal("NUI", "AnimationFinished removed!");
}

Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
Tizen.Log.Fatal("NUI", $"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
}
//pointLabel.TextColorAnimatable = Color.Red;
//pixelLabel.TextColorAnimatable = Color.Red;
break;

Window.Instance.SetClass($"Window.SetClass() Test #{win_test++}", "");
Tizen.Log.Fatal("NUI", $"Check with enlightenment_info -topwins ! Window.SetClass() Test #{win_test}");
}
else if (e.Key.KeyPressedName == "Return")
{
_animation.Play();
Tizen.Log.Fatal("NUI", "_animation play here!");
case "Return":
{
_animation.Play();
Tizen.Log.Fatal("NUI", "_animation play here!");
}
break;

case "Escape":
case "Back":
{
Exit();
}
break;
}
}
}
Expand Down

0 comments on commit af012cf

Please sign in to comment.