[NUI]Add layouts and refine codes for Samples (#1595)
[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.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
214             mItemView.SetMinimumSwipeSpeed(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                 LinearAlignment = LinearLayout.Alignment.Center
452             };
453             mRootView.Add(mContentView);
454         }
455
456
457         private void CreateToolBarLayer()
458         {
459             mToolBarLayer = new View()
460             {
461                 Name = "TOOLBAR",
462                 Size = new Size(1920, 80),
463                 BackgroundImage = TOOLBAR_IMAGE
464             };
465             mToolBarLayer.Layout = new LinearLayout()
466             {
467                 LinearOrientation = LinearLayout.Orientation.Horizontal,
468                 LinearAlignment = LinearLayout.Alignment.Center
469             };
470             mRootView.Add(mToolBarLayer);
471             mToolBarLayer.RaiseToTop();
472
473             CreateEditButton();
474             CreateToolBarTitle();
475             CreateLayoutButton();
476         }
477
478         public void CreateEditButton()
479         {
480             mEditButton = new Button();
481             var mEditButtonStyle = new ButtonStyle
482             {
483                 Text = null,
484                 BackgroundColor = new Selector<Color>(),
485                 BackgroundImage = new Selector<string>() { Normal = EDIT_IMAGE, Selected = EDIT_IMAGE_SELECTED }
486             };
487             mEditButton.ApplyStyle(mEditButtonStyle);
488             mEditButton.IsSelectable = true;
489             mEditButton.Size = new Size(34, 34);
490             mEditButton.LeaveRequired = true;
491             mEditButton.ClickEvent += (obj, e) =>
492             {
493                 SwitchToNextMode();
494             };
495             mToolBarLayer.Add(mEditButton);
496         }
497
498         private void CreateToolBarTitle()
499         {
500             mTitle = new TextLabel();
501             mTitle.Size = new Size(1800, 80);
502             mTitle.PointSize = 10.0f;
503             mTitle.Text = APPLICATION_TITLE;
504             mTitle.VerticalAlignment = VerticalAlignment.Center;
505             mTitle.HorizontalAlignment = HorizontalAlignment.Center;
506             mToolBarLayer.Add(mTitle);
507         }
508
509         private void CreateLayoutButton()
510         {
511             mLayoutButton = new Button();
512             var mLayoutButtonStyle = new ButtonStyle
513             {
514                 Text = null,
515                 BackgroundImage = new Selector<string>()
516                 {
517                     Normal = SPIRAL_LAYOUT_IMAGE,
518                     Selected = SPIRAL_LAYOUT_IMAGE_SELECTED
519                 }
520             };
521             mLayoutButton.ApplyStyle(mLayoutButtonStyle);
522             mLayoutButton.IsSelectable = true;
523             mLayoutButton.Size = new Size(34, 34);
524             mLayoutButton.LeaveRequired = true;
525             mLayoutButton.ClickEvent += (obj, e) =>
526             {
527                 mCurrentLayout = (mCurrentLayout + 1) % (int)mItemView.GetLayoutCount();
528                 ChangeLayout();
529                 SetLayoutTitle();
530                 SetLayoutImage();
531             };
532             mToolBarLayer.Add(mLayoutButton);
533         }
534
535         private void SetLayoutTitle()
536         {
537             if (Mode.MODE_NORMAL == mMode)
538             {
539                 string title = APPLICATION_TITLE;
540                 switch (mCurrentLayout)
541                 {
542                     case (int)AllImagesLayouts.SPIRAL_LAYOUT:
543                         title = title + ": " + SPIRAL_LABEL;
544                         break;
545                     case (int)AllImagesLayouts.GRID_LAYOUT:
546                         title = title + ": " + GRID_LABEL;
547                         break;
548                     case (int)AllImagesLayouts.DEPTH_LAYOUT:
549                         title = title + ": " + DEPTH_LABEL;
550                         break;
551                     default:
552                         break;
553                 }
554                 SetTitle(title);
555             }
556         }
557
558         private void CreateDeleteButton()
559         {
560             mDeleteButton = new Button();
561             var mDeleteButtonStyle = new ButtonStyle
562             {
563                 Text = null,
564                 BackgroundColor = new Selector<Color>(),
565                 BackgroundImage = new Selector<string>() { Normal = DELETE_IMAGE, Selected = DELETE_IMAGE_SELECTED }
566             };
567             mDeleteButton.ApplyStyle(mDeleteButtonStyle);
568             mDeleteButton.IsSelectable = true;
569             mDeleteButton.ParentOrigin = ParentOrigin.BottomRight;
570             mDeleteButton.PivotPoint = PivotPoint.BottomRight;
571             mDeleteButton.PositionUsesPivotPoint = true;
572             mDeleteButton.DrawMode = DrawModeType.Overlay2D;
573             mDeleteButton.Size = new Size(50, 50);
574             mDeleteButton.LeaveRequired = true;
575             mDeleteButton.Hide();
576             mDeleteButton.ClickEvent += (obj, e) =>
577             {
578                 ItemIdContainer removeList = new ItemIdContainer();
579                 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
580                 {
581                     View child = mItemView.GetChildAt(i);
582                     if (child != null)
583                     {
584                         View tick = child.FindChildByName("Tick");
585
586                         if (tick != null && tick.Visibility)
587                         {
588                             removeList.Add(mItemView.GetItemId(child));
589                         }
590                     }
591                 }
592
593                 if (removeList.Count != 0)
594                 {
595                     mItemView.RemoveItems(removeList, 0.5f);
596                 }
597             };
598             NUIApplication.GetDefaultWindow().Add(mDeleteButton);
599         }
600
601         private void CreateInsertButton()
602         {
603             mInsertButton = new Button();
604             var mInsertButtonStyle = new ButtonStyle
605             {
606                 Text = null,
607                 BackgroundColor = new Selector<Color>(),
608                 BackgroundImage = new Selector<string>() { Normal = INSERT_IMAGE, Selected = INSERT_IMAGE_SELECTED }
609             };
610             mInsertButton.ApplyStyle(mInsertButtonStyle);
611             mInsertButton.IsSelectable = true;
612             mInsertButton.ParentOrigin = ParentOrigin.BottomRight;
613             mInsertButton.PivotPoint = PivotPoint.BottomRight;
614             mInsertButton.PositionUsesPivotPoint = true;
615             mInsertButton.DrawMode = DrawModeType.Overlay2D;
616             mInsertButton.Size = new Size(50, 50);
617             mInsertButton.LeaveRequired = true;
618             mInsertButton.Hide();
619             mInsertButton.ClickEvent += (obj, e) =>
620             {
621                 ItemContainer insertList = new ItemContainer();
622                 Random random = new Random();
623                 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
624                 {
625                     View child = mItemView.GetChildAt(i);
626                     if (child != null)
627                     {
628                         View tick = child.FindChildByName("Tick");
629
630                         if (tick != null && tick.Visibility)
631                         {
632                             insertList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
633                         }
634                     }
635                 }
636                 if (insertList.Count != 0)
637                 {
638                     mItemView.InsertItems(insertList, 0.5f);
639                 }
640             };
641             NUIApplication.GetDefaultWindow().Add(mInsertButton);
642         }
643
644         private void CreateReplaceButton()
645         {
646             mReplaceButton = new Button();
647             var mReplaceButtonStyle = new ButtonStyle
648             {
649                 Text = null,
650                 BackgroundColor = new Selector<Color>(),
651                 BackgroundImage = new Selector<string>() { Normal = REPLACE_IMAGE, Selected = REPLACE_IMAGE_SELECTED }
652             };
653             mReplaceButton.ApplyStyle(mReplaceButtonStyle);
654             mReplaceButton.IsSelectable = true;
655             mReplaceButton.ParentOrigin = ParentOrigin.BottomRight;
656             mReplaceButton.PivotPoint = PivotPoint.BottomRight;
657             mReplaceButton.PositionUsesPivotPoint = true;
658             mReplaceButton.DrawMode = DrawModeType.Overlay2D;
659             mReplaceButton.Size = new Size(50, 50);
660             mReplaceButton.LeaveRequired = true;
661             mReplaceButton.Hide();
662             mReplaceButton.ClickEvent += (obj, e) =>
663             {
664                 ItemContainer replaceList = new ItemContainer();
665                 Random random = new Random();
666                 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
667                 {
668                     View child = mItemView.GetChildAt(i);
669                     if (child != null)
670                     {
671                         View tick = child.FindChildByName("Tick");
672
673                         if (tick != null && tick.Visibility)
674                         {
675                             replaceList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
676                         }
677                     }
678                 }
679
680                 if (replaceList.Count != 0)
681                 {
682                     mItemView.ReplaceItems(replaceList, 0.5f);
683                 }
684             };
685             NUIApplication.GetDefaultWindow().Add(mReplaceButton);
686         }
687
688         void SwitchToNextMode()
689         {
690             switch (mMode)
691             {
692                 case Mode.MODE_REMOVE:
693                     {
694                         ExitRemoveMode();
695                         mMode = Mode.MODE_REMOVE_MANY;
696                         EnterRemoveManyMode();
697                         break;
698                     }
699
700                 case Mode.MODE_REMOVE_MANY:
701                     {
702                         ExitRemoveManyMode();
703                         mMode = Mode.MODE_INSERT;
704                         EnterInsertMode();
705                         break;
706                     }
707
708                 case Mode.MODE_INSERT:
709                     {
710                         ExitInsertMode();
711                         mMode = Mode.MODE_INSERT_MANY;
712                         EnterInsertManyMode();
713                         break;
714                     }
715
716                 case Mode.MODE_INSERT_MANY:
717                     {
718                         ExitInsertManyMode();
719                         mMode = Mode.MODE_REPLACE;
720                         EnterReplaceMode();
721                         break;
722                     }
723
724                 case Mode.MODE_REPLACE:
725                     {
726                         ExitReplaceMode();
727                         mMode = Mode.MODE_REPLACE_MANY;
728                         EnterReplaceManyMode();
729                         break;
730                     }
731
732                 case Mode.MODE_REPLACE_MANY:
733                     {
734                         ExitReplaceManyMode();
735                         mMode = Mode.MODE_NORMAL;
736                         SetLayoutTitle();
737                         break;
738                     }
739
740                 case Mode.MODE_NORMAL:
741                 default:
742                     {
743                         mMode = Mode.MODE_REMOVE;
744                         EnterRemoveMode();
745                         break;
746                     }
747             }
748         }
749
750         void EnterRemoveMode()
751         {
752             SetTitle("Edit: Remove");
753             mTapDetector = new TapGestureDetector();
754
755             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
756             {
757                 if (mItemView.GetChildAt(i) != null)
758                 {
759                     mTapDetector.Attach(mItemView.GetChildAt(i));
760                 }
761             }
762
763             mTapDetector.Detected += (obj, e) =>
764             {
765                 View item = e.View;
766                 if (item != null)
767                 {
768                     mItemView.RemoveItem(mItemView.GetItemId(item), 0.5f);
769                 }
770             };
771         }
772
773         void ExitRemoveMode()
774         {
775             mTapDetector.DetachAll();
776             mTapDetector.Reset();
777         }
778
779         void EnterRemoveManyMode()
780         {
781             SetTitle("Edit: Remove Many");
782             mDeleteButton.Show();
783
784             mTapDetector = new TapGestureDetector();
785
786             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
787             {
788                 View child = mItemView.GetChildAt(i);
789                 if (child != null)
790                 {
791                     View box = child.FindChildByName("CheckBox");
792                     if (box)
793                     {
794                         mTapDetector.Attach(child);
795                         box.Show();
796                     }
797                 }
798             }
799
800             mTapDetector.Detected += (obj, e) =>
801             {
802                 View view = e.View;
803                 if (view != null)
804                 {
805                     Console.WriteLine("haha");
806                 }
807                 else
808                 {
809                     Console.WriteLine("hehe");
810                 }
811                 View tick = view.FindChildByName("Tick");
812                 if (tick)
813                 {
814                     if (tick.Visibility)
815                     {
816                         tick.Hide();
817                     }
818                     else
819                     {
820                         tick.Show();
821                     }
822                 }
823             };
824         }
825
826         void ExitRemoveManyMode()
827         {
828             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
829             {
830                 View child = mItemView.GetChildAt(i);
831                 if (child != null)
832                 {
833                     View box = child.FindChildByName("CheckBox");
834
835                     if (box)
836                     {
837                         box.Hide();
838
839                         View tick = box.FindChildByName("Tick");
840                         if (tick)
841                         {
842                             tick.Hide();
843                         }
844                     }
845                 }
846             }
847             mTapDetector.Reset();
848             mDeleteButton.Hide();
849         }
850
851         void EnterInsertMode()
852         {
853             SetTitle("Edit: Insert");
854             mTapDetector = new TapGestureDetector();
855
856             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
857             {
858                 if (mItemView.GetChildAt(i) != null)
859                 {
860                     mTapDetector.Attach(mItemView.GetChildAt(i));
861                 }
862
863             }
864             mTapDetector.Detected += (obj, e) =>
865             {
866                 if (e.View != null)
867                 {
868                     uint id = mItemView.GetItemId(e.View);
869                     Random random = new Random();
870
871                     View newActor = NewItemView((uint)random.Next(52));
872
873                     mItemView.InsertItem(new Item(id, newActor), 0.5f);
874                 }
875                 else
876                 {
877                     Tizen.Log.Fatal("NUI", "e.View is null when EnterInsertMode!");
878                 }
879             };
880         }
881
882         void ExitInsertMode()
883         {
884             mTapDetector.DetachAll();
885             mTapDetector.Reset();
886         }
887         void EnterInsertManyMode()
888         {
889             SetTitle("Edit: Insert Many");
890             mInsertButton.Show();
891
892             mTapDetector = new TapGestureDetector();
893
894             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
895             {
896                 View child = mItemView.GetChildAt(i);
897                 if (child != null)
898                 {
899                     View box = child.FindChildByName("CheckBox");
900
901                     if (box)
902                     {
903                         mTapDetector.Attach(child);
904                         box.Show();
905                     }
906                 }
907             }
908             mTapDetector.Detected += (obj, e) =>
909             {
910                 View tick = (e.View).FindChildByName("Tick");
911                 if (tick)
912                 {
913                     if (tick.Visibility)
914                     {
915                         tick.Hide();
916                     }
917                     else
918                     {
919                         tick.Show();
920                     }
921                 }
922             };
923         }
924
925         void ExitInsertManyMode()
926         {
927             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
928             {
929                 View child = mItemView.GetChildAt(i);
930                 if (child != null)
931                 {
932                     View box = child.FindChildByName("CheckBox");
933
934                     if (box)
935                     {
936                         box.Hide();
937
938                         View tick = box.FindChildByName("Tick");
939                         if (tick)
940                         {
941                             tick.Hide();
942                         }
943                     }
944                 }
945             }
946             mTapDetector.Reset();
947             mInsertButton.Hide();
948         }
949
950         void EnterReplaceMode()
951         {
952             SetTitle("Edit: Replace");
953             mTapDetector = new TapGestureDetector();
954
955             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
956             {
957                 if (mItemView.GetChildAt(i) != null)
958                 {
959                     mTapDetector.Attach(mItemView.GetChildAt(i));
960                 }
961             }
962
963             mTapDetector.Detected += (obj, e) =>
964             {
965                 Random random = new Random();
966                 mItemView.ReplaceItem(new Item(mItemView.GetItemId(e.View), NewItemView((uint)random.Next(52))), 0.5f);
967             };
968         }
969
970         void ExitReplaceMode()
971         {
972             mTapDetector.DetachAll();
973             mTapDetector.Reset();
974         }
975
976
977         void EnterReplaceManyMode()
978         {
979             SetTitle("Edit: Replace Many");
980             mReplaceButton.Show();
981
982             mTapDetector = new TapGestureDetector();
983
984             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
985             {
986                 View child = mItemView.GetChildAt(i);
987                 View box = child.FindChildByName("CheckBox");
988
989                 if (box)
990                 {
991                     mTapDetector.Attach(child);
992                     box.Show();
993                 }
994             }
995
996             mTapDetector.Detected += (obj, e) =>
997             {
998                 View tick = (e.View).FindChildByName("Tick");
999                 if (tick)
1000                 {
1001                     if (tick.Visibility)
1002                     {
1003                         tick.Hide();
1004                     }
1005                     else
1006                     {
1007                         tick.Show();
1008                     }
1009                 }
1010             };
1011         }
1012         void ExitReplaceManyMode()
1013         {
1014             for (uint i = 0; i < mItemView.GetChildCount(); ++i)
1015             {
1016                 View child = mItemView.GetChildAt(i);
1017                 View box = child.FindChildByName("CheckBox");
1018
1019                 if (box)
1020                 {
1021                     box.Hide();
1022
1023                     View tick = box.FindChildByName("Tick");
1024                     if (tick)
1025                     {
1026                         tick.Hide();
1027                     }
1028                 }
1029             }
1030             mTapDetector.Reset();
1031             mReplaceButton.Hide();
1032         }
1033
1034     }
1035 }