2 using Tizen.NUI.BaseComponents;
3 using Tizen.NUI.UIComponents;
5 namespace Tizen.NUI.Samples
7 public class ZItemViewSample : IExample
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;
19 private string APPLICATION_TITLE = "ItemView";
20 private string SPIRAL_LABEL = "Spiral";
21 private string GRID_LABEL = "Grid";
22 private string DEPTH_LABEL = "Depth";
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";
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";
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;
52 private LongPressGestureDetector mLongPressGestureDetector;
53 private TapGestureDetector mTapDetector;
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;
63 private Layer mToolBarLayer;
64 private View mContentView;
66 private int mDurationSeconds = 250;
68 public static Vector3 DepthLayoutItemSizeFunctionPortrait(float layoutWidth)
70 float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
73 return new Vector3(width, width, width);
76 public static Vector3 DepthLayoutItemSizeFunctionLandscape(float layoutWidth)
78 float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
81 return new Vector3(width, width, width);
84 private void SetTitle(string title)
92 public void CreateGridLayout()
94 mGridLayout = new PropertyMap();
95 mGridLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.GRID));
98 public void CreateDepthLayout()
100 mDepthLayout = new PropertyMap();
101 mDepthLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.DEPTH));
104 public void CreateSpiralLayout()
106 mSpiralLayout = new PropertyMap();
107 mSpiralLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.SPIRAL));
110 void SetLayoutImage()
114 switch (mCurrentLayout)
116 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
118 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE);
119 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE_SELECTED);
123 case (int)AllImagesLayouts.GRID_LAYOUT:
125 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(GRID_LAYOUT_IMAGE);
126 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(GRID_LAYOUT_IMAGE_SELECTED);
130 case (int)AllImagesLayouts.DEPTH_LAYOUT:
132 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(DEPTH_LAYOUT_IMAGE);
133 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(DEPTH_LAYOUT_IMAGE_SELECTED);
144 Animation animation = new Animation(mDurationSeconds);
145 animation.Finished += AnimationFinished;
146 animation.AnimateTo(mItemView, "Opacity", 0.0f);
150 void AnimationFinished(object sender, EventArgs e)
152 SetLayout(mCurrentLayout);
153 Animation animation = new Animation(mDurationSeconds);
154 animation.AnimateTo(mItemView, "Opacity", 1.0f);
158 private PropertyMap CreateImageVisual(string url)
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));
166 public void Activate()
168 Window window = NUIApplication.GetDefaultWindow();
169 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
170 window.BackgroundColor = Color.Black;
172 //CreateToolBarView();
173 CreateToolBarLayer();
175 CreateLayoutButton();
177 CreateInsertButton();
178 CreateReplaceButton();
179 CreateDeleteButton();
183 CreateSpiralLayout();
185 mLayout = new PropertyArray();
186 mLayout.PushBack(new PropertyValue(mSpiralLayout));
187 mLayout.PushBack(new PropertyValue(mDepthLayout));
188 mLayout.PushBack(new PropertyValue(mGridLayout));
191 mItemFactoryWrapper = new ItemFactoryWrapper();
192 mItemFactoryWrapper.GetNumberDelegate = GetNumberOfItems;
193 mItemFactoryWrapper.NewItemDelegate = NewItemView;
195 mItemView = new ItemView(mItemFactoryWrapper);
196 mItemView.PositionUsesPivotPoint = true;
197 mItemView.ParentOrigin = Position.ParentOriginCenter;
198 mItemView.PivotPoint = Position.PivotPointCenter;
199 window.Add(mItemView);
201 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
203 mItemView.Layout = mLayout;
204 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
205 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
207 SetLayout((int)mCurrentLayout);
211 mLongPressGestureDetector = new LongPressGestureDetector();
212 mLongPressGestureDetector.Attach(mItemView);
213 mLongPressGestureDetector.Detected += OnLongPressGestureDetected;
216 private void OnLongPressGestureDetected(object source, LongPressGestureDetector.DetectedEventArgs e)
218 switch (e.LongPressGesture.State)
220 case Gesture.StateType.Started:
222 Size2D windowSize = NUIApplication.GetDefaultWindow().Size;
223 ItemRange range = new ItemRange(0, 0);
224 mItemView.GetItemsRange(range);
226 uint item = (e.LongPressGesture.ScreenPoint.Y < 0.5f * (float)windowSize.Height) ? range.begin : range.end;
228 mItemView.ScrollToItem(item, SCROLL_TO_ITEM_ANIMATION_TIME);
232 case Gesture.StateType.Finished:
234 PropertyMap attributes = new PropertyMap();
235 mItemView.DoAction("stopScrolling", attributes);
245 void SetLayout(int layoutId)
247 Window window = NUIApplication.GetDefaultWindow();
248 switch (mCurrentLayout)
250 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
251 case (int)AllImagesLayouts.DEPTH_LAYOUT:
253 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
256 case (int)AllImagesLayouts.GRID_LAYOUT:
258 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.LayerUI;
263 Size2D windowSize = window.Size;
265 if (layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT)
267 mDepthLayout.Insert((int)DefaultItemLayoutProperty.ITEM_SIZE, new PropertyValue(DepthLayoutItemSizeFunctionPortrait(800)));
269 mLayout.PushBack(new PropertyValue(mSpiralLayout));
270 mLayout.PushBack(new PropertyValue(mDepthLayout));
271 mLayout.PushBack(new PropertyValue(mGridLayout));
272 mItemView.Layout = mLayout;
275 // Enable anchoring for depth layout only
276 mItemView.SetAnchoring(layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT);
278 // Activate the layout
279 mItemView.ActivateLayout((uint)layoutId, new Vector3(800, 800, 800), 0.0f);
284 public uint GetNumberOfItems()
289 public View NewItemView(uint itemId)
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();
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);
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);
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;
322 actor.Add(borderActor);
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;
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;
339 if (Mode.MODE_REMOVE_MANY != mMode &&
340 Mode.MODE_INSERT_MANY != mMode &&
341 Mode.MODE_REPLACE_MANY != mMode)
345 borderActor.Add(checkBox);
347 ImageView tick = new ImageView(SELECTED_IMAGE);
349 tick.ParentOrigin = ParentOrigin.TopRight;
350 tick.PivotPoint = PivotPoint.TopRight;
351 tick.Size = spiralItemSize;
357 mTapDetector.Attach(actor);
362 public void Deactivate()
364 if (mLayoutButton != null)
366 mLayoutButton.GetParent().Remove(mLayoutButton);
367 mLayoutButton.Dispose();
370 if (mEditButton != null)
372 mEditButton.GetParent().Remove(mEditButton);
373 mEditButton.Dispose();
376 if (mReplaceButton != null)
378 mReplaceButton.GetParent().Remove(mReplaceButton);
379 mReplaceButton.Dispose();
382 if (mInsertButton != null)
384 mInsertButton.GetParent().Remove(mInsertButton);
385 mInsertButton.Dispose();
388 if (mDeleteButton != null)
390 mDeleteButton.GetParent().Remove(mDeleteButton);
391 mDeleteButton.Dispose();
396 mTitle.GetParent().Remove(mTitle);
400 if (mToolBarBackground != null)
402 mToolBarBackground.GetParent().Remove(mToolBarBackground);
403 mToolBarBackground.Dispose();
406 if (mItemView != null)
408 mItemView.GetParent().Remove(mItemView);
412 if (mContentView != null)
414 NUIApplication.GetDefaultWindow().Remove(mContentView);
415 mContentView.Dispose();
418 if (mToolBarLayer != null)
420 NUIApplication.GetDefaultWindow().RemoveLayer(mToolBarLayer);
421 mToolBarLayer.Dispose();
424 NUIApplication.GetDefaultWindow().GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer2D;
427 public void CreateContentView()
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 NUIApplication.GetDefaultWindow().Add(mContentView);
437 mContentView.LowerToBottom();
441 private void CreateToolBarLayer()
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 NUIApplication.GetDefaultWindow().AddLayer(mToolBarLayer);
451 mToolBarLayer.RaiseToTop();
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);
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);
475 private void CreateLayoutButton()
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) =>
488 mCurrentLayout = (mCurrentLayout + 1) % (int)mItemView.GetLayoutCount();
495 mToolBarLayer.Add(mLayoutButton);
498 public void CreateEditButton()
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) =>
514 mToolBarLayer.Add(mEditButton);
517 private void SetLayoutTitle()
519 if (Mode.MODE_NORMAL == mMode)
521 string title = APPLICATION_TITLE;
522 switch (mCurrentLayout)
524 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
525 title = title + ": " + SPIRAL_LABEL;
527 case (int)AllImagesLayouts.GRID_LAYOUT:
528 title = title + ": " + GRID_LABEL;
530 case (int)AllImagesLayouts.DEPTH_LAYOUT:
531 title = title + ": " + DEPTH_LABEL;
540 private void CreateDeleteButton()
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) =>
555 ItemIdContainer removeList = new ItemIdContainer();
556 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
558 View child = mItemView.GetChildAt(i);
561 View tick = child.FindChildByName("Tick");
563 if (tick != null && tick.Visibility)
565 removeList.Add(mItemView.GetItemId(child));
570 if (removeList.Count != 0)
572 mItemView.RemoveItems(removeList, 0.5f);
576 NUIApplication.GetDefaultWindow().Add(mDeleteButton);
579 private void CreateInsertButton()
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) =>
594 ItemContainer insertList = new ItemContainer();
595 Random random = new Random();
596 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
598 View child = mItemView.GetChildAt(i);
601 View tick = child.FindChildByName("Tick");
603 if (tick != null && tick.Visibility)
605 insertList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
609 if (insertList.Count != 0)
611 mItemView.InsertItems(insertList, 0.5f);
615 NUIApplication.GetDefaultWindow().Add(mInsertButton);
618 private void CreateReplaceButton()
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) =>
633 ItemContainer replaceList = new ItemContainer();
634 Random random = new Random();
635 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
637 View child = mItemView.GetChildAt(i);
640 View tick = child.FindChildByName("Tick");
642 if (tick != null && tick.Visibility)
644 replaceList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
649 if (replaceList.Count != 0)
651 mItemView.ReplaceItems(replaceList, 0.5f);
655 NUIApplication.GetDefaultWindow().Add(mReplaceButton);
658 void SwitchToNextMode()
662 case Mode.MODE_REMOVE:
665 mMode = Mode.MODE_REMOVE_MANY;
666 EnterRemoveManyMode();
670 case Mode.MODE_REMOVE_MANY:
672 ExitRemoveManyMode();
673 mMode = Mode.MODE_INSERT;
678 case Mode.MODE_INSERT:
681 mMode = Mode.MODE_INSERT_MANY;
682 EnterInsertManyMode();
686 case Mode.MODE_INSERT_MANY:
688 ExitInsertManyMode();
689 mMode = Mode.MODE_REPLACE;
694 case Mode.MODE_REPLACE:
697 mMode = Mode.MODE_REPLACE_MANY;
698 EnterReplaceManyMode();
702 case Mode.MODE_REPLACE_MANY:
704 ExitReplaceManyMode();
705 mMode = Mode.MODE_NORMAL;
710 case Mode.MODE_NORMAL:
713 mMode = Mode.MODE_REMOVE;
720 void EnterRemoveMode()
722 SetTitle("Edit: Remove");
723 mTapDetector = new TapGestureDetector();
725 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
727 if (mItemView.GetChildAt(i) != null)
729 mTapDetector.Attach(mItemView.GetChildAt(i));
733 mTapDetector.Detected += (obj, e) =>
738 mItemView.RemoveItem(mItemView.GetItemId(item), 0.5f);
743 void ExitRemoveMode()
745 mTapDetector.DetachAll();
746 mTapDetector.Reset();
749 void EnterRemoveManyMode()
751 SetTitle("Edit: Remove Many");
752 mDeleteButton.Show();
754 mTapDetector = new TapGestureDetector();
756 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
758 View child = mItemView.GetChildAt(i);
761 View box = child.FindChildByName("CheckBox");
764 mTapDetector.Attach(child);
770 mTapDetector.Detected += (obj, e) =>
775 Console.WriteLine("haha");
779 Console.WriteLine("hehe");
781 View tick = view.FindChildByName("Tick");
796 void ExitRemoveManyMode()
798 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
800 View child = mItemView.GetChildAt(i);
803 View box = child.FindChildByName("CheckBox");
809 View tick = box.FindChildByName("Tick");
817 mTapDetector.Reset();
818 mDeleteButton.Hide();
821 void EnterInsertMode()
823 SetTitle("Edit: Insert");
824 mTapDetector = new TapGestureDetector();
826 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
828 if (mItemView.GetChildAt(i) != null)
830 mTapDetector.Attach(mItemView.GetChildAt(i));
834 mTapDetector.Detected += (obj, e) =>
838 uint id = mItemView.GetItemId(e.View);
839 Random random = new Random();
841 View newActor = NewItemView((uint)random.Next(52));
843 mItemView.InsertItem(new Item(id, newActor), 0.5f);
847 Tizen.Log.Fatal("NUI", "e.View is null when EnterInsertMode!");
852 void ExitInsertMode()
854 mTapDetector.DetachAll();
855 mTapDetector.Reset();
857 void EnterInsertManyMode()
859 SetTitle("Edit: Insert Many");
860 mInsertButton.Show();
862 mTapDetector = new TapGestureDetector();
864 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
866 View child = mItemView.GetChildAt(i);
869 View box = child.FindChildByName("CheckBox");
873 mTapDetector.Attach(child);
878 mTapDetector.Detected += (obj, e) =>
880 View tick = (e.View).FindChildByName("Tick");
895 void ExitInsertManyMode()
897 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
899 View child = mItemView.GetChildAt(i);
902 View box = child.FindChildByName("CheckBox");
908 View tick = box.FindChildByName("Tick");
916 mTapDetector.Reset();
917 mInsertButton.Hide();
920 void EnterReplaceMode()
922 SetTitle("Edit: Replace");
923 mTapDetector = new TapGestureDetector();
925 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
927 if (mItemView.GetChildAt(i) != null)
929 mTapDetector.Attach(mItemView.GetChildAt(i));
933 mTapDetector.Detected += (obj, e) =>
935 Random random = new Random();
936 mItemView.ReplaceItem(new Item(mItemView.GetItemId(e.View), NewItemView((uint)random.Next(52))), 0.5f);
940 void ExitReplaceMode()
942 mTapDetector.DetachAll();
943 mTapDetector.Reset();
947 void EnterReplaceManyMode()
949 SetTitle("Edit: Replace Many");
950 mReplaceButton.Show();
952 mTapDetector = new TapGestureDetector();
954 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
956 View child = mItemView.GetChildAt(i);
957 View box = child.FindChildByName("CheckBox");
961 mTapDetector.Attach(child);
966 mTapDetector.Detected += (obj, e) =>
968 View tick = (e.View).FindChildByName("Tick");
982 void ExitReplaceManyMode()
984 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
986 View child = mItemView.GetChildAt(i);
987 View box = child.FindChildByName("CheckBox");
993 View tick = box.FindChildByName("Tick");
1000 mTapDetector.Reset();
1001 mReplaceButton.Hide();