summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/MainPageLifeCycleTests.cs
blob: 5d14fca74006646b9e0a5922a8db16f6a95de3c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
namespace Xamarin.Forms.Controls
{
	public class MainPageLifeCycleTests : ContentPage
	{
		int _numTimesStarted;
		int _numTimesSlept;
		int _numTimesResumed;

		readonly StackLayout _numTimesStartedLayout;
		readonly StackLayout _numTimesSleptLayout;
		readonly StackLayout _numTimesResumedLayout;

		public MainPageLifeCycleTests ()
		{
			object timesStarted;
			if (!Application.Current.Properties.TryGetValue ("TimesStarted", out timesStarted)) {
				Application.Current.Properties["TimesStarted"] = 0;
			} 
			var numTimesStarted = (int)Application.Current.Properties["TimesStarted"];
			

			object timesSlept;
			if (!Application.Current.Properties.TryGetValue ("TimesSlept", out timesSlept)) {
				Application.Current.Properties["TimesSlept"] = 0;
			}
			var numTimesSlept = (int)Application.Current.Properties["TimesSlept"];
	

			object timesResumed;
			if (!Application.Current.Properties.TryGetValue ("TimesResumed", out timesResumed)) {
				Application.Current.Properties["TimesResumed"] = 0;
			}
			var numTimesResumed = (int)Application.Current.Properties["TimesResumed"];

			_numTimesStartedLayout = BuildLabelLayout ("TimesStarted", numTimesStarted);
			_numTimesSleptLayout = BuildLabelLayout ("TimesSlept", numTimesSlept);
			_numTimesResumedLayout = BuildLabelLayout ("TimesResumed", numTimesResumed);

			var layout = new StackLayout {
				Children = {
					_numTimesStartedLayout,
					_numTimesSleptLayout,
					_numTimesResumedLayout
				}
			};

			Content = layout;
		}

		StackLayout BuildLabelLayout (string title, int property)
		{
			var labelTitle = new Label {
				Text = title
			};

			var valueLabel = new Label {
				Text = property.ToString ()
			};

			return new StackLayout {
				Children = {
					labelTitle,
					valueLabel
				}
			};
		}

		public void UpdateLabels ()
		{
			((Label)_numTimesStartedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesStarted"]).ToString ();
			((Label)_numTimesSleptLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesSlept"]).ToString ();
			((Label)_numTimesResumedLayout.Children[1]).Text = ((int)Application.Current.Properties["TimesResumed"]).ToString ();
		}
	}
}