public void AddTest() { var v1 = (NSString)"1"; using (var st = new NSMutableSet <NSString> ()) { Assert.Throws <ArgumentNullException> (() => st.Add((NSString)null), "Add ANE 1"); st.Add(v1); Assert.IsTrue(st.Contains(v1), "Add 1"); Assert.AreSame(v1, st.AnyObject, "Add 2"); } }
private void RegisterHandoff(TalkModel talkModel) { var userInfo = new NSMutableDictionary(); var uri = new NSString(talkModel.GetAppLink().AppLinkUri.AbsoluteUri); userInfo.Add(new NSString("link"), uri); userInfo.Add(new NSString("Url"), uri); var keywords = new NSMutableSet <NSString>(new NSString(talkModel.Title)); foreach (var speaker in talkModel.Speakers) { keywords.Add(new NSString(speaker.FullName)); } foreach (var category in talkModel.Categories) { keywords.Add(new NSString(category.Name)); } this.activity.Keywords = new NSSet <NSString>(keywords); this.activity.WebPageUrl = NSUrl.FromString(talkModel.GetWebUrl()); this.activity.UserInfo = userInfo; // Provide context var attributes = new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.session") { Keywords = keywords.ToArray() .Select( k => k.ToString()) .ToArray(), Url = NSUrl.FromString( talkModel.GetAppLink() .AppLinkUri .AbsoluteUri) }; if (talkModel.StartTime.HasValue && talkModel.StartTime > DateTime.MinValue) { attributes.DueDate = talkModel.StartTime.Value.ToNSDate(); attributes.StartDate = talkModel.StartTime.Value.ToNSDate(); attributes.EndDate = talkModel.EndTime?.ToNSDate(); attributes.ImportantDates = new[] { attributes.StartDate, attributes.EndDate }; } this.activity.ContentAttributeSet = attributes; this.activity.EligibleForHandoff = true; }
void RegisterHandoff(Speaker speaker) { var userInfo = new NSMutableDictionary(); userInfo.Add(new NSString("Url"), new NSString(speaker.GetAppLink().AppLinkUri.AbsoluteUri)); var keywords = new NSMutableSet <NSString>(new NSString(speaker.FirstName), new NSString(speaker.LastName)); if (speaker.Sessions != null) { foreach (var session in speaker.Sessions) { keywords.Add(new NSString(session.Title)); } } _activity.Keywords = new NSSet <NSString>(keywords); _activity.WebPageUrl = NSUrl.FromString(speaker.GetWebUrl()); _activity.EligibleForHandoff = false; _activity.AddUserInfoEntries(userInfo); // Provide context var attributes = new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.speaker"); attributes.Keywords = keywords.ToArray().Select(k => k.ToString()).ToArray(); attributes.Url = NSUrl.FromString(speaker.GetAppLink().AppLinkUri.AbsoluteUri); _activity.ContentAttributeSet = attributes; }
NSSet <NSString> SelectableLayersFromSources(string [] layersId) { if (layersId == null) { return(null); } NSMutableSet <NSString> output = new NSMutableSet <NSString>(); foreach (string layerId in layersId) { var acceptedId = layerId.Replace("_", "-"); output.Add((NSString)acceptedId); output.Add((NSString)(acceptedId + " (1)")); } return(output.Copy() as NSSet <NSString>); }
partial void scanButtonClicked(Foundation.NSObject sender) { // The scanning behavior of the barcode picker is configured through scan // settings. We start with empty scan settings and enable a very generous // set of symbologies. In your own apps, only enable the symbologies you // actually need. ScanSettings settings = ScanSettings.DefaultSettings(); NSSet symbologiesToEnable = new NSSet( Symbology.EAN13, Symbology.EAN8, Symbology.UPC12, Symbology.UPCE, Symbology.Datamatrix, Symbology.QR, Symbology.Code39, Symbology.Code128, Symbology.ITF ); settings.EnableSymbologies(symbologiesToEnable); // Some 1d barcode symbologies allow you to encode variable-length data. By default, the // Scandit BarcodeScanner SDK only scans barcodes in a certain length range. If your // application requires scanning of one of these symbologies, and the length is falling // outside the default range, you may need to adjust the "active symbol counts" for this // symbology. This is shown in the following 3 lines of code. NSMutableSet codeLengths = new NSMutableSet(); int i = 0; for (i = 7; i <= 20; i++) { codeLengths.Add(new NSNumber(i)); } settings.SettingsForSymbology(Symbology.Code128).ActiveSymbolCounts = codeLengths; // For details on defaults and how to calculate the symbol counts for each symbology, take // a look at http://docs.scandit.com/stable/c_api/symbologies.html. // Setup the barcode scanner BarcodePicker picker = new BarcodePicker(settings); picker.OverlayView.ShowToolBar(true); // Add delegates for the scan and cancel event. We keep references to the // delegates until the picker is no longer used as the delegates are softly // referenced and can be removed because of low memory. scanDelegate = new PickerScanDelegate(); picker.ScanDelegate = scanDelegate; cancelDelegate = new OverlayCancelDelegate(this, picker); picker.OverlayView.CancelDelegate = cancelDelegate; PresentViewController(picker, true, null); picker.StartScanning(); }
public void WeakRequiredBillingContactFields() { TestRuntime.AssertXcodeVersion(9, 0); using (var pr = new PKPaymentRequest()) { Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count"); using (var set = new NSMutableSet()) { pr.WeakRequiredBillingContactFields = set; Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count-0"); set.Add(PKContactFields.PostalAddress.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(1), "Count-1"); set.Add(PKContactFields.EmailAddress.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(2), "Count-2"); set.Add(PKContactFields.PhoneNumber.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(3), "Count-3"); set.Add(PKContactFields.Name.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(4), "Count-5"); set.Add(PKContactFields.PhoneticName.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(5), "Count-5"); set.Add(PKContactFields.PhoneticName.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(5), "Count-5b"); set.Remove(PKContactFields.PhoneticName.GetConstant()); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(4), "Count-4b"); set.RemoveAll(); Assert.That(pr.WeakRequiredBillingContactFields.Count, Is.EqualTo(0), "Count-0b"); } } }
public void RequestProductData(List <string> productIds, ProductResponseDelegate responseDelegate) { NSMutableSet setIds = new NSMutableSet(); foreach (string s in productIds) { setIds.Add(new NSString(s)); } this.responseDelegate = responseDelegate; productsRequest = new SKProductsRequest(setIds); productsRequest.Delegate = this; productsRequest.Start(); }
private void RegisterHandoff(SpeakerModel speakerModel) { var userInfo = new NSMutableDictionary { { new NSString("Url"), new NSString( speakerModel.GetAppLink().AppLinkUri.AbsoluteUri) } }; var keywords = new NSMutableSet <NSString>( new NSString(speakerModel.FullName)); if (speakerModel.Talks != null) { foreach (var session in speakerModel.Talks) { keywords.Add(new NSString(session.Title)); } } this.activity.Keywords = new NSSet <NSString>(keywords); this.activity.WebPageUrl = NSUrl.FromString(speakerModel.GetWebUrl()); this.activity.EligibleForHandoff = false; this.activity.AddUserInfoEntries(userInfo); // Provide context var attributes = new CSSearchableItemAttributeSet($"{AboutThisApp.PackageName}.speaker") { Keywords = keywords.ToArray() .Select( k => k.ToString()) .ToArray(), Url = NSUrl.FromString( speakerModel .GetAppLink() .AppLinkUri .AbsoluteUri) }; this.activity.ContentAttributeSet = attributes; }
public static void RegisterNotifications() { var action = new UIMutableUserNotificationAction { Title = "Launch", Identifier = "trade", ActivationMode = UIUserNotificationActivationMode.Foreground, AuthenticationRequired = false }; var actionCategory = new UIMutableUserNotificationCategory { Identifier = "trade" }; var categories = new NSMutableSet(); categories.Add(actionCategory); actionCategory.SetActions(new UIUserNotificationAction[] { action }, UIUserNotificationActionContext.Default); var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Sound, categories); UIApplication.SharedApplication.RegisterUserNotificationSettings(settings); }
private void handleUITouch(UITouch touch, UIEvent evt) { var location = touch.LocationInView(null); PendingInputs.Enqueue(new MousePositionAbsoluteInput { Position = new Vector2((float)location.X * view.Scale, (float)location.Y * view.Scale) }); switch (touch.Phase) { case UITouchPhase.Moved: case UITouchPhase.Began: if (rightClickSupport && evt.ButtonMask == UIEventButtonMask.Secondary) { pendingRightClickTouches.Add(touch); PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Right, true)); } else { PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Left, true)); } break; case UITouchPhase.Cancelled: case UITouchPhase.Ended: if (pendingRightClickTouches.Contains(touch)) { pendingRightClickTouches.Remove(touch); PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Right, false)); } else { PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Left, false)); } break; } }
static public NSSet GetSet(PKContactFields values) { var set = new NSMutableSet(); if (values == PKContactFields.None) { return(set); } foreach (PKContactFields value in Enum.GetValues(typeof(PKContactFields))) { if (values.HasFlag(value)) { var constant = value.GetConstant(); // None does not have an associated native value and Contains would throw an ANE if (constant != null) { set.Add(constant); } } } return(set); }
public static SKNode Create(string filename, Type [] types, out NSError error) { // Let's fail early. if (filename == null) { throw new ArgumentNullException(nameof(filename)); } if (types == null) { throw new ArgumentNullException(nameof(filename)); } if (types.Length == 0) { throw new InvalidOperationException($"'{nameof (filename)}' length must be greater than zero."); } using (var classes = new NSMutableSet <Class> (types.Length)) { foreach (var type in types) { classes.Add(new Class(type)); } return(Create(filename, classes.Handle, out error)); } }
public static SKNode?Create(string filename, Type [] types, out NSError error) { // Let's fail early. if (filename == null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(filename)); } if (types == null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(types)); } if (types.Length == 0) { ObjCRuntime.ThrowHelper.ThrowArgumentException(nameof(types), "Length must be greater than zero."); } using (var classes = new NSMutableSet <Class> (types.Length)) { foreach (var type in types) { classes.Add(new Class(type)); } return(Create(filename, classes.Handle, out error)); } }
public override void ViewDidLoad() { base.ViewDidLoad(); linePickerModel = new LinePickerModel(); lineSelector.Model = linePickerModel; lineSelector.ShowSelectionIndicator = true; lineButton.TouchUpInside += SelectLines; // Profile Picture View may already been set when the Camera closes. if(profilePictureView == null) { profilePictureView = new UIImageView(); } else { // Set up Scroll View again when we have a new picture from the camera. var size = scrollView.Frame.Size; scrollView.ContentSize = profilePictureView.Frame.Size; scrollView.ContentInset = new UIEdgeInsets(size.Height * 0.8f, size.Width * 0.8f, size.Height * 0.8f, size.Width * 0.8f); scrollView.ContentOffset = new PointF(0, 0); } scrollView.AddSubview(profilePictureView); scrollView.MaximumZoomScale = 5f; scrollView.MinimumZoomScale = 0.2f; scrollView.Bounces = false; scrollView.BouncesZoom = false; scrollView.IndicatorStyle = UIScrollViewIndicatorStyle.Black; scrollView.ViewForZoomingInScrollView = (sender) => { return profilePictureView; }; if(profilePictureView.Image == null) LoadImage(UIImage.FromFile("ProfilePicture.jpg")); overlayImage = UIImage.FromFile(string.Format("FacebookOverlay{0}.png", numberOfLines)); facebookOverlay.Image = overlayImage; picker = new UIImagePickerController(); picker.Delegate = new ImagePickerDelegate(this); InitializePhotoButton(); facebookButton.Clicked += (o, e) => LoginToFacebook(true); mirrorButton.Clicked += (o, e) => MirrorImage(); hud = new ATMHud(); View.AddSubview(hud.View); AddCropHelpers(); var contentIdentifiers = new NSMutableSet(); contentIdentifiers.Add(new NSString("ADBannerContentSize320x50")); adView.RequiredContentSizeIdentifiers = contentIdentifiers; adView.Hidden = true; adView.AdLoaded += (o, e) => { adView.Hidden = false; Console.WriteLine("AdLoaded"); }; adView.FailedToReceiveAd += (object o, AdErrorEventArgs e) => { adView.Hidden = true; Console.WriteLine("FailedToReceiveAd: " + e.Error.ToString()); }; }
public KSCatalogViewController() : base(UITableViewStyle.Grouped, null) { PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Verbose; // Add some custom localization to ensure the bindings work. PSPDFKitGlobal.Localize("en", new NameValueCollection { { "Outline", "File Content" }, { "Bookmarks", "Remember" } }); // Call cache method to ensure the bindings for the cache work. var oPdfCache = PSPDFCache.SharedCache; oPdfCache.ClearCache( ); PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Info; NSUrl samplesURL = NSBundle.MainBundle.ResourceUrl.Append("Samples", true); NSUrl hackerMagURL = samplesURL.Append(HackerMagazineExample, false); NSUrl annotTestURL = samplesURL.Append(AnnotTestExample, false); this.Root = new RootElement("KSCatalogViewController") { new Section("Full example apps", "Can be used as a template for your own apps.") { // PDF playground. new StringElement("PSPDFViewController playground", () => { var doc = new PSPDFDocument(hackerMagURL); var kioskController = new KSKioskViewController(doc); kioskController.StatusBarStyleSetting = PSPDFStatusBarStyleSetting.Default; this.NavigationController.PushViewController(kioskController, true); }), }, new Section("Customizing") { // Combines various view controllers in a tab bar controller. new StringElement("Combine search, TOC and bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Don't use PSPDFVieController directly but a subclass that allows attaching to ViewDidDisappear in order to clear // the RightBarButtonItems property. Otherwise the tabBarBtn would keep a reference to the PSPDFViewController and the instances // would never be freed. //var controller = new PSPDFViewController(doc); var controller = new KSKioskViewController(doc); //controller.ViewDisappeared += (sender, args) => controller.RightBarButtonItems = new PSPDFBarButtonItem[0]; var tabBarController = new KSCombinedTabBarController(controller, doc); var tabBarBtn = new KSBarButtonItem(controller) { Title = "UITabBarController", Style = UIBarButtonItemStyle.Bordered }; tabBarBtn.Clicked += (object sender, EventArgs e) => controller.PresentViewControllerModalOrPopover(tabBarController, true, false, true, tabBarBtn, null); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem, controller.BookmarkButtonItem, tabBarBtn }; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject(new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Shows an alert when tapping a link annotation. new StringElement("Custom reaction on annotation links", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.Delegate = new KSCatchTappingLinkDelegate(); // There are link annotations on page 2. controller.SetPageAnimated(1, false); this.NavigationController.PushViewController(controller, true); }) }, new Section("Subclassing") { // Subclassing PSPDFAnnotationToolbar new StringElement("Subclass annotation toolbar and drawing toolbar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); var barButtons = new List <PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSAnnotationToolbar)).Handle, new Class(typeof(PSPDFAnnotationToolbar)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Demonstrates always visible vertical toolbar. new StringElement("Vertical always-visible annotation bar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSExampleAnnotationViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Tests potential binding issue when subclassing PSPDFViewController new StringElement("PSPDFViewController with NULL document", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSNoDocumentPDFViewController(); controller.Document = doc; this.NavigationController.PushViewController(controller, true); }), // Demonstrates capturing bookmark set/remove. new StringElement("Capture bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Create an entry for overriding the default bookmark parser. var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSBookmarkParser)).Handle, new Class(typeof(PSPDFBookmarkParser)).Handle); doc.OverrideClassNames = classDic; var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.BookmarkButtonItem, controller.SearchButtonItem, controller.OutlineButtonItem, controller.ViewModeButtonItem }; this.NavigationController.PushViewController(controller, true); }), // Demonstrates custom annotation provider. new StringElement("Custom Annotation Provider", () => { var doc = new PSPDFDocument(hackerMagURL); doc.SetDidCreateDocumentProviderBlock(delegate(PSPDFDocumentProvider documentProvider) { documentProvider.AnnotationParser.AnnotationProviders = new NSObject[] { new KSCustomAnnotationProvider(), documentProvider.AnnotationParser.FileAnnotationProvider }; }); var controller = new PSPDFViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Subclasses PDPFFileAnnotationProvider and injects additional annotations. // This example demonstrates: // * Make all built in annotations (those embedded in the PDF) immutable. // * All annotations added by the user can be modified. // * Workaround for PSPDFKit bug where the text of a non-editable annotation can still be changed. // * Immediate callback if an annotation has been changed. new StringElement("Subclass PSPDFFileAnnotationProvider", () => { var controller = new PSPDFViewController(); var barButtons = new List <PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); controller.SetPageAnimated(2, false); controller.PageMode = PSPDFPageMode.Automatic; controller.PageTransition = PSPDFPageTransition.ScrollContinuous; controller.ScrollDirection = PSPDFScrollDirection.Horizontal; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); var doc = new KSPDFDocument(hackerMagURL); //var doc = new PSPDFDocument(); //var doc = new PSPDFDocument(annotTestURL); // Create an entry for overriding the file annotation provider. classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSFileAnnotationProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle); classDic.LowlevelSetObject(new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject(new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; controller.Document = doc; }), // Set editable annotation types new StringElement("Set editable annotation types", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem }; var set = new NSMutableSet(); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringInk); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringNote); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringUnderline); controller.AnnotationButtonItem.AnnotationToolbar.EditableAnnotationTypes = set.ToNSOrderedSet(); this.NavigationController.PushViewController(controller, true); }) } }; }
/// <summary> /// Overridden from the base Game.Initialize. Once the GraphicsDevice is setup, /// we'll use the viewport to initialize some values. /// </summary> protected override void Initialize() { State = GameState.Menu; hookHeight = Math.Min (GraphicsDevice.Viewport.Height, MaxHookheight); player = new Player (); floor = new Floor (); playSound = true; hasPlayedSound = false; untilSpeedUpdate = GamePhysics.WhenToUpdateHookSpeed; previousTouches = new TouchCollection (); currentTouches = new TouchCollection (); // ad stuff UIViewController view = this.Services.GetService (typeof(UIViewController)) as UIViewController; adView = new ADBannerView (); NSMutableSet nsM = new NSMutableSet (); nsM.Add (ADBannerView.SizeIdentifierPortrait); adView.RequiredContentSizeIdentifiers = nsM; // delegate for ad is loaded adView.AdLoaded += delegate { adView.Frame = new System.Drawing.RectangleF(0, (UIScreen.MainScreen.Bounds.Height - adView.Frame.Height), adView.Frame.Width, adView.Frame.Height); adView.Hidden = false; }; // delegate for failed ad receive adView.FailedToReceiveAd += delegate(object sender, AdErrorEventArgs e) { Console.WriteLine(e.Error); adView.Hidden = true; }; // delegate for click on ad adView.ActionShouldBegin = delegate(ADBannerView banner, bool willLeaveApp) { // pause game here State = GameState.Paused; return true; }; // delegate for ad interaction finished adView.ActionFinished += delegate { // continue game now State = GameState.Menu; }; view.Add (adView); base.Initialize (); }
public KSCatalogViewController() : base(UITableViewStyle.Grouped, null) { PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Verbose; // Add some custom localization to ensure the bindings work. PSPDFKitGlobal.Localize("en", new NameValueCollection { {"Outline", "File Content"}, {"Bookmarks", "Remember"} }); // Call cache method to ensure the bindings for the cache work. var oPdfCache = PSPDFCache.SharedCache; oPdfCache.ClearCache ( ); PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Info; NSUrl samplesURL = NSBundle.MainBundle.ResourceUrl.Append ("Samples", true); NSUrl hackerMagURL = samplesURL.Append(HackerMagazineExample, false); NSUrl aesEncryptedURL = samplesURL.Append(AesEncryptedDoc, false); this.Root = new RootElement ("KSCatalogViewController") { new Section ("Full example apps", "Can be used as a template for your own apps.") { // PDF playground. new StringElement ("PSPDFViewController playground", () => { var doc = new PSPDFDocument(hackerMagURL); var kioskController = new KSKioskViewController(doc); kioskController.StatusBarStyleSetting = PSPDFStatusBarStyleSetting.Default; this.NavigationController.PushViewController(kioskController, true); }), }, new Section("Customizing") { // Combines various view controllers in a tab bar controller. new StringElement("Combine search, TOC and bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Don't use PSPDFVieController directly but a subclass that allows attaching to ViewDidDisappear in order to clear // the RightBarButtonItems property. Otherwise the tabBarBtn would keep a reference to the PSPDFViewController and the instances // would never be freed. //var controller = new PSPDFViewController(doc); var controller = new KSKioskViewController(doc); //controller.ViewDisappeared += (sender, args) => controller.RightBarButtonItems = new PSPDFBarButtonItem[0]; var tabBarController = new KSCombinedTabBarController(controller, doc); var tabBarBtn = new KSBarButtonItem(controller) { Title = "UITabBarController", Style = UIBarButtonItemStyle.Bordered }; tabBarBtn.Clicked += (object sender, EventArgs e) => controller.PresentViewControllerModalOrPopover(tabBarController, true, false, true, tabBarBtn, null); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem, controller.BookmarkButtonItem, tabBarBtn }; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Shows an alert when tapping a link annotation. new StringElement("Custom reaction on annotation links", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.Delegate = new KSCatchTappingLinkDelegate(); // There are link annotations on page 2. controller.SetPageAnimated(1, false); this.NavigationController.PushViewController(controller, true); }) }, new Section ("Subclassing") { // Subclassing PSPDFAnnotationToolbar new StringElement ("Subclass annotation toolbar and drawing toolbar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); var barButtons = new List<PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSAnnotationToolbar)).Handle, new Class(typeof(PSPDFAnnotationToolbar)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Demonstrates always visible vertical toolbar. new StringElement ("Vertical always-visible annotation bar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSExampleAnnotationViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Tests potential binding issue when subclassing PSPDFViewController new StringElement ("PSPDFViewController with NULL document", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSNoDocumentPDFViewController(); controller.Document = doc; this.NavigationController.PushViewController(controller, true); }), // Demonstrates capturing bookmark set/remove. new StringElement ("Capture bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Create an entry for overriding the default bookmark parser. var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSBookmarkParser)).Handle, new Class(typeof(PSPDFBookmarkParser)).Handle); doc.OverrideClassNames = classDic; var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.BookmarkButtonItem, controller.SearchButtonItem, controller.OutlineButtonItem, controller.ViewModeButtonItem }; this.NavigationController.PushViewController(controller, true); }), // Demonstrates custom annotation provider. new StringElement ("Custom Annotation Provider", () => { var doc = new PSPDFDocument(hackerMagURL); doc.SetDidCreateDocumentProviderBlock(delegate(PSPDFDocumentProvider documentProvider) { documentProvider.AnnotationParser.AnnotationProviders = new NSObject[] { new KSCustomAnnotationProvider(), documentProvider.AnnotationParser.FileAnnotationProvider }; }); var controller = new PSPDFViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Subclasses PDPFFileAnnotationProvider and injects additional annotations. // This example demonstrates: // * Make all built in annotations (those embedded in the PDF) immutable. // * All annotations added by the user can be modified. // * Workaround for PSPDFKit bug where the text of a non-editable annotation can still be changed. // * Immediate callback if an annotation has been changed. new StringElement ("Subclass PSPDFFileAnnotationProvider", () => { var controller = new PSPDFViewController(); var barButtons = new List<PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); controller.SetPageAnimated(2, false); controller.PageMode = PSPDFPageMode.Automatic; controller.PageTransition = PSPDFPageTransition.ScrollContinuous; controller.ScrollDirection = PSPDFScrollDirection.Horizontal; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); var doc = new KSPDFDocument(hackerMagURL); //var doc = new PSPDFDocument(); //var doc = new PSPDFDocument(annotTestURL); // Create an entry for overriding the file annotation provider. classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSFileAnnotationProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; controller.Document = doc; }), // Set editable annotation types new StringElement ("Set editable annotation types", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem }; var set = new NSMutableSet(); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringInk); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringNote); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringUnderline); controller.AnnotationButtonItem.AnnotationToolbar.EditableAnnotationTypes = set.ToNSOrderedSet(); this.NavigationController.PushViewController(controller, true); }) }, new Section("Security") { // This shows and tests decryption and viewing of a pre-encrypted document. new StringElement("Read AES encrypted document", () => { // Note: For shipping apps, you need to protect this string better, making it harder for hacker to simply disassemble and receive the key from the binary. Or add an internet service that fetches the key from an SSL-API. But then there's still the slight risk of memory dumping with an attached gdb. Or screenshots. Security is never 100% perfect; but using AES makes it way harder to get the PDF. You can even combine AES and a PDF password. string passphrase = @"afghadöghdgdhfgöhapvuenröaoeruhföaeiruaerub"; string salt = @"ducrXn9WaRdpaBfMjDTJVjUf3FApA6gtim0e61LeSGWV9sTxB0r26mPs59Lbcexn"; var cryptoWrapper = new PSPDFAESCryptoDataProvider(aesEncryptedURL, passphrase, salt); var provider = cryptoWrapper.DataProvider; var document = PSPDFDocument.PDFDocumentWithDataProvider(provider); document.Uid = AesEncryptedDoc; // manually set an UID for encrypted documents. // When PSPDFAESCryptoDataProvider is used, the cacheStrategy of PSPDFDocument is *automatically* set to PSPDFCacheNothing. // If you use your custom crypto solution, don't forget to set this to not leak out encrypted data as cached images. // document.cacheStrategy = PSPDFCacheNothing; var controller = new PSPDFViewController(document); this.NavigationController.PushViewController(controller, true); }), // This encrypts a PDF, saves it and then opens it. new StringElement("Encrypt a PDF and decrypt it again", () => { var targetFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "encrypted.pdf.aes"); // The passphrase is a secret! Keep it secret! string passphrase = "Hello World, I'm the secret!"; // The salt has to be at least 8 bytes. It should change for every encrypted document, just like the IV. // You can store it in cleartext together with your encrypted record, it's not a secret but used to prevent that // two identical passwords generate the same hash. // The salt should NOT be "12345678"! This is just for testing! Use something random. string salt = "132456789"; // PSPDFKit v2 does not allow passing the key directly. Instead it regegenerates the key using native PBKDF2. // PSPDFKit v3 will have different API where you can use the key directly. // Also note that PSPDFKit internally uses 50000 hashing iterations, so we have to use exactly the same algorithm. // Rfc2898DeriveBytes only supports SHA1, so we have a flexible version of it here where you can specify the hashing alogorithm. var deriveBytes = new Rfc2898DeriveBytesFlexible(passphrase, Encoding.UTF8.GetBytes(salt), 50000, new HMACSHA256()); // Encrypt the PDF. using (var rijndael = new RijndaelManaged()) { rijndael.KeySize = 256; rijndael.Key = deriveBytes.GetBytes ( rijndael.KeySize / 8 ); rijndael.IV = deriveBytes.GetBytes ( rijndael.BlockSize / 8 ); using(var readStream = File.Open("./Samples/" + HackerMagazineExample, FileMode.Open)) using(var writeStream = File.Open(targetFilePath, FileMode.Create)) using(var cryptoTrans = rijndael.CreateEncryptor ()) using(var encryptedStream = new CryptoStream (writeStream, cryptoTrans, CryptoStreamMode.Write)) { // Write the IV unencrypted first. writeStream.Write(rijndael.IV, 0, rijndael.IV.Length); // Then the encrypted PDF. readStream.CopyTo(encryptedStream); } } // Decrypt the just encrypted file and view it. var cryptoWrapper = new PSPDFAESCryptoDataProvider(NSUrl.FromFilename(targetFilePath), passphrase, salt); var provider = cryptoWrapper.DataProvider; var document = PSPDFDocument.PDFDocumentWithDataProvider(provider); document.Uid = AesEncryptedDoc; // manually set an UID for encrypted documents. // When PSPDFAESCryptoDataProvider is used, the cacheStrategy of PSPDFDocument is *automatically* set to PSPDFCacheNothing. // If you use your custom crypto solution, don't forget to set this to not leak out encrypted data as cached images. // document.cacheStrategy = PSPDFCacheNothing; var controller = new PSPDFViewController(document); this.NavigationController.PushViewController(controller, true); }) } }; }
/// <summary> /// Gets the categories to be registered for push notifications. /// </summary> /// <returns></returns> public async Task<NSSet> GetCategoriesAsync() { var set = new NSMutableSet(); var config = await GetConfigurationAsync(); // The configuration of the categories has to be on the main thread so we'll need to wait for // this to finish var waitHandle = new ManualResetEvent(false); UIApplication.SharedApplication.InvokeOnMainThread(() => { if (config != null) { foreach (var buttonSet in config) { foreach (var suffix in _suffixes) { var category = new UIMutableUserNotificationCategory { Identifier = buttonSet.ButtonSetId + suffix }; var currentSuffix = suffix; var index = -1; var actions = buttonSet.ButtonValues.Select(v => new UIMutableUserNotificationAction { ActivationMode = GetActivationMode(currentSuffix[index += 2]), Identifier = v, Title = v, Destructive = false, AuthenticationRequired = false }) .Cast<UIUserNotificationAction>() .ToArray(); category.SetActions(actions, UIUserNotificationActionContext.Default); category.SetActions(actions, UIUserNotificationActionContext.Minimal); set.Add(category); } } } waitHandle.Set(); }); // this will block the background thread, but only for a short period waitHandle.WaitOne(); return set; }
public KSCatalogViewController() : base(UITableViewStyle.Grouped, null) { PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Verbose; // Add some custom localization to ensure the bindings work. PSPDFKitGlobal.Localize("en", new NameValueCollection { {"Outline", "File Content"}, {"Bookmarks", "Remember"} }); // Call cache method to ensure the bindings for the cache work. var oPdfCache = PSPDFCache.SharedCache; oPdfCache.ClearCache ( ); PSPDFKitGlobal.LogLevel = PSPDFLogLevel.Info; NSUrl samplesURL = NSBundle.MainBundle.ResourceUrl.Append ("Samples", true); NSUrl hackerMagURL = samplesURL.Append(HackerMagazineExample, false); NSUrl annotTestURL = samplesURL.Append(AnnotTestExample, false); this.Root = new RootElement ("KSCatalogViewController") { new Section ("Full example apps", "Can be used as a template for your own apps.") { // PDF playground. new StringElement ("PSPDFViewController playground", () => { var doc = new PSPDFDocument(hackerMagURL); var kioskController = new KSKioskViewController(doc); kioskController.StatusBarStyleSetting = PSPDFStatusBarStyleSetting.Default; this.NavigationController.PushViewController(kioskController, true); }), }, new Section("Customizing") { // Combines various view controllers in a tab bar controller. new StringElement("Combine search, TOC and bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Don't use PSPDFVieController directly but a subclass that allows attaching to ViewDidDisappear in order to clear // the RightBarButtonItems property. Otherwise the tabBarBtn would keep a reference to the PSPDFViewController and the instances // would never be freed. //var controller = new PSPDFViewController(doc); var controller = new KSKioskViewController(doc); //controller.ViewDisappeared += (sender, args) => controller.RightBarButtonItems = new PSPDFBarButtonItem[0]; var tabBarController = new KSCombinedTabBarController(controller, doc); var tabBarBtn = new KSBarButtonItem(controller) { Title = "UITabBarController", Style = UIBarButtonItemStyle.Bordered }; tabBarBtn.Clicked += (object sender, EventArgs e) => controller.PresentViewControllerModalOrPopover(tabBarController, true, false, true, tabBarBtn, null); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem, controller.BookmarkButtonItem, tabBarBtn }; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Shows an alert when tapping a link annotation. new StringElement("Custom reaction on annotation links", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.Delegate = new KSCatchTappingLinkDelegate(); // There are link annotations on page 2. controller.SetPageAnimated(1, false); this.NavigationController.PushViewController(controller, true); }) }, new Section ("Subclassing") { // Subclassing PSPDFAnnotationToolbar new StringElement ("Subclass annotation toolbar and drawing toolbar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); var barButtons = new List<PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSAnnotationToolbar)).Handle, new Class(typeof(PSPDFAnnotationToolbar)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); }), // Demonstrates always visible vertical toolbar. new StringElement ("Vertical always-visible annotation bar", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSExampleAnnotationViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Tests potential binding issue when subclassing PSPDFViewController new StringElement ("PSPDFViewController with NULL document", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new KSNoDocumentPDFViewController(); controller.Document = doc; this.NavigationController.PushViewController(controller, true); }), // Demonstrates capturing bookmark set/remove. new StringElement ("Capture bookmarks", () => { var doc = new PSPDFDocument(hackerMagURL); // Create an entry for overriding the default bookmark parser. var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSBookmarkParser)).Handle, new Class(typeof(PSPDFBookmarkParser)).Handle); doc.OverrideClassNames = classDic; var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.BookmarkButtonItem, controller.SearchButtonItem, controller.OutlineButtonItem, controller.ViewModeButtonItem }; this.NavigationController.PushViewController(controller, true); }), // Demonstrates custom annotation provider. new StringElement ("Custom Annotation Provider", () => { var doc = new PSPDFDocument(hackerMagURL); doc.SetDidCreateDocumentProviderBlock(delegate(PSPDFDocumentProvider documentProvider) { documentProvider.AnnotationParser.AnnotationProviders = new NSObject[] { new KSCustomAnnotationProvider(), documentProvider.AnnotationParser.FileAnnotationProvider }; }); var controller = new PSPDFViewController(doc); this.NavigationController.PushViewController(controller, true); }), // Subclasses PDPFFileAnnotationProvider and injects additional annotations. // This example demonstrates: // * Make all built in annotations (those embedded in the PDF) immutable. // * All annotations added by the user can be modified. // * Workaround for PSPDFKit bug where the text of a non-editable annotation can still be changed. // * Immediate callback if an annotation has been changed. new StringElement ("Subclass PSPDFFileAnnotationProvider", () => { var controller = new PSPDFViewController(); var barButtons = new List<PSPDFBarButtonItem>(controller.RightBarButtonItems); barButtons.Add(controller.AnnotationButtonItem); controller.RightBarButtonItems = barButtons.ToArray(); controller.SetPageAnimated(2, false); controller.PageMode = PSPDFPageMode.Automatic; controller.PageTransition = PSPDFPageTransition.ScrollContinuous; controller.ScrollDirection = PSPDFScrollDirection.Horizontal; var classDic = new NSMutableDictionary(); classDic.LowlevelSetObject(new Class(typeof(KSNoteAnnotationController)).Handle, new Class(typeof(PSPDFNoteAnnotationController)).Handle); controller.OverrideClassNames = classDic; this.NavigationController.PushViewController(controller, true); var doc = new KSPDFDocument(hackerMagURL); //var doc = new PSPDFDocument(); //var doc = new PSPDFDocument(annotTestURL); // Create an entry for overriding the file annotation provider. classDic = new NSMutableDictionary(); classDic.LowlevelSetObject( new Class(typeof(KSFileAnnotationProvider)).Handle, new Class(typeof(PSPDFFileAnnotationProvider)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSInkAnnotation)).Handle, new Class(typeof(PSPDFInkAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSNoteAnnotation)).Handle, new Class(typeof(PSPDFNoteAnnotation)).Handle); classDic.LowlevelSetObject( new Class(typeof(KSHighlightAnnotation)).Handle, new Class(typeof(PSPDFHighlightAnnotation)).Handle); doc.OverrideClassNames = classDic; controller.Document = doc; }), // Set editable annotation types new StringElement ("Set editable annotation types", () => { var doc = new PSPDFDocument(hackerMagURL); var controller = new PSPDFViewController(doc); controller.RightBarButtonItems = new PSPDFBarButtonItem[] { controller.AnnotationButtonItem }; var set = new NSMutableSet(); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringInk); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringNote); set.Add(PSPDFAnnotation.PSPDFAnnotationTypeStringUnderline); controller.AnnotationButtonItem.AnnotationToolbar.EditableAnnotationTypes = set.ToNSOrderedSet(); this.NavigationController.PushViewController(controller, true); }) } }; }