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);
        }
        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;
                }
            });
        }
示例#3
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;
                });
            });
        }
示例#4
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);
                }
		public override void LoadView ()
		{
			base.LoadView ();

			// Show the URL of the item that was requested.
			NSExtensionItem item = ExtensionContext.InputItems.First ();
			NSItemProvider provider = item.Attachments[0];
			provider.LoadItem ("public.url", null, (arg1, arg2) =>
			{
				var url = (NSUrl)arg1;

				// See NSLogHelper for details on this vs Console.WriteLine
				ExtensionSamples.NSLogHelper.NSLog ($"ShareViewController - LoadView - {url}");

				BeginInvokeOnMainThread (() =>
				{
					TitleText.StringValue = url.ToString ();
				});
			});
		}
示例#6
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);
        }
示例#7
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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            extensionContext = this.ExtensionContext;
            // Do any additional setup after loading the view.
            NSExtensionItem[] outputItem = extensionContext.InputItems;
            NSExtensionItem   item       = extensionContext.InputItems[0];
            NSItemProvider    provider   = item.Attachments[0]; //provider is null, no attachments

            enviado = false;

            string[] type = outputItem[0].Attachments[0].RegisteredTypeIdentifiers;



            foreach (string x in type)
            {
                if ("public.zip-archive".Contains(x))
                {
                    if (!enviado)
                    {
                        enviado = true;



                        var item2 = extensionContext.InputItems[0];

                        NSItemProvider prov = null;
                        if (item2 != null)
                        {
                            prov = item2.Attachments[0];
                        }
                        if (prov != null)
                        {
                            prov.LoadItem(UTType.ZipArchive, null, (NSObject url, NSError error) =>
                            {
                                if (url == null)
                                {
                                    return;
                                }
                                NSUrl newUrl = (NSUrl)url;

                                InvokeOnMainThread(() =>
                                {
                                    //String encode1 = System.Web.HttpUtility.UrlEncode("thirdpartyappurlscheme://?param=" + rece);

                                    NSUrl request = new NSUrl("aclara-mtu-programmer://?script_path=" + newUrl);

                                    try
                                    {
                                        bool isOpened = UIApplication.SharedApplication.OpenUrl(request);

                                        if (isOpened == false)
                                        {
                                            UIApplication.SharedApplication.OpenUrl(new NSUrl("aclara-mtu-programmer://?script_path=" + newUrl));
                                        }
                                        extensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("Cannot open url: {0}, Error: {1}", request.AbsoluteString, ex.Message);
                                        var alertView = new UIAlertView("Error", ex.Message, null, "OK", null);

                                        alertView.Show();
                                    }
                                });
                            });
                        }
                    }
                }


                if ("public.xml".Contains(x))
                {
                    if (!enviado)
                    {
                        enviado = true;



                        var item2 = extensionContext.InputItems[0];

                        NSItemProvider prov = null;
                        if (item2 != null)
                        {
                            prov = item2.Attachments[0];
                        }
                        if (prov != null)
                        {
                            prov.LoadItem(UTType.XML, null, (NSObject url, NSError error) =>
                            {
                                if (url == null)
                                {
                                    return;
                                }
                                NSUrl newUrl = (NSUrl)url;


                                byte[] uploadData = (NSData.FromUrl((NSUrl)newUrl).ToArray());


                                // From byte array to string
                                string s = System.Text.Encoding.UTF8.GetString(uploadData, 0, uploadData.Length);


                                s = WebUtility.UrlEncode(s);

                                InvokeOnMainThread(() =>
                                {
                                    //String encode1 = System.Web.HttpUtility.UrlEncode("thirdpartyappurlscheme://?param=" + rece);

                                    NSUrl request = new NSUrl("aclara-mtu-programmer://?script_path=" + s.ToString());

                                    try
                                    {
                                        bool isOpened = UIApplication.SharedApplication.OpenUrl(request);

                                        if (isOpened == false)
                                        {
                                            UIApplication.SharedApplication.OpenUrl(new NSUrl("aclara-mtu-programmer://?script_path=" + s.ToString()));
                                        }
                                        extensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("Cannot open url: {0}, Error: {1}", request.AbsoluteString, ex.Message);
                                        var alertView = new UIAlertView("Error", ex.Message, null, "OK", null);

                                        alertView.Show();
                                    }
                                });
                            });
                        }
                    }
                }



                if ("public.data".Contains(x))
                {
                    if (!enviado)
                    {
                        enviado = true;


                        var item2 = extensionContext.InputItems[0];

                        NSItemProvider prov = null;
                        if (item2 != null)
                        {
                            prov = item2.Attachments[0];
                        }
                        if (prov != null)
                        {
                            prov.LoadItem(UTType.Data, null, (NSObject url, NSError error) =>
                            {
                                if (url == null)
                                {
                                    return;
                                }
                                NSUrl newUrl = (NSUrl)url;

                                InvokeOnMainThread(() =>
                                {
                                    //String encode1 = System.Web.HttpUtility.UrlEncode("thirdpartyappurlscheme://?param=" + rece);

                                    NSUrl request = new NSUrl("aclara-mtu-programmer://?script_path=" + newUrl.ToString());

                                    try
                                    {
                                        bool isOpened = UIApplication.SharedApplication.OpenUrl(request);

                                        if (isOpened == false)
                                        {
                                            UIApplication.SharedApplication.OpenUrl(new NSUrl("aclara-mtu-programmer://?script_path=" + newUrl.ToString()));
                                        }
                                        extensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("Cannot open url: {0}, Error: {1}", request.AbsoluteString, ex.Message);
                                        var alertView = new UIAlertView("Error", ex.Message, null, "OK", null);

                                        alertView.Show();
                                    }
                                });
                            });
                        }
                    }
                }



                if ("public.file-url".Contains(x))
                {
                    if (!enviado)
                    {
                        enviado = true;

                        string value = outputItem[0].AttributedContentText.Value.ToString();

                        String encode1 = System.Net.WebUtility.UrlEncode(value);

                        extensionContext.CompleteRequest(new NSExtensionItem[0], null);

                        UIApplication.SharedApplication.OpenUrl(new NSUrl("aclara-mtu-programmer://?script_path=" + encode1));
                    }
                }
            }
        }
        public override void ViewDidLoad()
        {
            nfloat h = 31.0f;
            nfloat w = View.Bounds.Width;

            base.ViewDidLoad();


            imageViewEx = new UIImageView(new CGRect(10, 100, 150, 200));
            Add(imageViewEx);

            titleLabel           = new UITextView();
            titleLabel.Frame     = new CGRect(110, 40, w - 180, 50);
            titleLabel.Font      = UIFont.SystemFontOfSize(22);
            titleLabel.Text      = "ADD NEW MOVIE";
            titleLabel.Editable  = false;
            titleLabel.TextColor = UIColor.Brown;

            View.AddSubview(titleLabel);

            tenphimLabel               = new UITextView();
            tenphimLabel.Frame         = new CGRect(170, 90, w - 180, 30);
            tenphimLabel.Font          = UIFont.SystemFontOfSize(18);
            tenphimLabel.Text          = "Movie's name:";
            tenphimLabel.Editable      = false;
            tenphimLabel.ScrollEnabled = false;
            tenphimLabel.ClipsToBounds = true;
            tenphimLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(tenphimLabel);

            tenphimTextViewEx                  = new UITextView();
            tenphimTextViewEx.Frame            = new CGRect(170, 140, w - 180, 100);
            tenphimTextViewEx.TextAlignment    = UITextAlignment.Center;
            tenphimTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            tenphimTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            // limit of up to 50 characters

            /*tenphimTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 40;
             * };*/
            View.AddSubview(tenphimTextViewEx);

            sotapLabel               = new UITextView();
            sotapLabel.Frame         = new CGRect(170, 250, w - 180, 30);
            sotapLabel.Font          = UIFont.SystemFontOfSize(18);
            sotapLabel.Text          = "Episodes:";
            sotapLabel.Editable      = false;
            sotapLabel.ScrollEnabled = false;
            sotapLabel.ClipsToBounds = true;
            sotapLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(sotapLabel);

            sotapTextViewEx                  = new UITextView();
            sotapTextViewEx.Frame            = new CGRect(170, 290, w - 180, 30);
            sotapTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            sotapTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            sotapTextViewEx.TextAlignment    = UITextAlignment.Center;
            sotapTextViewEx.KeyboardType     = UIKeyboardType.NumberPad;

            /*sotapTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 3;
             * };*/
            View.AddSubview(sotapTextViewEx);

            sophutLabel               = new UITextView();
            sophutLabel.Frame         = new CGRect(10, 330, w - 20, 30);
            sophutLabel.Font          = UIFont.SystemFontOfSize(18);
            sophutLabel.Text          = "Minutes watching:";
            sophutLabel.ScrollEnabled = false;
            sophutLabel.ClipsToBounds = true;
            sophutLabel.Editable      = false;
            sophutLabel.TextColor     = UIColor.Brown;
            //tenphimLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(sophutLabel);

            sophutTextViewEx                  = new UITextView();
            sophutTextViewEx.Frame            = new CGRect(10, 370, w - 20, h);
            sophutTextViewEx.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            sophutTextViewEx.TextAlignment    = UITextAlignment.Center;
            sophutTextViewEx.Font             = UIFont.SystemFontOfSize(18);
            sophutTextViewEx.KeyboardType     = UIKeyboardType.NumberPad;

            /*sophutTextViewEx.ShouldChangeCharacters = (textField, range, replacementString) =>
             * {
             *  var newLength = textField.Text.Length + replacementString.Length - range.Length;
             *  return newLength <= 4;
             * };*/
            View.AddSubview(sophutTextViewEx);



            addbutton       = new UIButton();
            addbutton.Frame = new CGRect(10, 450, w - 20, 50);
            addbutton.SetTitle("ADD NEW MOVIE", UIControlState.Normal);
            addbutton.BackgroundColor    = UIColor.Blue;
            addbutton.Layer.CornerRadius = 5f;
            View.AddSubview(addbutton);
            addbutton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            cancelbutton       = new UIButton();
            cancelbutton.Frame = new CGRect(10, 515, w - 20, 50);
            cancelbutton.SetTitle("CANCEL", UIControlState.Normal);
            cancelbutton.BackgroundColor    = UIColor.Red;
            cancelbutton.Layer.CornerRadius = 5f;
            View.AddSubview(cancelbutton);
            cancelbutton.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;

            var            urlstr = string.Empty;
            var            item   = ExtensionContext.InputItems[0];
            NSItemProvider prov   = null;

            if (item != null)
            {
                prov = item.Attachments[0];
            }
            if (prov != null)
            {
                prov.LoadItem(UTType.URL, null, (NSObject url, NSError error) =>
                {
                    if (url == null)
                    {
                        return;
                    }
                    NSUrl newUrl    = (NSUrl)url;
                    var newUrl2     = newUrl.ToString();
                    var resultSotap = Regex.Match(MetaScraper.GetMetaDataFromUrl(newUrl2).Title, @"\d+").Value;



                    //string dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "ormdemo.db3");
                    db            = new SQLiteConnection(ShareLibs.GetDatabasePath());
                    var PhimmoiEx = new movDatabase();
                    InvokeOnMainThread(() =>
                    {
                        tenphimTextViewEx.Text   = MetaScraper.GetMetaDataFromUrl(newUrl2).Title;
                        sotapTextViewEx.Text     = resultSotap;
                        imageViewEx.Image        = FromUrl(MetaScraper.GetMetaDataFromUrl(newUrl2).ImageUrl);
                        addbutton.TouchUpInside += (sender, e) =>
                        {
                            PhimmoiEx.Tenphim = tenphimTextViewEx.Text;
                            try
                            {
                                PhimmoiEx.img = StoreImageEx(tenphimTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            try
                            {
                                PhimmoiEx.Sotap = Convert.ToInt32(sotapTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            try
                            {
                                PhimmoiEx.min = Convert.ToInt32(sophutTextViewEx.Text);
                            }
                            catch
                            {
                            }
                            PhimmoiEx.link = newUrl2;
                            db.Insert(PhimmoiEx);

                            var alert = UIAlertController.Create("Movie Mark", "Added", UIAlertControllerStyle.Alert);
                            PresentViewController(alert, true, () =>
                            {
                                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 500000000), () =>
                                {
                                    // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
                                    ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                });
                            });
                        };
                        cancelbutton.TouchUpInside += (sender, e) =>
                        {
                            var alert = UIAlertController.Create("Movie Mark", "Canceled", UIAlertControllerStyle.Alert);
                            PresentViewController(alert, true, () =>
                            {
                                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 500000000), () =>
                                {
                                    // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
                                    ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
                                });
                            });
                        };
                    });
                });
            }
        }