2 using System.Collections.Generic;
3 using Tizen.NUI.BaseComponents;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.UIComponents;
7 namespace Tizen.NUI.Samples
9 public class ZItemViewSample : IExample
11 private const float MIN_SWIPE_DISTANCE = 15.0f;
12 private const float MIN_SWIPE_SPEED = 5.0f;
13 private const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.0f;
14 private const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
15 private const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
16 private const float DEPTH_LAYOUT_COLUMNS = 3.0f;
17 private const int BUTTON_BORDER = -10;
18 private const float ITEM_BORDER_SIZE = 2.0f;
19 private const int ITEM_COUNT = 300;
21 private string APPLICATION_TITLE = "ItemView";
22 private string SPIRAL_LABEL = "Spiral";
23 private string GRID_LABEL = "Grid";
24 private string DEPTH_LABEL = "Depth";
26 private string TOOLBAR_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/top-bar.png";
27 private string EDIT_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-edit.png";
28 private string EDIT_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-edit-selected.png";
29 private string DELETE_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-delete.png";
30 private string DELETE_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-delete-selected.png";
31 private string REPLACE_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-replace.png";
32 private string REPLACE_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-replace-selected.png";
33 private string INSERT_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-insert.png";
34 private string INSERT_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-insert-selected.png.png";
35 private string SELECTED_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/item-select-check.png";
37 private string SPIRAL_LAYOUT_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-spiral.png";
38 private string SPIRAL_LAYOUT_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-spiral-selected.png";
39 private string GRID_LAYOUT_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-grid.png";
40 private string GRID_LAYOUT_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-grid-selected.png";
41 private string DEPTH_LAYOUT_IMAGE = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-depth.png";
42 private string DEPTH_LAYOUT_IMAGE_SELECTED = CommonResource.GetFHResourcePath() + "ItemViewDemo/icon-item-view-layout-depth-selected.png";
45 private ItemView mItemView;
46 private ItemFactoryWrapper mItemFactoryWrapper;
47 private PropertyMap mGridLayout;
48 private PropertyMap mDepthLayout;
49 private PropertyMap mSpiralLayout;
50 private PropertyArray mLayout;
51 private int mCurrentLayout = (int)AllImagesLayouts.SPIRAL_LAYOUT;
52 private Mode mMode = Mode.MODE_NORMAL;
54 private LongPressGestureDetector mLongPressGestureDetector;
55 private TapGestureDetector mTapDetector;
57 private PushButton mLayoutButton;
58 private PushButton mEditButton;
59 private PushButton mDeleteButton;
60 private PushButton mInsertButton;
61 private PushButton mReplaceButton;
62 private TextLabel mTitle;
63 private ImageView mToolBarBackground;
65 private Layer mToolBarLayer;
66 //private Layer mContentLayer;
67 private View mContentView;
68 //private View mToolBarView;
70 private int mDurationSeconds = 250;
72 public static Vector3 DepthLayoutItemSizeFunctionPortrait(float layoutWidth)
74 float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
77 return new Vector3(width, width, width);
80 public static Vector3 DepthLayoutItemSizeFunctionLandscape(float layoutWidth)
82 float width = (layoutWidth / (DEPTH_LAYOUT_COLUMNS + 1.0f)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
85 return new Vector3(width, width, width);
88 private void SetTitle(string title)
96 public void CreateGridLayout()
98 mGridLayout = new PropertyMap();
99 mGridLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.GRID));
100 //mGridLayout.Add((int)DefaultItemLayoutProperty.GRID_COLUMN_NUMBER, new Dali.Property.Value(_columnNumber))
101 // .Add((int)DefaultItemLayoutProperty.GRID_ROW_SPACING, new Dali.Property.Value(_rowSpacing))
102 // .Add((int)DefaultItemLayoutProperty.GRID_COLUMN_SPACING, new Dali.Property.Value(_columnSpacing))
103 // .Add((int)DefaultItemLayoutProperty.GRID_TOP_MARGIN, new Dali.Property.Value(TopMargin))
104 // .Add((int)DefaultItemLayoutProperty.GRID_BOTTOM_MARGIN, new Dali.Property.Value(BottomMargin))
105 // .Add((int)DefaultItemLayoutProperty.GRID_BOTTOM_MARGIN, new Dali.Property.Value(SideMargin));
108 public void CreateDepthLayout()
110 mDepthLayout = new PropertyMap();
111 mDepthLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.DEPTH));
114 public void CreateSpiralLayout()
116 mSpiralLayout = new PropertyMap();
117 mSpiralLayout.Insert((int)DefaultItemLayoutProperty.TYPE, new PropertyValue((int)DefaultItemLayoutType.SPIRAL));
120 void SetLayoutImage()
124 switch (mCurrentLayout)
126 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
128 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE);
129 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE_SELECTED);
133 case (int)AllImagesLayouts.GRID_LAYOUT:
135 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(GRID_LAYOUT_IMAGE);
136 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(GRID_LAYOUT_IMAGE_SELECTED);
140 case (int)AllImagesLayouts.DEPTH_LAYOUT:
142 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(DEPTH_LAYOUT_IMAGE);
143 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(DEPTH_LAYOUT_IMAGE_SELECTED);
154 Animation animation = new Animation(mDurationSeconds);
155 animation.Finished += AnimationFinished;
156 animation.AnimateTo(mItemView, "Opacity", 0.0f);
160 void AnimationFinished(object sender, EventArgs e)
162 SetLayout(mCurrentLayout);
163 Animation animation = new Animation(mDurationSeconds);
164 animation.AnimateTo(mItemView, "Opacity", 1.0f);
168 private PropertyMap CreateImageVisual(string url)
170 PropertyMap temp = new PropertyMap();
171 temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
172 temp.Insert(ImageVisualProperty.URL, new PropertyValue(url));
176 public void Activate()
178 Window window = Window.Instance;
179 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
180 window.BackgroundColor = Color.Black;
182 //CreateToolBarView();
183 CreateToolBarLayer();
185 CreateLayoutButton();
187 CreateInsertButton();
188 CreateReplaceButton();
189 CreateDeleteButton();
193 CreateSpiralLayout();
195 mLayout = new PropertyArray();
196 mLayout.PushBack(new PropertyValue(mSpiralLayout));
197 mLayout.PushBack(new PropertyValue(mDepthLayout));
198 mLayout.PushBack(new PropertyValue(mGridLayout));
201 mItemFactoryWrapper = new ItemFactoryWrapper();
202 mItemFactoryWrapper.GetNumberDelegate = GetNumberOfItems;
203 mItemFactoryWrapper.NewItemDelegate = NewItemView;
205 mItemView = new ItemView(mItemFactoryWrapper);
206 //mItemView.BackgroundColor = Color.Blue;
207 mItemView.ParentOrigin = Position.ParentOriginCenter;
208 mItemView.PivotPoint = Position.PivotPointCenter;
209 mItemView.PositionUsesPivotPoint = true;
210 window.Add(mItemView);
212 window.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
214 mItemView.Layout = mLayout;
215 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
216 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
218 SetLayout((int)mCurrentLayout);
222 mLongPressGestureDetector = new LongPressGestureDetector();
223 mLongPressGestureDetector.Attach(mItemView);
224 mLongPressGestureDetector.Detected += OnLongPressGestureDetected;
227 private void OnLongPressGestureDetected(object source, LongPressGestureDetector.DetectedEventArgs e)
229 switch (e.LongPressGesture.State)
231 case Gesture.StateType.Started:
233 Size2D windowSize = Window.Instance.Size;
234 ItemRange range = new ItemRange(0, 0);
235 mItemView.GetItemsRange(range);
237 uint item = (e.LongPressGesture.ScreenPoint.Y < 0.5f * (float)windowSize.Height) ? range.begin : range.end;
239 mItemView.ScrollToItem(item, SCROLL_TO_ITEM_ANIMATION_TIME);
243 case Gesture.StateType.Finished:
245 PropertyMap attributes = new PropertyMap();
246 mItemView.DoAction("stopScrolling", attributes);
256 void SetLayout(int layoutId)
258 Window window = Window.Instance;
259 switch (mCurrentLayout)
261 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
262 case (int)AllImagesLayouts.DEPTH_LAYOUT:
264 Window.Instance.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer3D;
267 case (int)AllImagesLayouts.GRID_LAYOUT:
269 Window.Instance.GetDefaultLayer().Behavior = Layer.LayerBehavior.LayerUI;
274 // Set the new orientation to the layout
276 //mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
278 Size2D windowSize = Window.Instance.Size;
280 if (layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT)
282 mDepthLayout.Insert((int)DefaultItemLayoutProperty.ITEM_SIZE, new PropertyValue(DepthLayoutItemSizeFunctionPortrait(800)));
284 mLayout.PushBack(new PropertyValue(mSpiralLayout));
285 mLayout.PushBack(new PropertyValue(mDepthLayout));
286 mLayout.PushBack(new PropertyValue(mGridLayout));
287 mItemView.Layout = mLayout;
289 // Set up the depth layout according to the new orientation
291 //if (Toolkit::IsVertical(mDepthLayout->GetOrientation()))
293 // mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionPortrait(stageSize.width));
297 // mDepthLayout->SetItemSize(DepthLayoutItemSizeFunctionLandscape(stageSize.height));
301 // Enable anchoring for depth layout only
302 mItemView.SetAnchoring(layoutId == (int)AllImagesLayouts.DEPTH_LAYOUT);
304 // Activate the layout
305 mItemView.ActivateLayout((uint)layoutId, new Vector3(800, 800, 800), 0.0f);
306 //mItemView.ActivateLayout((uint)layoutId, new Vector3(windowSize.Width, windowSize.Height, windowSize.Width), 0.0f);
311 public uint GetNumberOfItems()
316 public View NewItemView(uint itemId)
318 // Create an image view for this item
319 string imagePath = CommonResource.GetFHResourcePath() + "ItemViewDemo/gallery/gallery-medium-";
320 uint id = itemId % 53;
321 imagePath += id.ToString();
323 PropertyMap propertyMap = new PropertyMap();
324 propertyMap.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
325 propertyMap.Insert(ImageVisualProperty.URL, new PropertyValue(imagePath));
326 propertyMap.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)VisualFittingModeType.FitKeepAspectRatio));
327 ImageView actor = new ImageView();
328 actor.Image = propertyMap;
329 actor.PositionZ = 0.0f;
330 actor.Position = new Position(1000.0f, 0, -1000.0f);
332 // Add a border image child actor
333 ImageView borderActor = new ImageView();
334 borderActor.ParentOrigin = ParentOrigin.Center;
335 borderActor.PivotPoint = PivotPoint.Center;
336 borderActor.PositionUsesPivotPoint = true;
337 borderActor.HeightResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
338 borderActor.WidthResizePolicy = ResizePolicyType.SizeFixedOffsetFromParent;
339 borderActor.SetSizeModeFactor(new Vector3(2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f));
340 //borderActor.SetColorMode(ColorMode.UseParentColor);
342 PropertyMap borderProperty = new PropertyMap();
343 borderProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Border));
344 borderProperty.Insert(BorderVisualProperty.Color, new PropertyValue(Color.White));
345 borderProperty.Insert(BorderVisualProperty.Size, new PropertyValue(ITEM_BORDER_SIZE));
346 borderProperty.Insert(BorderVisualProperty.AntiAliasing, new PropertyValue(true));
347 borderActor.Image = borderProperty;
349 actor.Add(borderActor);
351 Size spiralItemSize = new Size(30, 30, 0);
352 //static_cast < ItemLayout &> (*mSpiralLayout).GetItemSize(0u, Vector3(Stage::GetCurrent().GetSize()), spiralItemSize);
353 // Add a checkbox child actor; invisible until edit-mode is enabled
354 ImageView checkBox = new ImageView();
355 checkBox.Name = "CheckBox";
356 //checkBox.SetColorMode(ColorMode.UseParentColor);
357 checkBox.ParentOrigin = ParentOrigin.TopRight;
358 checkBox.PivotPoint = PivotPoint.TopRight;
359 checkBox.Size = spiralItemSize;
360 checkBox.PositionZ = 0.1f;
362 PropertyMap solidColorProperty = new PropertyMap();
363 solidColorProperty.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Color));
364 solidColorProperty.Insert(ColorVisualProperty.MixColor, new PropertyValue(new Color(0.0f, 0.0f, 0.0f, 0.6f)));
365 checkBox.Image = solidColorProperty;
367 if (Mode.MODE_REMOVE_MANY != mMode &&
368 Mode.MODE_INSERT_MANY != mMode &&
369 Mode.MODE_REPLACE_MANY != mMode)
373 borderActor.Add(checkBox);
375 ImageView tick = new ImageView(SELECTED_IMAGE);
377 //tick.SetColorMode(ColorMode.UseParentColor);
378 tick.ParentOrigin = ParentOrigin.TopRight;
379 tick.PivotPoint = PivotPoint.TopRight;
380 tick.Size = spiralItemSize;
386 mTapDetector.Attach(actor);
391 public void Deactivate()
393 if(mLayoutButton != null)
395 mLayoutButton.GetParent().Remove(mLayoutButton);
396 mLayoutButton.Dispose();
399 if (mEditButton != null)
401 mEditButton.GetParent().Remove(mEditButton);
402 mEditButton.Dispose();
405 if (mReplaceButton != null)
407 mReplaceButton.GetParent().Remove(mReplaceButton);
408 mReplaceButton.Dispose();
411 if (mInsertButton != null)
413 mInsertButton.GetParent().Remove(mInsertButton);
414 mInsertButton.Dispose();
417 if (mDeleteButton != null)
419 mDeleteButton.GetParent().Remove(mDeleteButton);
420 mDeleteButton.Dispose();
425 mTitle.GetParent().Remove(mTitle);
429 if (mToolBarBackground != null)
431 mToolBarBackground.GetParent().Remove(mToolBarBackground);
432 mToolBarBackground.Dispose();
435 if(mItemView != null)
437 mItemView.GetParent().Remove(mItemView);
441 if (mContentView != null)
443 Window.Instance.Remove(mContentView);
444 mContentView.Dispose();
447 if(mToolBarLayer != null)
449 Window.Instance.RemoveLayer(mToolBarLayer);
450 mToolBarLayer.Dispose();
453 Window.Instance.GetDefaultLayer().Behavior = Layer.LayerBehavior.Layer2D;
456 public void CreateContentView()
458 mContentView = new View();
459 mContentView.ParentOrigin = ParentOrigin.Center;
460 mContentView.PivotPoint = PivotPoint.Center;
461 mContentView.PositionUsesPivotPoint = true;
462 mContentView.WidthResizePolicy = ResizePolicyType.FillToParent;
463 mContentView.HeightResizePolicy = ResizePolicyType.FillToParent;
464 Window.Instance.Add(mContentView);
466 mContentView.LowerToBottom();
470 //public void CreateToolBarView()
472 // mToolBarView = new View();
473 // mToolBarView.Name = "TOOLBAR";
474 // mToolBarView.BackgroundImage = TOOLBAR_IMAGE;
475 // mToolBarView.ParentOrigin = ParentOrigin.TopCenter;
476 // mToolBarView.PivotPoint = PivotPoint.TopCenter;
477 // mToolBarView.PositionUsesPivotPoint = true;
478 // mToolBarView.WidthResizePolicy = ResizePolicyType.FillToParent;
479 // mToolBarView.Size2D = new Size2D(0, 80);
480 // Window.Instance.Add(mToolBarView);
482 // mToolBarView.RaiseToTop();
484 // mTitle = new TextLabel();
485 // mTitle.ParentOrigin = ParentOrigin.TopLeft;
486 // mTitle.PivotPoint = PivotPoint.TopLeft;
487 // mTitle.PositionUsesPivotPoint = true;
488 // mTitle.PointSize = 10.0f;
489 // mTitle.WidthResizePolicy = ResizePolicyType.FillToParent;
490 // mTitle.HeightResizePolicy = ResizePolicyType.FillToParent;
491 // mTitle.Text = APPLICATION_TITLE;
492 // mTitle.VerticalAlignment = VerticalAlignment.Center;
493 // mTitle.HorizontalAlignment = HorizontalAlignment.Center;
494 // mToolBarView.Add(mTitle);
497 private void CreateToolBarLayer()
499 mToolBarLayer = new Layer();
500 mToolBarLayer.Name = "TOOLBAR";
501 //mToolBarLayer.BackgroundImage = TOOLBAR_IMAGE;
502 //mToolBarLayer.PositionUsesPivotPoint = true;
503 mToolBarLayer.SetAnchorPoint(PivotPoint.TopCenter);
504 mToolBarLayer.SetParentOrigin(ParentOrigin.TopCenter);
505 mToolBarLayer.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.Width);
506 mToolBarLayer.SetSize(0, 80);
507 Window.Instance.AddLayer(mToolBarLayer);
509 mToolBarLayer.RaiseToTop();
511 mToolBarBackground = new ImageView();
512 mToolBarBackground.ParentOrigin = ParentOrigin.TopLeft;
513 mToolBarBackground.PivotPoint = PivotPoint.TopLeft;
514 mToolBarBackground.PositionUsesPivotPoint = true;
515 mToolBarBackground.WidthResizePolicy = ResizePolicyType.FillToParent;
516 mToolBarBackground.HeightResizePolicy = ResizePolicyType.FillToParent;
517 mToolBarBackground.ResourceUrl = TOOLBAR_IMAGE;
518 mToolBarLayer.Add(mToolBarBackground);
520 mTitle = new TextLabel();
521 mTitle.ParentOrigin = ParentOrigin.TopLeft;
522 mTitle.PivotPoint = PivotPoint.TopLeft;
523 mTitle.PositionUsesPivotPoint = true;
524 mTitle.PointSize = 10.0f;
525 mTitle.WidthResizePolicy = ResizePolicyType.FillToParent;
526 mTitle.HeightResizePolicy = ResizePolicyType.FillToParent;
527 mTitle.Text = APPLICATION_TITLE;
528 mTitle.VerticalAlignment = VerticalAlignment.Center;
529 mTitle.HorizontalAlignment = HorizontalAlignment.Center;
530 mToolBarLayer.Add(mTitle);
533 private void CreateLayoutButton()
535 mLayoutButton = new PushButton();
536 mLayoutButton.UnselectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE);
537 mLayoutButton.SelectedBackgroundVisual = CreateImageVisual(SPIRAL_LAYOUT_IMAGE_SELECTED);
538 mLayoutButton.Size2D = new Size2D(34, 34);
539 mLayoutButton.ParentOrigin = ParentOrigin.TopRight;
540 mLayoutButton.PivotPoint = PivotPoint.TopRight;
541 mLayoutButton.Position2D = new Position2D(0, 25);
542 mLayoutButton.PositionUsesPivotPoint = true;
543 mLayoutButton.LeaveRequired = true;
544 mLayoutButton.Clicked += (obj, e) =>
546 mCurrentLayout = (mCurrentLayout + 1) % (int)mItemView.GetLayoutCount();
553 //mToolBarView.Add(mLayoutButton);
554 mToolBarLayer.Add(mLayoutButton);
557 public void CreateEditButton()
559 mEditButton = new PushButton();
560 mEditButton.UnselectedBackgroundVisual = CreateImageVisual(EDIT_IMAGE);
561 mEditButton.SelectedBackgroundVisual = CreateImageVisual(EDIT_IMAGE_SELECTED);
562 mEditButton.Size2D = new Size2D(34, 34);
563 mEditButton.ParentOrigin = ParentOrigin.TopLeft;
564 mEditButton.PivotPoint = PivotPoint.TopLeft;
565 mEditButton.Position2D = new Position2D(5, 25);
566 mEditButton.PositionUsesPivotPoint = true;
567 mEditButton.LeaveRequired = true;
568 mEditButton.Clicked += (obj, e) =>
573 //mToolBarView.Add(mEditButton);
574 mToolBarLayer.Add(mEditButton);
577 private void SetLayoutTitle()
579 if (Mode.MODE_NORMAL == mMode)
581 string title = APPLICATION_TITLE;
582 switch (mCurrentLayout)
584 case (int)AllImagesLayouts.SPIRAL_LAYOUT:
585 title = title + ": " + SPIRAL_LABEL;
587 case (int)AllImagesLayouts.GRID_LAYOUT:
588 title = title + ": " + GRID_LABEL;
590 case (int)AllImagesLayouts.DEPTH_LAYOUT:
591 title = title + ": " + DEPTH_LABEL;
600 private void CreateDeleteButton()
602 mDeleteButton = new PushButton();
603 //mDeleteButton.BackgroundColor = Color.Red;
604 mDeleteButton.ParentOrigin = ParentOrigin.BottomRight;
605 mDeleteButton.PivotPoint = PivotPoint.BottomRight;
606 mDeleteButton.PositionUsesPivotPoint = true;
607 mDeleteButton.Position2D = new Position2D(BUTTON_BORDER, BUTTON_BORDER);
608 mDeleteButton.DrawMode = DrawModeType.Overlay2D;
609 mDeleteButton.UnselectedBackgroundVisual = CreateImageVisual(DELETE_IMAGE);
610 mDeleteButton.SelectedBackgroundVisual = CreateImageVisual(DELETE_IMAGE_SELECTED);
611 mDeleteButton.Size2D = new Size2D(50, 50);
612 mDeleteButton.LeaveRequired = true;
613 mDeleteButton.Hide();
614 mDeleteButton.Clicked += (obj, e) =>
616 ItemIdContainer removeList = new ItemIdContainer();
617 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
618 //for (uint i = 0; i < ITEM_COUNT; ++i)
620 View child = mItemView.GetChildAt(i);
623 View tick = child.FindChildByName("Tick");
625 if (tick != null && tick.Visibility)
627 removeList.Add(mItemView.GetItemId(child));
632 if (removeList.Count != 0)
634 mItemView.RemoveItems(removeList, 0.5f);
638 Window.Instance.Add(mDeleteButton);
641 private void CreateInsertButton()
643 mInsertButton = new PushButton();
644 //mInsertButton.BackgroundColor = Color.Red;
645 mInsertButton.ParentOrigin = ParentOrigin.BottomRight;
646 mInsertButton.PivotPoint = PivotPoint.BottomRight;
647 mInsertButton.PositionUsesPivotPoint = true;
648 mInsertButton.Position2D = new Position2D(BUTTON_BORDER, BUTTON_BORDER);
649 mInsertButton.DrawMode = DrawModeType.Overlay2D;
650 mInsertButton.UnselectedBackgroundVisual = CreateImageVisual(INSERT_IMAGE);
651 mInsertButton.SelectedBackgroundVisual = CreateImageVisual(INSERT_IMAGE_SELECTED);
652 mInsertButton.Size2D = new Size2D(50, 50);
653 mInsertButton.LeaveRequired = true;
654 mInsertButton.Hide();
655 mInsertButton.Clicked += (obj, e) =>
657 ItemContainer insertList = new ItemContainer();
658 Random random = new Random();
659 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
660 //for (uint i = 0; i < ITEM_COUNT; ++i)
662 View child = mItemView.GetChildAt(i);
665 View tick = child.FindChildByName("Tick");
667 if (tick != null && tick.Visibility)
669 insertList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
673 if (insertList.Count != 0)
675 mItemView.InsertItems(insertList, 0.5f);
679 Window.Instance.Add(mInsertButton);
682 private void CreateReplaceButton()
684 mReplaceButton = new PushButton();
685 //mReplaceButton.BackgroundColor = Color.Red;
686 mReplaceButton.ParentOrigin = ParentOrigin.BottomRight;
687 mReplaceButton.PivotPoint = PivotPoint.BottomRight;
688 mReplaceButton.PositionUsesPivotPoint = true;
689 mReplaceButton.Position2D = new Position2D(BUTTON_BORDER, BUTTON_BORDER);
690 mReplaceButton.DrawMode = DrawModeType.Overlay2D;
691 mReplaceButton.UnselectedBackgroundVisual = CreateImageVisual(REPLACE_IMAGE);
692 mReplaceButton.SelectedBackgroundVisual = CreateImageVisual(REPLACE_IMAGE_SELECTED);
693 mReplaceButton.Size2D = new Size2D(50, 50);
694 mReplaceButton.LeaveRequired = true;
695 mReplaceButton.Hide();
696 mReplaceButton.Clicked += (obj, e) =>
698 ItemContainer replaceList = new ItemContainer();
699 Random random = new Random();
700 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
701 //for (uint i = 0; i < ITEM_COUNT; ++i)
703 View child = mItemView.GetChildAt(i);
706 View tick = child.FindChildByName("Tick");
708 if (tick != null && tick.Visibility)
710 replaceList.Add(new Item(mItemView.GetItemId(child), NewItemView((uint)random.Next(52))));
715 if (replaceList.Count != 0)
717 mItemView.ReplaceItems(replaceList, 0.5f);
721 Window.Instance.Add(mReplaceButton);
724 void SwitchToNextMode()
728 case Mode.MODE_REMOVE:
731 mMode = Mode.MODE_REMOVE_MANY;
732 EnterRemoveManyMode();
736 case Mode.MODE_REMOVE_MANY:
738 ExitRemoveManyMode();
739 mMode = Mode.MODE_INSERT;
744 case Mode.MODE_INSERT:
747 mMode = Mode.MODE_INSERT_MANY;
748 EnterInsertManyMode();
752 case Mode.MODE_INSERT_MANY:
754 ExitInsertManyMode();
755 mMode = Mode.MODE_REPLACE;
760 case Mode.MODE_REPLACE:
763 mMode = Mode.MODE_REPLACE_MANY;
764 EnterReplaceManyMode();
768 case Mode.MODE_REPLACE_MANY:
770 ExitReplaceManyMode();
771 mMode = Mode.MODE_NORMAL;
776 case Mode.MODE_NORMAL:
779 mMode = Mode.MODE_REMOVE;
786 void EnterRemoveMode()
788 SetTitle("Edit: Remove");
789 mTapDetector = new TapGestureDetector();
791 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
792 //for (uint i = 0; i < ITEM_COUNT; ++i)
794 if(mItemView.GetChildAt(i) != null)
796 mTapDetector.Attach(mItemView.GetChildAt(i));
800 mTapDetector.Detected += (obj, e) =>
805 mItemView.RemoveItem(mItemView.GetItemId(item), 0.5f);
810 void ExitRemoveMode()
812 mTapDetector.DetachAll();
813 mTapDetector.Reset();
816 void EnterRemoveManyMode()
818 SetTitle("Edit: Remove Many");
819 mDeleteButton.Show();
821 mTapDetector = new TapGestureDetector();
823 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
824 //for (uint i = 0; i < ITEM_COUNT; ++i)
826 View child = mItemView.GetChildAt(i);
829 View box = child.FindChildByName("CheckBox");
832 mTapDetector.Attach(child);
838 mTapDetector.Detected += (obj, e) =>
843 Console.WriteLine("haha");
847 Console.WriteLine("hehe");
849 View tick = view.FindChildByName("Tick");
864 void ExitRemoveManyMode()
866 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
867 //for (uint i = 0; i < ITEM_COUNT; ++i)
869 View child = mItemView.GetChildAt(i);
872 View box = child.FindChildByName("CheckBox");
878 View tick = box.FindChildByName("Tick");
886 mTapDetector.Reset();
887 mDeleteButton.Hide();
890 void EnterInsertMode()
892 SetTitle("Edit: Insert");
893 mTapDetector = new TapGestureDetector();
895 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
896 //for (uint i = 0; i < ITEM_COUNT; ++i)
898 if(mItemView.GetChildAt(i) != null)
900 mTapDetector.Attach(mItemView.GetChildAt(i));
904 mTapDetector.Detected += (obj, e) =>
908 uint id = mItemView.GetItemId(e.View);
909 Random random = new Random();
911 View newActor = NewItemView((uint)random.Next(52));
913 mItemView.InsertItem(new Item(id, newActor), 0.5f);
917 Tizen.Log.Fatal("NUI", "e.View is null when EnterInsertMode!");
922 void ExitInsertMode()
924 mTapDetector.DetachAll();
925 mTapDetector.Reset();
927 void EnterInsertManyMode()
929 SetTitle("Edit: Insert Many");
930 mInsertButton.Show();
932 mTapDetector = new TapGestureDetector();
934 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
935 //for (uint i = 0; i < ITEM_COUNT; ++i)
937 View child = mItemView.GetChildAt(i);
940 View box = child.FindChildByName("CheckBox");
944 mTapDetector.Attach(child);
949 mTapDetector.Detected += (obj, e) =>
951 View tick = (e.View).FindChildByName("Tick");
966 void ExitInsertManyMode()
968 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
969 //for (uint i = 0; i < ITEM_COUNT; ++i)
971 View child = mItemView.GetChildAt(i);
974 View box = child.FindChildByName("CheckBox");
980 View tick = box.FindChildByName("Tick");
988 mTapDetector.Reset();
989 mInsertButton.Hide();
992 void EnterReplaceMode()
994 SetTitle("Edit: Replace");
995 mTapDetector = new TapGestureDetector();
997 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
998 //for (uint i = 0; i < ITEM_COUNT; ++i)
1000 if(mItemView.GetChildAt(i) != null)
1002 mTapDetector.Attach(mItemView.GetChildAt(i));
1006 mTapDetector.Detected += (obj, e) =>
1008 Random random = new Random();
1009 mItemView.ReplaceItem(new Item(mItemView.GetItemId(e.View), NewItemView((uint)random.Next(52))), 0.5f);
1013 void ExitReplaceMode()
1015 mTapDetector.DetachAll();
1016 mTapDetector.Reset();
1020 void EnterReplaceManyMode()
1022 SetTitle("Edit: Replace Many");
1023 mReplaceButton.Show();
1025 mTapDetector = new TapGestureDetector();
1027 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
1028 //for (uint i = 0; i < ITEM_COUNT; ++i)
1030 View child = mItemView.GetChildAt(i);
1031 View box = child.FindChildByName("CheckBox");
1035 mTapDetector.Attach(child);
1040 mTapDetector.Detected += (obj, e) =>
1042 View tick = (e.View).FindChildByName("Tick");
1045 if (tick.Visibility)
1056 void ExitReplaceManyMode()
1058 for (uint i = 0; i < mItemView.GetChildCount(); ++i)
1059 //for (uint i = 0; i < ITEM_COUNT; ++i)
1061 View child = mItemView.GetChildAt(i);
1062 View box = child.FindChildByName("CheckBox");
1068 View tick = box.FindChildByName("Tick");
1075 mTapDetector.Reset();
1076 mReplaceButton.Hide();