private void HandleItemSelect(KSStapleMenuItem item, int index)
 {
     this.SelectItem(item.Id, index);
     this.Collapse(true);
     if (this.ItemSelected != null)
     {
         this.ItemSelected(item.Id, index);
     }
 }
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            viewController            = new KSStapleMenuViewController();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible();

            var txt = new UITextField(new RectangleF(0, 0, 400, 30));

            txt.TextAlignment = UITextAlignment.Center;
            viewController.View.AddSubview(txt);
            txt.Center = new PointF(viewController.View.Center.X, viewController.View.Center.Y + 60);


            // Create a new annotation/sync/review selection toolbar.
            var stapleMenu                = new KSStapleMenu(KSStapleMenu.STAPLEMENU_MODE.Right, 80f, new SizeF(80f, 80f));
            KSStapleMenuItem inkItem      = null;
            KSStapleMenuItem noteItem     = null;
            KSStapleMenuItem freetextItem = null;
            KSStapleMenuItem hilightItem  = null;

            inkItem = new KSStapleMenuItem("INK", UIImage.FromBundle("Assets/Images/PDF/annot-ink-0"), "Ink 0", 12f, UIColor.Black);
            for (int i = 1; i <= 3; i++)
            {
                inkItem.AddElement(UIImage.FromBundle("Assets/Images/PDF/annot-ink-" + i), "Ink " + i, 12f, UIColor.Black);
            }
            hilightItem = new KSStapleMenuItem("HIGHLIGHT", UIImage.FromBundle("Assets/Images/PDF/annot-highlight-0"), "Highlight 0", 12f, UIColor.Black);
            for (int i = 1; i <= 3; i++)
            {
                hilightItem.AddElement(UIImage.FromBundle("Assets/Images/PDF/annot-highlight-" + i), "Highlight " + i, 12f, UIColor.Black);
            }
            noteItem     = new KSStapleMenuItem("NOTE", UIImage.FromBundle("Assets/Images/PDF/annot-note"), "Note", 12f, UIColor.Black);
            freetextItem = new KSStapleMenuItem("FREETEXT", UIImage.FromBundle("Assets/Images/PDF/annot-freetext"), "Freetext", 12f, UIColor.Black);

            KSStapleMenuItem syncItem          = null;
            KSStapleMenuItem switchReviewsItem = null;

            // Only show sync and review selection button if server side reviews are enabled and the user has permissions to annotate.
            syncItem          = new KSStapleMenuItem("SYNC", UIImage.FromBundle("Assets/Images/PDF/annot-sync"), "Sync", 12f, UIColor.Black);
            switchReviewsItem = new KSStapleMenuItem("REVIEWS", UIImage.FromBundle("Assets/Images/PDF/reviewselect"), "Switch", 12f, UIColor.Black);

            stapleMenu.AddItems(inkItem, hilightItem, noteItem, freetextItem, syncItem, switchReviewsItem);

            // Add a callback to get informed if an element was tapped.
            stapleMenu.ItemSelected += (string id, int index) =>
            {
                Console.WriteLine("Selected item {0} with index {1}", id, index);
                txt.Text = string.Format("Selected item {0} with index {1}", id, index);
            };

            viewController.View.AddSubview(stapleMenu);



            return(true);
        }
Exemple #3
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow (UIScreen.MainScreen.Bounds);

            viewController = new KSStapleMenuViewController ();
            window.RootViewController = viewController;
            window.MakeKeyAndVisible ();

            var txt = new UITextField(new RectangleF(0, 0, 400, 30));
            txt.TextAlignment = UITextAlignment.Center;
            viewController.View.AddSubview(txt);
            txt.Center = new PointF (viewController.View.Center.X, viewController.View.Center.Y + 60);

            // Create a new annotation/sync/review selection toolbar.
            var stapleMenu = new KSStapleMenu ( KSStapleMenu.STAPLEMENU_MODE.Right, 80f, new SizeF ( 80f, 80f ) );
            KSStapleMenuItem inkItem = null;
            KSStapleMenuItem noteItem = null;
            KSStapleMenuItem freetextItem = null;
            KSStapleMenuItem hilightItem = null;

            inkItem = new KSStapleMenuItem ( "INK", UIImage.FromBundle ( "Assets/Images/PDF/annot-ink-0" ), "Ink 0", 12f, UIColor.Black );
            for ( int i = 1; i <= 3; i++ )
            {
                inkItem.AddElement ( UIImage.FromBundle ( "Assets/Images/PDF/annot-ink-" + i ), "Ink " + i, 12f, UIColor.Black );
            }
            hilightItem = new KSStapleMenuItem ( "HIGHLIGHT", UIImage.FromBundle ( "Assets/Images/PDF/annot-highlight-0" ), "Highlight 0", 12f, UIColor.Black );
            for ( int i = 1; i <= 3; i++ )
            {
                hilightItem.AddElement ( UIImage.FromBundle ( "Assets/Images/PDF/annot-highlight-" + i ), "Highlight " + i, 12f, UIColor.Black );
            }
            noteItem = new KSStapleMenuItem ( "NOTE", UIImage.FromBundle ( "Assets/Images/PDF/annot-note" ), "Note", 12f, UIColor.Black );
            freetextItem = new KSStapleMenuItem ( "FREETEXT", UIImage.FromBundle ( "Assets/Images/PDF/annot-freetext" ), "Freetext", 12f, UIColor.Black );

            KSStapleMenuItem syncItem = null;
            KSStapleMenuItem switchReviewsItem = null;
            // Only show sync and review selection button if server side reviews are enabled and the user has permissions to annotate.
            syncItem = new KSStapleMenuItem ( "SYNC", UIImage.FromBundle ( "Assets/Images/PDF/annot-sync" ), "Sync", 12f, UIColor.Black );
            switchReviewsItem = new KSStapleMenuItem ( "REVIEWS", UIImage.FromBundle ( "Assets/Images/PDF/reviewselect" ), "Switch", 12f, UIColor.Black );

            stapleMenu.AddItems ( inkItem, hilightItem, noteItem, freetextItem, syncItem, switchReviewsItem );

            // Add a callback to get informed if an element was tapped.
            stapleMenu.ItemSelected += (string id, int index) =>
            {
                Console.WriteLine ("Selected item {0} with index {1}", id, index);
                txt.Text = string.Format ("Selected item {0} with index {1}", id, index);
            };

            viewController.View.AddSubview (stapleMenu);

            return true;
        }
        /// <summary>
        /// Adds items to the menu.
        /// </summary>
        /// <param name="itemsToAdd">Items to add.</param>
        public void AddItems(params KSStapleMenuItem[] itemsToAdd)
        {
            Debug.Assert(itemsToAdd != null, "Provide valid items for initialization!");

            if (this.items == null)
            {
                this.items = new ObservableCollection <KSStapleMenuItem> ();
            }

            this.items.CollectionChanged -= this.HandleItemsCollectionChanged;
            for (int i = 0; i < itemsToAdd.Length; ++i)
            {
                KSStapleMenuItem currentItem = itemsToAdd[i];
                if (currentItem == null)
                {
                    continue;
                }
                this.items.Add(currentItem);

                currentItem.SizeElements(this.ItemSize);
                currentItem.OnLongPress += this.HandleItemLongPress;
                currentItem.OnSelect    += this.HandleItemSelect;

                var containerView = new KSMenuItemHostView(this, currentItem);

                // Make container wide enough to hold all items.
                containerView.Frame = new RectangleF(0, 0, this.ItemSize.Width * currentItem.NumberOfElements, this.ItemSize.Height);

                // Add element views to container view.
                for (int elementIndex = 0; elementIndex < currentItem.NumberOfElements; elementIndex++)
                {
                    var itemView = currentItem.GetViewForIndex(elementIndex);
                    containerView.AddSubview(itemView);

                    if (this.Mode == STAPLEMENU_MODE.Right)
                    {
                        itemView.Center = new PointF(containerView.Bounds.Width - itemView.Bounds.Width / 2f, containerView.Bounds.Height / 2f);
                    }
                    else
                    {
                        itemView.Center = new PointF(itemView.Bounds.Width / 2f, containerView.Bounds.Height / 2f);
                    }
                }

                this.AddSubview(containerView);
            }
            this.items.CollectionChanged += this.HandleItemsCollectionChanged;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KSStapleMenu.KSMenuItemHostView"/> class.
        /// </summary>
        /// <param name="menu">the menu that is using this view</param>
        /// <param name="menuItem">the item encapsulated by the host view</param>
        internal KSMenuItemHostView(KSStapleMenu menu, KSStapleMenuItem menuItem) : base()
        {
            this.menu   = menu;
            this.ItemId = menuItem.Id;

//			this.BackgroundColor = UIColor.Blue;
//			this.Layer.BorderColor = UIColor.Yellow.CGColor;
//			this.Layer.BorderWidth = 2f;

            if (menuItem.NumberOfElements > 1)
            {
                this.expandIndicatorView = new ExpandIndicatorView(new RectangleF(0, 0, 8, 16))
                {
                    BackgroundColor = UIColor.Clear,
                };

                this.AddSubview(this.expandIndicatorView);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KSStapleMenu.KSMenuItemHostView"/> class.
        /// </summary>
        /// <param name="menu">the menu that is using this view</param>
        /// <param name="menuItem">the item encapsulated by the host view</param>
        internal KSMenuItemHostView(KSStapleMenu menu, KSStapleMenuItem menuItem)
            : base()
        {
            this.menu = menu;
            this.ItemId = menuItem.Id;

            //			this.BackgroundColor = UIColor.Blue;
            //			this.Layer.BorderColor = UIColor.Yellow.CGColor;
            //			this.Layer.BorderWidth = 2f;

            if(menuItem.NumberOfElements > 1)
            {
                this.expandIndicatorView = new ExpandIndicatorView(new RectangleF(0, 0, 8, 16))
                {
                    BackgroundColor = UIColor.Clear,
                };

                this.AddSubview(this.expandIndicatorView);
            }
        }
 private void HandleItemSelect(KSStapleMenuItem item, int index)
 {
     this.SelectItem (item.Id, index);
     this.Collapse (true);
     if(this.ItemSelected != null)
     {
         this.ItemSelected(item.Id, index);
     }
 }
        private void HandleItemLongPress(object sender, EventArgs args)
        {
            KSStapleMenuItem item = (KSStapleMenuItem)sender;

            this.ExpandItem(item.Id, true);
        }