forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCarousel_Mobile.cs
291 lines (247 loc) · 11.1 KB
/
Carousel_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
#region Copyright Syncfusion Inc. 2001-2021.
// Copyright Syncfusion Inc. 2001-2021. 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.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Com.Syncfusion.Carousel;
using Java.Util;
using Android.Graphics;
namespace SampleBrowser
{
public class Carousel_Mobile
{
/*********************************
**Local Variable Inizialisation**
*********************************/
LinearLayout.LayoutParams lineParams, labelParams, entryParams, adjustParams, lineParams2;
LinearLayout propertylayout, offSetStack, scaleStack, rotateStack;
EditText offSet, scaleOffset, RotateAngle;
SfCarousel carousel;
int offSetValue = 60, RotationAngleValue = 45, width;
double scaleOffsetValue = 0.8;
Spinner tickSpinner;
ArrayAdapter<String> dataAdapter;
ViewMode viewMode;
Context context;
public View GetSampleContent(Context context1)
{
context = context1;
carousel = new SfCarousel(context);
List<SfCarouselItem> tempCollection = new List<SfCarouselItem>();
for (int i = 1; i <= 7; i++)
{
SfCarouselItem carouselItem = new SfCarouselItem(context);
carouselItem.ImageName = "images" + i;
tempCollection.Add(carouselItem);
}
carousel.DataSource = tempCollection;
carousel.SelectedIndex = 3;
carousel.ScaleOffset = 0.8f;
if (context.Resources.DisplayMetrics.Density > 1.5)
{
carousel.ItemHeight = Convert.ToInt32(250 * context.Resources.DisplayMetrics.Density);
carousel.ItemWidth = Convert.ToInt32(180 * context.Resources.DisplayMetrics.Density);
}
carousel.LayoutParameters = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
return carousel;
}
public View GetPropertyWindowLayout(Context context)
{
int dp = (int)context.Resources.DisplayMetrics.Density;
width = (context.Resources.DisplayMetrics.WidthPixels) / 2;
propertylayout = new LinearLayout(context);
propertylayout.Orientation = Orientation.Vertical;
offsetLayout();
ScaleOffsetLayout();
RotationAngleLayout();
VisualModeLayout();
return propertylayout;
}
private void offsetLayout()
{
lineParams = new LinearLayout.LayoutParams(width * 2, 5);
lineParams.SetMargins(0, 10, 0, 0);
//labelParams
labelParams = new LinearLayout.LayoutParams(width, ViewGroup.LayoutParams.MatchParent);
labelParams.SetMargins(0, 5, 0, 0);
entryParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
adjustParams = new LinearLayout.LayoutParams(width / 3, ViewGroup.LayoutParams.WrapContent);
entryParams.SetMargins(0, 5, 20, 0);
propertylayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
propertylayout.SetBackgroundColor(Color.White);
//offsetLabel
TextView offsetLabel = new TextView(context);
offsetLabel.Text = "Offset";
offsetLabel.TextSize = 20;
offsetLabel.Gravity = GravityFlags.CenterVertical;
offSetStack = new LinearLayout(context);
TextView centerLabel1 = new TextView(context);
//offSet
offSet = new EditText(context);
offSet.Text = "60";
offSet.InputType = Android.Text.InputTypes.ClassNumber;
offSet.TextSize = 20;
offSet.SetTextColor(Color.Black);
offSetStack.AddView(offsetLabel, labelParams);
offSetStack.AddView(centerLabel1, adjustParams);
offSetStack.SetGravity(GravityFlags.Center);
offSetStack.AddView(offSet, entryParams);
offSetStack.Orientation = Orientation.Horizontal;
propertylayout.AddView(offSetStack);
//offSet TextChanged Listener
offSet.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
if (offSet.Text.Length > 0)
{
int i = Convert.ToInt32(e.Text.ToString());
if (i >= 40 && i <= 100)
offSetValue = i;
else
offSetValue = 60;
}
};
//lineParams
lineParams2 = new LinearLayout.LayoutParams(width * 2, 5);
lineParams2.SetMargins(0, 20, 0, 0);
}
private void ScaleOffsetLayout()
{
//scaleLabel
TextView scaleLabel = new TextView(context);
scaleLabel.Text = "Scale Offset";
scaleLabel.TextSize = 20;
scaleLabel.Gravity = GravityFlags.CenterVertical;
scaleStack = new LinearLayout(context);
TextView centerLabel2 = new TextView(context);
TextView textSpacing = new TextView(context);
propertylayout.AddView(textSpacing);
//scaleOffset
scaleOffset = new EditText(context);
scaleOffset.InputType = Android.Text.InputTypes.NumberFlagDecimal | Android.Text.InputTypes.NumberFlagSigned | Android.Text.InputTypes.ClassNumber;
scaleOffset.TextSize = 20;
scaleOffset.Text = "0.8";
scaleOffset.SetTextColor(Color.Black);
scaleStack.AddView(scaleLabel, labelParams);
scaleStack.AddView(centerLabel2, adjustParams);
scaleStack.AddView(scaleOffset, entryParams);
scaleStack.SetGravity(GravityFlags.Center);
scaleStack.Orientation = Orientation.Horizontal;
propertylayout.AddView(scaleStack);
//scaleOffset TextChanged Listener
scaleOffset.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
if (scaleOffset.Text.Length > 0)
{
float i = (float)Convert.ToDouble(e.Text.ToString());
if (i >= 0.5 && i <= 1)
scaleOffsetValue = i;
else
scaleOffsetValue = 0.8;
}
};
}
private void RotationAngleLayout()
{
//rotateLabel
TextView rotateLabel = new TextView(context);
rotateLabel.Text = "Rotation Angle";
rotateLabel.TextSize = 20;
rotateLabel.Gravity = GravityFlags.CenterVertical;
rotateStack = new LinearLayout(context);
TextView centerLabel3 = new TextView(context);
TextView textSpacing = new TextView(context);
propertylayout.AddView(textSpacing);
//RotateAngle
RotateAngle = new EditText(context);
RotateAngle.InputType = Android.Text.InputTypes.ClassNumber;
RotateAngle.TextSize = 20;
RotateAngle.Text = "45";
RotateAngle.SetTextColor(Color.Black);
rotateStack.AddView(rotateLabel, labelParams);
rotateStack.AddView(centerLabel3, adjustParams);
rotateStack.AddView(RotateAngle, entryParams);
rotateStack.SetGravity(GravityFlags.Center);
rotateStack.Orientation = Orientation.Horizontal;
propertylayout.AddView(rotateStack);
//RotateAngle TextChanged Listener
RotateAngle.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
if (RotateAngle.Text.Length > 0)
{
int i = Convert.ToInt32(e.Text.ToString());
if (i >= 0 && i <= 360)
RotationAngleValue = i;
else
RotationAngleValue = 45;
}
};
propertylayout.SetPadding(5, 0, 5, 0);
}
private void VisualModeLayout()
{
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width * 2, 5);
layoutParams.SetMargins(0, 5, 0, 0);
TextView adjLabe5 = new TextView(context);
propertylayout.AddView(adjLabe5);
//Visual Mode
TextView placementLabel = new TextView(context);
placementLabel.Text = "View Mode";
placementLabel.TextSize = 20;
placementLabel.Typeface = Typeface.Create("Roboto", TypefaceStyle.Normal);
placementLabel.SetTextColor(Color.Black);
placementLabel.Gravity = GravityFlags.Left;
TextView adjLabel2 = new TextView(context);
adjLabel2.SetHeight(14);
//tickSpinner
tickSpinner = new Spinner(context,SpinnerMode.Dialog);
tickSpinner.SetPadding(0, 0, 0, 0);
propertylayout.AddView(placementLabel);
SeparatorView separate = new SeparatorView(context, width * 2);
separate.LayoutParameters = new ViewGroup.LayoutParams(width * 2, 5);
//adjLabel
TextView adjLabel3 = new TextView(context);
adjLabel3.SetHeight(20);
propertylayout.AddView(tickSpinner);
TextView adjLabel4 = new TextView(context);
propertylayout.AddView(adjLabel4);
//positionList
List<String> positionList = new List<String>();
positionList.Add("Default");
positionList.Add("Linear");
//dataAdapter
dataAdapter = new ArrayAdapter<String>(context, Android.Resource.Layout.SimpleSpinnerItem, positionList);
dataAdapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
//tickSpinner
tickSpinner.Adapter = dataAdapter;
tickSpinner.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
{
String selectedItem = dataAdapter.GetItem(e.Position);
if (selectedItem.Equals("Default"))
{
viewMode = ViewMode.Default;
}
else if (selectedItem.Equals("Linear"))
{
viewMode = ViewMode.Linear;
}
};
}
public void OnApplyChanges()
{
carousel.Offset = offSetValue;
carousel.RotationAngle = RotationAngleValue;
carousel.ScaleOffset = (float)scaleOffsetValue;
carousel.ViewMode = viewMode;
}
}
}