Esempio n. 1
0
        public override void DidSelectPost()
        {
            // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
            var description = "";
            var url         = "";

            foreach (var extensionItem in ExtensionContext.InputItems)
            {
                if (extensionItem.Attachments != null)
                {
                    foreach (var attachment in extensionItem.Attachments)
                    {
                        if (attachment.HasItemConformingTo(UTType.URL))
                        {
                            attachment.LoadItem(UTType.URL, null, (data, error) =>
                            {
                                var nsUrl = data as NSUrl;
                                url       = nsUrl.AbsoluteString;
                                WriteToDebugFile($"URL - {url}");
                                //Save  off the url and description here
                            });
                        }
                    }
                }
                if (!string.IsNullOrWhiteSpace(extensionItem.AttributedContentText.Value))
                {
                    description = extensionItem.AttributedContentText.Value;
                    WriteToDebugFile($"URL description - {description}");
                }
            }
            // 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);
        }
        partial void Cancel(Foundation.NSObject sender)
        {
            NSExtensionItem outputItem  = new NSExtensionItem();
            var             outputItems = new[] { outputItem };

            ExtensionContext.CompleteRequest(outputItems, null);
        }
        public void CompleteRequest(NSDictionary itemData)
        {
            Debug.WriteLine("BW LOG, itemData: " + itemData);

            var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
            var resultsItem     = new NSExtensionItem {
                Attachments = new NSItemProvider[] { resultsProvider }
            };
            var returningItems = new NSExtensionItem[] { resultsItem };

            if (itemData != null)
            {
                _googleAnalyticsService.TrackExtensionEvent("AutoFilled", _context.ProviderType);
            }
            else
            {
                _googleAnalyticsService.TrackExtensionEvent("Closed", _context.ProviderType);
            }

            _googleAnalyticsService.Dispatch(() =>
            {
                NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                {
                    Resolver.ResetResolver();
                    ExtensionContext?.CompleteRequest(returningItems, null);
                });
            });
        }
Esempio n. 4
0
        public override void DidSelectPost()
        {
            var description = "";
            var url         = "";

            foreach (var extensionItem in ExtensionContext.InputItems)
            {
                if (extensionItem.Attachments != null)
                {
                    foreach (var attachment in extensionItem.Attachments)
                    {
                        if (attachment.HasItemConformingTo(UTType.URL))
                        {
                            attachment.LoadItem(UTType.URL, null, (data, error) =>
                            {
                                var nsUrl = data as NSUrl;
                                url       = nsUrl.AbsoluteString;
                                WriteToDebugFile($"URL - {url}");
                                //Save  off the url and description here
                            });
                        }
                    }
                }

                if (!string.IsNullOrWhiteSpace(extensionItem.AttributedContentText.Value))
                {
                    description = extensionItem.AttributedContentText.Value;
                    WriteToDebugFile($"URL description - {description}");
                }
            }

            ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
        }
Esempio n. 5
0
        public override void DidSelectPost()
        {
            // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.

            // 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);
        }
        private void InvokeApp(string invokeArgs)
        {
            NSUrl request = new NSUrl("steepshot://" + invokeArgs);

            UIApplication.SharedApplication.OpenUrl(request);
            ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
        }
Esempio n. 7
0
        public void CompleteRequest(string username = null, string password = null, string totp = null)
        {
            ServiceContainer.Reset();

            if ((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password))
            {
                ExtensionContext?.CompleteExtensionConfigurationRequest();
                return;
            }

            if (_context == null || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
                NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CancelRequest(err));
                return;
            }

            if (!string.IsNullOrWhiteSpace(totp))
            {
                UIPasteboard.General.String = totp;
            }

            var cred = new ASPasswordCredential(username, password);

            NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CompleteRequest(cred, null));
        }
Esempio n. 8
0
        private void Done()
        {
            _db.Dispose();

            // Return any edited content to the host app.
            // This template doesn't do anything, so we just echo the passed-in items.
            ExtensionContext.CompleteRequest(ExtensionContext.InputItems, null);
        }
Esempio n. 9
0
        public override void DidSelectPost()
        {
            string shortenedUrl = "";

            try
            {
                foreach (NSItemProvider itemProvider in this.ExtensionContext.InputItems[0].Attachments)
                {
                    if (itemProvider.HasItemConformingTo(MobileCoreServices.UTType.URL))
                    {
                        itemProvider.LoadItem(MobileCoreServices.UTType.URL, null, async(item, error) =>
                        {
                            if (item is NSUrl)
                            {
                                var urlToShorten = ((NSUrl)item).AbsoluteUrl.ToString();

                                var request = new ShortRequest
                                {
                                    TagWt    = false,
                                    TagUtm   = false,
                                    Campaign = ContentText,
                                    Mediums  = new List <string>()
                                    {
                                        "twitter"
                                    },
                                    Input = urlToShorten
                                };

                                var defaults = new NSUserDefaults(Constants.GroupName, NSUserDefaultsType.SuiteName);
                                var url      = defaults.StringForKey(Constants.IOS_SettingsKey);

                                shortenedUrl = await ShorteningService.ShortenUrl(request, url);

                                InvokeOnMainThread(() =>
                                {
                                    UIPasteboard clipboard = UIPasteboard.General;
                                    clipboard.String       = shortenedUrl;

                                    UIAlertController alert = UIAlertController.Create("Share extension", $"https://{shortenedUrl} has been copied!", UIAlertControllerStyle.Alert);
                                    PresentViewController(alert, true, () =>
                                    {
                                        var dt = new DispatchTime(DispatchTime.Now, TimeSpan.FromSeconds(1));
                                        DispatchQueue.MainQueue.DispatchAfter(dt, () =>
                                        {
                                            ExtensionContext.CompleteRequest(null, null);
                                        });
                                    });
                                });
                            }
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 10
0
        private async Task FormatErrorAlert()
        {
            var alert = UIAlertController.Create(Strings.ErrorFormat, null, UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(Strings.Ok, UIAlertActionStyle.Default, (action) => {
                ExtensionContext.CompleteRequest(null, null);
            }));
            await PresentViewControllerAsync(alert, true);
        }
Esempio n. 11
0
 partial void DoneClicked(NSObject sender)
 {
     // Return any edited content to the host app.
     // This template doesn't do anything, so we just echo the passed-in items.
     NSOperationQueue.MainQueue.AddOperation(delegate
     {
         ExtensionContext.CompleteRequest(ExtensionContext.InputItems, null);
     });
 }
Esempio n. 12
0
        private void UserDidFinishSetup(object sender, EventArgs e)
        {
            // URL of the resource where broadcast can be viewed that will be returned to the application
            var broadcastURL = new NSUrl("https://appr.tc/r/" + _roomNameField.Text);
            // Dictionary with setup information that will be provided to broadcast extension when broadcast
            // is started
            var setupInfo = new NSDictionary <NSString, INSCoding>(new NSString("roomName"), new NSString(_roomNameField.Text));

            // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
            ExtensionContext.CompleteRequest(broadcastURL, setupInfo);
        }
        public override void DidSelectPost()
        {
            // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
            UIAlertController alert = UIAlertController.Create("Share extension", "This is the step where you should post the ContentText value: \"" + ContentText + "\" to your targeted service.", UIAlertControllerStyle.Alert);

            PresentViewController(alert, true, () => {
                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 5000000000), () => {
                    ExtensionContext.CompleteRequest(null, null);
                });
            });
        }
Esempio n. 14
0
        private void CloseExtension()
        {
            log.Info("Closing Extension...");

            //Static variables can remain for re-use if the Extension runs again from the same instance of the container application. In this
            //demo app this causes more harm than good so we dispose of the session so that it is re-loaded from IosSharedSettings manager next launch
            SessionController.DisposeSession();

            // Return any edited content to the host app.
            // This template doesn't do anything, so we just echo the passed-in items.
            ExtensionContext.CompleteRequest(ExtensionContext.InputItems, null);
        }
Esempio n. 15
0
        public void CompleteRequest(NSDictionary itemData)
        {
            ServiceContainer.Reset();

            Debug.WriteLine("BW LOG, itemData: " + itemData);
            var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
            var resultsItem     = new NSExtensionItem {
                Attachments = new NSItemProvider[] { resultsProvider }
            };
            var returningItems = new NSExtensionItem[] { resultsItem };

            NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CompleteRequest(returningItems, null));
        }
        partial void OnDoneClicked(UIBarButtonItem sender)
        {
            // Create the NSExtensionItem and NSItemProvider in which we return the image
            var extensionItem = new NSExtensionItem {
                AttributedTitle = new NSAttributedString("Inverted Image"),
                Attachments     = new [] {
                    new NSItemProvider(ImageView.Image, UTType.Image)
                }
            };

            ExtensionContext.CompleteRequest(new [] {
                extensionItem
            }, null);
        }
Esempio n. 17
0
        public override void DidSelectPost()
        {
            // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.
            var alert = UIAlertController.Create("Share extension", $"This is the step where you should post the ContentText value: '{ContentText}' to your targeted service.", UIAlertControllerStyle.Alert);

            PresentViewController(alert, true, () =>
            {
                DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 5000000000), () =>
                {
                    // 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);
                });
            });
        }
Esempio n. 18
0
        //private void UserDidCancelSetup()
        //{
        //    throw new NotImplementedException();
        //}

        ////private void UserDidFinishSetup()
        ////{
        ////    throw new NotImplementedException();
        ////}

        private void UserDidFinishSetup()
        {
            // _roomNameField.Text = "859502387";
            // URL of the resource where broadcast can be viewed that will be returned to the application
            string broadcastUrlString = "https://192.168.1.29/api/wipc";
            var    broadcastUrl       = NSUrl.FromString(broadcastUrlString);

            // Service specific broadcast data example which will be supplied to the process extension during broadcast
            var keys      = new NSString[] { new NSString("IPAddress") };
            var objects   = new INSCoding[] { new NSString(broadcastUrlString) };
            var setupInfo = NSDictionary <NSString, INSCoding> .FromObjectsAndKeys(objects, keys);

            // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
            ExtensionContext.CompleteRequest(broadcastUrl, setupInfo);
            // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
            //ExtensionContext.CompleteRequest(broadcastURL, setupInfo);
        }
Esempio n. 19
0
        public override SLComposeSheetConfigurationItem[] GetConfigurationItems()
        {
            if (PathList.Count == ExtensionContext.InputItems[0].Attachments.Length)
            {
                string path = "";
                path = JsonConvert.SerializeObject(PathList);
                var defs = new NSUserDefaults("group.com.shareapp.ios", NSUserDefaultsType.SuiteName);
                defs.SetString(path, "FilePathList");
                defs.Synchronize();


                ExtensionContext.CompleteRequest(new NSExtensionItem[0], null);
                UIApplication.SharedApplication.OpenUrl(new NSUrl("com.shareapp.test://"));
            }

            // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here.
            return(new SLComposeSheetConfigurationItem[0]);
        }
Esempio n. 20
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            var items = ExtensionContext.InputItems;

            if (items != null && items.Length > 0)
            {
                var attachments = items.First().Attachments;
                if (attachments != null && attachments.Length > 0)
                {
                    string firstImage    = null;
                    string secondImage   = null;
                    var    firstItemTask = Task.Run(async() =>
                    {
                        var path   = await attachments[0].LoadItemAsync(UTType.Image, null);
                        firstImage = WebUtility.UrlEncode(Convert.ToBase64String(File.ReadAllBytes(RemoveFilePrefix(path.ToString()))));
                    });

                    var secondItemTask = Task.CompletedTask;
                    if (attachments.Length > 1)
                    {
                        secondItemTask = Task.Run(async() =>
                        {
                            var path    = await attachments[1].LoadItemAsync(UTType.Image, null);
                            secondImage = WebUtility.UrlEncode(Convert.ToBase64String(File.ReadAllBytes(RemoveFilePrefix(path.ToString()))));
                        });
                    }

                    await Task.WhenAll(firstItemTask, secondItemTask);

                    const string BASE_URL = "crosscam://crosscam?";
                    if (firstImage != null)
                    {
                        var secondParameter = secondImage != null
                            ? "&second=" + secondImage
                            : "";
                        var url = new NSUrl(BASE_URL + "first=" + firstImage + secondParameter);
                        UIApplication.SharedApplication.OpenUrl(url);
                        ExtensionContext.CompleteRequest(ExtensionContext.InputItems, null);
                    }
                }
            }
        }
Esempio n. 21
0
        public void UserDidFinishSetup()
        {
            // Broadcast url that will be returned to the application
            var broadcastURL = NSUrl.FromString("http://broadcastURL_example/stream1");

            // Service specific broadcast data example which will be supplied to the process extension during broadcast
            var keys      = new[] { "userID", "endpointURL" };
            var objects   = new[] { "user1", "http://broadcastURL_example/stream1/upload" };
            var setupInfo = NSDictionary.FromObjectsAndKeys(objects, keys);

            // Set broadcast settings
            var broadcastConfig = new RPBroadcastConfiguration
            {
                ClipDuration = 5.0 // deliver movie clips every 5 seconds
            };

            // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
            ExtensionContext.CompleteRequest(broadcastURL, broadcastConfig, (NSDictionary <NSString, INSCoding>)setupInfo);
        }
Esempio n. 22
0
        private void PassSelectedItemsToApp()
        {
            NSExtensionItem firstItem = base.ExtensionContext.InputItems[0];

            var    itemsCount = firstItem.Attachments.Length;
            var    itemInd    = 0;
            string invokeArgs = string.Empty;

            if (itemsCount > 1)
            {
                UIAlertController alert = UIAlertController.Create("Steepshot", "You can post only one photo for the moment", UIAlertControllerStyle.Alert);
                PresentViewController(alert, true, () =>
                {
                    DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 5000000000), () =>
                    {
                        ExtensionContext.CompleteRequest(null, null);
                    });
                });
                base.DidSelectPost();
            }
            else
            {
                foreach (NSItemProvider itemProvider in firstItem.Attachments)
                {
                    if (itemProvider.HasItemConformingTo(UTType.Image))
                    {
                        itemProvider.LoadItemAsync(UTType.Image, null).ContinueWith((item) =>
                        {
                            var imageData = NSData.FromUrl((NSUrl)item.Result);
                            var image     = UIImage.LoadFromData(imageData);
                            var path      = SavePhotosToSharedStorage(image, itemInd);
                            invokeArgs   += string.IsNullOrEmpty(invokeArgs) ? path : $"%{path}";
                            if (++itemInd >= itemsCount)
                            {
                                InvokeOnMainThread(() =>
                                                   InvokeApp(invokeArgs));
                            }
                        });
                    }
                }
            }
        }
Esempio n. 23
0
        public void CompleteRequest(string id, NSDictionary itemData)
        {
            Debug.WriteLine("BW LOG, itemData: " + itemData);
            var resultsProvider = new NSItemProvider(itemData, UTType.PropertyList);
            var resultsItem     = new NSExtensionItem {
                Attachments = new NSItemProvider[] { resultsProvider }
            };
            var returningItems = new NSExtensionItem[] { resultsItem };

            NSRunLoop.Main.BeginInvokeOnMainThread(async() =>
            {
                if (!string.IsNullOrWhiteSpace(id) && itemData != null)
                {
                    var eventService = ServiceContainer.Resolve <IEventService>("eventService");
                    await eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
                }
                ServiceContainer.Reset();
                ExtensionContext?.CompleteRequest(returningItems, null);
            });
        }
        public void CompleteRequest(string username = null, string password = null, string totp = null)
        {
            if ((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password))
            {
                ExtensionContext?.CompleteExtensionConfigurationRequest();
                return;
            }

            if (_context == null || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                _googleAnalyticsService.TrackAutofillExtensionEvent("Canceled");
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
                _googleAnalyticsService.Dispatch(() =>
                {
                    NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                    {
                        ExtensionContext?.CancelRequest(err);
                    });
                });
                return;
            }

            if (!string.IsNullOrWhiteSpace(totp))
            {
                UIPasteboard.General.String = totp;
            }

            _googleAnalyticsService.TrackAutofillExtensionEvent("AutoFilled");
            var cred = new ASPasswordCredential(username, password);

            _googleAnalyticsService.Dispatch(() =>
            {
                NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                {
                    ExtensionContext?.CompleteRequest(cred, null);
                });
            });
        }
Esempio n. 25
0
        public void CompleteRequest(string id       = null, string username = null,
                                    string password = null, string totp     = null)
        {
            if ((_context?.Configuring ?? true) && string.IsNullOrWhiteSpace(password))
            {
                ServiceContainer.Reset();
                ExtensionContext?.CompleteExtensionConfigurationRequest();
                return;
            }

            if (_context == null || string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                ServiceContainer.Reset();
                var err = new NSError(new NSString("ASExtensionErrorDomain"),
                                      Convert.ToInt32(ASExtensionErrorCode.UserCanceled), null);
                NSRunLoop.Main.BeginInvokeOnMainThread(() => ExtensionContext?.CancelRequest(err));
                return;
            }

            if (!string.IsNullOrWhiteSpace(totp))
            {
                UIPasteboard.General.String = totp;
            }

            var cred = new ASPasswordCredential(username, password);

            NSRunLoop.Main.BeginInvokeOnMainThread(async() =>
            {
                if (!string.IsNullOrWhiteSpace(id))
                {
                    var eventService = ServiceContainer.Resolve <IEventService>("eventService");
                    await eventService.CollectAsync(Bit.Core.Enums.EventType.Cipher_ClientAutofilled, id);
                }
                ServiceContainer.Reset();
                ExtensionContext?.CompleteRequest(cred, null);
            });
        }
        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);
                                });
                            });
                        };
                    });
                });
            }
        }
Esempio n. 27
0
		partial void Close (NSObject sender)
		{
			var outputItem = new NSExtensionItem ();
			var outputItems = new[] { outputItem };
			ExtensionContext.CompleteRequest (outputItems, null);
		}
Esempio n. 28
0
        public override void DidSelectPost()
        {
            if (ExtensionContext.InputItems != null)
            {
                NSExtensionItem item = ExtensionContext.InputItems[0];

                if (item.Attachments != null && item.Attachments.Length > 0)
                {
                    var    fileManager           = new NSFileManager();
                    var    appGroupContainer     = fileManager.GetContainerUrl("group.com.shareapp.ios");
                    var    appGroupContainerPath = appGroupContainer.Path;
                    string directoryPath         = Path.Combine(appGroupContainerPath, "DocPro");
                    Directory.Delete(directoryPath, true);
                    fileManager.CreateDirectory(directoryPath, true, null);
                    int count = 0;

                    foreach (NSItemProvider itemProvider in item.Attachments)
                    {
                        if (itemProvider.HasItemConformingTo(UTType.Image))
                        {
                            string tempPath = string.Empty;

                            try
                            {
                                itemProvider.LoadItem(UTType.Image, null, (NSObject itemObject, NSError error) =>
                                {
                                    NSData imgData = null;

                                    if (itemObject is UIImage)
                                    {
                                        using (imgData = ((UIImage)itemObject).AsPNG())
                                        {
                                            byte[] myByteArray = new byte[imgData.Length];
                                            Marshal.Copy(imgData.Bytes, myByteArray, 0, Convert.ToInt32(imgData.Length));

                                            var fileIOS = new FileIOS();
                                            fileIOS.WriteAllBytes("Teste123.png", myByteArray);
                                            tempPath = fileIOS.GetFilePath("Teste123.png");
                                        }
                                    }
                                    else if (itemObject is NSUrl)
                                    {
                                        NSUrl nsurl = (NSUrl)itemObject;
                                        var nsdata  = NSData.FromUrl(nsurl);
                                        if (nsdata != null)
                                        {
                                            var data = UIImage.LoadFromData(nsdata);

                                            string pngFilename = Path.Combine(directoryPath, $"Img{count}.png");
                                            count++;

                                            using (imgData = data.AsPNG())
                                            {
                                                //NSError err = null;
                                                //bool isSaved = imgData.Save(pngFilename, false, out err);
                                                bool isFileCreated = fileManager.CreateFile(pngFilename, imgData, (NSDictionary)null);
                                            }
                                        }
                                        //using (imgData = (Data).AsPNG())
                                        //{
                                        //    byte[] myByteArray = new byte[imgData.Length];
                                        //    Marshal.Copy(imgData.Bytes, myByteArray, 0, Convert.ToInt32(imgData.Length));

                                        //    var fileIOS = new FileIOS();
                                        //    fileIOS.WriteAllBytes("Teste123.png", myByteArray);
                                        //}
                                    }
                                });

                                //var alert2 = UIAlertController.Create("Funfou", tempPath, UIAlertControllerStyle.Alert);
                                //PresentViewController(alert2, true, () =>
                                //{
                                //    DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 5000000000), () =>
                                //    {
                                //        // 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.
                                //    });
                                //});

                                UIApplication.SharedApplication.OpenUrl(new NSUrl("com.shareapp.test://"));
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                }

                ExtensionContext.CompleteRequest(ExtensionContext.InputItems, null);
            }
        }
Esempio n. 29
0
        public override async void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            var imageItem = ExtensionContext.InputItems[0];

            if (imageItem == null)
            {
                await this.FormatErrorAlert();

                return;
            }
            var imageItemProvider = imageItem.Attachments[0];

            if (imageItemProvider == null)
            {
                await this.FormatErrorAlert();

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

                return;
            }
            UIImage image = null;
            var     obj   = await imageItemProvider.LoadItemAsync(UTType.Image, null);

            // This is true when you call extension from Photo's ActivityViewController
            if (obj is NSUrl nsUrl)
            {
                image = UIImage.LoadFromData(NSData.FromUrl(nsUrl));
            }
            // This is true when you call extension from Main App
            if (image == null)
            {
                image = obj as UIImage;
            }

            var source = new CancellationTokenSource();
            var alert  = UIAlertController.Create(Strings.Uploading, null, UIAlertControllerStyle.Alert);

            alert.AddAction(UIAlertAction.Create(Strings.Cancel, UIAlertActionStyle.Default, (action) => {
                source.Cancel();
                ExtensionContext.CompleteRequest(null, null);
            }));
            await PresentViewControllerAsync(alert, true);

            string url = await this.UploadToImgur(image, source.Token);

            await DismissViewControllerAsync(true);

            source.Dispose();
            alert = UIAlertController.Create(
                null,
                url != null ?
                Strings.CopiedToClipboardToast + ":\n" + url :
                Strings.AppName + ": " + Strings.ErrorCheckConnection,
                UIAlertControllerStyle.Alert
                );
            alert.AddAction(UIAlertAction.Create(Strings.Ok, UIAlertActionStyle.Default, (action) => {
                if (url != null)
                {
                    Plugin.Clipboard.CrossClipboard.Current.SetText(url);
                    var userDefaults       = new NSUserDefaults("group.com.vlbor.SmartPrintScreen", NSUserDefaultsType.SuiteName);
                    string screenshotsList = userDefaults.StringForKey(Shared.ScreenshotsListKey);
                    if (string.IsNullOrEmpty(screenshotsList))
                    {
                        screenshotsList = "";
                    }
                    screenshotsList += url + "\n";
                    userDefaults.SetString(screenshotsList, Shared.ScreenshotsListKey);
                }
                // 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(null, null);
            }));
            await PresentViewControllerAsync(alert, true);
        }