forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumericTextBox_Mobile.cs
388 lines (359 loc) · 15.5 KB
/
NumericTextBox_Mobile.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
#region Copyright Syncfusion Inc. 2001-2022
// Copyright Syncfusion Inc. 2001-2022. 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 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_Mobile : SampleView
{
UIPickerView culturePicker;
UILabel titleLabel, descriptionLabel, formulaLabel, principalLabel, interestRateLabel, termLabel, interestLabel, cultureLabel, allowNullLabel, allowDefaultDecimal;
UISwitch allowSwitch, allowDecimalSwitch;
UIButton cultureDoneButton, cultureButton;
private string cultureSelectedType;
SfNumericTextBox principalNumericTextBox;
SfNumericTextBox interestRateNumericTextBox;
SfNumericTextBox periodNumericTextBox;
SfNumericTextBox outputNumericTextBox;
public UIView option = new UIView();
private readonly IList<string> cultureList = new List<string>();
public void optionView()
{
this.option.AddSubview(allowNullLabel);
this.option.AddSubview(allowSwitch);
this.option.AddSubview(allowDefaultDecimal);
this.option.AddSubview(allowDecimalSwitch);
this.option.AddSubview(cultureLabel);
this.option.AddSubview(cultureDoneButton);
this.option.AddSubview(culturePicker);
this.option.AddSubview(cultureButton);
}
public override void LayoutSubviews()
{
foreach (var view in this.Subviews)
{
view.Frame = Bounds;
this.OptionView.Frame = view.Frame;
this.option.Frame = new CGRect(0, 70, Frame.Width, Frame.Height);
principalNumericTextBox.Frame = new CGRect(15, 130, view.Frame.Width - 50, 50);
interestRateNumericTextBox.Frame = new CGRect(15, 220, view.Frame.Width - 50, 50);
periodNumericTextBox.Frame = new CGRect(15, 310, view.Frame.Width - 50, 50);
outputNumericTextBox.Frame = new CGRect(15, 400, view.Frame.Width - 50, 50);
titleLabel.Frame = new CGRect(15, 10, this.Frame.Size.Width - 20, 30);
descriptionLabel.Frame = new CGRect(15, 50, this.Frame.Size.Width - 20, 20);
formulaLabel.Frame = new CGRect(15, 70, this.Frame.Size.Width - 20, 20);
principalLabel.Frame = new CGRect(15, 100, this.Frame.Size.Width - 20, 30);
interestRateLabel.Frame = new CGRect(15, 190, this.Frame.Size.Width - 15, 30);
termLabel.Frame = new CGRect(15, 280, this.Frame.Size.Width - 15, 30);
interestLabel.Frame = new CGRect(15, 370, this.Frame.Size.Width - 20, 30);
cultureLabel.Frame = new CGRect(15, 40, this.Frame.Size.Width - 20, 40);
cultureButton.Frame = new CGRect(10, 80, this.Frame.Size.Width - 20, 40);
allowNullLabel.Frame = new CGRect(15, 140, this.Frame.Size.Width - 20, 40);
allowSwitch.Frame = new CGRect(250, 140, this.Frame.Size.Width - 20, 40);
allowDefaultDecimal.Frame = new CGRect(15, 180, this.Frame.Size.Width - 20, 40);
allowDecimalSwitch.Frame = new CGRect(250, 180, this.Frame.Size.Width - 20, 40);
culturePicker.Frame = new CGRect(0, this.Frame.Size.Height / 4 + 20, this.Frame.Size.Width, this.Frame.Size.Height / 3);
cultureDoneButton.Frame = new CGRect(0, this.Frame.Size.Height / 4 - 20, this.Frame.Size.Width, 40);
}
this.optionView();
base.LayoutSubviews();
}
static bool UserInterfaceIdiomIsPhone
{
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public NumericTextBox_Mobile()
{
this.OptionView = new UIView();
//cultureList
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");
//principalNumericTextBox
principalNumericTextBox = new SfNumericTextBox();
principalNumericTextBox.Watermark = "Enter Principal";
principalNumericTextBox.AllowNull = true;
principalNumericTextBox.MaximumNumberDecimalDigits = 2;
principalNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
principalNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnKeyFocus;
principalNumericTextBox.FormatString = "c";
principalNumericTextBox.Layer.BorderWidth = 1f;
principalNumericTextBox.Value = 1000;
principalNumericTextBox.CultureInfo = new NSLocale("en_US");
principalNumericTextBox.AllowDefaultDecimalDigits = true;
this.AddSubview(principalNumericTextBox);
//interestRateNumericTextBox
interestRateNumericTextBox = new SfNumericTextBox();
interestRateNumericTextBox.Watermark = "Enter RI";
interestRateNumericTextBox.AllowNull = true;
interestRateNumericTextBox.MaximumNumberDecimalDigits = 1;
interestRateNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
interestRateNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnKeyFocus;
interestRateNumericTextBox.FormatString = @"p";
interestRateNumericTextBox.ClearButtonMode = UITextFieldViewMode.WhileEditing;
interestRateNumericTextBox.Value = 0.2f;
interestRateNumericTextBox.Layer.BorderWidth = 1f;
interestRateNumericTextBox.CultureInfo = new NSLocale("en_US");
interestRateNumericTextBox.AllowDefaultDecimalDigits = true;
this.AddSubview(interestRateNumericTextBox);
//periodNumericTextBox
periodNumericTextBox = new SfNumericTextBox();
periodNumericTextBox.Watermark = @"Enter Years";
periodNumericTextBox.AllowNull = true;
periodNumericTextBox.MaximumNumberDecimalDigits = 0;
periodNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
periodNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnKeyFocus;
periodNumericTextBox.FormatString = @"years";
periodNumericTextBox.Value = 20;
periodNumericTextBox.Layer.BorderWidth = 1f;
periodNumericTextBox.CultureInfo = new NSLocale("en_US");
this.AddSubview(periodNumericTextBox);
//outputNumericTextBox
outputNumericTextBox = new SfNumericTextBox();
outputNumericTextBox.Watermark = @"Enter a number";
outputNumericTextBox.AllowNull = true;
outputNumericTextBox.MaximumNumberDecimalDigits = 0;
outputNumericTextBox.PercentDisplayMode = SFNumericTextBoxPercentDisplayMode.Compute;
outputNumericTextBox.ValueChangeMode = SFNumericTextBoxValueChangeMode.OnLostFocus;
outputNumericTextBox.FormatString = @"c";
outputNumericTextBox.Value = 2000;
outputNumericTextBox.Enabled = false;
outputNumericTextBox.Layer.BorderWidth = 1f;
outputNumericTextBox.TextColor = UIColor.Gray;
outputNumericTextBox.CultureInfo = new NSLocale("en_US");
this.AddSubview(outputNumericTextBox);
principalNumericTextBox.ValueChanged += Box_ValueChanged;
periodNumericTextBox.ValueChanged += Box_ValueChanged;
interestRateNumericTextBox.ValueChanged += Box_ValueChanged;
mainPageDesign();
}
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", 22f);
this.AddSubview(titleLabel);
//descriptionLabell
descriptionLabel = new UILabel();
descriptionLabel.TextColor = UIColor.Black;
descriptionLabel.BackgroundColor = UIColor.Clear;
descriptionLabel.Text = @"The formula for finding simple interest is:";
descriptionLabel.TextAlignment = UITextAlignment.Left;
descriptionLabel.Font = UIFont.FromName("Helvetica", 14f);
this.AddSubview(descriptionLabel);
//formulaLabell
formulaLabel = new UILabel();
formulaLabel.TextColor = UIColor.Black;
formulaLabel.BackgroundColor = UIColor.Clear;
formulaLabel.Text = @"Amount = Principal * Rate * Time";
formulaLabel.Font = UIFont.ItalicSystemFontOfSize(14f);
formulaLabel.TextAlignment = UITextAlignment.Left;
this.AddSubview(formulaLabel);
//principalLabell
principalLabel = new UILabel();
principalLabel.TextColor = UIColor.Black;
principalLabel.BackgroundColor = UIColor.Clear;
principalLabel.Text = @"Principal";
principalLabel.TextAlignment = UITextAlignment.Left;
principalLabel.Font = UIFont.FromName("Helvetica", 16f);
this.AddSubview(principalLabel);
//interestRateLabell
interestRateLabel = new UILabel();
interestRateLabel.TextColor = UIColor.Black;
interestRateLabel.BackgroundColor = UIColor.Clear;
interestRateLabel.Text = @"Interest Rate";
interestRateLabel.TextAlignment = UITextAlignment.Left;
interestRateLabel.Font = UIFont.FromName("Helvetica", 16f);
this.AddSubview(interestRateLabel);
//termLabell
termLabel = new UILabel();
termLabel.TextColor = UIColor.Black;
termLabel.BackgroundColor = UIColor.Clear;
termLabel.Text = @"Term (in years)";
termLabel.TextAlignment = UITextAlignment.Left;
termLabel.Font = UIFont.FromName("Helvetica", 16f);
this.AddSubview(termLabel);
//interestLabell
interestLabel = new UILabel();
interestLabel.TextColor = UIColor.Black;
interestLabel.BackgroundColor = UIColor.Clear;
interestLabel.Text = @"Amount";
interestLabel.TextAlignment = UITextAlignment.Left;
interestLabel.Font = UIFont.FromName("Helvetica", 16f);
this.AddSubview(interestLabel);
//allowNullLabell
allowNullLabel = new UILabel();
allowNullLabel.TextColor = UIColor.Black;
allowNullLabel.BackgroundColor = UIColor.Clear;
allowNullLabel.Text = @"Allow Null";
allowNullLabel.TextAlignment = UITextAlignment.Left;
allowNullLabel.Font = UIFont.FromName("Helvetica", 16f);
//allowDefaultDecimal
allowDefaultDecimal = new UILabel();
allowDefaultDecimal.TextColor = UIColor.Black;
allowDefaultDecimal.BackgroundColor = UIColor.Clear;
allowDefaultDecimal.Text = @"Allow Default Decimal Digits";
allowDefaultDecimal.TextAlignment = UITextAlignment.Left;
allowDefaultDecimal.Font = UIFont.FromName("Helvetica", 16f);
//allowSwitchh
allowSwitch = new UISwitch();
allowSwitch.ValueChanged += allowNullToggleChanged;
allowSwitch.On = true;
//allowDecimalSwitchh
allowDecimalSwitch = new UISwitch();
allowDecimalSwitch.ValueChanged += AllowDecimalSwitch_ValueChanged;
allowDecimalSwitch.On = true;
//cultureLabell
cultureLabel = new UILabel();
cultureLabel.TextColor = UIColor.Black;
cultureLabel.BackgroundColor = UIColor.Clear;
cultureLabel.Text = @"Culture";
cultureLabel.TextAlignment = UITextAlignment.Left;
cultureLabel.Font = UIFont.FromName("Helvetica", 16f);
// this.OptionView.AddSubview(cultureLabel);
//cultureButtonn
cultureButton = new UIButton();
cultureButton.SetTitle("United States", UIControlState.Normal);
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 += ShowCulturePicker;
//culturePickerr
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 = new UIPickerView();
culturePicker.ShowSelectionIndicator = true;
culturePicker.Hidden = true;
culturePicker.Model = culturePickermodel;
culturePicker.BackgroundColor = UIColor.White;
//cultureDoneButtonn
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.TouchUpInside += HideCulturePicker;
this.BackgroundColor = UIColor.White;
}
private void AllowDecimalSwitch_ValueChanged(object sender, EventArgs e)
{
if (((UISwitch)sender).On)
{
principalNumericTextBox.AllowDefaultDecimalDigits = true;
interestRateNumericTextBox.AllowDefaultDecimalDigits = true;
}
else
{
principalNumericTextBox.AllowDefaultDecimalDigits = false;
interestRateNumericTextBox.AllowDefaultDecimalDigits = false;
}
}
void ShowCulturePicker(object sender, EventArgs e)
{
cultureDoneButton.Hidden = false;
culturePicker.Hidden = false;
this.BecomeFirstResponder();
}
void HideCulturePicker(object sender, EventArgs e)
{
cultureDoneButton.Hidden = true;
culturePicker.Hidden = true;
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);
}
}
}