forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericTextBox_Tablet.cs
438 lines (394 loc) · 17.4 KB
/
NumericTextBox_Tablet.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
#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
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using Syncfusion.SfNumericTextBox.iOS;
using System.Collections.Generic;
#if __UNIFIED__
using Foundation;
using UIKit;
using CoreGraphics;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreGraphics;
using nint = System.Int32;
using nuint = System.Int32;
using CGSize = System.Drawing.SizeF;
using CGRect = System.Drawing.RectangleF;
using nfloat = System.Single;
#endif
namespace SampleBrowser
{
public class NumericTextBox_Tablet : SampleView
{
UIPickerView culturePicker;
UILabel titleLabel, descriptionLabel, formulaLabel, principalLabel, interestRateLabel, termLabel, interestLabel, cultureLabel,allowNullLabel,propertiesLabel;
UISwitch allowSwitch;
UIButton cultureDoneButton,cultureButton;
UIView subView = new UIView();
UIView contentView,controlView;
UIButton showPropertyButton,closeButton;
private string cultureSelectedType;
SfNumericTextBox principalNumericTextBox;
SfNumericTextBox interestRateNumericTextBox;
SfNumericTextBox periodNumericTextBox;
SfNumericTextBox outputNumericTextBox;
private readonly IList<string> cultureList = new List<string> ();
public override void LayoutSubviews ()
{
foreach (var view in this.Subviews) {
view.Frame = Bounds;
subView.Frame = new CGRect (0, this.Frame.Size.Height-this.Frame.Size.Height/3+75, this.Frame.Size.Width, this.Frame.Height / 3-75);
controlView.Frame=new CGRect(150,40,this.Frame.Size.Width-200,this.Frame.Size.Height-40);
contentView.Frame=new CGRect(0,40,subView.Frame.Size.Width,subView.Frame.Size.Height-30);
principalNumericTextBox.Frame = new CGRect(200, 120, controlView.Frame.Width-320, 40);
interestRateNumericTextBox.Frame = new CGRect(200, 180, controlView.Frame.Width-320, 40);
periodNumericTextBox.Frame = new CGRect(200, 240, controlView.Frame.Width-320, 40);
outputNumericTextBox.Frame = new CGRect(200, 300, controlView.Frame.Width-320, 40);
titleLabel.Frame =new CGRect(15, 0, controlView.Frame.Size.Width-20, 50);
descriptionLabel.Frame = new CGRect(15, 48, controlView.Frame.Size.Width-20, 50);
formulaLabel.Frame = new CGRect(269, 48, controlView.Frame.Size.Width-20, 50);
principalLabel.Frame = new CGRect(15, 120, controlView.Frame.Size.Width-20, 50);
interestRateLabel.Frame = new CGRect(15, 180, controlView.Frame.Size.Width-20, 50);
termLabel.Frame = new CGRect(15, 240, controlView.Frame.Size.Width-20, 50);
interestLabel.Frame = new CGRect(15, 300, controlView.Frame.Size.Width-20, 50);
cultureLabel.Frame=new CGRect(110, 40, contentView.Frame.Size.Width-220, 40);
cultureButton.Frame=new CGRect(350,40, contentView.Frame.Size.Width-520, 40);
allowNullLabel.Frame=new CGRect(110, 100, contentView.Frame.Size.Width-220, 40);
allowSwitch.Frame=new CGRect(350,100, contentView.Frame.Size.Width-220, 40);
culturePicker.Frame=new CGRect(100,20, contentView.Frame.Size.Width-200,150);
cultureDoneButton.Frame=new CGRect(100, 0, contentView.Frame.Size.Width-200, 40);
showPropertyButton.Frame = new CGRect (0, this.Frame.Size.Height -25, this.Frame.Size.Width, 30);
closeButton.Frame = new CGRect (this.Frame.Size.Width - 30, 5, 20, 30);
propertiesLabel.Frame = new CGRect (10, 5, this.Frame.Width, 30);
}
base.LayoutSubviews ();
}
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public NumericTextBox_Tablet ()
{
controlView = new UIView();
//principalNumericTextBox
principalNumericTextBox= new SfNumericTextBox();
principalNumericTextBox.Watermark = "Enter Principal";
principalNumericTextBox.AllowNull = true;
principalNumericTextBox.MaximumNumberDecimalDigits = 2;
principalNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
principalNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnLostFocus;
principalNumericTextBox.FormatString = "c";
principalNumericTextBox.Value = 1000;
principalNumericTextBox.Layer.CornerRadius = 8;
principalNumericTextBox.ClipsToBounds = true;
principalNumericTextBox.Layer.BorderWidth = (nfloat)1.2;
principalNumericTextBox.Layer.BorderColor = UIColor.Black.CGColor;
principalNumericTextBox.CultureInfo = new NSLocale ("en_US");
controlView.AddSubview(principalNumericTextBox);
//interestRateNumericTextBox
interestRateNumericTextBox= new SfNumericTextBox();
interestRateNumericTextBox.Watermark = "Enter RI";
interestRateNumericTextBox.AllowNull = true;
interestRateNumericTextBox.Layer.CornerRadius = 8;
interestRateNumericTextBox.ClipsToBounds = true;
interestRateNumericTextBox.Layer.BorderWidth = (nfloat)1.2;
interestRateNumericTextBox.MaximumNumberDecimalDigits = 0;
interestRateNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
interestRateNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnLostFocus;
interestRateNumericTextBox.FormatString = @"p";
interestRateNumericTextBox.Value = 1f;
interestRateNumericTextBox.CultureInfo = new NSLocale ("en_US");
controlView.AddSubview(interestRateNumericTextBox);
//periodNumericTextBox
periodNumericTextBox= new SfNumericTextBox();
periodNumericTextBox.Watermark = @"Enter Years";
periodNumericTextBox.AllowNull = true;
periodNumericTextBox.MaximumNumberDecimalDigits = 0;
periodNumericTextBox.Layer.CornerRadius = 8;
periodNumericTextBox.ClipsToBounds = true;
periodNumericTextBox.Layer.BorderWidth = (nfloat)1.2;
periodNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
periodNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnLostFocus;
periodNumericTextBox.FormatString = @"years";
periodNumericTextBox.Value = 20;
periodNumericTextBox.CultureInfo = new NSLocale ("en_US");
controlView.AddSubview(periodNumericTextBox);
//outputNumericTextBox
outputNumericTextBox= new SfNumericTextBox();
outputNumericTextBox.Watermark = @"Enter a number";
outputNumericTextBox.AllowNull = true;
outputNumericTextBox.MaximumNumberDecimalDigits = 0;
outputNumericTextBox.Layer.CornerRadius = 8;
outputNumericTextBox.ClipsToBounds = true;
outputNumericTextBox.Layer.BorderWidth = (nfloat)1.2;
outputNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
outputNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnLostFocus;
outputNumericTextBox.FormatString = @"c";
outputNumericTextBox.Value = 2000;
outputNumericTextBox.Enabled = false;
outputNumericTextBox.TextColor = UIColor.Gray;
outputNumericTextBox.CultureInfo = new NSLocale ("en_US");
controlView.AddSubview(outputNumericTextBox);
this.AddSubview (controlView);
principalNumericTextBox.ValueChanged += Box_ValueChanged;
periodNumericTextBox.ValueChanged += Box_ValueChanged;
interestRateNumericTextBox.ValueChanged += Box_ValueChanged;
this.mainPageDesign();
this.loadOptionView();
}
void Box_ValueChanged(object sender, ValueEventArgs e)
{
outputNumericTextBox.Value = Convert.ToDecimal( principalNumericTextBox.Value )* Convert.ToDecimal(interestRateNumericTextBox.Value) * Convert.ToDecimal(periodNumericTextBox.Value);
}
public void mainPageDesign()
{
//titleLabell
titleLabel = new UILabel();
titleLabel.TextColor = UIColor.Black;
titleLabel.BackgroundColor = UIColor.Clear;
titleLabel.Text = @"Simple Interest Calculator";
titleLabel.TextAlignment = UITextAlignment.Left;
titleLabel.Font = UIFont.FromName("Helvetica-Bold", 20f);
controlView.AddSubview(titleLabel);
//descriptionLabell
descriptionLabel = new UILabel();
descriptionLabel.TextColor = UIColor.Black;
descriptionLabel.BackgroundColor = UIColor.Clear;
descriptionLabel.Text = @"The formula for finding simple interest ";
descriptionLabel.TextAlignment = UITextAlignment.Left;
descriptionLabel.Font = UIFont.FromName("Helvetica", 14f);
controlView.AddSubview(descriptionLabel);
//formulaLabell
formulaLabel = new UILabel();
formulaLabel.TextColor = UIColor.Black;
formulaLabel.BackgroundColor = UIColor.Clear;
formulaLabel.Text = @"= Principal * Rate * Time";
formulaLabel.TextAlignment = UITextAlignment.Left;
formulaLabel.Font = UIFont.FromName("Helvetica", 14f);
controlView.AddSubview(formulaLabel);
//principalLabell
principalLabel = new UILabel();
principalLabel.TextColor = UIColor.Black;
principalLabel.BackgroundColor = UIColor.Clear;
principalLabel.Text = @"Principal";
principalLabel.Font = UIFont.FromName("Helvetica", 16f);
principalLabel.TextAlignment = UITextAlignment.Left;
controlView.AddSubview(principalLabel);
//interestRateLabell
interestRateLabel = new UILabel();
interestRateLabel.TextColor = UIColor.Black;
interestRateLabel.BackgroundColor = UIColor.Clear;
interestRateLabel.Font = UIFont.FromName("Helvetica", 16f);
interestRateLabel.Text = @"Interest Rate";
interestRateLabel.TextAlignment = UITextAlignment.Left;
controlView.AddSubview(interestRateLabel);
//termLabell
termLabel = new UILabel();
termLabel.TextColor = UIColor.Black;
termLabel.BackgroundColor = UIColor.Clear;
termLabel.Text = @"Term";
termLabel.TextAlignment = UITextAlignment.Left;
termLabel.Font = UIFont.FromName("Helvetica", 16f);
controlView.AddSubview(termLabel);
//interestLabell
interestLabel = new UILabel();
interestLabel.TextColor = UIColor.Black;
interestLabel.BackgroundColor = UIColor.Clear;
interestLabel.Text = @"Interest";
interestLabel.TextAlignment = UITextAlignment.Left;
interestLabel.Font = UIFont.FromName("Helvetica", 16f);
controlView.AddSubview(interestLabel);
}
public void loadOptionView()
{
contentView = new UIView();
//allowNullLabel
allowNullLabel = new UILabel();
allowNullLabel.TextColor = UIColor.Black;
allowNullLabel.BackgroundColor = UIColor.Clear;
allowNullLabel.Text = @"Allow Null";
allowNullLabel.TextAlignment = UITextAlignment.Left;
allowNullLabel.Font = UIFont.FromName("Helvetica", 14f);
contentView.AddSubview(allowNullLabel);
//allowSwitch
allowSwitch = new UISwitch();
allowSwitch.OnTintColor = UIColor.FromRGB(50, 150, 221);
allowSwitch.ValueChanged += allowNullToggleChanged;
allowSwitch.On = true;
contentView.AddSubview(allowSwitch);
//cultureLabel
cultureLabel = new UILabel();
cultureLabel.TextColor = UIColor.Black;
cultureLabel.BackgroundColor = UIColor.Clear;
cultureLabel.Text = @"Culture";
cultureLabel.TextAlignment = UITextAlignment.Left;
cultureLabel.Font = UIFont.FromName("Helvetica", 14f);
contentView.AddSubview(cultureLabel);
//adding locale to culture listt
this.cultureList.Add((NSString)"United States");
this.cultureList.Add((NSString)"United Kingdom");
this.cultureList.Add((NSString)"Japan");
this.cultureList.Add((NSString)"France");
this.cultureList.Add((NSString)"Italy");
//cultureButton
cultureButton = new UIButton();
cultureButton.SetTitle("United States", UIControlState.Normal);
cultureButton.Font = UIFont.FromName("Helvetica", 14f);
cultureButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
cultureButton.BackgroundColor = UIColor.Clear;
cultureButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
cultureButton.Hidden = false;
cultureButton.Layer.BorderColor = UIColor.FromRGB(246, 246, 246).CGColor;
cultureButton.Layer.BorderWidth = 4;
cultureButton.Layer.CornerRadius = 8;
cultureButton.TouchUpInside += (object sender, EventArgs e) =>
{
cultureDoneButton.Hidden = false;
culturePicker.Hidden = false;
allowNullLabel.Hidden = true;
allowSwitch.Hidden = true;
};
contentView.AddSubview(cultureButton);
//culturePickerModel
PickerModel culturePickermodel = new PickerModel(this.cultureList);
culturePickermodel.PickerChanged += (sender, e) =>
{
this.cultureSelectedType = e.SelectedValue;
cultureButton.SetTitle(cultureSelectedType, UIControlState.Normal);
if (cultureSelectedType == "United States")
{
principalNumericTextBox.CultureInfo = new NSLocale("en_US");
interestRateNumericTextBox.CultureInfo = new NSLocale("en_US");
periodNumericTextBox.CultureInfo = new NSLocale("en_US");
outputNumericTextBox.CultureInfo = new NSLocale("en_US");
}
else if (cultureSelectedType == "United Kingdom")
{
principalNumericTextBox.CultureInfo = new NSLocale("en_UK");
interestRateNumericTextBox.CultureInfo = new NSLocale("en_UK");
periodNumericTextBox.CultureInfo = new NSLocale("en_UK");
outputNumericTextBox.CultureInfo = new NSLocale("en_UK");
}
else if (cultureSelectedType == "Japan")
{
principalNumericTextBox.CultureInfo = new NSLocale("ja_JP");
interestRateNumericTextBox.CultureInfo = new NSLocale("ja_JP");
periodNumericTextBox.CultureInfo = new NSLocale("ja_JP");
outputNumericTextBox.CultureInfo = new NSLocale("ja_JP");
}
else if (cultureSelectedType == "France")
{
principalNumericTextBox.CultureInfo = new NSLocale("fr_FR");
interestRateNumericTextBox.CultureInfo = new NSLocale("fr_FR");
periodNumericTextBox.CultureInfo = new NSLocale("fr_FR");
outputNumericTextBox.CultureInfo = new NSLocale("fr_FR");
}
else if (cultureSelectedType == "Italy")
{
principalNumericTextBox.CultureInfo = new NSLocale("it_IT");
interestRateNumericTextBox.CultureInfo = new NSLocale("it_IT");
periodNumericTextBox.CultureInfo = new NSLocale("it_IT");
outputNumericTextBox.CultureInfo = new NSLocale("it_IT");
}
};
//culturePicker
culturePicker = new UIPickerView();
culturePicker.ShowSelectionIndicator = true;
culturePicker.Hidden = true;
culturePicker.Model = culturePickermodel;
culturePicker.BackgroundColor = UIColor.Gray;
contentView.AddSubview(culturePicker);
//cultureDoneButton
cultureDoneButton = new UIButton();
cultureDoneButton.SetTitle("Done\t", UIControlState.Normal);
cultureDoneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
cultureDoneButton.BackgroundColor = UIColor.FromRGB(240, 240, 240);
cultureDoneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
cultureDoneButton.Hidden = true;
cultureDoneButton.Font = UIFont.FromName("Helvetica", 14f);
cultureDoneButton.TouchUpInside += HideCulturePicker;
contentView.AddSubview(cultureDoneButton);
//propertiesLabel
propertiesLabel = new UILabel();
propertiesLabel.Text = "OPTIONS";
//showPropertyButton
showPropertyButton = new UIButton();
showPropertyButton.Hidden = true;
showPropertyButton.SetTitle(" OPTIONS\t", UIControlState.Normal);
showPropertyButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
showPropertyButton.BackgroundColor = UIColor.FromRGB(240, 240, 240);
showPropertyButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
showPropertyButton.TouchUpInside += (object sender, EventArgs e) =>
{
subView.Hidden = false;
showPropertyButton.Hidden = true;
};
this.AddSubview(showPropertyButton);
//closeButton
closeButton = new UIButton();
closeButton.SetTitle("X\t", UIControlState.Normal);
closeButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
closeButton.BackgroundColor = UIColor.FromRGB(230, 230, 230);
closeButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
closeButton.TouchUpInside += (object sender, EventArgs e) =>
{
subView.Hidden = true;
showPropertyButton.Hidden = false;
};
//subVieww
subView.AddSubview(closeButton);
subView.AddSubview(propertiesLabel);
subView.BackgroundColor = UIColor.FromRGB(230, 230, 230);
contentView.BackgroundColor = UIColor.FromRGB(240, 240, 240);
subView.AddSubview(contentView);
this.AddSubview(subView);
//AddingGesture
UITapGestureRecognizer tapgesture = new UITapGestureRecognizer(() =>
{
subView.Hidden = true;
showPropertyButton.Hidden = false;
}
);
propertiesLabel.UserInteractionEnabled = true;
propertiesLabel.AddGestureRecognizer(tapgesture);
}
void ShowCulturePicker (object sender, EventArgs e) {
cultureDoneButton.Hidden = false;
culturePicker.Hidden = false;
allowNullLabel.Hidden = true;
allowSwitch.Hidden = true;
cultureLabel.Hidden = true;
this.BecomeFirstResponder ();
}
void HideCulturePicker (object sender, EventArgs e) {
cultureDoneButton.Hidden = true;
culturePicker.Hidden = true;
allowNullLabel.Hidden = false;
allowSwitch.Hidden = false;
cultureLabel.Hidden = false;
this.BecomeFirstResponder ();
}
private void allowNullToggleChanged(object sender, EventArgs e)
{
if (((UISwitch)sender).On) {
principalNumericTextBox.AllowNull = true;
interestRateNumericTextBox.AllowNull = true;
periodNumericTextBox.AllowNull = true;
outputNumericTextBox.AllowNull = true;
} else {
principalNumericTextBox.AllowNull = false;
interestRateNumericTextBox.AllowNull = false;
periodNumericTextBox.AllowNull = false;
outputNumericTextBox.AllowNull = false;
}
}
public override void TouchesBegan (NSSet touches, UIEvent evt){
this.EndEditing (true);
}
}
}