forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ranges.cs
307 lines (265 loc) · 11.7 KB
/
Ranges.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
#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 System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.Gauges.SfLinearGauge;
namespace SampleBrowser
{
public class Ranges : SamplePage
{
public static int pointervalue = 35;
LinearLayout range1Layout, range2Layout, range3Layout;
SfLinearGauge linearGauge1, linearGauge2, linearGauge3;
Context context;
public override View GetSampleContent(Android.Content.Context con)
{
context = con;
RangeLayout1();
RangeLayout2();
RangeLayout3();
//Main View
LinearLayout mainLinearGaugeLayout = GetView(con);
ScrollView mainView = new ScrollView(con);
mainView.AddView(mainLinearGaugeLayout);
return mainView;
}
private void RangeLayout1()
{
DisplayMetrics displayMetrics = context.Resources.DisplayMetrics;
float screenHeight = displayMetrics.HeightPixels;
/****************
**Linear Gauge**
****************/
linearGauge1 = new SfLinearGauge(context);
ObservableCollection<LinearScale> scales = new ObservableCollection<LinearScale>();
ObservableCollection<LinearPointer> pointers = new ObservableCollection<LinearPointer>();
ObservableCollection<LinearRange> ranges = new ObservableCollection<LinearRange>();
linearGauge1.SetX(0);
linearGauge1.SetY(0);
linearGauge1.SetBackgroundColor(Color.Rgb(255, 255, 255));
linearGauge1.SetOrientation(SfLinearGauge.Orientation.Horizontal);
//OuterScale
LinearScale outerScale = new LinearScale();
outerScale.Minimum = 0;
outerScale.Maximum = 100;
outerScale.Interval = 25;
outerScale.LabelOffset = 15;
outerScale.ScaleBarColor = Color.Transparent;
outerScale.MinorTicksPerInterval = 0;
outerScale.LabelFontSize = 14;
outerScale.LabelColor = Color.ParseColor("#424242");
outerScale.ShowTicks = false;
//Symbol Pointer
SymbolPointer outerScale_needlePointer = new SymbolPointer();
outerScale_needlePointer.SymbolPosition = SymbolPointerPosition.Far;
outerScale_needlePointer.Value = pointervalue;
outerScale_needlePointer.StrokeWidth = 10;
outerScale_needlePointer.Color = Color.Black;
outerScale_needlePointer.MarkerShape = MarkerShape.InvertedTriangle;
pointers.Add(outerScale_needlePointer);
outerScale.Pointers = pointers;
//Symbol Range
LinearRange range = new LinearRange();
range.StartWidth = 20;
range.EndWidth = 20;
range.Color = Color.ParseColor("#1A237E");
range.StartValue = 0;
range.EndValue = 25;
ranges.Add(range);
//Symbol Range1
LinearRange range1 = new LinearRange();
range1.StartWidth = 20;
range1.EndWidth = 20;
range1.Color = Color.ParseColor("#283593");
range1.StartValue = 25;
range1.EndValue = 50;
ranges.Add(range1);
//Symbol Range2
LinearRange range2 = new LinearRange();
range2.StartWidth = 20;
range2.EndWidth = 20;
range2.Color = Color.ParseColor("#3F51B5");
range2.StartValue = 50;
range2.EndValue = 75;
ranges.Add(range2);
//Symbol Range3
LinearRange range3 = new LinearRange();
range3.StartWidth = 20;
range3.EndWidth = 20;
range3.Color = Color.ParseColor("#5C6BC0");
range3.StartValue = 75;
range3.EndValue = 100;
ranges.Add(range3);
outerScale.Ranges = ranges;
scales.Add(outerScale);
linearGauge1.Scales = scales;
linearGauge1.LayoutParameters = (new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, (int)(screenHeight / 4)));
//Range Layout
range1Layout = new LinearLayout(context);
range1Layout.SetGravity(GravityFlags.Center);
range1Layout.AddView(linearGauge1);
}
private void RangeLayout2()
{
DisplayMetrics displayMetrics = context.Resources.DisplayMetrics;
float screenHeight = displayMetrics.HeightPixels;
/****************
**Linear Gauge**
****************/
linearGauge2 = new SfLinearGauge(context);
ObservableCollection<LinearScale> scales = new ObservableCollection<LinearScale>();
ObservableCollection<LinearPointer> pointers = new ObservableCollection<LinearPointer>();
ObservableCollection<LinearRange> ranges = new ObservableCollection<LinearRange>();
linearGauge2.SetX(0);
linearGauge2.SetY(0);
linearGauge2.SetBackgroundColor(Color.Rgb(255, 255, 255));
linearGauge2.SetOrientation(SfLinearGauge.Orientation.Horizontal);
//OuterScale
LinearScale outerScale = new LinearScale();
outerScale.Minimum = 0;
outerScale.Maximum = 100;
outerScale.Interval = 25;
outerScale.ScaleBarColor = Color.Transparent;
outerScale.MinorTicksPerInterval = 0;
outerScale.LabelFontSize = 14;
outerScale.LabelOffset = 23;
outerScale.LabelColor = Color.ParseColor("#424242");
outerScale.ShowTicks = false;
//Symbol Pointer
SymbolPointer outerScale_needlePointer = new SymbolPointer();
outerScale_needlePointer.SymbolPosition = SymbolPointerPosition.Far;
outerScale_needlePointer.Value = pointervalue;
outerScale_needlePointer.StrokeWidth = 10;
outerScale_needlePointer.Color = Color.Black;
outerScale_needlePointer.MarkerShape = MarkerShape.InvertedTriangle;
pointers.Add(outerScale_needlePointer);
outerScale.Pointers = pointers;
//Symbol Range
LinearRange range = new LinearRange();
range.StartWidth = 10;
range.EndWidth = 15;
range.Color = Color.ParseColor("#6de500");
range.StartValue = 0;
range.EndValue = 25;
ranges.Add(range);
//Symbol Range1
LinearRange range1 = new LinearRange();
range1.StartWidth = 15;
range1.EndWidth = 20;
range1.Color = Color.ParseColor("#53ad00");
range1.StartValue = 25;
range1.EndValue = 50;
ranges.Add(range1);
//Symbol Range2
LinearRange range2 = new LinearRange();
range2.StartWidth = 20;
range2.EndWidth = 25;
range2.Color = Color.ParseColor("#009148");
range2.StartValue = 50;
range2.EndValue = 75;
ranges.Add(range2);
//Symbol Range3
LinearRange range3 = new LinearRange();
range3.StartWidth = 25;
range3.EndWidth = 30;
range3.Color = Color.ParseColor("#026623");
range3.StartValue = 75;
range3.EndValue = 100;
ranges.Add(range3);
outerScale.Ranges = ranges;
scales.Add(outerScale);
linearGauge2.Scales = scales;
linearGauge2.LayoutParameters = (new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, (int)screenHeight / 4));
//Range Layout
range2Layout = new LinearLayout(context);
range2Layout.SetGravity(GravityFlags.Center);
range2Layout.AddView(linearGauge2);
}
private void RangeLayout3()
{
DisplayMetrics displayMetrics = context.Resources.DisplayMetrics;
float screenHeight = displayMetrics.HeightPixels;
/****************
**Linear Gauge**
****************/
linearGauge3 = new SfLinearGauge(context);
ObservableCollection<LinearScale> scales = new ObservableCollection<LinearScale>();
ObservableCollection<LinearPointer> pointers = new ObservableCollection<LinearPointer>();
ObservableCollection<LinearRange> ranges = new ObservableCollection<LinearRange>();
linearGauge3.SetX(0);
linearGauge3.SetY(0);
linearGauge3.SetBackgroundColor(Color.Rgb(255, 255, 255));
linearGauge3.SetOrientation(SfLinearGauge.Orientation.Horizontal);
//OuterScale
LinearScale outerScale = new LinearScale();
outerScale.LabelFontSize = 14;
outerScale.Interval = 25;
outerScale.LabelOffset = 15;
outerScale.ScaleBarSize = 20;
outerScale.ScaleBarColor = Color.Transparent;
outerScale.LabelColor = Color.ParseColor("#424242");
outerScale.ShowTicks = false;
//Symbol Pointer
SymbolPointer outerScale_needlePointer = new SymbolPointer();
outerScale_needlePointer.SymbolPosition = SymbolPointerPosition.Far;
outerScale_needlePointer.Value = pointervalue;
outerScale_needlePointer.StrokeWidth = 10;
outerScale_needlePointer.Color = Color.Black;
outerScale_needlePointer.MarkerShape = MarkerShape.InvertedTriangle;
pointers.Add(outerScale_needlePointer);
outerScale.Pointers = pointers;
//Symbol Range
LinearRange range = new LinearRange();
range.StartWidth = 20;
range.EndWidth = 20;
range.StartValue = 0;
range.EndValue = 100;
ranges.Add(range);
outerScale.Ranges = ranges;
range.GradientStops = new ObservableCollection<GaugeGradientStop>()
{
new GaugeGradientStop() { Value = 0, Color = Color.ParseColor("#FFF9C2C3") },
new GaugeGradientStop() { Value = 100, Color = Color.ParseColor("#FFD91D71") }
};
scales.Add(outerScale);
linearGauge3.Scales = scales;
linearGauge3.LayoutParameters = (new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WrapContent, (int)screenHeight / 4));
//Range Layout
range3Layout = new LinearLayout(context);
range3Layout.SetGravity(GravityFlags.Center);
range3Layout.AddView(linearGauge3);
}
private LinearLayout GetView(Context con)
{
//Ranges Layout
LinearLayout rangesLayout = new LinearLayout(con);
rangesLayout.Orientation = Orientation.Vertical;
rangesLayout.AddView(range1Layout);
rangesLayout.AddView(range2Layout);
rangesLayout.AddView(range3Layout);
rangesLayout.SetGravity(GravityFlags.Center);
//Main Layout
LinearLayout mainLayout = new LinearLayout(con);
mainLayout.AddView(rangesLayout);
mainLayout.SetBackgroundColor(Color.White);
mainLayout.SetGravity(GravityFlags.Center);
return mainLayout;
}
}
}