-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainActivity.cs
146 lines (128 loc) · 5.56 KB
/
MainActivity.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Views;
using Android.Widget;
namespace AndroidPageLayout.App {
[Activity(Label = "AndroidPageLayout.App", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/AppTheme")]
public class MainActivity : AppCompatActivity {
private const string label = nameof(MainActivity);
private PageLayout pageLayout;
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
pageLayout = FindViewById<PageLayout>(Resource.Id.PageLayout);
pageLayout.FirstVisiblePageFloatChanged += currentFirstVisiblePageFloatChanged;
if (pageLayout == null) {
throw new Exception("pagelayout is null");
}
try {
var f = pageLayout.CurrentFirstVisiblePageFloat;
} catch (Exception) {
throw new Exception("pagelayout.current null");
}
setTitle(pageLayout.CurrentFirstVisiblePageFloat);
using (var page = FindViewById<View>(Resource.Id.SimpleVertical)) {
page.Click += click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleHorizontal)) {
page.Click += click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleNestedScrollingParent)) {
page.Click += click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleMultiplePage)) {
page.Click += click;
}
using (var page = FindViewById<View>(Resource.Id.DynamicAddOrRemovePage)) {
page.Click += click;
}
// TwitterLikeImageViewer
using (var image = FindViewById<ImageView>(Resource.Id.Image1)) {
image.Click += click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image2)) {
image.Click += click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image3)) {
image.Click += click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image4)) {
image.Click += click;
}
}
protected override void OnDestroy() {
using (var page = FindViewById<View>(Resource.Id.SimpleVertical)) {
page.Click -= click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleHorizontal)) {
page.Click -= click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleNestedScrollingParent)) {
page.Click -= click;
}
using (var page = FindViewById<View>(Resource.Id.SimpleMultiplePage)) {
page.Click -= click;
}
using (var page = FindViewById<View>(Resource.Id.DynamicAddOrRemovePage)) {
page.Click -= click;
}
// TwitterLikeImageViewer
using (var image = FindViewById<ImageView>(Resource.Id.Image1)) {
image.Click -= click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image2)) {
image.Click -= click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image3)) {
image.Click -= click;
}
using (var image = FindViewById<ImageView>(Resource.Id.Image4)) {
image.Click -= click;
}
pageLayout.FirstVisiblePageFloatChanged -= currentFirstVisiblePageFloatChanged;
pageLayout.Dispose();
base.OnDestroy();
}
private void click(object sender, EventArgs args) {
var view = sender as View;
switch (view.Id) {
case Resource.Id.SimpleVertical:
SimpleVerticalActivity.Start(this);
break;
case Resource.Id.SimpleHorizontal:
SimpleHorizontalActivity.Start(this);
break;
case Resource.Id.SimpleNestedScrollingParent:
SimpleNestedScrollingParent.Start(this);
break;
case Resource.Id.SimpleMultiplePage:
SimpleMultiplePageActivity.Start(this);
break;
case Resource.Id.DynamicAddOrRemovePage:
DynamicAddOrRemovePageActivity.Start(this);
break;
// TwitterLikeImageViewer
case Resource.Id.Image1:
TwitterLikeImageViewerActivity.Start(this, view as ImageView, 0);
break;
case Resource.Id.Image2:
TwitterLikeImageViewerActivity.Start(this, view as ImageView, 1);
break;
case Resource.Id.Image3:
TwitterLikeImageViewerActivity.Start(this, view as ImageView, 2);
break;
case Resource.Id.Image4:
TwitterLikeImageViewerActivity.Start(this, view as ImageView, 3);
break;
}
}
private void currentFirstVisiblePageFloatChanged(object sender, FirstVisiblePageFloatChangedEventArgs args) {
setTitle(args.FirstVisiblePageFloat);
}
private void setTitle(float currentFirstVisiblePageFloat) {
SupportActionBar.Title = $"{label} Page:{currentFirstVisiblePageFloat}";
}
}
}