[NUI] Remove build warning messages in NUI Samples (#4932)
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Samples / Tizen.NUI.Samples / Samples / ItemViewDemo / ItemViewSample.cs
1 using System;
2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.Components;
4
5 namespace Tizen.NUI.Samples
6 {
7     public class ZItemViewSample : IExample
8     {
9         private const float MIN_SWIPE_DISTANCE = 15.0f;
10         private const float MIN_SWIPE_SPEED = 5.0f;
11         private const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.0f;
12         private const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
13         private const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
14         private const float DEPTH_LAYOUT_COLUMNS = 3.0f;
15         private const int BUTTON_BORDER = -10;
16         private const float ITEM_BORDER_SIZE = 2.0f;
17         private const int ITEM_COUNT = 300;
18
19         private string APPLICATION_TITLE = "ItemView";
20         private string SPIRAL_LABEL = "Spiral";
21         private string GRID_LABEL = "Grid";
22         private string DEPTH_LABEL = "Depth";
23
24         private string TOOLBAR_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/top-bar.png";
25         private string EDIT_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-edit.png";
26         private string EDIT_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-edit-selected.png";
27         private string DELETE_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-delete.png";
28         private string DELETE_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-delete-selected.png";
29         private string REPLACE_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-replace.png";
30         private string REPLACE_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-replace-selected.png";
31         private string INSERT_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-insert.png";
32         private string INSERT_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-insert-selected.png.png";
33         private string SELECTED_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/item-select-check.png";
34
35         private string SPIRAL_LAYOUT_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-spiral.png";
36         private string SPIRAL_LAYOUT_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-spiral-selected.png";
37         private string GRID_LAYOUT_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-grid.png";
38         private string GRID_LAYOUT_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-grid-selected.png";
39         private string DEPTH_LAYOUT_IMAGE = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-depth.png";
40         private string DEPTH_LAYOUT_IMAGE_SELECTED = CommonResource.GetDaliResourcePath() + "ItemViewDemo/icon-item-view-layout-depth-selected.png";
41
42         private ItemView mItemView;
43         private ItemFactoryWrapper mItemFactoryWrapper;
44         private PropertyMap mGridLayout;
45         private PropertyMap mDepthLayout;
46         private PropertyMap mSpiralLayout;
47         private PropertyArray mLayout;
48         private int mCurrentLayout = (int)AllImagesLayouts.SPIRAL_LAYOUT;
49         private Mode mMode = Mode.MODE_NORMAL;
50
51         private LongPressGestureDetector mLongPressGestureDetector;
52         private TapGestureDetector mTapDetector;
53
54         private Button mLayoutButton;
55         private Button mEditButton;
56         private Button mDeleteButton;
57         private Button mInsertButton;
58         private Button mReplaceButton;
59         private TextLabel mTitle;
60
61         private Layer mDefaultLayer;
62         private View mRootView;
63         private View mToolBarLayer;
64         private View mContentView;
65
66         private int mDurationSeconds = 250;
67
68         public static Vector3 DepthLayoutItemSizeFunctionPortrait(float layoutWidth)
69         {
70             float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
71
72             // 1x1 aspect ratio
73             return new Vector3(width, width, width);
74         }
75
76         public static Vector3 DepthLayoutItemSizeFunctionLandscape(float layoutWidth)
77         {
78             float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
79
80             // 1x1 aspect ratio
81             return new Vector3(width, width, width);
82         }
83
84         private void SetTitle(string title)
85         {
86             if (mTitle != null)
87             {
88                 mTitle.Text = title;
89             }
90         }
91
92         public void CreateGridLayout()
93         {
94             mGridLayout = new PropertyMap();
95             mGridLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.GRID));
96         }
97
98         public void CreateDepthLayout()
99         {
100             mDepthLayout = new PropertyMap();
101             mDepthLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.DEPTH));
102         }
103
104         public void CreateSpiralLayout()
105         {
106             mSpiralLayout = new PropertyMap();
107             mSpiralLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.SPIRAL));
108         }
109
110         void SetLayoutImage()
111         {
112             if (mLayoutButton)
113             {
114                 switch (mCurrentLayout)
115                 {
116                     case (int)AllImagesLayouts.SPIRAL_LAYOUT:
117                         {
118                             var style = mLayoutButton.Style;
119                             style.BackgroundImage = new Selector<string>() { Normal = SPIRAL_LAYOUT_IMAGE, Selected = SPIRAL_LAYOUT_IMAGE_SELECTED };
120                             mLayoutButton.ApplyStyle(style);
121                             break;
122                         }
123
124                     case (int)AllImagesLayouts.GRID_LAYOUT:
125                         {
126                             var style = mLayoutButton.Style;
127                             style.BackgroundImage = new Selector<string>() { Normal = GRID_LAYOUT_IMAGE, Selected = GRID_LAYOUT_IMAGE_SELECTED };
128                             mLayoutButton.ApplyStyle(style);
129                             break;
130                         }
131
132                     case (int)AllImagesLayouts.DEPTH_LAYOUT:
133                         {
134                             var style = mLayoutButton.Style;
135                             style.BackgroundImage = new Selector<string>() { Normal = DEPTH_LAYOUT_IMAGE, Selected = DEPTH_LAYOUT_IMAGE_SELECTED };
136                             mLayoutButton.ApplyStyle(style);
137                             break;
138                         }
139                     default:
140                         break;
141                 }
142             }
143         }
144
145         void ChangeLayout()
146         {
147             Animation animation = new Animation(mDurationSeconds);
148             animation.Finished += AnimationFinished;
149             animation.AnimateTo(mItemView, "Opacity", 0.0f);
150             animation.Play();
151         }
152
153         void AnimationFinished(object sender, EventArgs e)
154         {
155             SetLayout(mCurrentLayout);
156             Animation animation = new Animation(mDurationSeconds);
157             animation.AnimateTo(mItemView, "Opacity", 1.0f);
158             animation.Play();
159         }
160
161         private PropertyMap CreateImageVisual(string url)
162         {
163             PropertyMap temp = new PropertyMap();
164             temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
165             temp.Insert(ImageVisualProperty.URL, new PropertyValue(url));
166             return temp;
167         }
168
169         public void Activate()
170         {
171             Window window = NUIApplication.GetDefaultWindow();
172             mDefaultLayer = window.GetDefaultLayer();
173             mDefaultLayer.Behavior = Layer.LayerBehavior.Layer3D;
174             window.BackgroundColor = Color.Black;
175
176             mRootView = new View()
177             {
178                 Size = new Size(1920, 1080)
179             };
180             mRootView.Layout = new LinearLayout()
181             {
182                 LinearOrientation = LinearLayout.Orientation.Vertical
183             };
184             mDefaultLayer.Add(mRootView);
185
186             CreateToolBarLayer();
187             CreateContentView();
188
189             CreateInsertButton();
190             CreateReplaceButton();
191             CreateDeleteButton();
192
193             CreateSpiralLayout();
194             CreateGridLayout();
195             CreateDepthLayout();
196
197             mLayout = new PropertyArray();
198             mLayout.PushBack(new PropertyValue(mSpiralLayout));
199             mLayout.PushBack(new PropertyValue(mDepthLayout));
200             mLayout.PushBack(new PropertyValue(mGridLayout));
201
202             mItemFactoryWrapper = new ItemFactoryWrapper();
203             mItemFactoryWrapper.GetNumberDelegate = GetNumberOfItems;
204             mItemFactoryWrapper.NewItemDelegate = NewItemView;
205
206             mItemView = new ItemView(mItemFactoryWrapper)
207             { 
208                 Size = new Size(800, 800, 800)
209             };
210             mContentView.Add(mItemView);
211
212             mItemView.Layout = mLayout;
213             mItemView.MinimumSwipeDistance = MIN_SWIPE_DISTANCE;
214             mItemView.MinimumSwipeSpeed = MIN_SWIPE_SPEED;
215
216             SetLayout((int)mCurrentLayout);
217             SetLayoutTitle();
218             SetLayoutImage();
219
220             mLongPressGestureDetector = new LongPressGestureDetector();
221             mLongPressGestureDetector.Attach(mItemView);
222             mLongPressGestureDetector.Detected += OnLongPressGestureDetected;
223         }
224
225         private void OnLongPressGestureDetected(object source, LongPressGestureDetector.DetectedEventArgs e)
226         {
227             switch (e.LongPressGesture.State)
228             {
229                 case Gesture.StateType.Started:
230                     {
231                         Size windowSize = NUIApplication.GetDefaultWindow().Size;
232                         ItemRange range = new ItemRange(0, 0);
233                         mItemView.GetItemsRange(range);
234
235                         uint item = (e.LongPressGesture.ScreenPoint.Y < 0.5f * (float)windowSize.Height) ? range.begin : range.end;
236
237                         mItemView.ScrollToItem(item, SCROLL_TO_ITEM_ANIMATION_TIME);
238
239                         break;
240                     }
241                 case Gesture.StateType.Finished:
242                     {
243                         PropertyMap attributes = new PropertyMap();
244                         mItemView.DoAction("stopScrolling", attributes);
245                         break;
246                     }
247                 default:
248                     {
249                         break;
250                     }
251             }
252         }
253
254         void SetLayout(int layoutId)
255         {
256             Window window = NUIApplication.GetDefaultWindow();
257             switch (mCurrentLayout)
258             {
259                 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
260                 case (int)AllImagesLayouts.DEPTH_LAYOUT:
261                     {
262                         window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
263                         break;
264                     }
265                 case (int)AllImagesLayouts.GRID_LAYOUT:
266                     {
267                         window.GetDefaultLayer().Behavior = Layer.LayerBehavior.LayerUI;
268                         break;
269                     }
270             }
271
272             Size windowSize = window.Size;
273
274             if (layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT)
275             {
276                 mDepthLayout.Insert((int)DefaultItemLayoutProperty.ITEM_SIZE, new PropertyValue(DepthLayoutItemSizeFunctionPortrait(800)));
277                 mLayout.Clear();
278                 mLayout.PushBack(new PropertyValue(mSpiralLayout));
279                 mLayout.PushBack(new PropertyValue(mDepthLayout));
280                 mLayout.PushBack(new PropertyValue(mGridLayout));
281                 mItemView.Layout = mLayout;
282             }
283
284             // Enable anchoring for depth layout only
285             mItemView.SetAnchoring(layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT);
286
287             // Activate the layout
288             mItemView.ActivateLayout((uint)layoutId, new Vector3(800, 800, 800), 0.0f);
289         }
290
291         public uint GetNumberOfItems()
292         {
293             return ITEM_COUNT;
294         }
295
296         public View NewItemView(uint itemId)
297         {
298             // Create an image view for this item
299             string imagePath = CommonResource.GetDaliResourcePath() + "ItemViewDemo/gallery/gallery-medium-";
300             uint id = itemId % 53;
301             imagePath += id.ToString();
302             imagePath += ".jpg";
303             PropertyMap propertyMap = new PropertyMap();
304             propertyMap.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
305             propertyMap.Insert(ImageVisualProperty.URL, new PropertyValue(imagePath));
306             propertyMap.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)VisualFittingModeType.FitKeepAspectRatio));
307             ImageView actor = new ImageView();
308             actor.Image = propertyMap;
309
310             // Add a border image child actor
311             ImageView borderActor = new ImageView();
312             borderActor.ParentOrigin = ParentOrigin.Center;
313             borderActor.PivotPoint = PivotPoint.Center;
314             borderActor.PositionUsesPivotPoint = true;
315             borderActor.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
316             borderActor.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
317             borderActor.SetSizeModeFactor(new Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f));
318             borderActor.SetColorMode(ColorMode.UseParentColor);
319
320             PropertyMap borderProperty = new PropertyMap();
321             borderProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Border));
322             borderProperty.Insert(BorderVisualProperty.Color, new PropertyValue(Color.White));
323             borderProperty.Insert(BorderVisualProperty.Size, new PropertyValue(ITEM_BORDER_SIZE));
324             borderProperty.Insert(BorderVisualProperty.AntiAliasing, new PropertyValue(true));
325             borderActor.Image = borderProperty;
326
327             actor.Add(borderActor);
328
329             Size spiralItemSize = new Size(30, 30, 0);
330             // Add a checkbox child actor; invisible until edit-mode is enabled
331             ImageView checkBox = new ImageView();
332             checkBox.Name = "CheckBox";
333             checkBox.SetColorMode(ColorMode.UseParentColor);
334             checkBox.ParentOrigin = ParentOrigin.TopRight;
335             checkBox.PivotPoint = PivotPoint.TopRight;
336             checkBox.Size = spiralItemSize;
337             checkBox.PositionZ = 0.1f;
338             
339             PropertyMap solidColorProperty = new PropertyMap();
340             solidColorProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color));
341             solidColorProperty.Insert(ColorVisualProperty.MixColor, new PropertyValue(new Color(0.0f, 0.0f, 0.0f, 0.6f)));
342             checkBox.Image = solidColorProperty;
343
344             if (Mode.MODE_REMOVE_MANY != mMode &&
345                 Mode.MODE_INSERT_MANY != mMode &&
346                 Mode.MODE_REPLACE_MANY != mMode)
347             {
348                 checkBox.Hide();
349             }
350             borderActor.Add(checkBox);
351
352             ImageView tick = new ImageView(SELECTED_IMAGE);
353             tick.Name = "Tick";
354             tick.ParentOrigin = ParentOrigin.TopRight;
355             tick.PivotPoint = PivotPoint.TopRight;
356             tick.Size = spiralItemSize;
357             tick.Hide();
358             checkBox.Add(tick);
359
360             if (mTapDetector)
361             {
362                 mTapDetector.Attach(actor);
363             }
364             return actor;
365         }
366
367         public void Deactivate()
368         {
369             if (mEditButton != null)
370             {
371                 mToolBarLayer.Remove(mEditButton);
372                 mEditButton.Dispose();
373                 mEditButton = null;
374             }
375
376             if (mTitle != null)
377             {
378                 mToolBarLayer.Remove(mTitle);
379                 mTitle.Dispose();
380                 mTitle = null;
381             }
382
383             if (mLayoutButton != null)
384             {
385                 mToolBarLayer.Remove(mLayoutButton);
386                 mLayoutButton.Dispose();
387                 mLayoutButton = null;
388             }
389
390             if (mToolBarLayer != null)
391             {
392                 mRootView.Remove(mToolBarLayer);
393                 mToolBarLayer.Dispose();
394                 mToolBarLayer = null;
395             }
396
397             if (mReplaceButton != null)
398             {
399                 mReplaceButton.GetParent().Remove(mReplaceButton);
400                 mReplaceButton.Dispose();
401                 mReplaceButton = null;
402             }
403
404             if (mInsertButton != null)
405             {
406                 mInsertButton.GetParent().Remove(mInsertButton);
407                 mInsertButton.Dispose();
408                 mInsertButton = null;
409             }
410
411             if (mDeleteButton != null)
412             {
413                 mDeleteButton.GetParent().Remove(mDeleteButton);
414                 mDeleteButton.Dispose();
415                 mDeleteButton = null;
416             }
417
418             if (mItemView != null)
419             {
420                 mContentView.Remove(mItemView);
421                 mItemView.Dispose();
422                 mItemView = null;
423             }
424
425             if (mContentView != null)
426             {
427                 mRootView.Remove(mContentView);
428                 mContentView.Dispose();
429                 mContentView = null;
430             }
431
432             if (mRootView != null)
433             {
434                 mDefaultLayer.Remove(mRootView);
435                 mRootView.Dispose();
436                 mRootView = null;
437             }
438
439             NUIApplication.GetDefaultWindow().GetDefaultLayer().Behavior = Layer.LayerBehavior.LayerUI;
440         }
441
442         public void CreateContentView()
443         {
444             mContentView = new View()
445             {
446                 Size = new Size(1920, 1080)
447             };
448             mContentView.Layout = new LinearLayout()
449             {
450                 LinearOrientation = LinearLayout.Orientation.Horizontal,
451                 HorizontalAlignment = HorizontalAlignment.Center,
452                 VerticalAlignment = VerticalAlignment.Center,
453             };
454             mRootView.Add(mContentView);
455         }
456
457
458         private void CreateToolBarLayer()
459         {
460             mToolBarLayer = new View()
461             {
462                 Name = "TOOLBAR",
463                 Size = new Size(1920, 80),
464                 BackgroundImage = TOOLBAR_IMAGE
465             };
466             mToolBarLayer.Layout = new LinearLayout()
467             {
468                 LinearOrientation = LinearLayout.Orientation.Horizontal,
469                 HorizontalAlignment = HorizontalAlignment.Center,
470                 VerticalAlignment = VerticalAlignment.Center,
471             };
472             mRootView.Add(mToolBarLayer);
473             mToolBarLayer.RaiseToTop();
474
475             CreateEditButton();
476             CreateToolBarTitle();
477             CreateLayoutButton();
478         }
479
480         public void CreateEditButton()
481         {
482             mEditButton = new Button();
483             var mEditButtonStyle = new ButtonStyle
484             {
485                 Text = null,
486                 BackgroundColor = new Selector<Color>(),
487                 BackgroundImage = new Selector<string>() { Normal = EDIT_IMAGE, Selected = EDIT_IMAGE_SELECTED }
488             };
489             mEditButton.ApplyStyle(mEditButtonStyle);
490             mEditButton.IsSelectable = true;
491             mEditButton.Size = new Size(34, 34);
492             mEditButton.LeaveRequired = true;
493             mEditButton.Clicked += (obj, e) =>
494             {
495                 SwitchToNextMode();
496             };
497             mToolBarLayer.Add(mEditButton);
498         }
499
500         private void CreateToolBarTitle()
501         {
502             mTitle = new TextLabel();
503             mTitle.Size = new Size(1800, 80);
504             mTitle.PointSize = 10.0f;
505             mTitle.Text = APPLICATION_TITLE;
506             mTitle.VerticalAlignment = VerticalAlignment.Center;
507             mTitle.HorizontalAlignment = HorizontalAlignment.Center;
508             mToolBarLayer.Add(mTitle);
509         }
510
511         private void CreateLayoutButton()
512         {
513             mLayoutButton = new Button();
514             var mLayoutButtonStyle = new ButtonStyle
515             {
516                 Text = null,
517                 BackgroundImage = new Selector<string>()
518                 {
519                     Normal = SPIRAL_LAYOUT_IMAGE,
520                     Selected = SPIRAL_LAYOUT_IMAGE_SELECTED
521                 }
522             };
523             mLayoutButton.ApplyStyle(mLayoutButtonStyle);
524             mLayoutButton.IsSelectable = true;
525             mLayoutButton.Size = new Size(34, 34);
526             mLayoutButton.LeaveRequired = true;
527             mLayoutButton.Clicked += (obj, e) =>
528             {
529                 mCurrentLayout = (mCurrentLayout + 1) % (int)mItemView.GetLayoutCount();
530                 ChangeLayout();
531                 SetLayoutTitle();
532                 SetLayoutImage();
533             };
534             mToolBarLayer.Add(mLayoutButton);
535         }
536
537         private void SetLayoutTitle()
538         {
539             if (Mode.MODE_NORMAL == mMode)
540             {
541                 string title = APPLICATION_TITLE;
542                 switch (mCurrentLayout)
543                 {
544                     case (int)AllImagesLayouts.SPIRAL_LAYOUT:
545                         title = title + ": " + SPIRAL_LABEL;
546                         break;
547                     case (int)AllImagesLayouts.GRID_LAYOUT:
548                         title = title + ": " + GRID_LABEL;
549                         break;
550                     case (int)AllImagesLayouts.DEPTH_LAYOUT:
551                         title = title + ": " + DEPTH_LABEL;
552                         break;
553                     default:
554                         break;
555                 }
556                 SetTitle(title);
557             }
558         }
559
560         private void CreateDeleteButton()
561         {
562             mDeleteButton = new Button();
563             var mDeleteButtonStyle = new ButtonStyle
564             {
565                 Text = null,
566                 BackgroundColor = new Selector<Color>(),
567                 BackgroundImage = new Selector<string>() { Normal = DELETE_IMAGE, Selected = DELETE_IMAGE_SELECTED }
568             };
569             mDeleteButton.ApplyStyle(mDeleteButtonStyle);
570             mDeleteButton.IsSelectable = true;
571             mDeleteButton.ParentOrigin = ParentOrigin.BottomRight;
572             mDeleteButton.PivotPoint = PivotPoint.BottomRight;
573             mDeleteButton.PositionUsesPivotPoint = true;
574             mDeleteButton.DrawMode = DrawModeType.Overlay2D;
575             mDeleteButton.Size = new Size(50, 50);
576             mDeleteButton.LeaveRequired = true;
577             mDeleteButton.Hide();
578             mDeleteButton.Clicked += (obj, e) =>
579             {
580                 ItemIdCollection removeList = new ItemIdCollection();
581                 for (uint i = 0; i < mItemView.ChildCount; ++i)
582                 {
583                     View child = mItemView.GetChildAt(i);
584                     if (child != null)
585                     {
586                         View tick = child.FindChildByName("Tick");
587
588                         if (tick != null && tick.Visibility)
589                         {
590                             removeList.Add(mItemView.GetItemId(child));
591                         }
592                     }
593                 }
594
595                 if (removeList.Count != 0)
596                 {
597                     mItemView.RemoveItems(removeList, 0.5f);
598                 }
599             };
600             NUIApplication.GetDefaultWindow().Add(mDeleteButton);
601         }
602
603         private void CreateInsertButton()
604         {
605             mInsertButton = new Button();
606             var mInsertButtonStyle = new ButtonStyle
607             {
608                 Text = null,
609                 BackgroundColor = new Selector<Color>(),
610                 BackgroundImage = new Selector<string>() { Normal = INSERT_IMAGE, Selected = INSERT_IMAGE_SELECTED }
611             };
612             mInsertButton.ApplyStyle(mInsertButtonStyle);
613             mInsertButton.IsSelectable = true;
614             mInsertButton.ParentOrigin = ParentOrigin.BottomRight;
615             mInsertButton.PivotPoint = PivotPoint.BottomRight;
616             mInsertButton.PositionUsesPivotPoint = true;
617             mInsertButton.DrawMode = DrawModeType.Overlay2D;
618             mInsertButton.Size = new Size(50, 50);
619             mInsertButton.LeaveRequired = true;
620             mInsertButton.Hide();
621             mInsertButton.Clicked += (obj, e) =>
622             {
623                 ItemCollection insertList = new ItemCollection();
624                 Random random = new Random();
625                 for (uint i = 0; i < mItemView.ChildCount; ++i)
626                 {
627                     View child = mItemView.GetChildAt(i);
628                     if (child != null)
629                     {
630                         View tick = child.FindChildByName("Tick");
631
632                         if (tick != null && tick.Visibility)
633                         {
634                             insertList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
635                         }
636                     }
637                 }
638                 if (insertList.Count != 0)
639                 {
640                     mItemView.InsertItems(insertList, 0.5f);
641                 }
642             };
643             NUIApplication.GetDefaultWindow().Add(mInsertButton);
644         }
645
646         private void CreateReplaceButton()
647         {
648             mReplaceButton = new Button();
649             var mReplaceButtonStyle = new ButtonStyle
650             {
651                 Text = null,
652                 BackgroundColor = new Selector<Color>(),
653                 BackgroundImage = new Selector<string>() { Normal = REPLACE_IMAGE, Selected = REPLACE_IMAGE_SELECTED }
654             };
655             mReplaceButton.ApplyStyle(mReplaceButtonStyle);
656             mReplaceButton.IsSelectable = true;
657             mReplaceButton.ParentOrigin = ParentOrigin.BottomRight;
658             mReplaceButton.PivotPoint = PivotPoint.BottomRight;
659             mReplaceButton.PositionUsesPivotPoint = true;
660             mReplaceButton.DrawMode = DrawModeType.Overlay2D;
661             mReplaceButton.Size = new Size(50, 50);
662             mReplaceButton.LeaveRequired = true;
663             mReplaceButton.Hide();
664             mReplaceButton.Clicked += (obj, e) =>
665             {
666                 ItemCollection replaceList = new ItemCollection();
667                 Random random = new Random();
668                 for (uint i = 0; i < mItemView.ChildCount; ++i)
669                 {
670                     View child = mItemView.GetChildAt(i);
671                     if (child != null)
672                     {
673                         View tick = child.FindChildByName("Tick");
674
675                         if (tick != null && tick.Visibility)
676                         {
677                             replaceList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
678                         }
679                     }
680                 }
681
682                 if (replaceList.Count != 0)
683                 {
684                     mItemView.ReplaceItems(replaceList, 0.5f);
685                 }
686             };
687             NUIApplication.GetDefaultWindow().Add(mReplaceButton);
688         }
689
690         void SwitchToNextMode()
691         {
692             switch (mMode)
693             {
694                 case Mode.MODE_REMOVE:
695                     {
696                         ExitRemoveMode();
697                         mMode = Mode.MODE_REMOVE_MANY;
698                         EnterRemoveManyMode();
699                         break;
700                     }
701
702                 case Mode.MODE_REMOVE_MANY:
703                     {
704                         ExitRemoveManyMode();
705                         mMode = Mode.MODE_INSERT;
706                         EnterInsertMode();
707                         break;
708                     }
709
710                 case Mode.MODE_INSERT:
711                     {
712                         ExitInsertMode();
713                         mMode = Mode.MODE_INSERT_MANY;
714                         EnterInsertManyMode();
715                         break;
716                     }
717
718                 case Mode.MODE_INSERT_MANY:
719                     {
720                         ExitInsertManyMode();
721                         mMode = Mode.MODE_REPLACE;
722                         EnterReplaceMode();
723                         break;
724                     }
725
726                 case Mode.MODE_REPLACE:
727                     {
728                         ExitReplaceMode();
729                         mMode = Mode.MODE_REPLACE_MANY;
730                         EnterReplaceManyMode();
731                         break;
732                     }
733
734                 case Mode.MODE_REPLACE_MANY:
735                     {
736                         ExitReplaceManyMode();
737                         mMode = Mode.MODE_NORMAL;
738                         SetLayoutTitle();
739                         break;
740                     }
741
742                 case Mode.MODE_NORMAL:
743                 default:
744                     {
745                         mMode = Mode.MODE_REMOVE;
746                         EnterRemoveMode();
747                         break;
748                     }
749             }
750         }
751
752         void EnterRemoveMode()
753         {
754             SetTitle("Edit: Remove");
755             mTapDetector = new TapGestureDetector();
756
757             for (uint i = 0; i < mItemView.ChildCount; ++i)
758             {
759                 if (mItemView.GetChildAt(i) != null)
760                 {
761                     mTapDetector.Attach(mItemView.GetChildAt(i));
762                 }
763             }
764
765             mTapDetector.Detected += (obj, e) =>
766             {
767                 View item = e.View;
768                 if (item != null)
769                 {
770                     mItemView.RemoveItem(mItemView.GetItemId(item), 0.5f);
771                 }
772             };
773         }
774
775         void ExitRemoveMode()
776         {
777             mTapDetector.DetachAll();
778             mTapDetector.Reset();
779         }
780
781         void EnterRemoveManyMode()
782         {
783             SetTitle("Edit: Remove Many");
784             mDeleteButton.Show();
785
786             mTapDetector = new TapGestureDetector();
787
788             for (uint i = 0; i < mItemView.ChildCount; ++i)
789             {
790                 View child = mItemView.GetChildAt(i);
791                 if (child != null)
792                 {
793                     View box = child.FindChildByName("CheckBox");
794                     if (box)
795                     {
796                         mTapDetector.Attach(child);
797                         box.Show();
798                     }
799                 }
800             }
801
802             mTapDetector.Detected += (obj, e) =>
803             {
804                 View view = e.View;
805                 if (view != null)
806                 {
807                     Console.WriteLine("haha");
808                 }
809                 else
810                 {
811                     Console.WriteLine("hehe");
812                 }
813                 View tick = view.FindChildByName("Tick");
814                 if (tick)
815                 {
816                     if (tick.Visibility)
817                     {
818                         tick.Hide();
819                     }
820                     else
821                     {
822                         tick.Show();
823                     }
824                 }
825             };
826         }
827
828         void ExitRemoveManyMode()
829         {
830             for (uint i = 0; i < mItemView.ChildCount; ++i)
831             {
832                 View child = mItemView.GetChildAt(i);
833                 if (child != null)
834                 {
835                     View box = child.FindChildByName("CheckBox");
836
837                     if (box)
838                     {
839                         box.Hide();
840
841                         View tick = box.FindChildByName("Tick");
842                         if (tick)
843                         {
844                             tick.Hide();
845                         }
846                     }
847                 }
848             }
849             mTapDetector.Reset();
850             mDeleteButton.Hide();
851         }
852
853         void EnterInsertMode()
854         {
855             SetTitle("Edit: Insert");
856             mTapDetector = new TapGestureDetector();
857
858             for (uint i = 0; i < mItemView.ChildCount; ++i)
859             {
860                 if (mItemView.GetChildAt(i) != null)
861                 {
862                     mTapDetector.Attach(mItemView.GetChildAt(i));
863                 }
864
865             }
866             mTapDetector.Detected += (obj, e) =>
867             {
868                 if (e.View != null)
869                 {
870                     uint id = mItemView.GetItemId(e.View);
871                     Random random = new Random();
872
873                     View newActor = NewItemView((uint)random.Next(52));
874
875                     mItemView.InsertItem(new Item(id, newActor), 0.5f);
876                 }
877                 else
878                 {
879                     Tizen.Log.Fatal("NUI", "e.View is null when EnterInsertMode!");
880                 }
881             };
882         }
883
884         void ExitInsertMode()
885         {
886             mTapDetector.DetachAll();
887             mTapDetector.Reset();
888         }
889         void EnterInsertManyMode()
890         {
891             SetTitle("Edit: Insert Many");
892             mInsertButton.Show();
893
894             mTapDetector = new TapGestureDetector();
895
896             for (uint i = 0; i < mItemView.ChildCount; ++i)
897             {
898                 View child = mItemView.GetChildAt(i);
899                 if (child != null)
900                 {
901                     View box = child.FindChildByName("CheckBox");
902
903                     if (box)
904                     {
905                         mTapDetector.Attach(child);
906                         box.Show();
907                     }
908                 }
909             }
910             mTapDetector.Detected += (obj, e) =>
911             {
912                 View tick = (e.View).FindChildByName("Tick");
913                 if (tick)
914                 {
915                     if (tick.Visibility)
916                     {
917                         tick.Hide();
918                     }
919                     else
920                     {
921                         tick.Show();
922                     }
923                 }
924             };
925         }
926
927         void ExitInsertManyMode()
928         {
929             for (uint i = 0; i < mItemView.ChildCount; ++i)
930             {
931                 View child = mItemView.GetChildAt(i);
932                 if (child != null)
933                 {
934                     View box = child.FindChildByName("CheckBox");
935
936                     if (box)
937                     {
938                         box.Hide();
939
940                         View tick = box.FindChildByName("Tick");
941                         if (tick)
942                         {
943                             tick.Hide();
944                         }
945                     }
946                 }
947             }
948             mTapDetector.Reset();
949             mInsertButton.Hide();
950         }
951
952         void EnterReplaceMode()
953         {
954             SetTitle("Edit: Replace");
955             mTapDetector = new TapGestureDetector();
956
957             for (uint i = 0; i < mItemView.ChildCount; ++i)
958             {
959                 if (mItemView.GetChildAt(i) != null)
960                 {
961                     mTapDetector.Attach(mItemView.GetChildAt(i));
962                 }
963             }
964
965             mTapDetector.Detected += (obj, e) =>
966             {
967                 Random random = new Random();
968                 mItemView.ReplaceItem(new Item(mItemView.GetItemId(e.View), NewItemView((uint)random.Next(52))), 0.5f);
969             };
970         }
971
972         void ExitReplaceMode()
973         {
974             mTapDetector.DetachAll();
975             mTapDetector.Reset();
976         }
977
978
979         void EnterReplaceManyMode()
980         {
981             SetTitle("Edit: Replace Many");
982             mReplaceButton.Show();
983
984             mTapDetector = new TapGestureDetector();
985
986             for (uint i = 0; i < mItemView.ChildCount; ++i)
987             {
988                 View child = mItemView.GetChildAt(i);
989                 View box = child.FindChildByName("CheckBox");
990
991                 if (box)
992                 {
993                     mTapDetector.Attach(child);
994                     box.Show();
995                 }
996             }
997
998             mTapDetector.Detected += (obj, e) =>
999             {
1000                 View tick = (e.View).FindChildByName("Tick");
1001                 if (tick)
1002                 {
1003                     if (tick.Visibility)
1004                     {
1005                         tick.Hide();
1006                     }
1007                     else
1008                     {
1009                         tick.Show();
1010                     }
1011                 }
1012             };
1013         }
1014         void ExitReplaceManyMode()
1015         {
1016             for (uint i = 0; i < mItemView.ChildCount; ++i)
1017             {
1018                 View child = mItemView.GetChildAt(i);
1019                 View box = child.FindChildByName("CheckBox");
1020
1021                 if (box)
1022                 {
1023                     box.Hide();
1024
1025                     View tick = box.FindChildByName("Tick");
1026                     if (tick)
1027                     {
1028                         tick.Hide();
1029                     }
1030                 }
1031             }
1032             mTapDetector.Reset();
1033             mReplaceButton.Hide();
1034         }
1035
1036     }
1037 }