-
Notifications
You must be signed in to change notification settings - Fork 204
/
CalcQuickCalculation.cs
300 lines (238 loc) · 8.24 KB
/
CalcQuickCalculation.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
#region Copyright Syncfusion Inc. 2001-2024.
// Copyright Syncfusion Inc. 2001-2024. 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 UIKit;
using CoreGraphics;
using System.Collections.ObjectModel;
using CoreAnimation;
using SampleBrowser;
using Foundation;
using Syncfusion.Calculate;
namespace SampleBrowser
{
public partial class CalcQuickCalculation : SampleView
{
#region Fields
CalcQuickView calcQuickView;
#endregion
#region Constructor
public CalcQuickCalculation ()
{
calcQuickView = new CalcQuickView ();
this.AddSubview (calcQuickView);
}
#endregion
#region Methods
public override void LayoutSubviews ()
{
foreach (var view in this.Subviews) {
view.Frame = Bounds;
}
base.LayoutSubviews ();
}
protected override void Dispose (bool disposing)
{
calcQuickView.Dispose ();
base.Dispose (disposing);
}
#endregion
}
public class CalcQuickView : UIScrollView
{
#region Fields
CalcQuickBase calcQuickBase;
UITextField editTextA;
UITextField editTextB;
UITextField editTextC;
UILabel titleLabel;
UILabel expressionTitle;
UILabel descripLabel;
UILabel expression1;
UILabel expression2;
UILabel expression3;
UILabel result1;
UILabel result2;
UILabel result3;
UILabel textA;
UILabel textB;
UILabel textC;
CALayer layer1;
CALayer layer2;
CALayer layer3;
UIButton calculateButton;
NSObject showNotification;
NSObject hideNotification;
#endregion
#region Constructor
public CalcQuickView ()
{
InitializeCalcQuick ();
CreateCalcQuickDesign ();
RegisterForKeyboardNotifications ();
}
#endregion
#region Methods
public override void LayoutSubviews ()
{
this.ContentSize = new CGSize (Frame.Width, 550);
var width = Frame.Width - 20;
var height = Frame.Height;
titleLabel.Frame = new CGRect (5, 15, width, 25);
descripLabel.Frame = new CGRect (5, 45, width, 30);
textA.Frame = new CGRect (5, 70, width / 2 , 40);
editTextA.Frame = new CGRect ((width / 2) + 5, 70, width / 2, 40);
textB.Frame = new CGRect (5, 110, width / 2 , 40);
editTextB.Frame = new CGRect ((width / 2) + 5, 110, width / 2, 40);
textC.Frame = new CGRect (5, 150, width / 2 , 40);
editTextC.Frame = new CGRect ((width / 2) + 5, 150, width / 2, 40);
calculateButton.Frame = new CGRect (5, 200, width, 30);
expressionTitle.Frame = new CGRect (5, 240, width, 30);
expression1.Frame = new CGRect (5, 270, width / 2, 40);
result1.Frame = new CGRect ((width / 2) + 5, 270, width / 2, 40);
layer1.Frame = new CGRect (result1.Bounds.Left, result1.Bounds.Bottom - 5, result1.Bounds.Right, 1);
expression2.Frame = new CGRect (5, 310, width / 2, 40);
result2.Frame = new CGRect ((width / 2) + 5, 310, width / 2, 40);
layer2.Frame = new CGRect (result2.Bounds.Left, result2.Bounds.Bottom - 5, result2.Bounds.Right, 1);
expression3.Frame = new CGRect (5, 350, width / 2, 40);
result3.Frame = new CGRect ((width / 2) + 5, 350, width / 2, 40);
layer3.Frame = new CGRect (result3.Bounds.Left, result3.Bounds.Bottom - 5, result3.Bounds.Right, 1);
base.LayoutSubviews ();
}
private void CreateCalcQuickDesign()
{
#region Header
titleLabel = new UILabel();
titleLabel.Text = "CalcQuick Calculation";
titleLabel.Font = UIFont.FromName ("Helvetica-Bold", 25f);
titleLabel.TextAlignment = UITextAlignment.Center;
descripLabel = new UILabel();
descripLabel.Text = "This sample demonstrates the calculation via keys and expressions using CalcQuick.";
descripLabel.Lines = 0;
descripLabel.LineBreakMode = UILineBreakMode.WordWrap;
descripLabel.Font = UIFont.FromName ("Helvetica", 12f);
#endregion
#region Arguments and Result
textA = CreateLabel ("Key A");
textB = CreateLabel ("Key B");
textC = CreateLabel ("Key C");
expression1 = CreateLabel ("Sum([A],[B],[C])");
expression2 = CreateLabel ("PI()*([A]^2)");
expression3 = CreateLabel ("Concatenate([A],[B],[C])");
layer1 = new CALayer() { BorderWidth = 1 , BorderColor = UIColor.Black.CGColor};
layer2 = new CALayer() { BorderWidth = 1 , BorderColor = UIColor.Black.CGColor};
layer3 = new CALayer() { BorderWidth = 1 , BorderColor = UIColor.Black.CGColor};
result1 = CreateLabel (calcQuickBase["Exp1"]);
result1.Layer.AddSublayer(layer1);
result2 = CreateLabel (calcQuickBase["Exp2"]);
result2.Layer.AddSublayer(layer2);
result3 = CreateLabel (calcQuickBase["Exp3"]);
result3.Layer.AddSublayer(layer3);
editTextA = CreateTextField (calcQuickBase["A"]);
editTextB = CreateTextField (calcQuickBase["B"]);
editTextC = CreateTextField (calcQuickBase["C"]);
expressionTitle = new UILabel();
expressionTitle.Text = "CalcQuick Calculation";
expressionTitle.Font = UIFont.FromName ("Helvetica-Bold", 18f);
#endregion
#region Compute
calculateButton = new UIButton();
calculateButton.SetTitle("Compute", UIControlState.Normal);
calculateButton.Layer.BorderWidth = 1;
calculateButton.Layer.CornerRadius = 4;
calculateButton.SetTitleColor(UIColor.Black,UIControlState.Highlighted);
calculateButton.BackgroundColor = UIColor.LightGray;
calculateButton.TouchUpInside += CalculateButton_TouchUpInside;
#endregion
AddSubview (titleLabel);
AddSubview (descripLabel);
AddSubview (textA);
AddSubview (textB);
AddSubview (textC);
AddSubview (editTextA);
AddSubview (editTextB);
AddSubview (editTextC);
AddSubview (calculateButton);
AddSubview (expressionTitle);
AddSubview (expression1);
AddSubview (expression2);
AddSubview (expression3);
AddSubview (result1);
AddSubview (result2);
AddSubview (result3);
}
private void InitializeCalcQuick()
{
calcQuickBase = new CalcQuickBase();
calcQuickBase.Engine.UseNoAmpersandQuotes = true;
calcQuickBase["A"] = "25";
calcQuickBase["B"] = "50";
calcQuickBase["C"] = "10";
calcQuickBase["Exp1"] = "=Sum([A],[B],[C])";
calcQuickBase["Exp2"] = "=PI()*([A]^2)";
calcQuickBase["Exp3"] = "=Concatenate([A],[B],[C])";
}
private void CalculateButton_TouchUpInside (object sender, EventArgs e)
{
this.EndEditing(true);
calcQuickBase["A"] = editTextA.Text;
calcQuickBase["B"] = editTextB.Text;
calcQuickBase["C"] = editTextC.Text;
calcQuickBase.SetDirty();
result1.Text = calcQuickBase["Exp1"];
result2.Text = calcQuickBase["Exp2"];
result3.Text = calcQuickBase["Exp3"];
}
private UILabel CreateLabel(string text)
{
return new UILabel () {
Text = text,
Font = UIFont.FromName ("Helvetica", 14f)
};
}
private UITextField CreateTextField(string text)
{
var textField = new UITextField () {
Text = text,
Font = UIFont.FromName ("Helvetica", 14f)
};
textField.ResignFirstResponder ();
return textField;
}
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
this.EndEditing(true);
}
protected virtual void RegisterForKeyboardNotifications()
{
hideNotification = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification);
showNotification = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification);
}
private void OnKeyboardNotification (NSNotification notification)
{
var visible = notification.Name == UIKeyboard.WillShowNotification;
var keyboardFrame = visible
? UIKeyboard.FrameEndFromNotification(notification)
: UIKeyboard.FrameBeginFromNotification(notification);
if (visible)
this.SetContentOffset (new CGPoint (this.Frame.Left, (this.Frame.Height - keyboardFrame.Height) / 2), false);
else
this.SetContentOffset (new CGPoint (this.Frame.Left, this.Frame.Top), false);
}
protected override void Dispose (bool disposing)
{
if (calcQuickBase != null) {
calcQuickBase.Dispose ();
calcQuickBase = null;
}
NSNotificationCenter.DefaultCenter.RemoveObserver(showNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver(hideNotification);
base.Dispose (disposing);
}
#endregion
}
}