예제 #1
0
        void HandleDidRenderPageViewEvent(PSPDFPageView pageView)
        {
            Page page = BooksOnDeviceAccessor.GetPage(book.ID, (int)pageView.Page + 1);

            if (page != null)
            {
                // Set current page id for Dashboard menu button action
                Settings.CurrentPageID = page.ID;

                // Clear the pageview
                foreach (UIView subview in pageView)
                {
                    if (subview.Tag == -1)
                    {
                        subview.RemoveFromSuperview();
                        break;
                    }
                }

                // bookmark
                Bookmark bookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, page.ID);

                // bookmarkButton
                UIButton bookmarkButton = GenerateBookmarkButton(pageView, page, bookmark);
                bookmarkButton.Tag = -1;
                pageView.AddSubview(bookmarkButton);

                UpdateBookmarkLocation(bookmarkButton);
            }
        }
 public override void DidRenderPageView(PSPDFViewController pdfController, PSPDFPageView pageView)
 {
     if (DidRenderPageViewEvent != null)
     {
         DidRenderPageViewEvent(pageView);
     }
 }
 public override void WillUnloadPageView(PSPDFViewController pdfController, PSPDFPageView pageView)
 {
     if (WillUnloadPageViewEvent != null)
     {
         WillUnloadPageViewEvent(pageView);
     }
 }
예제 #4
0
 public override void DidLoadPageView(PSPDFViewController pdfController, PSPDFPageView pageView)
 {
     // Fixed in 2.6.4 bindings. Looping subviews no longer crashes.
     foreach (UIView oSubview in pageView.Subviews)
     {
         Console.WriteLine(oSubview.DebugDescription);
     }
 }
 public override void DidLoadPageView(PSPDFViewController pdfController, PSPDFPageView pageView)
 {
     // Fixed in 2.6.4 bindings. Looping subviews no longer crashes.
     foreach(UIView oSubview in pageView.Subviews)
     {
         Console.WriteLine(oSubview.DebugDescription);
     }
 }
 public override bool DidTapOnAnnotation(PSPDFViewController pdfController, PSPDFAnnotation annotation, System.Drawing.PointF annotationPoint, PSPDFAnnotationViewProtocol annotationView, PSPDFPageView pageView, System.Drawing.PointF viewPoint)
 {
     if(annotation is PSPDFLinkAnnotation)
     {
         var linkAnnot = (PSPDFLinkAnnotation)annotation;
         Console.WriteLine("Tapped a link annotation!");
         var alert = new UIAlertView("TapTap", "Tapped link annotation. Target: " + linkAnnot.SiteLinkTarget, null, null, "OK");
         alert.Show();
         return true;
     }
     return false;
 }
예제 #7
0
        void HandleDidShowHideHudEvent()
        {
            UIButton      bookmarkButton = null;
            PSPDFPageView pageView       = this.PageViewForPage(this.Page);

            foreach (UIView subview in pageView)
            {
                if (subview is UIButton && subview.Tag == -1)
                {
                    bookmarkButton = subview as UIButton;
                    break;
                }
            }

            UpdateBookmarkLocation(bookmarkButton);
        }
예제 #8
0
        void HandleDidEndPageZoomingEvent(nfloat scale)
        {
            UIButton      bookmarkButton = null;
            PSPDFPageView pageView       = this.PageViewForPage(this.Page);

            if (pageView != null)
            {
                foreach (UIView subview in pageView)
                {
                    if (subview is UIButton && subview.Tag == -1)
                    {
                        bookmarkButton = subview as UIButton;
                        break;
                    }
                }

                if (scale == 1f)
                {
                    zoomed = false;

                    UpdateBookmarkLocation(bookmarkButton);

                    UIView.Animate(0.3d, delegate
                    {
                        if (bookmarkButton != null)
                        {
                            bookmarkButton.Alpha = 1;
                        }
                    });
                }
                else
                {
                    zoomed = true;

                    UIView.Animate(0.3d, delegate
                    {
                        if (bookmarkButton != null)
                        {
                            bookmarkButton.Alpha = 0;
                        }
                    });
                }
            }
        }
예제 #9
0
        private void ShowPanel(UIView panel)
        {
            if (Settings.PageMode == StringRef.Double)
            {
                Settings.WritePageMode(StringRef.Single);
                HandlePageModeEvent();
            }

            PSPDFPageView pageView = this.PageViewForPage(this.Page);

            if (pageView != null)
            {
                // Update
                Page page = BooksOnDeviceAccessor.GetPage(book.ID, (int)pageView.Page + 1);

                if (panel is NotePanel)
                {
                    notePanel.LoadNoteListView(page.ID);
                }
                else if (panel is PrintPanel)
                {
                    printPanel.UpdatePageID(page.ID);
                }

                UIView.Animate(0.3d, delegate
                {
                    panel.Frame = new CGRect(this.View.Bounds.Size.Width - panel.Frame.Width, panel.Frame.Y, panel.Frame.Width, panel.Frame.Height);
                }, delegate
                {
                    // Lock HUD
                    ((CustomPSPDFViewControllerDelegate)this.Delegate).Hud_Lock = true;

                    this.UpdateConfigurationWithoutReloading(delegate(PSPDFConfigurationBuilder builder)
                    {
                        builder.ShouldHideHUDOnPageChange = false;
                    });
                });
            }
        }
예제 #10
0
        private UIButton GenerateBookmarkButton(PSPDFPageView pageView, Page page, Bookmark bookmark)
        {
            UIButton button = UIButton.FromType(UIButtonType.Custom);

            // Image
            if (bookmark == null)
            {
                button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Normal);
                button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Highlighted);
            }
            else
            {
                button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Normal);
                button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Highlighted);
            }

            button.Frame = new CGRect(30, 0, button.CurrentBackgroundImage.Size.Width, button.CurrentBackgroundImage.Size.Height);

            // Action
            button.TouchUpInside += (object sender, EventArgs e) =>
            {
                UIAlertView alertView = new UIAlertView("Bookmark", "Please enter bookmark title and press Save.", null, StringRef.cancel, "Save");
                alertView.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
                alertView.GetTextField(0).ReturnKeyType = UIReturnKeyType.Done;
                alertView.GetTextField(0).Placeholder   = "Bookmark Title";

                // Show bookmark title if already exist
                bookmark = BooksOnDeviceAccessor.GetBookmark(book.ID, page.ID);
                if (bookmark != null)
                {
                    alertView.GetTextField(0).Text = bookmark.Title;
                }

                alertView.Dismissed += delegate(object sender1, UIButtonEventArgs e1)
                {
                    if (e1.ButtonIndex == 1)
                    {
                        String text = alertView.GetTextField(0).Text;
                        BookmarkUpdater.SaveBookmark(book, page.ID, text);

                        if (String.IsNullOrEmpty(text))
                        {
                            RemoveBookmarkFromBookmarkParser(this.Page);

                            button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Normal);
                            button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_add.png"), UIControlState.Highlighted);
                        }
                        else
                        {
                            AddBookmarkToBookmarkParser(this.Page);

                            button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Normal);
                            button.SetBackgroundImage(UIImage.FromBundle("Assets/Buttons/bookmark_solid.png"), UIControlState.Highlighted);
                        }
                    }
                };
                alertView.WillDismiss += delegate
                {
                    alertView.GetTextField(0).ResignFirstResponder();
                };
                alertView.Show();
            };

            return(button);
        }
        public override PSPDFMenuItem[] ShouldShowMenuItemsForSelectedText(PSPDFViewController pdfController, PSPDFMenuItem[] menuItems, CGRect rect, String selectedText, CGRect textRect, PSPDFPageView pageView)
        {
            int addIndex = 0;

            PSPDFMenuItem[] newItems = new PSPDFMenuItem[1];
            if (menuItems != null)
            {
                for (int i = 0; i < menuItems.Length; i++)
                {
                    if (menuItems [i].Identifier == "Search")
                    {
                        newItems [addIndex] = menuItems [i];
                        addIndex++;
                    }
                }
            }

            if (newItems != null && addIndex != 0)
            {
                return(newItems);
            }
            return(null);
        }
 public override PSPDFMenuItem[] ShouldShowMenuItemsForSelectedImage(PSPDFViewController pdfController, PSPDFMenuItem[] menuItems, CGRect rect, PSPDFImageInfo selectedImage, CGRect textRect, PSPDFPageView pageView)
 {
     return(null);
 }
 public override bool DidTapOnAnnotation(PSPDFViewController pdfController, PSPDFAnnotation annotation, System.Drawing.PointF annotationPoint, PSPDFAnnotationViewProtocol annotationView, PSPDFPageView pageView, System.Drawing.PointF viewPoint)
 {
     if (annotation is PSPDFLinkAnnotation)
     {
         var linkAnnot = (PSPDFLinkAnnotation)annotation;
         Console.WriteLine("Tapped a link annotation!");
         var alert = new UIAlertView("TapTap", "Tapped link annotation. Target: " + linkAnnot.SiteLinkTarget, null, null, "OK");
         alert.Show();
         return(true);
     }
     return(false);
 }
예제 #14
0
        public void DidSelectAnnotations(PSPDFViewController pdfController, PSPDFAnnotation [] annotations, PSPDFPageView pageView)
        {
            if (annotations == null)
            {
                return;
            }

            foreach (var annotation in annotations)
            {
                Console.WriteLine($"Selected Annotation: {annotation.Name}");
            }
        }
        public override PSPDFMenuItem[] ShouldShowMenuItemsForAnnotations(PSPDFViewController pdfController, PSPDFMenuItem[] menuItems, CGRect rect, PSPDFAnnotation[] annotations, CGRect textRect, PSPDFPageView pageView)
        {
            if (annotations != null)
            {
                PSPDFMenuItem[] newItems = new PSPDFMenuItem[1];

                PSPDFMenuItem removeMenu = new PSPDFMenuItem(StringRef.Remove, delegate
                {
                    annotations[0].Deleted = true;
                    pageView.RemoveAnnotation(annotations[0], null, true);

                    if (SaveAnnotationEvent != null)
                    {
                        SaveAnnotationEvent();
                    }
                }, StringRef.Remove);
                newItems[0] = removeMenu;

                return(newItems);
            }

            return(menuItems);
        }
예제 #16
0
        public PSPDFMenuItem[] ShouldShowMenuItemsForSelectedText(PSPDFViewController pdfController, PSPDFMenuItem[] menuItems, CGRect rect, string selectedText, CGRect textRect, PSPDFPageView pageView)
        {
            // Disable Wikipedia
            // Be sure to check for PSPDFMenuItem class; there might also be classic UIMenuItems in the array.
            // Note that for words that are in the iOS dictionary, instead of Wikipedia we show the "Define" menu item with the native dict.
            // There is also a simpler way to disable wikipedia (See PSPDFTextSelectionMenuAction)
            var newMenuItems = menuItems.Where((item) => !(item.IsKindOfClass(new Class(typeof(PSPDFMenuItem))) && item.Identifier == "Wikipedia")).ToList();

            // Add option to Google for it.
            newMenuItems.Add(new PSPDFMenuItem("Google", () => {
                var queryUri = new Uri(string.Format("https://www.google.com/search?q={0}", selectedText));
                var nsurl    = new NSUrl(queryUri.GetComponents(UriComponents.HttpRequestUrl, UriFormat.UriEscaped));

                var browser = new PSPDFWebViewController(nsurl)
                {
                    Delegate             = pdfController,
                    PreferredContentSize = new CGSize(600, 500)
                };

                var browserOptions = NSDictionary <NSString, NSObject> .FromObjectsAndKeys(
                    new NSObject[] { NSValue.FromCGRect(rect), NSNumber.FromBoolean(true), NSNumber.FromBoolean(true) },
                    new NSObject[] { PSPDFPresentationKeys.RectKey, PSPDFPresentationKeys.InNavigationControllerKey, PSPDFPresentationKeys.CloseButtonKey }
                    );

                pdfController.PresentViewController(browser, browserOptions, true, null, null);
            }, "Google"));

            return(newMenuItems.ToArray());
        }
예제 #17
0
        public List <AnnotationItem> GenerateParseItem(nuint page, PSPDFAnnotationType type)
        {
            List <AnnotationItem> items = null;

            PSPDFAnnotation[] anns = this.Document.AnnotationsForPage(page, type);
            if (anns != null)
            {
                if (anns.Length > 0)
                {
                    items = new List <AnnotationItem>();

                    PSPDFPageView pageView = this.PageViewForPage(page);
                    if (pageView != null)
                    {
                        for (int i = 0; i < anns.Length; i++)
                        {
                            if (!anns[i].Deleted)
                            {
                                String             dictionaryKey = StringRef.Pen;
                                PSPDFInkAnnotation ann           = (PSPDFInkAnnotation)anns[i];
                                if (ann.LineWidth > 10)
                                {
                                    dictionaryKey = StringRef.Highlighter;
                                }
                                dictionaryKey += " " + i.ToString();

                                // boundingBox
                                String description = String.Empty;
                                String boundingBox = ann.DictionaryValue["boundingBox"].ToString();
                                description += "[BoundingBox]" + boundingBox;

                                // color
                                String color = ann.DictionaryValue["color"].ToString();
                                description += "[Color]" + color;

                                // lineWidth
                                String lineWidth = ann.DictionaryValue["lineWidth"].ToString();
                                description += "[LineWidth]" + lineWidth;

                                // Add description to the dictionary
                                items.Add(new AnnotationItem(dictionaryKey, description));

                                // Lines
                                String points  = String.Empty;
                                String pdfSize = StringRef.pdfSize + pageView.Frame.Width + "x" + pageView.Frame.Height;
                                for (int j = 0; j < ann.Lines.Count; j++)
                                {
                                    if (j != 0)
                                    {
                                        points += StringRef.annDivider;
                                    }

                                    String pointStr = String.Empty;
                                    if (ann.Lines[j] != null && ann.Lines[j].Length > 0)
                                    {
                                        for (int k = 0; k < ann.Lines[j].Length; k++)
                                        {
                                            pointStr += ann.Lines[j][k].ToString();
                                        }
                                    }

                                    List <CGPoint> pointList = AnnotationsDataAccessor.GeneratePointF(pointStr);
                                    if (pointList != null && pointList.Count > 0)
                                    {
                                        points += pdfSize + StringRef.viewPoints;
                                        foreach (CGPoint point in pointList)
                                        {
                                            points += pageView.ConvertPdfPointToViewPoint(point);
                                        }

                                        points += StringRef.pdfPoints;
                                        foreach (CGPoint point in pointList)
                                        {
                                            points += point;
                                        }
                                    }
                                }

                                // Add line points to the dictionary
                                items.Add(new AnnotationItem(dictionaryKey, points));
                            }
                        }
                    }
                }
            }

            return(items);
        }