private void ShowAppExtension(ExtensionPageViewModel extensionPageViewModel) { var itemProvider = new NSItemProvider(new NSDictionary(), Core.Constants.UTTypeAppExtensionSetup); var extensionItem = new NSExtensionItem { Attachments = new NSItemProvider[] { itemProvider } }; var activityViewController = new UIActivityViewController(new NSExtensionItem[] { extensionItem }, null) { CompletionHandler = (activityType, completed) => { extensionPageViewModel.EnabledExtension(completed && activityType == iOSCoreHelpers.AppExtensionId); } }; var modal = UIApplication.SharedApplication.KeyWindow.RootViewController.ModalViewController; if (activityViewController.PopoverPresentationController != null) { activityViewController.PopoverPresentationController.SourceView = modal.View; var frame = UIScreen.MainScreen.Bounds; frame.Height /= 2; activityViewController.PopoverPresentationController.SourceRect = frame; } modal.PresentViewController(activityViewController, true, null); }
/// <summary> /// Gets the items for beginning drag session. /// </summary> /// <returns>The items for beginning drag session.</returns> /// <param name="tableView">Table view.</param> /// <param name="session">Session.</param> /// <param name="indexPath">Index path.</param> public UIDragItem[] GetItemsForBeginningDragSession(UITableView tableView, IUIDragSession session, NSIndexPath indexPath) { var section = Element.Model.GetSection(indexPath.Section); if (!section.UseDragSort) { return(new UIDragItem[] {}); } var cell = Element.Model.GetCell(indexPath.Section, indexPath.Row); if (!cell.IsEnabled) { return(new UIDragItem[] { }); } // set "sectionIndex,rowIndex" as string var data = NSData.FromString($"{indexPath.Section},{indexPath.Row}"); var itemProvider = new NSItemProvider(); itemProvider.RegisterDataRepresentation(UTType.PlainText, NSItemProviderRepresentationVisibility.All, (completionHandler) => { completionHandler(data, null); return(null); }); return(new UIDragItem[] { new UIDragItem(itemProvider) }); }
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); }); }); }
private bool ProcessChangePasswordProvider(NSItemProvider itemProvider) { return(ProcessItemProvider(itemProvider, Constants.UTTypeAppExtensionChangePasswordAction, (dict) => { var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber; var url = dict[Constants.AppExtensionUrlStringKey] as NSString; var title = dict[Constants.AppExtensionTitleKey] as NSString; var sectionTitle = dict[Constants.AppExtensionSectionTitleKey] as NSString; var username = dict[Constants.AppExtensionUsernameKey] as NSString; var password = dict[Constants.AppExtensionPasswordKey] as NSString; var oldPassword = dict[Constants.AppExtensionOldPasswordKey] as NSString; var notes = dict[Constants.AppExtensionNotesKey] as NSString; var fields = dict[Constants.AppExtensionFieldsKey] as NSDictionary; if (url != null) { _context.UrlString = url; } _context.LoginTitle = title; _context.Username = username; _context.Password = password; _context.OldPassword = oldPassword; _context.Notes = notes; _context.PasswordOptions = DeserializeDictionary <PasswordGenerationOptions>(dict[Constants.AppExtensionPasswordGeneratorOptionsKey] as NSDictionary); })); }
/// <summary> /// Required for drag operations from a table /// </summary> public UIDragItem[] GetItemsForBeginningDragSession(UITableView tableView, IUIDragSession session, NSIndexPath indexPath) { var todo = todoItems[indexPath.Row]; var stringToDrop = todo.Name; if (todo.Done) { // we can modify the data that is dragged stringToDrop += " [" + NSBundle.MainBundle.LocalizedString("Done", "") + "]"; } var data = NSData.FromString(stringToDrop, NSStringEncoding.UTF8); var itemProvider = new NSItemProvider(); itemProvider.RegisterDataRepresentation(UTType.PlainText, NSItemProviderRepresentationVisibility.All, (completion) => { completion(data, null); return(null); }); var dragItem = new UIDragItem(itemProvider); //dragItem.LocalObject = if your object is a subclass of NSObject return(new UIDragItem[] { dragItem }); }
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(); } }); } }
public UIDragItem[] GetItemsForBeginningDragSession(UITableView tableView, IUIDragSession session, NSIndexPath indexPath) { _sourceTableView = tableView; _sourceListView = Element; _dragItem = (Item)((IList)Element.ItemsSource)[indexPath.Row]; // https://forums.xamarin.com/discussion/66953/how-to-save-c-object-into-nsdata-and-get-the-same-object-from-nsdata //var data = NSKeyedArchiver.ArchivedDataWithRootObject(indexPath); //var data = NSData.FromString(placeName, NSStringEncoding.UTF8); var data = NSData.FromString(_dragItem.Id); var itemProvider = new NSItemProvider(); itemProvider.RegisterDataRepresentation(UTType.PlainText, NSItemProviderRepresentationVisibility.All, (completion) => { completion(data, null); return(null); }); var uidragItem = new UIDragItem(itemProvider); return(new[] { uidragItem }); }
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 UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { bool isEven = Convert.ToInt16(NumberLabel.Text) % 2 == 0; var provider = new NSItemProvider(new NSString(NumberLabel.Text)); var item = new UIDragItem(provider) { LocalObject = new NSNumber(isEven) }; return(new UIDragItem[] { item }); }
public override void BeginRequestWithExtensionContext(NSExtensionContext context) { var attachment = new NSItemProvider(NSBundle.MainBundle.GetUrlForResource("blockerList", "json")); var item = new NSExtensionItem { Attachments = new[] { attachment } }; context.CompleteRequest(new[] { item }, null); }
private bool ProcessFindLoginProvider(NSItemProvider itemProvider) { return(ProcessItemProvider(itemProvider, Constants.UTTypeAppExtensionFindLoginAction, (dict) => { var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber; var url = dict[Constants.AppExtensionUrlStringKey] as NSString; if (url != null) { _context.UrlString = url; } })); }
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)); }
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; } }); }
private bool ProcessFindLoginBrowserProvider(NSItemProvider itemProvider, string action) { return(ProcessItemProvider(itemProvider, action, (dict) => { var version = dict[Constants.AppExtensionVersionNumberKey] as NSNumber; var url = dict[Constants.AppExtensionUrlStringKey] as NSString; if (url != null) { _context.Url = new Uri(url); } _context.Details = DeserializeDictionary <PageDetails>(dict[Constants.AppExtensionWebViewPageDetails] as NSDictionary); })); }
internal PHPickerFile(NSItemProvider provider) { this.provider = provider; NameWithoutExtension = provider?.SuggestedName; identifier = provider?.RegisteredTypeIdentifiers?.FirstOrDefault(); if (string.IsNullOrWhiteSpace(identifier)) { return; } Extension = GetExtension(identifier); ContentType = GetMIMEType(identifier); }
private bool ProcessWebUrlProvider(NSItemProvider itemProvider) { return(ProcessItemProvider(itemProvider, UTType.PropertyList, (dict) => { var result = dict[NSJavaScriptExtension.PreprocessingResultsKey]; if (result == null) { return; } _context.UrlString = result.ValueForKey(new NSString(Constants.AppExtensionUrlStringKey)) as NSString; var jsonStr = result.ValueForKey(new NSString(Constants.AppExtensionWebViewPageDetails)) as NSString; _context.Details = DeserializeString <PageDetails>(jsonStr); })); }
public UIDragItem [] GetItemsForBeginningDragSession(UICollectionView collectionView, IUIDragSession session, NSIndexPath indexPath) { var selectedPhoto = GetPhoto(indexPath); var userActivity = selectedPhoto.OpenDetailUserActivity(); var itemProvider = new NSItemProvider(UIImage.FromFile(selectedPhoto.Name)); itemProvider.RegisterObject(userActivity, NSItemProviderRepresentationVisibility.All); var dragItem = new UIDragItem(itemProvider) { LocalObject = selectedPhoto }; return(new [] { dragItem }); }
public UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { var results = new List <UIDragItem>(); if (MapItem == null) { return(results.ToArray()); } var itemProvider = new NSItemProvider(MapItem); itemProvider.RegisterObject(Image, NSItemProviderRepresentationVisibility.All); results.Add(new UIDragItem(itemProvider)); return(results.ToArray()); }
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; }); }); }
UIDragItem[] IUIDragInteractionDelegate.GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { var results = new List <UIDragItem>(); foreach (QRDetectionResult qrCode in QRCodes) { var itemProvider = new NSItemProvider((NSString)qrCode.Message); itemProvider.RegisterObject(qrCode.CroppedImage, NSItemProviderRepresentationVisibility.All); var item = new UIDragItem(itemProvider) { LocalObject = qrCode }; results.Add(item); } return(results.ToArray()); }
public virtual UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { // no data needed since we directly have access to the view thanks to the OnTouched event // so we put stub data so that the provider doesn't provide null objects TouchesBegan(null, null); var provider = new NSItemProvider(new NSString("")); var item = new UIDragItem(provider) { LocalObject = new NSNumber(true) }; return(new UIDragItem[] { item }); //return new UIDragItem[] { new UIDragItem(default(NSItemProvider)) }; }
/// <summary> /// A helper function that serves as an interface to the data mode, called /// by the `tableView(_:itemsForBeginning:at:)` method. /// </summary> public UIDragItem[] DragItems(NSIndexPath indexPath) { var placeName = PlaceNames[indexPath.Row]; var data = NSData.FromString(placeName, NSStringEncoding.UTF8); var itemProvider = new NSItemProvider(); itemProvider.RegisterDataRepresentation(UTType.PlainText, NSItemProviderRepresentationVisibility.All, (completion) => { completion(data, null); return(null); }); return(new UIDragItem[] { new UIDragItem(itemProvider) }); }
public UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { var point = session.LocationInView(interaction.View); var index = ImageIndex(point); if (index >= 0) { var image = Images[index]; var itemProvider = new NSItemProvider(image); var dragItem = new UIDragItem(itemProvider); dragItem.LocalObject = new NSNumber(index); return(new UIDragItem[] { dragItem }); } return(new UIDragItem[0]); }
public UIDragItem[] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { Console.WriteLine(interaction); Console.WriteLine(session); var scene = Scenes[1]; var activity = new NSUserActivity("IOS13DemoScene") { Title = scene.Type.AssemblyQualifiedName }; var itemProvider = new NSItemProvider(activity); itemProvider.RegisterObject(activity, NSItemProviderRepresentationVisibility.All); return(new[] { new UIDragItem(itemProvider) { LocalObject = activity } }); }
/// <summary> /// 'GetItemsForBeginningSession' allows dragging from a view. /// </summary> public UIDragItem [] GetItemsForBeginningSession(UIDragInteraction interaction, IUIDragSession session) { var image = ImageView.Image; if (image == null) { return new UIDragItem [] { } } ; var provider = new NSItemProvider(image); var item = new UIDragItem(provider) { LocalObject = image }; // If a non empty array is returned, dragging is enabled. return(new UIDragItem [] { item }); }
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 (); }); }); }
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); }); }
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); }