forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rating_Mobile.cs
350 lines (312 loc) · 12 KB
/
Rating_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
#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 System.Collections.Generic;
using Syncfusion.SfRating.iOS;
#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 Rating_Mobile : SampleView
{
UILabel precisionLabel,toolTipLabel,itemCountLabel;
UILabel movieRateLabel,walkLabel,timeLabel,descriptionLabel,rateLabel,valueLabel;
UITextView itemCountTextfield;
UIImageView image1;
UIView customView;
UIButton precisionButton = new UIButton ();
UIButton toolTipButton = new UIButton ();
UIButton doneButton=new UIButton();
UIPickerView precisionPicker, toolTipPicker;
public UIView option=new UIView();
private string selectedType;
SfRating rating2,rating1;
private readonly IList<string> precisionList = new List<string>
{
"Standard",
"Half",
"Exact"
};
private readonly IList<string> toottipplace = new List<string>
{
"TopLeft",
"BottomRight",
"None"
};
public void optionView()
{
this.option.AddSubview (precisionLabel);
this.option.AddSubview (toolTipLabel);
this.option.AddSubview (precisionButton);
this.option.AddSubview (itemCountLabel);
this.option.AddSubview (toolTipButton);
this.option.AddSubview (precisionPicker);
this.option.AddSubview (toolTipPicker);
this.option.AddSubview (doneButton);
this.option.AddSubview (itemCountTextfield);
}
void Rating_ValueChanged(object sender, ValueChangedEventArgs e)
{
UpdateText();
}
public Rating_Mobile()
{
SfRatingSettings ratingSetting1 = new SfRatingSettings();
ratingSetting1.RatedStrokeWidth = 2;
ratingSetting1.UnRatedStrokeWidth = 2;
//Rating 1
rating1 = new SfRating ();
rating1.ItemCount=5;
rating1.Precision= SFRatingPrecision.Standard;
rating1.TooltipPlacement= SFRatingTooltipPlacement.None;
rating1.ItemSize=30;
rating1.RatingSettings = ratingSetting1;
rating1.Value = 3;
rating1.ItemSpacing = 5;
rating1.EnableAutoSize = true;
rating1.ValueChanged += Rating_ValueChanged;
//RatingSettings
SfRatingSettings ratingSetting = new SfRatingSettings ();
ratingSetting.RatedFill = UIColor.FromRGB (251,209,10);
ratingSetting.RatedStroke = UIColor.FromRGB (251,209,10);
//Rating 2
rating2 = new SfRating();
rating2.ItemCount=5;
rating2.RatingSettings = ratingSetting;
rating2.Precision = SFRatingPrecision.Half;
rating2.TooltipPlacement= SFRatingTooltipPlacement.None;
rating2.ItemSize=10;
rating2.Readonly=true;
rating2.Value=(nfloat)3.5;
rating2.ItemSpacing = 5;
this.AddSubview (rating1);
this.AddSubview (rating2);
mainPageDesign();
}
public void mainPageDesign()
{
customView = new UIView();
customView.BackgroundColor = UIColor.FromRGB(165, 165, 165);
this.OptionView = new UIView();
image1 = new UIImageView();
precisionPicker = new UIPickerView();
toolTipPicker = new UIPickerView();
PickerModel model = new PickerModel(precisionList);
precisionPicker.Model = model;
PickerModel model1 = new PickerModel(toottipplace);
toolTipPicker.Model = model1;
precisionLabel = new UILabel();
toolTipLabel = new UILabel();
itemCountLabel = new UILabel();
movieRateLabel = new UILabel();
walkLabel = new UILabel();
timeLabel = new UILabel();
descriptionLabel = new UILabel();
rateLabel = new UILabel();
valueLabel = new UILabel();
precisionButton = new UIButton();
toolTipButton = new UIButton();
image1.Image = UIImage.FromBundle("Images/walk.png");
precisionLabel.Text = "Precision";
precisionLabel.TextColor = UIColor.Black;
precisionLabel.TextAlignment = UITextAlignment.Left;
toolTipLabel.Text = "ToolTip Placement";
toolTipLabel.TextColor = UIColor.Black;
toolTipLabel.TextAlignment = UITextAlignment.Left;
itemCountLabel.Text = "Item Count";
itemCountLabel.TextColor = UIColor.Black;
itemCountLabel.TextAlignment = UITextAlignment.Left;
itemCountLabel.Font = UIFont.FromName("Helvetica", 14f);
movieRateLabel.Text = "Movie Rating";
movieRateLabel.TextColor = UIColor.Black;
movieRateLabel.TextAlignment = UITextAlignment.Left;
movieRateLabel.Font = UIFont.FromName("Helvetica", 22f);
walkLabel.Text = "The Walk (2015)";
walkLabel.TextColor = UIColor.Black;
walkLabel.TextAlignment = UITextAlignment.Left;
walkLabel.Font = UIFont.FromName("Helvetica", 18f);
timeLabel.Text = "PG | 2 h 20 min";
timeLabel.TextColor = UIColor.Black;
timeLabel.TextAlignment = UITextAlignment.Left;
timeLabel.Font = UIFont.FromName("Helvetica", 10f);
descriptionLabel.Text = "In 1974, high-wire artist Philippe Petit recruits a team of people to help him realize his dream: to walk the immense void between the world Trade Centre towers.";
descriptionLabel.TextColor = UIColor.Black;
descriptionLabel.TextAlignment = UITextAlignment.Left;
descriptionLabel.Font = UIFont.FromName("Helvetica", 12f);
descriptionLabel.LineBreakMode = UILineBreakMode.WordWrap;
descriptionLabel.Lines = 0;
rateLabel.Text = "Rate";
rateLabel.TextColor = UIColor.Black;
rateLabel.TextAlignment = UITextAlignment.Left;
rateLabel.Font = UIFont.FromName("Helvetica", 18f);
valueLabel.TextColor = UIColor.Black;
valueLabel.TextAlignment = UITextAlignment.Left;
valueLabel.Font = UIFont.FromName("Helvetica", 14f);
UpdateText();
precisionButton.SetTitle("Standard", UIControlState.Normal);
precisionButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
precisionButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
precisionButton.Layer.CornerRadius = 8;
precisionButton.Layer.BorderWidth = 2;
precisionButton.TouchUpInside += ShowPicker1;
precisionButton.Layer.BorderColor = UIColor.FromRGB(246, 246, 246).CGColor;
toolTipButton.SetTitle("None", UIControlState.Normal);
toolTipButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
toolTipButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
toolTipButton.Layer.CornerRadius = 8;
toolTipButton.Layer.BorderWidth = 2;
toolTipButton.TouchUpInside += ShowPicker2;
toolTipButton.Layer.BorderColor = UIColor.FromRGB(246, 246, 246).CGColor;
doneButton.SetTitle("Done\t", UIControlState.Normal);
doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
doneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
doneButton.TouchUpInside += HidePicker;
doneButton.Hidden = true;
doneButton.BackgroundColor = UIColor.FromRGB(246, 246, 246);
model.PickerChanged += SelectedIndexChanged;
model1.PickerChanged += SelectedIndexChanged1;
precisionPicker.ShowSelectionIndicator = true;
precisionPicker.Hidden = true;
toolTipPicker.Hidden = true;
//precisionPicker.BackgroundColor = UIColor.Gray;
//toolTipPicker.BackgroundColor = UIColor.Gray;
toolTipPicker.ShowSelectionIndicator = true;
itemCountTextfield = new UITextView();
itemCountTextfield.TextAlignment = UITextAlignment.Center;
itemCountTextfield.Layer.BorderColor = UIColor.Black.CGColor;
itemCountTextfield.BackgroundColor = UIColor.FromRGB(246, 246, 246);
itemCountTextfield.KeyboardType = UIKeyboardType.NumberPad;
itemCountTextfield.Text = "5";
itemCountTextfield.Changed += (object sender, EventArgs e) =>
{
if (itemCountTextfield.Text.Length > 0)
{
rating1.ItemCount = int.Parse(itemCountTextfield.Text);
}
else {
rating1.ItemCount = 5;
}
UpdateText();
};
this.AddSubview(movieRateLabel);
this.AddSubview(walkLabel);
this.AddSubview(timeLabel);
this.AddSubview(descriptionLabel);
this.AddSubview(rateLabel);
this.AddSubview(valueLabel);
this.AddSubview(image1);
this.AddSubview(itemCountTextfield);
}
private void UpdateText()
{
nint tempIntValue = (nint)rating1.Value;
nfloat tempFloatValue = rating1.Value;
nfloat differencevalue = tempFloatValue - tempIntValue;
if(differencevalue == 0)
valueLabel.Text = "Rating : "+tempIntValue+" / "+rating1.ItemCount;
else
valueLabel.Text = "Rating : "+ Math.Round (tempFloatValue,1)+" / "+rating1.ItemCount;
}
void ShowPicker1 (object sender, EventArgs e) {
doneButton.Hidden = false;
precisionPicker.Hidden = false;
toolTipPicker.Hidden = true;
itemCountLabel.Hidden = true;
itemCountTextfield.Hidden = true;
}
void HidePicker (object sender, EventArgs e) {
doneButton.Hidden = true;
toolTipPicker.Hidden = true;
precisionPicker.Hidden = true;
itemCountLabel.Hidden = false;
itemCountTextfield.Hidden = false;
}
void ShowPicker2 (object sender, EventArgs e) {
doneButton.Hidden = false;
precisionPicker.Hidden = true;
toolTipPicker.Hidden = false;
itemCountLabel.Hidden = true;
itemCountTextfield.Hidden = true;
}
private void SelectedIndexChanged(object sender, PickerChangedEventArgs e)
{
this.selectedType = e.SelectedValue;
precisionButton.SetTitle (selectedType, UIControlState.Normal);
if (selectedType == "Standard") {
rating1.Precision = SFRatingPrecision.Standard;
} else if (selectedType == "Half") {
rating1.Precision = SFRatingPrecision.Half;
} else if (selectedType == "Exact") {
rating1.Precision = SFRatingPrecision.Exact;
}
}
public override void TouchesBegan (NSSet touches, UIEvent evt){
this.EndEditing (true);
}
private void SelectedIndexChanged1(object sender, PickerChangedEventArgs e)
{
this.selectedType = e.SelectedValue;
toolTipButton.SetTitle (selectedType, UIControlState.Normal);
if (selectedType == "TopLeft") {
rating1.TooltipPlacement = SFRatingTooltipPlacement.TopLeft;
}
else if (selectedType == "BottomRight") {
rating1.TooltipPlacement = SFRatingTooltipPlacement.BottomRight;
}
else if (selectedType == "None")
{
rating1.TooltipPlacement = SFRatingTooltipPlacement.None;
}
}
public override void LayoutSubviews ()
{
foreach (var view in this.Subviews) {
view.Frame = Bounds;
this.OptionView.Frame = view.Frame;
option.Frame = new CGRect (0, 90, Frame.Width, Frame.Height);
customView.Frame = new CGRect (10, 260,view.Frame.Width-20, 1);
rating1.Frame = new CGRect (10,320,270,50);
rating2.Frame = new CGRect (235,80,200,20);
movieRateLabel.Frame = new CGRect (10,10,200,30);
walkLabel.Frame = new CGRect (160,50,160,30);
timeLabel.Frame = new CGRect (160,71,80,30);
if ((UIDevice.CurrentDevice).UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
descriptionLabel.Frame = new CGRect (160, 30, 400, 200);
}
else
descriptionLabel.Frame = new CGRect (160, 70, 150, 200);
rateLabel.Frame = new CGRect (10,280,200,30);
valueLabel.Frame = new CGRect (10,370,200,30);
image1.Frame = new CGRect (10, 50, 140, 180);
precisionLabel.Frame = new CGRect (10,0, this.Frame.Size.Width-10, 30);
toolTipLabel.Frame = new CGRect (10, 80, this.Frame.Size.Width-20, 30);
itemCountLabel.Frame = new CGRect (10, 160,this.Frame.Size.Width-10 , 30);
precisionButton.Frame=new CGRect (10, 40, this.Frame.Size.Width - 20, 30);
toolTipButton.Frame=new CGRect (10, 120, this.Frame.Size.Width - 20, 30);
itemCountTextfield.Frame = new CGRect (230, 160, this.Frame.Size.Width - 250, 30);
precisionPicker.Frame = new CGRect (0, this.Frame.Size.Height/4+50, this.Frame.Size.Width, this.Frame.Size.Height/3-30);
toolTipPicker.Frame = new CGRect (0, this.Frame.Size.Height/4+50, this.Frame.Size.Width , this.Frame.Size.Height/3-30);
doneButton.Frame = new CGRect (0, this.Frame.Size.Height/4+50, this.Frame.Size.Width, 40);
}
this.optionView ();
base.LayoutSubviews ();
}
}
}