Пример #1
0
        private void LoadAttachment(NSItemProvider itemProvider)
        {
            NSString typeOfItem = NSString.Empty;

            if (itemProvider.HasItemConformingTo(UTType.URL))
            {
                typeOfItem = UTType.URL;
            }
            else if (itemProvider.HasItemConformingTo(UTType.Image))
            {
                typeOfItem = UTType.Image;
            }

            if (typeOfItem != NSString.Empty)
            {
                log.Debug("Calling Load Item..." + typeOfItem.ToString());
                itemProvider.LoadItemAsync(typeOfItem, null).ContinueWith((task) =>
                {
                    log.Debug("Load Item complete");
                    if (task != null && task.Result != null)
                    {
                        log.Debug("Processing Data");
                        ItemLoadCompletedUrl(task.Result);
                    }
                    else
                    {
                        log.Error("Error loading item. No result returned!");
                        this.totalNumberOfAttachmentsLoaded++;
                        CheckAttachmentsProcessed();
                    }
                });
            }
        }
        private bool ProcessItemProvider(NSItemProvider itemProvider, string type, Action <NSDictionary> dictAction,
                                         Action <NSUrl> urlAction = null)
        {
            if (!itemProvider.HasItemConformingTo(type))
            {
                return(false);
            }

            itemProvider.LoadItem(type, null, (NSObject list, NSError error) =>
            {
                if (list == null)
                {
                    return;
                }

                _context.ProviderType = type;

                var dict = list as NSDictionary;
                if (dict != null && dictAction != null)
                {
                    dictAction(dict);
                }
                else if (list is NSUrl && urlAction != null)
                {
                    var url = list as NSUrl;
                    urlAction(url);
                }
                else
                {
                    throw new Exception("Cannot parse list for action. List is " +
                                        (list?.GetType().ToString() ?? "null"));
                }

                _googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type);

                Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType);
                Debug.WriteLine("BW LOG, Url: " + _context.UrlString);
                Debug.WriteLine("BW LOG, Title: " + _context.LoginTitle);
                Debug.WriteLine("BW LOG, Username: "******"BW LOG, Password: "******"BW LOG, Old Password: "******"BW LOG, Notes: " + _context.Notes);
                Debug.WriteLine("BW LOG, Details: " + _context.Details);

                if (_context.PasswordOptions != null)
                {
                    Debug.WriteLine("BW LOG, PasswordOptions Min Length: " + _context.PasswordOptions.MinLength);
                    Debug.WriteLine("BW LOG, PasswordOptions Max Length: " + _context.PasswordOptions.MaxLength);
                    Debug.WriteLine("BW LOG, PasswordOptions Require Digits: " + _context.PasswordOptions.RequireDigits);
                    Debug.WriteLine("BW LOG, PasswordOptions Require Symbols: " + _context.PasswordOptions.RequireSymbols);
                    Debug.WriteLine("BW LOG, PasswordOptions Forbidden Chars: " + _context.PasswordOptions.ForbiddenCharacters);
                }
            });

            return(true);
        }
        private bool ProcessExtensionSetupProvider(NSItemProvider itemProvider)
        {
            if (itemProvider.HasItemConformingTo(Constants.UTTypeAppExtensionSetup))
            {
                _context.ProviderType = Constants.UTTypeAppExtensionSetup;
                return(true);
            }

            return(false);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Enable the Cancel button, disable the Done button
            CancelButton.Enabled = true;
            DoneButton.Enabled   = false;

            // Verify that we have a valid NSExtensionItem
            NSExtensionItem imageItem = ExtensionContext.InputItems [0];

            if (imageItem == null)
            {
                return;
            }

            // Verify that we have a valid NSItemProvider
            NSItemProvider imageItemProvider = imageItem.Attachments [0];

            if (imageItemProvider == null)
            {
                return;
            }

            // Look for an image inside the NSItemProvider
            if (!imageItemProvider.HasItemConformingTo(UTType.Image))
            {
                return;
            }

            imageItemProvider.LoadItem(UTType.Image, null, (NSObject image, NSError error) => {
                UIImage img;

                // This is true when you call extension from Photo's ActivityViewController
                var url = image as NSUrl;
                if (url != null)
                {
                    img = UIImage.LoadFromData(NSData.FromUrl(url));
                    InitWithImage(img);
                    return;
                }

                // This is true when you call extension from Main App
                img = image as UIImage;
                if (img != null)
                {
                    InitWithImage(img);
                    return;
                }
            });
        }
Пример #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Enable the Cancel button, disable the Done button
            CancelButton.Enabled = true;
            DoneButton.Enabled   = false;

            // Verify that we have a valid NSExtensionItem
            NSExtensionItem imageItem = ExtensionContext.InputItems [0];

            if (imageItem == null)
            {
                return;
            }

            // Verify that we have a valid NSItemProvider
            NSItemProvider imageItemProvider = imageItem.Attachments [0];

            if (imageItemProvider == null)
            {
                return;
            }

            // Look for an image inside the NSItemProvider
            if (!imageItemProvider.HasItemConformingTo(UTType.Image))
            {
                return;
            }

            imageItemProvider.LoadItem(UTType.Image, null, (NSObject image, NSError error) => {
                if (image == null)
                {
                    return;
                }

                // Invert the image, enable the Done button
                InvokeOnMainThread(() => {
                    // Invert the image
                    UIImage invertedImage = InvertedImage((UIImage)image);

                    // Set the inverted image in the UIImageView
                    ImageView.Image    = invertedImage;
                    DoneButton.Enabled = true;
                });
            });
        }
Пример #6
0
        private bool ProcessItemProvider(NSItemProvider itemProvider, string type, Action <NSDictionary> dictAction,
                                         Action <NSUrl> urlAction = null)
        {
            if (!itemProvider.HasItemConformingTo(type))
            {
                return(false);
            }

            itemProvider.LoadItem(type, null, (NSObject list, NSError error) =>
            {
                if (list == null)
                {
                    return;
                }

                _context.ProviderType = type;
                if (list is NSDictionary dict && dictAction != null)
                {
                    dictAction(dict);
                }
Пример #7
0
        private bool ProcessItemProvider(NSItemProvider itemProvider, string type, Action <NSDictionary> action)
        {
            if (!itemProvider.HasItemConformingTo(type))
            {
                return(false);
            }

            itemProvider.LoadItem(type, null, (NSObject list, NSError error) =>
            {
                if (list == null)
                {
                    return;
                }

                _context.ProviderType = type;
                var dict = list as NSDictionary;
                action(dict);

                _googleAnalyticsService.TrackExtensionEvent("ProcessItemProvider", type);

                Debug.WriteLine("BW LOG, ProviderType: " + _context.ProviderType);
                Debug.WriteLine("BW LOG, Url: " + _context.Url);
                Debug.WriteLine("BW LOG, Title: " + _context.SiteTitle);
                Debug.WriteLine("BW LOG, Username: "******"BW LOG, Password: "******"BW LOG, Old Password: "******"BW LOG, Notes: " + _context.Notes);
                Debug.WriteLine("BW LOG, Details: " + _context.Details);

                if (_context.PasswordOptions != null)
                {
                    Debug.WriteLine("BW LOG, PasswordOptions Min Length: " + _context.PasswordOptions.MinLength);
                    Debug.WriteLine("BW LOG, PasswordOptions Max Length: " + _context.PasswordOptions.MaxLength);
                    Debug.WriteLine("BW LOG, PasswordOptions Require Digits: " + _context.PasswordOptions.RequireDigits);
                    Debug.WriteLine("BW LOG, PasswordOptions Require Symbols: " + _context.PasswordOptions.RequireSymbols);
                    Debug.WriteLine("BW LOG, PasswordOptions Forbidden Chars: " + _context.PasswordOptions.ForbiddenCharacters);
                }
            });

            return(true);
        }
Пример #8
0
        public void OnShareClicked(UIBarButtonItem button)
        {
            UIActivityViewController activityViewController = new UIActivityViewController(new NSObject[] {
                ImageView.Image
            }, null);
            var popover = activityViewController.PopoverPresentationController;

            if (popover != null)
            {
                popover.BarButtonItem = ShareItem;
            }

            // Set a completion handler to handle what the UIActivityViewController returns
            activityViewController.SetCompletionHandler((activityType, completed, returnedItems, error) => {
                if (returnedItems == null ||
                    returnedItems.Length == 0)
                {
                    return;
                }

                NSExtensionItem extensionItem    = returnedItems [0];
                NSItemProvider imageItemProvider = extensionItem.Attachments [0];

                if (!imageItemProvider.HasItemConformingTo(UTType.Image))
                {
                    return;
                }

                imageItemProvider.LoadItem(UTType.Image, null, (item, loadError) => {
                    if (item != null && loadError == null)
                    {
                        InvokeOnMainThread(() => {
                            ImageView.Image = (UIImage)item;
                        });
                    }
                });
            });

            PresentViewController(activityViewController, true, null);
        }