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