public void RedownloadFailedURLs()
        {
            if (BookUpdater.CurrentBook != null && BookUpdater.CurrentBook.FailedURLs != null)
            {
                ASINetworkQueue networkQueue = new ASINetworkQueue();
                networkQueue.Reset();
                networkQueue.ShowAccurateProgress             = false;
                networkQueue.ShouldCancelAllRequestsOnFailure = false;
                networkQueue.Delegate = this;

                networkQueue.RequestDidFail   = new Selector("requestDidFail:");
                networkQueue.RequestDidFinish = new Selector("requestDidFinish:");
                networkQueue.QueueDidFinish   = new Selector("queueDidFinish:");

                ASIHTTPRequest request = null;
                foreach (String url in BookUpdater.CurrentBook.FailedURLs)
                {
                    DownloadedFilesCache.RemoveFile(url);

                    request = new ASIHTTPRequest(NSUrl.FromString(url));
                    request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    request.Username = Settings.UserID;
                    request.Password = KeychainAccessor.Password;
                    request.Domain   = Settings.Domain;

                    networkQueue.AddOperation(request);
                }

                // Clear failedUrls before starting to re-download
                BookUpdater.CurrentBook.FailedURLs.Clear();

                networkQueue.Go();
            }
        }
        public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
        {
            var cell = (PageCell)collectionView.DequeueReusableCell(cellID, indexPath);

            var page = list[indexPath.Row];
            if (page != null)
            {
                cell.PageID = page.ID;

                if (page.ID != StringRef.Empty || page.ChapterID != StringRef.Empty)
                {
                    String url = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    if (!String.IsNullOrEmpty(url))
                    {
                        CGPDFDocument pdfDoc = CGPDFDocument.FromFile(url);
                        if (pdfDoc != null)
                        {
                            CGPDFPage pdfPage = pdfDoc.GetPage(1);

							UIImage image = ImageHelper.PDF2Image(pdfPage, 150, UIScreen.MainScreen.Scale);

                            // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                            SkipBackup2iCloud.SetAttribute(url);

                            if (image != null)
                            {
                                cell.Image = image;
                            }
                        }
                    }
                }
            }

            return cell;
        }
예제 #3
0
        public void UpdateImage(String url)
        {
            if (imageSpinner != null)
            {
                imageSpinner.StopAnimating();
            }

            String  localPath = DownloadedFilesCache.BuildCachedFilePath(url);
            UIImage image     = UIImage.FromFile(localPath);

            if (image != null)
            {
                imageView.Image = image;
            }
        }
예제 #4
0
        private static void DownloadPDFsWork(String bookID, List <String> urlList)
        {
            if (urlList.Count > 0)
            {
                networkQueue.Reset();
                networkQueue.ShowAccurateProgress             = false;
                networkQueue.ShouldCancelAllRequestsOnFailure = false;
                networkQueue.Delegate = ParentViewController;

                networkQueue.RequestDidFail   = new Selector("requestDidFail:");
                networkQueue.RequestDidFinish = new Selector("requestDidFinish:");
                networkQueue.QueueDidFinish   = new Selector("queueDidFinish:");

                ASIHTTPRequest request = null;
                foreach (String url in urlList)
                {
                    // Remove page if this is an update
                    if (CurrentBook.Status == Book.BookStatus.UPDATING)
                    {
                        DownloadedFilesCache.RemoveFile(url);
                    }

                    request = new ASIHTTPRequest(NSUrl.FromString(url));
                    request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    request.Username = Settings.UserID;
                    request.Password = KeychainAccessor.Password;
                    request.Domain   = Settings.Domain;

                    networkQueue.AddOperation(request);
                }

                // Clear failedUrls before starting to re-download
                InitializeFailedURLs();

                networkQueue.Go();
            }
            else
            {
                // Finished downloading
                if (DownloadFinishEvent != null)
                {
                    DownloadFinishEvent(bookID);
                }
            }
        }
        private PSPDFDocument GenerateDocument()
        {
            try
            {
                // Build local pdf file path array
                List <Page> pageList = BooksOnDeviceAccessor.GetPages(book.ID);
                if (pageList != null && pageList.Count > 0)
                {
                    List <String> urlList = new List <String>();
                    foreach (Page page in pageList)
                    {
                        urlList.Add(DownloadedFilesCache.BuildCachedFilePath(page.URL));
                    }

                    // Generate NSData array for each pdf file
                    List <NSData> dataList = new List <NSData>();
                    foreach (String url in urlList)
                    {
                        NSData data = NSData.FromFile(url);
                        dataList.Add(data);
                    }

                    // Generate PSPDFDocument from NSData array
                    if (dataList.Count > 0)
                    {
                        PSPDFDocument document = PSPDFDocument.FromData(dataList.ToArray());
                        if (document != null)
                        {
                            document.Title = book.Title;
                            return(document);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("DashboardViewController - GenerateDocument: {0}", ex.ToString());
            }

            return(null);
        }
예제 #6
0
        public static bool Download(String url, UIViewController controller, bool forceDownload = false)
        {
            bool exist = false;

            if (!String.IsNullOrEmpty(url) && url.Contains("http"))
            {
                try
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(url);
                    if (File.Exists(localPath) && !forceDownload)
                    {
                        exist = true;
                    }
                    else
                    {
                        if (Reachability.IsDefaultNetworkAvailable())
                        {
                            BackgroundWorker downloadWorker = new BackgroundWorker();
                            downloadWorker.DoWork += delegate
                            {
                                ASIHTTPRequest request = new ASIHTTPRequest(NSUrl.FromString(url));
                                request.Username                = Settings.UserID;
                                request.Password                = KeychainAccessor.Password;
                                request.Domain                  = Settings.Domain;
                                request.Delegate                = controller;
                                request.DidFinishSelector       = new Selector("requestFinish:");
                                request.DownloadDestinationPath = DownloadedFilesCache.BuildCachedFilePath(url);
                                request.StartAsynchronous();
                            };
                            downloadWorker.RunWorkerAsync();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLineDebugging("FileDownloader - Download: {0}", ex.ToString());
                }
            }

            return(exist);
        }
        public PopoverSearchResultView(Book book, CGRect frame) : base(frame)
        {
            this.BackgroundColor = UIColor.Clear;

            // imageView
            UIImageView imageView = new UIImageView(new CGRect(10, 10, 80, 80));

            imageView.ContentMode = UIViewContentMode.ScaleAspectFit;
            this.AddSubview(imageView);

            String localImagePath = DownloadedFilesCache.BuildCachedFilePath(book.LargeImageURL);

            if (File.Exists(localImagePath))
            {
                imageView.Image = UIImage.FromFile(localImagePath);
            }

            TitleDescriptionView tdView = new TitleDescriptionView(book.Title, book.Description, frame.Width - (imageView.Frame.Width + 30));

            tdView.Frame = new CGRect(imageView.Frame.Right + 10, frame.Height / 2 - tdView.Frame.Height / 2, tdView.Frame.Width, tdView.TotalHeight);
            this.AddSubview(tdView);
        }
예제 #8
0
        public ChapterView(String bookID, Chapter chapter, int index) : base(new CGRect(0, 0, 220, 388.33f))
        {
            this.BookChapter = chapter;

            this.BackgroundColor     = UIColor.White;
            this.Layer.ShadowColor   = UIColor.Black.CGColor;
            this.Layer.ShadowOpacity = 0.3f;
            this.Layer.ShadowRadius  = 2f;
            this.Layer.ShadowOffset  = new CGSize(5f, 5f);

            // imageView
            UIImageView imageView = new UIImageView();

            imageView.Frame = new CGRect(0, 0, this.Frame.Width, 293.33f);
            String localImagePath = DownloadedFilesCache.BuildCachedFilePath(BookChapter.LargeImageURL);

            imageView.Image       = UIImage.FromFile(localImagePath);
            imageView.ContentMode = UIViewContentMode.ScaleToFill;
            this.AddSubview(imageView);

            // chapterLabel
            UILabel chapterLabel = eBriefingAppearance.GenerateLabel(14);

            chapterLabel.Frame = new CGRect(10, imageView.Frame.Bottom + 8, 200, 21);
            chapterLabel.Text  = "Chapter " + (index + 1).ToString();
            this.AddSubview(chapterLabel);

            // titleLabel
            UILabel titleLabel = eBriefingAppearance.GenerateLabel(14);

            titleLabel.Frame         = new CGRect(10, chapterLabel.Frame.Bottom + 4, 200, 21);
            titleLabel.LineBreakMode = UILineBreakMode.TailTruncation;
            titleLabel.Text          = chapter.Title;
            this.AddSubview(titleLabel);

            // Add book info layer
            AddBookInfoView(bookID, chapter);
        }
        private void UpdateImage()
        {
            try
            {
                String localImagePath = DownloadedFilesCache.BuildCachedFilePath(book.LargeImageURL);
                if (File.Exists(localImagePath))
                {
                    spinner1.StopAnimating();

                    imageView.Alpha = 0f;
                    imageView.Image = UIImage.FromFile(localImagePath);

                    UIView.Animate(0.3d, delegate
                    {
                        imageView.Alpha = 1f;
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("BookOverviewController - UpdateImage: {0}", ex.ToString());
            }
        }
예제 #10
0
        private static List <String> RemoveAlreadyDownloadedFiles(List <String> fileUrlsToDownload)
        {
            // Set total number of downloads required
            TotalDownloadCount = fileUrlsToDownload.Count;

            if (CurrentBook.Status == Book.BookStatus.DOWNLOADING)
            {
                List <String> removeList = null;
                for (int i = 0; i < fileUrlsToDownload.Count; i++)
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(fileUrlsToDownload[i]);
                    if (File.Exists(localPath))
                    {
                        if (removeList == null)
                        {
                            removeList = new List <String>();
                        }

                        removeList.Add(fileUrlsToDownload[i]);
                    }
                }

                if (removeList != null)
                {
                    for (int i = 0; i < removeList.Count; i++)
                    {
                        fileUrlsToDownload.Remove(removeList[i]);
                    }
                }
            }

            // Set total number of already downloaded files
            CurrentBook.DownloadCount = TotalDownloadCount - fileUrlsToDownload.Count;

            return(fileUrlsToDownload);
        }
예제 #11
0
        public NoteCellView(String bookID, Note note)
        {
            this.BackgroundColor = UIColor.Clear;
            this.pageID          = pageID;
            this.note            = note;

            nfloat height = 300;

            Page page = BooksOnDeviceAccessor.GetPage(bookID, note.PageID);

            if (note.Text == "Header: " + note.PageID)
            {
                this.Frame = new CGRect(0, 0, 200, height);

                // pageView
                UIImageView pageView = new UIImageView();
                pageView.Frame = new CGRect(15, 20, 170, height - 80);
                this.AddSubview(pageView);

                bool notFound = true;
                if (page != null)
                {
                    String        localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    CGPDFDocument pdfDoc    = CGPDFDocument.FromFile(localPath);
                    if (pdfDoc != null)
                    {
                        notFound = false;

                        CGPDFPage pdfPage   = pdfDoc.GetPage(1);
                        UIImage   pageImage = ImageHelper.PDF2Image(pdfPage, pageView.Frame.Width, UIScreen.MainScreen.Scale);
                        pageView.Image = pageImage;
                    }
                }

                if (notFound)
                {
                    pageView.Image = UIImage.FromBundle("Assets/Icons/empty_page.png");

                    // emptyLabel
                    UILabel emptyLabel = eBriefingAppearance.GenerateLabel(17);
                    emptyLabel.Frame         = pageView.Frame;
                    emptyLabel.Text          = "Empty";
                    emptyLabel.TextAlignment = UITextAlignment.Center;
                    emptyLabel.SizeToFit();
                    emptyLabel.Center = pageView.Center;
                    this.AddSubview(emptyLabel);
                }

                // pageView
                NotePageView circleView = new NotePageView(page, pageView.Frame.Width / 2);
                circleView.Center = new CGPoint(pageView.Center.X, pageView.Frame.Bottom);
                this.AddSubview(circleView);
            }
            else if (note.Text == "Footer: " + note.PageID)
            {
                this.Frame = new CGRect(0, 0, 50, height);

                // footerView
//				UIImageView footerView = new UIImageView(UIImage.FromBundle("Assets/Icons/endPageNote.png"));
//				footerView.Frame = new CGRect(15, ((height - 40) / 2 - 10), 20, 20);
//                this.AddSubview(footerView);
            }
            else
            {
                this.Frame = new CGRect(0, 0, 250, height);

                // noteView
                NoteCellNoteView noteView = new NoteCellNoteView(note, height - 80);
                noteView.Frame          = new CGRect(15, 20, noteView.Frame.Width, noteView.Frame.Height);
                noteView.TouchUpInside += delegate
                {
                    if (ItemPressedEvent != null)
                    {
                        ItemPressedEvent(page.ID, note);
                    }
                };
                this.AddSubview(noteView);
            }
        }
예제 #12
0
        bool GenerateImage(Dictionary <Page, eBriefingMobile.Annotation> dict1, Dictionary <Page, List <eBriefingMobile.Note> > dict2)
        {
            try
            {
                if (pageList != null)
                {
                    nuint       totalImageSize = 0;
                    List <Note> notes          = new List <eBriefingMobile.Note> ();

                    foreach (var page in pageList)
                    {
                        String localPath     = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                        var    printItemDict = new Dictionary <UIImage, List <Note> >();

                        if (!String.IsNullOrEmpty(localPath))
                        {
                            CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                            if (pdfDoc != null)
                            {
                                CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                if (pdfPage != null)
                                {
                                    CGRect  pageRect = pdfPage.GetBoxRect(CGPDFBox.Media);
                                    UIImage pdfImg   = ImageHelper.PDF2Image(pdfPage, pageRect.Width, scale);

                                    // Add annotation if option selected
                                    if (dict1.ContainsKey(page))
                                    {
                                        Annotation annotation = dict1 [page];
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> coordinateDict = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (coordinateDict != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in coordinateDict)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value);

                                                    if (annImg != null)
                                                    {
                                                        // Scale down the annotation image
                                                        annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height));

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, scale);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Create image from text
                                    bool    printNote = false;
                                    UIImage noteImg   = null;
                                    if (dict2.ContainsKey(page) && dict2 [page] != null)
                                    {
                                        printNote = true;
                                        notes     = dict2 [page];

                                        // Create image from text
                                        //noteImg = ImageHelper.Text2Image(_notesText, pdfImg.Size);
                                    }
                                    else
                                    {
                                        notes = null;
                                    }

                                    // Scale down and add to canvas
                                    // Used 900 and 1200 because couldn't control the paper margin
//								if (Orientation == ORIENTATION.PORTRAIT)
//								{
//									//if (printNote)
//									{
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0, (1024 / 2) - (pdfImg.Size.Height / 2)), scale);
//
//										// Overlap pdfImg and noteImg
//										//pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(500, 0), scale);
//									}
//									//else
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 900);
//										//pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((768 / 2) - (pdfImg.Size.Width / 2), (1024 / 2) - (pdfImg.Size.Height / 2)), scale);
//									}
//								}
//								else
//								{
//									//if (printNote)
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,500,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//									//		pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint(0,0), scale*2, UIInterfaceOrientation.LandscapeLeft);
//										// Overlap pdfImg and noteImg
//										//pdfImg = ImageHelper.Overlap(pdfImg, noteImg, CGPoint.Empty, new CGPoint(756, 0), scale);
//									}
//									//else
//									{
//										//pdfImg=ImageHelper.MaxResizeImage(pdfImg,1000,scale);
//										//pdfImg = ImageHelper.Scale(pdfImg, 500);
//										///pdfImg = ImageHelper.Add2Canvas(pdfImg, new CGPoint((1024 / 2) - (pdfImg.Size.Width / 2), (768 / 2) - (pdfImg.Size.Height / 2)), scale*2, UIInterfaceOrientation.LandscapeLeft);
//									}
//
//									// Rotate canvas
//									//pdfImg = ImageHelper.Rotate(pdfImg);
//								}

                                    // Save
//								if (printItems == null)
//								{
//									printItems = new List<UIImage>();
//								}
//								printItems.Add(pdfImg);

                                    if (dict == null)
                                    {
                                        dict = new Dictionary <int, Dictionary <UIImage, List <Note> > > ();
                                    }

                                    if (pdfImg != null)
                                    {
                                        printItemDict.Add(pdfImg, notes);
                                        dict.Add(page.PageNumber, printItemDict);

                                        var pngImage = pdfImg.AsPNG();
                                        totalImageSize = pngImage.Length + totalImageSize;
                                        Console.WriteLine("Img : " + totalImageSize.ToString());

                                        //image dispose
                                        pdfImg = null;

                                        if (CheckReachMemoryLimit(totalImageSize))
                                        {
                                            PagesNum = dict.Count - 1;

                                            dict.Clear();
                                            dict = null;

                                            return(false);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    PagesNum = dict.Count;

                    return(true);
                }
                return(false);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #13
0
        public DashboardView(Book book, CGRect frame) : base(frame)
        {
            this.book            = book;
            this.BackgroundColor = UIColor.White;

            // overview
            UILabel overview = eBriefingAppearance.GenerateLabel(21);

            overview.Frame = new CGRect(20, 20, frame.Width - 40, 21);
            overview.Text  = "Overview";
            this.AddSubview(overview);

            // imageView
            UIImageView imageView = new UIImageView();

            imageView.Frame = new CGRect(overview.Frame.X, overview.Frame.Bottom + 16, overview.Frame.Width, 150);

            String localImagePath = DownloadedFilesCache.BuildCachedFilePath(book.LargeImageURL);

            if (File.Exists(localImagePath))
            {
                imageView.Image = UIImage.FromFile(localImagePath);
            }

            this.AddSubview(imageView);

            // bookInfoView
            bookInfoView       = new BookInfoView("0", "0", "0", book.PageCount.ToString(), false, false, frame.Width - 60);
            bookInfoView.Frame = new CGRect(30, imageView.Frame.Bottom + 8, bookInfoView.Frame.Width, bookInfoView.Frame.Height);
            this.AddSubview(bookInfoView);

            // line0
            UIView line0 = new UIView();

            line0.BackgroundColor = eBriefingAppearance.Gray4;
            line0.Frame           = new CGRect(overview.Frame.X, bookInfoView.Frame.Bottom + 10, overview.Frame.Width, 1);
            this.AddSubview(line0);

            // descLabel
            UILabel descLabel = GenerateLabel("Description", true);

            descLabel.Frame = new CGRect(overview.Frame.X, line0.Frame.Bottom + 10, overview.Frame.Width, 21);
            this.AddSubview(descLabel);

            // desc
            UILabel desc = GenerateLabel(book.Description, false);

            desc.Frame = new CGRect(overview.Frame.X, descLabel.Frame.Bottom + 8, overview.Frame.Width, 1);
            desc.Lines = 0;
            desc.SizeToFit();
            this.AddSubview(desc);

            // line1
            UIView line1 = new UIView();

            line1.BackgroundColor = eBriefingAppearance.Gray4;
            line1.Frame           = new CGRect(overview.Frame.X, desc.Frame.Bottom + 10, overview.Frame.Width, 1);
            this.AddSubview(line1);

            // versionLabel
            UILabel versionLabel = GenerateLabel("Version", true);

            versionLabel.Frame = new CGRect(overview.Frame.X, line1.Frame.Bottom + 10, overview.Frame.Width, 21);
            this.AddSubview(versionLabel);

            // version
            UILabel version = GenerateLabel(book.Version.ToString(), false);

            version.Frame = new CGRect(overview.Frame.X, versionLabel.Frame.Bottom + 8, overview.Frame.Width, 21);
            this.AddSubview(version);

            // line2
            UIView line2 = new UIView();

            line2.BackgroundColor = eBriefingAppearance.Gray4;
            line2.Frame           = new CGRect(overview.Frame.X, version.Frame.Bottom + 10, overview.Frame.Width, 1);
            this.AddSubview(line2);

            // createdLabel
            UILabel createdLabel = GenerateLabel("Date Created", true);

            createdLabel.Frame = new CGRect(overview.Frame.X, line2.Frame.Bottom + 10, overview.Frame.Width, 21);
            this.AddSubview(createdLabel);

            // created
            UILabel created = GenerateLabel(book.UserAddedDate.ToString("MMMM dd, yyyy"), false);

            created.Frame = new CGRect(overview.Frame.X, createdLabel.Frame.Bottom + 8, overview.Frame.Width, 21);
            this.AddSubview(created);

            // line3
            UIView line3 = new UIView();

            line3.BackgroundColor = eBriefingAppearance.Gray4;
            line3.Frame           = new CGRect(overview.Frame.X, created.Frame.Bottom + 10, overview.Frame.Width, 1);
            this.AddSubview(line3);

            // modifiedLabel
            UILabel modifiedLabel = GenerateLabel("Date Modified", true);

            modifiedLabel.Frame = new CGRect(overview.Frame.X, line3.Frame.Bottom + 10, overview.Frame.Width, 21);
            this.AddSubview(modifiedLabel);

            // modified
            UILabel modified = GenerateLabel(book.UserModifiedDate.ToString("MMMM dd, yyyy"), false);

            modified.Frame = new CGRect(overview.Frame.X, modifiedLabel.Frame.Bottom + 8, overview.Frame.Width, 21);
            this.AddSubview(modified);

            // shadow
            UIImageView shadow = new UIImageView();

            shadow.AutoresizingMask = UIViewAutoresizing.FlexibleHeight;
            shadow.Frame            = new CGRect(frame.Right - 3, 0, 3, frame.Height);
            shadow.Image            = UIImage.FromBundle("Assets/Backgrounds/shadow.png").CreateResizableImage(new UIEdgeInsets(2, 0, 2, 0));
            this.AddSubview(shadow);

            this.ContentSize = new CGSize(frame.Width, modified.Frame.Bottom + 20);
        }
예제 #14
0
        private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // activityIndicator
                UIActivityIndicatorView activityIndicator = new UIActivityIndicatorView();
                activityIndicator.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.White;
                activityIndicator.StartAnimating();
                activityIndicator.HidesWhenStopped = true;
                activityIndicator.Frame            = new RectangleF((this.Frame.Width / 2) - 10, (this.Frame.Height / 2) - 10, 20, 20);
                this.AddSubview(activityIndicator);

                // Generate pdf thumbnail
                Page             page       = null;
                Annotation       annotation = null;
                BackgroundWorker worker     = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    page = BooksOnDeviceAccessor.GetPage(bookID, pageID);

                    if (String.IsNullOrEmpty(text))
                    {
                        annotation = BooksOnDeviceAccessor.GetAnnotation(bookID, pageID);
                    }
                };
                worker.RunWorkerCompleted += delegate
                {
                    this.InvokeOnMainThread(delegate
                    {
                        activityIndicator.StopAnimating();

                        if (page != null)
                        {
                            String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                            if (!String.IsNullOrEmpty(localPath))
                            {
                                CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                                if (pdfDoc != null)
                                {
                                    CGPDFPage pdfPage = pdfDoc.GetPage(1);
                                    if (pdfPage != null)
                                    {
                                        UIImage pdfImg = PDFConverter.Transform2Image(pdfPage, this.Frame.Width);

                                        // pageView
                                        UIImageView pageView = new UIImageView();
                                        pageView.Frame       = new RectangleF(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                        // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                        if (annotation != null)
                                        {
                                            Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((UInt32)page.PageNumber - 1, annotation);
                                            if (dictionary != null)
                                            {
                                                foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                                {
                                                    // Create full size annotation
                                                    UIImage annImg = DrawAnnotation(item.Key, item.Value);

                                                    if (annImg != null)
                                                    {
                                                        // Scale down the annotation image
                                                        annImg = annImg.Scale(new SizeF(pdfImg.Size.Width, pdfImg.Size.Height));

                                                        // Overlap pdfImg and annImg
                                                        pdfImg = Overlap(pdfImg, annImg);
                                                    }
                                                }
                                            }
                                        }

                                        pageView.Image = pdfImg;
                                        this.AddSubview(pageView);

                                        // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                                        SkipBackup2iCloud.SetAttribute(localPath);

                                        // Add ribbon if this is bookmark thumbnail
                                        if (bookmark)
                                        {
                                            UIImageView ribbon = new UIImageView();
                                            ribbon.Image       = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                            ribbon.Frame       = new RectangleF(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                            this.AddSubview(ribbon);
                                        }

                                        // Do not add text if this is annotation thumbnail
                                        if (!String.IsNullOrEmpty(text))
                                        {
                                            // titleLabel
                                            UILabel titleLabel         = new UILabel();
                                            titleLabel.Frame           = new RectangleF(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                            titleLabel.Font            = UIFont.SystemFontOfSize(16f);
                                            titleLabel.BackgroundColor = UIColor.Clear;
                                            titleLabel.TextColor       = eBriefingAppearance.DarkGrayColor;
                                            titleLabel.Lines           = 2;
                                            titleLabel.LineBreakMode   = UILineBreakMode.TailTruncation;
                                            titleLabel.TextAlignment   = UITextAlignment.Center;
                                            titleLabel.Text            = text;
                                            this.AddSubview(titleLabel);
                                        }
                                    }
                                }
                            }
                        }
                    });
                };
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
예제 #15
0
        async private void GenerateThumbnail(String bookID, String pageID, String text, bool bookmark = false)
        {
            try
            {
                // spinner
                RTSpinKitView spinner = eBriefingAppearance.GenerateBounceSpinner();
                spinner.Center = this.Center;
                this.AddSubview(spinner);

                // Generate pdf thumbnail
                Page page = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetPage(bookID, pageID));

                Annotation annotation = null;
                if (String.IsNullOrEmpty(text))
                {
                    annotation = await eBriefingService.Run(() => BooksOnDeviceAccessor.GetAnnotation(bookID, pageID));
                }

                spinner.StopAnimating();

                if (page != null)
                {
                    String localPath = DownloadedFilesCache.BuildCachedFilePath(page.URL);
                    if (!String.IsNullOrEmpty(localPath))
                    {
                        CGPDFDocument pdfDoc = CGPDFDocument.FromFile(localPath);
                        if (pdfDoc != null)
                        {
                            CGPDFPage pdfPage = pdfDoc.GetPage(1);
                            if (pdfPage != null)
                            {
                                UIImage pdfImg = ImageHelper.PDF2Image(pdfPage, this.Frame.Width, UIScreen.MainScreen.Scale);

                                // pageView
                                UIImageView pageView = new UIImageView();
                                pageView.Frame = new CGRect(0, (this.Frame.Height / 2) - (pdfImg.Size.Height / 2), pdfImg.Size.Width, pdfImg.Size.Height);

                                // If this is annotation thumbnail, draw annotation overlay on top of pdf
                                if (annotation != null)
                                {
                                    Dictionary <String, PSPDFInkAnnotation> dictionary = AnnotationsDataAccessor.GenerateAnnDictionary((nuint)page.PageNumber - 1, annotation);
                                    if (dictionary != null)
                                    {
                                        foreach (KeyValuePair <String, PSPDFInkAnnotation> item in dictionary)
                                        {
                                            // Create full size annotation
                                            UIImage annImg = ImageHelper.DrawPSPDFAnnotation(item.Key, item.Value);

                                            if (annImg != null)
                                            {
                                                // Scale down the annotation image
                                                annImg = annImg.Scale(new CGSize(pdfImg.Size.Width, pdfImg.Size.Height));

                                                // Overlap pdfImg and annImg
                                                pdfImg = ImageHelper.Overlap(pdfImg, annImg, CGPoint.Empty, CGPoint.Empty, UIScreen.MainScreen.Scale);
                                            }
                                        }
                                    }
                                }

                                pageView.Image = pdfImg;
                                this.AddSubview(pageView);

                                if (pdfImg.Size.Height < this.Frame.Height)
                                {
                                    this.BackgroundColor = UIColor.Clear;
                                }

                                // THIS IS REQUIRED TO SKIP iCLOUD BACKUP
                                SkipBackup2iCloud.SetAttribute(localPath);

                                // Add ribbon if this is bookmark thumbnail
                                if (bookmark)
                                {
                                    UIImageView ribbon = new UIImageView();
                                    ribbon.Image = UIImage.FromBundle("Assets/Buttons/bookmark_solid.png");
                                    ribbon.Frame = new CGRect(pageView.Frame.Right - 35, pageView.Frame.Y, 25, 33.78f);
                                    this.AddSubview(ribbon);
                                }

                                // Do not add text if this is annotation thumbnail
                                if (!String.IsNullOrEmpty(text))
                                {
                                    // titleLabel
                                    UILabel titleLabel = eBriefingAppearance.GenerateLabel(16);
                                    titleLabel.Frame         = new CGRect(0, pageView.Frame.Bottom + 4, this.Frame.Width, 42);
                                    titleLabel.Lines         = 2;
                                    titleLabel.LineBreakMode = UILineBreakMode.TailTruncation;
                                    titleLabel.TextAlignment = UITextAlignment.Center;
                                    titleLabel.Text          = text;
                                    this.AddSubview(titleLabel);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("ThumbnailView - GenerateThumbnail: {0}", ex.ToString());
            }
        }
예제 #16
0
        public ChapterView(String bookID, Chapter chapter, Int32 index) : base(new RectangleF(0, 0, 220, 388.33f))
        {
            this.BackgroundColor     = UIColor.Clear;
            this.Layer.ShadowColor   = UIColor.Black.CGColor;
            this.Layer.ShadowOpacity = 0.3f;
            this.Layer.ShadowRadius  = 2f;
            this.Layer.ShadowOffset  = new SizeF(0f, 2f);

            this.Layer.ShadowPath         = UIBezierPath.FromRoundedRect(this.Frame, 7f).CGPath;
            this.Layer.ShouldRasterize    = true;
            this.Layer.RasterizationScale = UIScreen.MainScreen.Scale;

            this.BookChapter = chapter;

            // For rounded corner and shadow
            UIView subView = new UIView(new RectangleF(0, 0, 220, 388.33f));

            subView.BackgroundColor     = UIColor.White;
            subView.Layer.CornerRadius  = 7f;
            subView.Layer.MasksToBounds = true;
            this.AddSubview(subView);

            // imageView
            UIImageView imageView = new UIImageView();

            imageView.Frame = new RectangleF(0, 0, this.Frame.Width, 293.33f);
            String localImagePath = DownloadedFilesCache.BuildCachedFilePath(BookChapter.LargeImageURL);

            imageView.Image       = UIImage.FromFile(localImagePath);
            imageView.ContentMode = UIViewContentMode.ScaleToFill;
            subView.AddSubview(imageView);

            // chapterLabel
            UILabel chapterLabel = new UILabel();

            chapterLabel.Frame           = new RectangleF(10, imageView.Frame.Bottom + 8, 200, 21);
            chapterLabel.Font            = UIFont.SystemFontOfSize(14f);
            chapterLabel.TextAlignment   = UITextAlignment.Left;
            chapterLabel.BackgroundColor = UIColor.Clear;
            chapterLabel.TextColor       = UIColor.DarkGray;
            chapterLabel.Text            = "Chapter " + (index + 1).ToString();
            this.AddSubview(chapterLabel);

            // titleLabel
            UILabel titleLabel = new UILabel();

            titleLabel.Frame           = new RectangleF(10, chapterLabel.Frame.Bottom + 4, 200, 21);
            titleLabel.Font            = UIFont.SystemFontOfSize(14f);
            titleLabel.BackgroundColor = UIColor.Clear;
            titleLabel.TextColor       = UIColor.DarkGray;
            titleLabel.LineBreakMode   = UILineBreakMode.TailTruncation;
            titleLabel.Text            = chapter.Title;
            this.AddSubview(titleLabel);

            // bookInfoView
            String numNotes       = "0";
            String numBookmarks   = "0";
            String numAnnotations = "0";

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                numNotes       = BooksOnDeviceAccessor.GetNumNotesInChapter(bookID, chapter.ID);
                numBookmarks   = BooksOnDeviceAccessor.GetNumBookmarksInChapter(bookID, chapter.ID);
                numAnnotations = BooksOnDeviceAccessor.GetNumAnnotationsInChapter(bookID, chapter.ID);
            };
            worker.RunWorkerCompleted += delegate
            {
                this.InvokeOnMainThread(delegate
                {
                    BookInfoView bookInfoView = new BookInfoView(numNotes, numBookmarks, numAnnotations, chapter.Pagecount.ToString(), false, false, this.Frame.Width - 30);
                    bookInfoView.Frame        = new RectangleF(10, this.Frame.Bottom - 40, bookInfoView.Frame.Width, bookInfoView.Frame.Height);
                    this.AddSubview(bookInfoView);
                });
            };
            worker.RunWorkerAsync();
        }