LockScreen.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Linq;
  3. using Xamarin.Forms;
  4. namespace XamarinInsights
  5. {
  6. public class LockScreen : ContentPage
  7. {
  8. Level level;
  9. public Level Level {
  10. get { return level; }
  11. set { BindingContext = level = value; }
  12. }
  13. public LockScreen ()
  14. {
  15. Level = new Level ();
  16. StackLayout stack = new StackLayout ();
  17. stack.VerticalOptions = LayoutOptions.FillAndExpand;
  18. var box = new BoxView{ HeightRequest = 40 };
  19. stack.Children.Add (box);
  20. var levelLabel = new Label {
  21. XAlign = TextAlignment.Center,
  22. Font = Font.SystemFontOfSize (NamedSize.Medium),
  23. };
  24. levelLabel.SetBinding (Label.TextProperty, "CurrentLevel");
  25. stack.Children.Add (levelLabel);
  26. var timeRemaining = new Label {
  27. Font = Font.SystemFontOfSize (NamedSize.Large),
  28. TextColor = Color.Red,
  29. };
  30. timeRemaining.SetBinding (Label.TextProperty, "TimeRemainingDisplay");
  31. stack.Children.Add (timeRemaining);
  32. stack.Children.Add (new Label {
  33. Text = "Passcode",
  34. XAlign = TextAlignment.Center,
  35. Font = Font.SystemFontOfSize (NamedSize.Large)
  36. });
  37. var passCode = new Label {
  38. XAlign = TextAlignment.Center,
  39. Font = Font.SystemFontOfSize (NamedSize.Medium),
  40. TextColor = Color.Gray
  41. };
  42. passCode.SetBinding (Label.TextProperty, "CurrentCombination");
  43. stack.Children.Add (passCode);
  44. var currentPass = new Label {
  45. XAlign = TextAlignment.Center,
  46. YAlign = TextAlignment.Center,
  47. Font = Font.SystemFontOfSize (NamedSize.Large),
  48. HeightRequest = 50,
  49. };
  50. currentPass.SetBinding (Label.TextProperty, "CombinationSoFar");
  51. stack.Children.Add (currentPass);
  52. var grid = new Grid () {
  53. VerticalOptions = new LayoutOptions (LayoutAlignment.Fill, true),
  54. HorizontalOptions = new LayoutOptions (LayoutAlignment.Fill, true),
  55. };
  56. Enumerable.Range (0, 3).ToList ().ForEach (x => grid.ColumnDefinitions.Add (new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }));
  57. Enumerable.Range (0, 4).ToList ().ForEach (x => grid.RowDefinitions.Add (new RowDefinition { Height = new GridLength (1, GridUnitType.Star) }));
  58. stack.Children.Add (grid);
  59. grid.Children.Add (CreateKey ("1"), 0, 0);
  60. grid.Children.Add (CreateKey ("2"), 1, 0);
  61. grid.Children.Add (CreateKey ("3"), 2, 0);
  62. grid.Children.Add (CreateKey ("4"), 0, 1);
  63. grid.Children.Add (CreateKey ("5"), 1, 1);
  64. grid.Children.Add (CreateKey ("6"), 2, 1);
  65. grid.Children.Add (CreateKey ("7"), 0, 2);
  66. grid.Children.Add (CreateKey ("8"), 1, 2);
  67. grid.Children.Add (CreateKey ("9"), 2, 2);
  68. grid.Children.Add (CreateKey ("0"), 1, 3);
  69. Content = stack;
  70. }
  71. Button CreateKey (string key)
  72. {
  73. var button = new Button {
  74. Text = key,
  75. Font = Font.SystemFontOfSize (NamedSize.Large),
  76. Command = new Command (() => Level.PressKey (key)),
  77. VerticalOptions = new LayoutOptions (LayoutAlignment.Fill, true),
  78. HorizontalOptions = new LayoutOptions (LayoutAlignment.Fill, true),
  79. };
  80. return button;
  81. }
  82. protected override async void OnAppearing ()
  83. {
  84. base.OnAppearing ();
  85. Analytics.LogPageView ("Lock Screen");
  86. level.NewLevel ();
  87. level.StopTimer ();
  88. await DisplayAlert ("Hurry!", string.Format ("You have {0} seconds to type the passcode", Level.TimeRemaining / 1000), "Go");
  89. level.StartTimer ();
  90. }
  91. }
  92. }