Exemple #1
0
        public void ValidateIndexPath()
        {
            RunOnUIThread.Execute(() =>
            {
                IndexPath path = IndexPath.CreateFromIndices(null);
                Verify.AreEqual(0, path.GetSize());

                path = IndexPath.CreateFrom(5);
                Verify.AreEqual(1, path.GetSize());
                Verify.AreEqual(5, path.GetAt(0));

                path = IndexPath.CreateFrom(1, 2);
                Verify.AreEqual(2, path.GetSize());
                Verify.AreEqual(1, path.GetAt(0));
                Verify.AreEqual(2, path.GetAt(1));

                Verify.AreEqual(0, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(0, 1)));
                Verify.AreEqual(-1, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(1, 0)));
                Verify.AreEqual(1, IndexPath.CreateFrom(0, 1).CompareTo(IndexPath.CreateFrom(0, 0)));

                Verify.AreEqual(-1, IndexPath.CreateFrom(1, 0).CompareTo(IndexPath.CreateFrom(1, 1)));
                Verify.AreEqual(0, IndexPath.CreateFrom(1, 0).CompareTo(IndexPath.CreateFrom(1, 0)));
                Verify.AreEqual(1, IndexPath.CreateFrom(1, 1).CompareTo(IndexPath.CreateFrom(1, 0)));


                var emptyPath = IndexPath.CreateFromIndices(null);
                Verify.AreEqual(0, emptyPath.CompareTo(emptyPath));
                var path1 = IndexPath.CreateFrom(1);
                Verify.AreEqual(-1, emptyPath.CompareTo(path1));
                Verify.AreEqual(1, path1.CompareTo(emptyPath));
                var path12 = IndexPath.CreateFrom(1, 2);
                Verify.AreEqual(-1, path1.CompareTo(path12));
                Verify.AreEqual(1, path12.CompareTo(path1));
            });
        }
Exemple #2
0
        public void SelectRangeRegressionTest()
        {
            RunOnUIThread.Execute(() =>
            {
                var selectionModel = new SelectionModel()
                {
                    Source = CreateNestedData(1, 2, 3)
                };

                // length of start smaller than end used to cause an out of range error.
                selectionModel.SelectRange(IndexPath.CreateFrom(0), IndexPath.CreateFrom(1, 1));

                ValidateSelection(selectionModel,
                                  new List <IndexPath>()
                {
                    Path(0, 0),
                    Path(0, 1),
                    Path(0, 2),
                    Path(0),
                    Path(1, 0),
                    Path(1, 1)
                },
                                  new List <IndexPath>()
                {
                    Path(),
                    Path(1)
                },
                                  1 /* selectedInnerNodes */);
            });
        }
Exemple #3
0
 public void ValidateCanSetSelectedIndex()
 {
     RunOnUIThread.Execute(() =>
     {
         var model           = new SelectionModel();
         var ip              = IndexPath.CreateFrom(34);
         model.SelectedIndex = ip;
         Verify.AreEqual(0, ip.CompareTo(model.SelectedIndex));
     });
 }
Exemple #4
0
        private object GetData(SelectionModel selectionModel, IndexPath indexPath)
        {
            var data = selectionModel.Source;

            for (int i = 0; i < indexPath.GetSize(); i++)
            {
                var listData = data as IList;
                data = listData[indexPath.GetAt(i)];
            }

            return(data);
        }
Exemple #5
0
 private void SelectRangeFromAnchor(SelectionModel manager, IndexPath index, bool select)
 {
     Log.Comment("SelectRangeFromAnchor " + index + " select: " + select.ToString());
     if (select)
     {
         manager.SelectRangeFromAnchorTo(index);
     }
     else
     {
         manager.DeselectRangeFromAnchorTo(index);
     }
 }
Exemple #6
0
 private void Select(SelectionModel manager, IndexPath index, bool select)
 {
     Log.Comment((select ? "Selecting " : "DeSelecting ") + index);
     if (select)
     {
         manager.SelectAt(index);
     }
     else
     {
         manager.DeselectAt(index);
     }
 }
Exemple #7
0
        private bool Contains(List <IndexPath> list, IndexPath index)
        {
            bool contains = false;

            foreach (var item in list)
            {
                if (item.CompareTo(index) == 0)
                {
                    contains = true;
                    break;
                }
            }

            return(contains);
        }
        private static bool IsRealized(IndexPath indexPath)
        {
            bool isRealized = true;

            for (int i = 0; i < indexPath.GetSize(); i++)
            {
                if (indexPath.GetAt(i) < 0)
                {
                    isRealized = false;
                    break;
                }
            }

            return(isRealized);
        }
Exemple #9
0
        private bool AreEqual(IndexPath a, IndexPath b)
        {
            if (a.GetSize() != b.GetSize())
            {
                return(false);
            }

            for (int i = 0; i < a.GetSize(); i++)
            {
                if (a.GetAt(i) != b.GetAt(i))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #10
0
        private static void Traverse(object root, Action <TreeWalkNodeInfo> nodeAction)
        {
            var       pendingNodes = new Stack <TreeWalkNodeInfo>();
            IndexPath current      = Path(null);

            pendingNodes.Push(new TreeWalkNodeInfo()
            {
                Current = root, Path = current
            });

            while (pendingNodes.Count > 0)
            {
                var currentNode   = pendingNodes.Pop();
                var currentObject = currentNode.Current as IList;

                if (currentObject != null)
                {
                    for (int i = currentObject.Count - 1; i >= 0; i--)
                    {
                        var        child = currentObject[i];
                        List <int> path  = new List <int>();
                        for (int idx = 0; idx < currentNode.Path.GetSize(); idx++)
                        {
                            path.Add(currentNode.Path.GetAt(idx));
                        }

                        path.Add(i);
                        var childPath = IndexPath.CreateFromIndices(path);
                        if (child != null)
                        {
                            pendingNodes.Push(new TreeWalkNodeInfo()
                            {
                                Current = child, Path = childPath
                            });
                        }
                    }
                }

                nodeAction(currentNode);
            }
        }
        private IndexPath GetIndexPath()
        {
            var        child  = this as FrameworkElement;
            var        parent = child.Parent as FrameworkElement;
            List <int> path   = new List <int>();

            // TOOD: Hack to know when to stop
            while (!(parent is ItemsRepeater) || (parent as ItemsRepeater).Name != "rootRepeater")
            {
                if (parent is ItemsRepeater)
                {
                    path.Insert(0, (parent as ItemsRepeater).GetElementIndex(child));
                }

                child  = parent;
                parent = parent.Parent as FrameworkElement;
            }

            path.Insert(0, (parent as ItemsRepeater).GetElementIndex(child));

            return(IndexPath.CreateFromIndices(path));
        }
Exemple #12
0
 public static IndexPath Path(params int[] path)
 {
     return(IndexPath.CreateFromIndices(path));
 }
Exemple #13
0
 private void SetAnchorIndex(SelectionModel manager, IndexPath index)
 {
     Log.Comment("SetAnchor " + index);
     manager.AnchorIndex = index;
 }