forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GettingStarted.cs
254 lines (221 loc) · 9.59 KB
/
GettingStarted.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#region Copyright Syncfusion Inc. 2001-2019.
// Copyright Syncfusion Inc. 2001-2019. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Android.Content;
using Android.Graphics;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.SfPicker;
namespace SampleBrowser
{
public class SfPickerDemo : SamplePage
{
SfPicker sfpicker;
TextView eventLog;
Spinner showHeaderSpinner, showColumnHeaderSpinner;
int width;
Context context1;
TextView showHeaderText, showColumnHeaderText, headerText;
EditText headerTextView;
ArrayAdapter<String> dataAdapter;
public SfPickerDemo()
{
}
public override View GetSampleContent(Context con)
{
float height = con.Resources.DisplayMetrics.HeightPixels; ;
LinearLayout layout = new LinearLayout(con);
Typeface tf = Typeface.CreateFromAsset(con.Assets, "Segoe_MDL2_Assets.ttf");
layout.Orientation = Android.Widget.Orientation.Vertical;
sfpicker = new SfPicker(con);
sfpicker.ShowHeader = true;
List<String> source = new List<string>();
source.Add("Yellow");
source.Add("Green");
source.Add("Orange");
source.Add("Lime");
source.Add("LightBlue");
source.Add("Pink");
source.Add("SkyBlue");
source.Add("White");
source.Add("Red");
source.Add("Aqua");
sfpicker.ItemsSource = source;
sfpicker.LayoutParameters = new ViewGroup.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, (int)(height * 0.60));
sfpicker.PickerMode = PickerMode.Default;
sfpicker.ShowFooter = false;
sfpicker.ShowColumnHeader = false;
sfpicker.UnSelectedItemTextColor = Color.Black;
sfpicker.SelectedIndex = 7;
float density = con.Resources.DisplayMetrics.Density;
eventLog = new TextView(con);
eventLog.LayoutParameters = new ViewGroup.LayoutParams(800, 400);
layout.SetGravity(GravityFlags.CenterHorizontal);
layout.AddView(sfpicker);
string headerText1 = "PICK A COLOR";
sfpicker.ShowHeader = true;
sfpicker.HeaderText = headerText1;
sfpicker.BorderColor = Color.Red;
TextView textview = new TextView(con);
textview.Text = "Event Log";
textview.Typeface = tf;
textview.SetTextColor(Color.Black);
textview.TextSize = 20;
if (density > 2)
textview.SetPadding(20, 0, 0, 20);
else
textview.SetPadding(10, 0, 0, 10);
layout.AddView(textview);
var scrollviewer = new ScrollView(con);
var textFrame = new LinearLayout(con);
textFrame.Orientation = Android.Widget.Orientation.Vertical;
scrollviewer.AddView(textFrame);
scrollviewer.VerticalScrollBarEnabled = true;
FrameLayout bottomFrame = new FrameLayout(con);
bottomFrame.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(height * 0.40));
bottomFrame.SetBackgroundColor(Color.Silver);
bottomFrame.AddView(scrollviewer);
bottomFrame.SetPadding(10, 0, 10, 0);
layout.AddView(bottomFrame);
sfpicker.ColumnHeaderText = "COLOR";
sfpicker.OnSelectionChanged += (sender, e) =>
{
eventLog = new TextView(con);
eventLog.SetTextColor(Color.Black);
if (textFrame.ChildCount == 6)
textFrame.RemoveViewAt(0);
textFrame.AddView(eventLog);
eventLog.Text = (e.NewValue).ToString() + " " + "has been Selected";
Color color = PickerHelper.GetColor(e.NewValue.ToString());
sfpicker.SetBackgroundColor(color);
sfpicker.Alpha = 0.4f;
scrollviewer.ScrollTo(0, textFrame.Bottom);
};
return layout;
}
public override View GetPropertyWindowLayout(Android.Content.Context context)
{
context1 = context;
width = (context.Resources.DisplayMetrics.WidthPixels) / 2;
showHeaderLayout();
showColumnHeaderLayout();
HeaderTextLayout();
/******************
**propertylayout**
******************/
//Separator
LinearLayout.LayoutParams separatorLayoutParams = new LinearLayout.LayoutParams(width * 2, 5);
separatorLayoutParams.SetMargins(0, 20, 0, 0);
SeparatorView separate = new SeparatorView(context1, width * 2);
separate.LayoutParameters = new ViewGroup.LayoutParams(width * 2, 5);
LinearLayout propertylayout = new LinearLayout(context);
propertylayout.Orientation = Orientation.Vertical;
propertylayout.AddView(showHeaderText);
propertylayout.AddView(showHeaderSpinner);
propertylayout.SetPadding(10, 10, 10, 40);
propertylayout.AddView(showColumnHeaderText);
propertylayout.AddView(showColumnHeaderSpinner);
propertylayout.AddView(headerText);
propertylayout.AddView(headerTextView);
showHeaderText.SetPadding(0, 0, 0, 40);
showHeaderSpinner.SetPadding(0, 0, 0, 50);
showColumnHeaderText.SetPadding(0, 40, 0, 40);
showColumnHeaderSpinner.SetPadding(0, 0, 0, 50);
headerText.SetPadding(0, 40, 0, 40);
headerTextView.SetPadding(0, 0, 0, 50);
return propertylayout;
}
private void showHeaderLayout()
{
showHeaderText = new TextView(context1);
showHeaderText.TextSize = 20;
showHeaderText.Text = "Show Header";
showHeaderSpinner = new Spinner(context1, SpinnerMode.Dialog);
//View Mode List
List<String> showHeaderList = new List<String>();
showHeaderList.Add("False");
showHeaderList.Add("True");
//Data Adapter
dataAdapter = new ArrayAdapter<String>(context1, Android.Resource.Layout.SimpleSpinnerItem, showHeaderList);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
showHeaderSpinner.Adapter = dataAdapter;
//Mode Spinner Item Selected Listener
showHeaderSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
{
String selectedItem = dataAdapter.GetItem(e.Position);
if (selectedItem.Equals("True"))
{
sfpicker.ShowHeader = true;
}
if (selectedItem.Equals("False"))
{
sfpicker.ShowHeader = false;
}
};
}
private void showColumnHeaderLayout()
{
showColumnHeaderText = new TextView(context1);
showColumnHeaderText.TextSize = 20;
showColumnHeaderText.Text = "Show Column Header";
showColumnHeaderSpinner = new Spinner(context1, SpinnerMode.Dialog);
//View Mode List
List<String> showColumnHeaderList = new List<String>();
showColumnHeaderList.Add("False");
showColumnHeaderList.Add("True");
//Data Adapter
dataAdapter = new ArrayAdapter<String>(context1, Android.Resource.Layout.SimpleSpinnerItem, showColumnHeaderList);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
showColumnHeaderSpinner.Adapter = dataAdapter;
//Mode Spinner Item Selected Listener
showColumnHeaderSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
{
String selectedItem = dataAdapter.GetItem(e.Position);
if (selectedItem.Equals("True"))
{
sfpicker.ShowColumnHeader = true;
}
if (selectedItem.Equals("False"))
{
sfpicker.ShowColumnHeader = false;
}
};
}
private void HeaderTextLayout()
{
headerText = new TextView(context1);
headerText.TextSize = 20;
headerText.Text = "Header Text";
headerTextView = new EditText(context1);
headerTextView.TextSize = 18;
headerTextView.Text = "PICK A COLOR";
headerTextView.TextChanged += (sender, e) => { sfpicker.HeaderText = e.Text.ToString(); };
}
}
public static class PickerHelper
{
static Dictionary<string, Color> colors = new Dictionary<string, Color>();
public static Color GetColor(object color)
{
colors.Clear();
colors.Add("Yellow", Color.Yellow);
colors.Add("Green", Color.Green);
colors.Add("Orange", Color.Orange);
colors.Add("Lime", Color.Lime);
colors.Add("LightBlue", Color.LightBlue);
colors.Add("Pink", Color.Pink);
colors.Add("SkyBlue", Color.SkyBlue);
colors.Add("White", Color.White);
colors.Add("Red", Color.Red);
colors.Add("Aqua", Color.Aqua);
return colors[color.ToString()];
}
}
}