forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadialMenuCustomization.cs
336 lines (302 loc) · 14.2 KB
/
RadialMenuCustomization.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
#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.Graphics;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Syncfusion.SfRadialMenu.Android;
namespace SampleBrowser
{
public class RadialMenuCustomization : SamplePage
{
LinearLayout mainLayout; double width, height; int buttonCount; float density; DoodleDraw dd;
SfRadialMenu radialMenu;
public override View GetSampleContent(Context context)
{
mainLayout = new LinearLayout(context);
mainLayout.Orientation = Orientation.Vertical;
mainLayout.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
LinearLayout colorPalatte1 = new LinearLayout(context);
height = context.Resources.DisplayMetrics.HeightPixels;
width = context.Resources.DisplayMetrics.WidthPixels;
density = context.Resources.DisplayMetrics.Density;
dd = new DoodleDraw(context);
TextView pickColor = new TextView(context);
pickColor.Text = "Pick Color";
pickColor.TextSize = 20;
pickColor.Left = (int)(5 * density);
pickColor.SetTextColor(Color.Black);
//mainLayout.AddView(pickColor);
buttonCount = (int)(width / (35 * density));
for (int i = 0; i < buttonCount; i++)
{
RoundButton btn = new RoundButton(context, (30 * density), (30 * density), GetRandomColor(), dd);
btn.LayoutParameters = new ViewGroup.LayoutParams((int)(30 * density), (int)(30 * density));
colorPalatte1.AddView(new TextView(context), new ViewGroup.LayoutParams((int)(5 * density), ViewGroup.LayoutParams.MatchParent));
colorPalatte1.AddView(btn);
}
colorPalatte1.SetBackgroundColor(Color.LightGray);
colorPalatte1.SetPadding((int)(10 * density), (int)(10 * density), (int)(10 * density), (int)(10 * density));
colorPalatte1.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
mainLayout.AddView(colorPalatte1);
dd.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
FrameLayout frame = new FrameLayout(context);
frame.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, (int)(0.80 * height));
frame.AddView(dd);
mainLayout.AddView(frame);
Typeface typeface = Typeface.CreateFromAsset(context.Assets, "Android.ttf");
Button touchDraw = new Button(context);
touchDraw.Text = "Touch to draw";
touchDraw.SetTextColor(Color.Blue);
touchDraw.SetBackgroundColor(Color.Transparent);
touchDraw.TextSize = TypedValue.ApplyDimension(ComplexUnitType.Pt, 3, context.Resources.DisplayMetrics);
frame.AddView(touchDraw, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.Center));
radialMenu = new SfRadialMenu(context);
radialMenu.RimColor = Color.Transparent;
FrameLayout penLayout = new FrameLayout(context);
penLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView penImage = new ImageView(context);
penImage.LayoutParameters = penLayout.LayoutParameters;
penImage.SetImageResource(Resource.Drawable.green);
penImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView penText = new TextView(context);
penText.LayoutParameters = penLayout.LayoutParameters;
penText.Text = "L";
penText.Typeface = typeface;
penText.TextSize = 20;
penText.TextAlignment = TextAlignment.Center;
penText.Gravity = GravityFlags.Center;
penText.SetTextColor(Color.White);
penLayout.AddView(penImage);
penLayout.AddView(penText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem pen = new SfRadialMenuItem(context) { View = penLayout, ItemWidth = 70, ItemHeight = 70 };
pen.ItemTapped += Pen_ItemTapped;
radialMenu.Items.Add(pen);
FrameLayout brushLayout = new FrameLayout(context);
brushLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView brushImage = new ImageView(context);
brushImage.LayoutParameters = brushLayout.LayoutParameters;
brushImage.SetImageResource(Resource.Drawable.green);
brushImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView brushText = new TextView(context);
brushText.LayoutParameters = brushLayout.LayoutParameters;
brushText.Text = "A";
brushText.Typeface = typeface;
brushText.TextSize = 20;
brushText.TextAlignment = TextAlignment.Center;
brushText.Gravity = GravityFlags.Center;
brushText.SetTextColor(Color.White);
brushLayout.AddView(brushImage);
brushLayout.AddView(brushText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem brush = new SfRadialMenuItem(context) { View = brushLayout, ItemWidth = 70, ItemHeight = 70 };
brush.SetBackgroundColor(Color.Transparent);
brush.ItemTapped += Brush_ItemTapped; ;
radialMenu.Items.Add(brush);
FrameLayout eraserLayout = new FrameLayout(context);
eraserLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView eraserImage = new ImageView(context);
eraserImage.LayoutParameters = eraserLayout.LayoutParameters;
eraserImage.SetImageResource(Resource.Drawable.green);
eraserImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView eraserText = new TextView(context);
eraserText.LayoutParameters = eraserLayout.LayoutParameters;
eraserText.Text = "R";
eraserText.Typeface = typeface;
eraserText.TextSize = 20;
eraserText.TextAlignment = TextAlignment.Center;
eraserText.Gravity = GravityFlags.Center;
eraserText.SetTextColor(Color.White);
eraserLayout.AddView(eraserImage);
eraserLayout.AddView(eraserText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem eraser = new SfRadialMenuItem(context) { View = eraserLayout, ItemWidth = 70, ItemHeight = 70 };
eraser.ItemTapped += Eraser_ItemTapped;
eraser.SetBackgroundColor(Color.Transparent);
radialMenu.Items.Add(eraser);
FrameLayout clearLayout = new FrameLayout(context);
clearLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView clearImage = new ImageView(context);
clearImage.LayoutParameters = clearLayout.LayoutParameters;
clearImage.SetImageResource(Resource.Drawable.green);
clearImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView clearText = new TextView(context);
clearText.LayoutParameters = clearLayout.LayoutParameters;
clearText.Text = "Q";
clearText.Typeface = typeface;
clearText.TextSize = 20;
clearText.TextAlignment = TextAlignment.Center;
clearText.Gravity = GravityFlags.Center;
clearText.SetTextColor(Color.White);
clearLayout.AddView(clearImage);
clearLayout.AddView(clearText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem clear = new SfRadialMenuItem(context) { View = clearLayout, ItemWidth = 70, ItemHeight = 70 };
clear.ItemTapped += Clear_ItemTapped;
clear.SetBackgroundColor(Color.Transparent);
radialMenu.Items.Add(clear);
FrameLayout thickLayout = new FrameLayout(context);
thickLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView thickImage = new ImageView(context);
thickImage.LayoutParameters = thickLayout.LayoutParameters;
thickImage.SetImageResource(Resource.Drawable.green);
thickImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView thickText = new TextView(context);
thickText.LayoutParameters = thickLayout.LayoutParameters;
thickText.Text = "G";
thickText.Typeface = typeface;
thickText.TextSize = 20;
brushText.TextAlignment = TextAlignment.Center;
thickText.Gravity = GravityFlags.Center;
thickText.SetTextColor(Color.White);
thickLayout.AddView(thickImage);
thickLayout.AddView(thickText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem thickBrush = new SfRadialMenuItem(context) { View = thickLayout, ItemWidth = 70, ItemHeight = 70 };
thickBrush.ItemTapped += ThickBrush_ItemTapped;
thickBrush.SetBackgroundColor(Color.Transparent);
radialMenu.Items.Add(thickBrush);
FrameLayout paintBoxLayout = new FrameLayout(context);
paintBoxLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView paintBoxImage = new ImageView(context);
paintBoxImage.LayoutParameters = paintBoxLayout.LayoutParameters;
paintBoxImage.SetImageResource(Resource.Drawable.green);
paintBoxImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView paintBoxText = new TextView(context);
paintBoxText.LayoutParameters = paintBoxLayout.LayoutParameters;
paintBoxText.Text = "V";
paintBoxText.Typeface = typeface;
paintBoxText.TextSize = 20;
paintBoxText.TextAlignment = TextAlignment.Center;
paintBoxText.Gravity = GravityFlags.Center;
paintBoxText.SetTextColor(Color.White);
paintBoxLayout.AddView(paintBoxImage);
paintBoxLayout.AddView(paintBoxText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
SfRadialMenuItem paintBox = new SfRadialMenuItem(context) { View = paintBoxLayout, ItemWidth = 70, ItemHeight = 70 };
paintBox.ItemTapped += PaintBox_ItemTapped;
paintBox.SetBackgroundColor(Color.Transparent);
radialMenu.Items.Add(paintBox);
FrameLayout menuLayout = new FrameLayout(context);
menuLayout.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
ImageView menuImage = new ImageView(context);
menuImage.LayoutParameters = menuLayout.LayoutParameters;
menuImage.SetImageResource(Resource.Drawable.blue);
menuImage.SetScaleType(ImageView.ScaleType.FitXy);
TextView menuText = new TextView(context);
menuText.LayoutParameters = new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent);
menuText.Text = "U";
menuText.Typeface = typeface;
menuText.TextSize = 40;
menuText.TextAlignment = TextAlignment.Center;
menuText.Gravity = GravityFlags.Center;
menuText.SetTextColor(Color.White);
menuLayout.AddView(menuImage);
menuLayout.AddView(menuText, new ViewGroup.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent));
radialMenu.CenterButtonView = menuLayout;
radialMenu.IsDragEnabled = false;
radialMenu.OuterRimColor = Color.Transparent;
radialMenu.CenterButtonRadius = 30;
radialMenu.RimRadius = 100;
radialMenu.SelectionColor = Color.Transparent;
radialMenu.CenterButtonBackground = Color.Transparent;
frame.AddView(radialMenu, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, GravityFlags.Center));
radialMenu.Point = new Point(0,(int)(context.Resources.DisplayMetrics.HeightPixels / context.Resources.DisplayMetrics.Density / 3.5));
touchDraw.Click += (sender, e) =>
{
touchDraw.Visibility = ViewStates.Gone;
};
return mainLayout;
}
private int getNavigationBarHeight(Android.Content.Context con)
{
int navBarHeight = 0;
int resourceId = con.Resources.GetIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0)
{
navBarHeight = con.Resources.GetDimensionPixelSize(resourceId);
}
return navBarHeight;
}
View GetIconView(Context con, Typeface typeface, string v1, int v2)
{
FrameLayout frame = new FrameLayout(con);
ImageView backImage = new ImageView(con);
backImage.SetScaleType(ImageView.ScaleType.FitXy);
frame.LayoutParameters = new FrameLayout.LayoutParams(v2, v2);
backImage.LayoutParameters = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
frame.AddView(backImage);
TextView menuIcon = new TextView(con);
menuIcon.Text = v1;
menuIcon.TextSize = 10 * density;
menuIcon.Typeface = typeface;
frame.AddView(menuIcon);
return frame;
}
static Random rand = new Random();
public static Color GetRandomColor()
{
Color color = Color.Rgb(rand.Next(255), rand.Next(255), rand.Next(255));
return color;
}
public void OnClick(View v)
{
if (v != null)
{
dd.drawColor = (v as RoundButton).fillColor;
dd.Invalidate();
}
}
void Pen_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.strokeWidth = 2;
dd.isPaintTapped = false;
radialMenu.Close();
//dd.Invalidate();
}
void Brush_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.style = Paint.Style.Stroke;
dd.strokeWidth = 12;
dd.isPaintTapped = false;
radialMenu.Close();
//dd.Invalidate();
}
void ThickBrush_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.style = Paint.Style.Stroke;
dd.strokeWidth = 80;
dd.isPaintTapped = false;
radialMenu.Close();
}
void Eraser_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.style = Paint.Style.Stroke;
dd.strokeWidth = 30;
dd.drawColor = Color.White;
dd.isPaintTapped = false;
radialMenu.Close();
}
void PaintBox_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.isPaintTapped = true;
radialMenu.Close();
}
void Clear_ItemTapped(object sender, RadialMenuItemTappedEventArgs e)
{
dd.isPaintTapped = false;
dd.mCanvas.DrawColor(Color.White, PorterDuff.Mode.Clear);
dd.mPath.Reset();
dd.Invalidate();
radialMenu.Close();
}
}
}