Beispiel #1
0
 public FontTypefaceHandler(NSArray descriptor)
 {
     PostScriptName = (string)Messaging.GetNSObject <NSString>(descriptor.ValueAt(0));
     _name          = (string)Messaging.GetNSObject <NSString>(descriptor.ValueAt(1));
     Weight         = Messaging.GetNSObject <NSNumber>(descriptor.ValueAt(2))?.Int32Value ?? 1;
     Traits         = (NSFontTraitMask)(Messaging.GetNSObject <NSNumber>(descriptor.ValueAt(3))?.Int32Value ?? 0);
 }
Beispiel #2
0
 public FontTypefaceHandler(NSArray descriptor)
 {
     PostScriptName = (string)new NSString(descriptor.ValueAt(0));
     name           = (string)new NSString(descriptor.ValueAt(1));
     Weight         = new NSNumber(descriptor.ValueAt(2)).Int32Value;
     Traits         = (NSFontTraitMask) new NSNumber(descriptor.ValueAt(3)).Int32Value;
 }
Beispiel #3
0
        public override bool PerformDragOperation(NSDraggingInfo sender)
        {
            NSPasteboard pb   = sender.DraggingPasteboard;
            NSArray      data = null;

            if (pb.Types.Contains(NSPasteboard.NSFilenamesType))
            {
                data = pb.GetPropertyListForType(NSPasteboard.NSFilenamesType) as NSArray;
            }
            if (data != null)
            {
                for (int i = 0; i < data.Count; i++)
                {
                    string path = (string)NSString.FromHandle(data.ValueAt((uint)i));
                    Console.WriteLine("From pasteboard Item {0} = {1}", i, path);

                    var url     = NSUrl.FromFilename(path);
                    var baseDir = url.Path;
                    var rootDir = baseDir.Substring(0, baseDir.LastIndexOf('/'));
                    var d       = new Directory(baseDir);
                    ScanDirectories(rootDir, baseDir, d);

                    var outlineView = Subviews [0].Subviews [0] as NSOutlineView;
                    ((TreeDataSource)outlineView.DataSource).Directories.Add(d);
                    outlineView.ReloadData();

                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
        UIImage [] GetImageArray(IntPtr handle)
        {
            using (var array = new NSArray(handle)) {
                var ret = new UIImage [array.Count];
                for (uint i = 0; i < ret.Length; i++)
                {
                    var     obj  = Runtime.GetNSObject(array.ValueAt(i));
                    var     data = obj as NSData;
                    UIImage img;

                    if (data != null)
                    {
                        img = new UIImage(data);
                    }
                    else
                    {
                        img = (UIImage)obj;
                    }

                    ret [i] = img;
                }

                return(ret);
            }
        }
		/* Could not test what sort of unique CFNumberRef value it's

		[iOS (5,0)]
		static public int InputSource {
			get {
				return GetInt (AudioSessionProperty.InputSource);
			}
			set {
				SetInt (AudioSessionProperty.InputSource, value);
			}
		}

		[iOS (5,0)]
		static public int OutputDestination {
			get {
				return GetInt (AudioSessionProperty.OutputDestination);
			}
			set {
				SetInt (AudioSessionProperty.OutputDestination, value);
			}
		}

		*/

		static internal AudioSessionInputRouteKind GetInputRoute (NSArray arr)
		{
			if (arr == null || arr.Count == 0)
				return AudioSessionInputRouteKind.None;
			
			var dict = new NSDictionary (arr.ValueAt (0));
			
			if (dict == null || dict.Count == 0)
				return AudioSessionInputRouteKind.None;
			
			var val = (NSString) dict [AudioRouteKey_Type];
			
			if (val == null)
				return AudioSessionInputRouteKind.None;
			
			if (val == InputRoute_LineIn) {
				return AudioSessionInputRouteKind.LineIn;
			} else if (val == InputRoute_BuiltInMic) {
				return AudioSessionInputRouteKind.BuiltInMic;
			} else if (val == InputRoute_HeadsetMic) {
				return AudioSessionInputRouteKind.HeadsetMic;
			} else if (val == InputRoute_BluetoothHFP) {
				return AudioSessionInputRouteKind.BluetoothHFP;
			} else if (val == InputRoute_USBAudio) {
				return AudioSessionInputRouteKind.USBAudio;
			} else {
				return (AudioSessionInputRouteKind) val.Handle;
			}
		}
Beispiel #6
0
        public override void Load()
        {
            var prefs = NSUserDefaults.StandardUserDefaults.ToDictionary();

            foreach (var item in prefs)
            {
                this[item.Key.ToString()] = item.Value.ToString();
            }

            foreach (var item in NSBundle.MainBundle.InfoDictionary)
            {
                if (item.Value is NSArray)
                {
                    string key = item.Key.ToString();

                    this[key] = string.Empty;

                    NSArray array = (NSArray)item.Value;
                    for (uint i = 0; i < array.Count; i++)
                    {
                        this[key] += new NSObject(array.ValueAt(i)).ToString();
                        if (i < array.Count - 1)
                        {
                            this[key] += "|";
                        }
                    }
                }
                else
                {
                    this[item.Key.ToString()] = item.Value.ToString();
                }
            }
        }
        private void LoadVideoDescView()
        {
            NSArray views = NSBundle.MainBundle.LoadNib("VoteVideoDescView", this, new NSDictionary());

            if (1 == views.Count)
            {
                UIView tempView = Runtime.GetNSObject(views.ValueAt(0)) as UIView;

                if (tempView is VoteImageDescView)
                {
                    var descView = tempView as VoteImageDescView;
                    descView.UpdateUIWith(SelectedVote);

                    descView.Frame = new System.Drawing.RectangleF(0, 0, (float)View.Bounds.Width, (float)View.Bounds.Height);
                    View.AddSubview(descView);

                    _asset      = AVAsset.FromUrl(NSUrl.FromString(SelectedVote.VideoUrl));
                    _playerItem = new AVPlayerItem(_asset);

                    _player            = new AVPlayer(_playerItem);
                    _playerLayer       = AVPlayerLayer.FromPlayer(_player);
                    _playerLayer.Frame = View.Frame;

                    descView.Layer.AddSublayer(_playerLayer);

                    _player.Play();
                }
            }
        }
        //========================================================================

        //========================================================================
        /// <summary>
        /// Writes out the key and value information to the console, useful for debugging,
        /// or understanding how the user preferences are stored.
        /// </summary>
        private static void WriteKeyAndValueToOutput(NSDictionary dict, NSObject key)
        {
            Console.Write(key.ToString() + ":");

            if (dict[key] is NSString)
            {
                Console.WriteLine(dict[key].ToString());
            }
            else
            {
                switch (dict[key].GetType().ToString())
                {
                case "MonoTouch.Foundation.NSNumber":
                    Console.WriteLine((dict[key] as NSNumber).FloatValue.ToString());
                    break;

                case "MonoTouch.Foundation.NSArray":
                    Console.WriteLine("");
                    NSArray items = dict[key] as NSArray;

                    for (uint j = 0; j < items.Count; j++)
                    {
                        Console.WriteLine("\t" + NSString.FromHandle(items.ValueAt(j)).ToString());
                    }
                    break;
                }
            }
        }
Beispiel #9
0
        private Object[] ConvertToArray(NSArray nsArray)
        {
            Object[] arr = new Object[nsArray.Count];
            for (uint i = 0; i < nsArray.Count; i++)
            {
                var o = ObjCRuntime.Runtime.GetNSObject(nsArray.ValueAt(i));
                if (o is NSArray)
                {
                    arr[i] = ConvertToArray((o as NSArray));
                }
                else if (o is NSDictionary)
                {
                }
                else if (o is NSMutableDictionary)
                {
                    arr[i] = ConvertToDictionary((o as NSMutableDictionary));
                }
                if (o is NSString)
                {
                    arr[i] = (o as NSString).Description;
                }
                else if (o is NSNumber)
                {
                    arr[i] = (o as NSNumber).Int16Value;
                }
            }

            return(arr);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            /*
             * set up Line
             */
            _lineLeft  = _line.Frame.X;
            _lineRight = _line.Frame.X + 116;

            /*
             * Add page 1
             */
            NSArray array  = NSBundle.MainBundle.LoadNib("Slide1", this, null);
            UIView  slide1 = Runtime.GetNSObject(array.ValueAt(0)) as UIView;

            slide1.Frame = new CoreGraphics.CGRect(0, 0, this.View.Frame.Width, scrollview.Frame.Height);
            scrollview.AddSubview(slide1);

            /*
             * Add page 2
             */
            NSArray array2 = NSBundle.MainBundle.LoadNib("Slide2", this, null);
            UIView  slide2 = Runtime.GetNSObject(array2.ValueAt(0)) as UIView;

            slide2.Frame = new CoreGraphics.CGRect(this.View.Frame.Width, 0, this.View.Frame.Width, scrollview.Frame.Height);
            scrollview.AddSubview(slide2);

            /*
             * Change scrollview contentsize
             */
            scrollview.ContentSize = new CoreGraphics.CGSize(this.View.Frame.Width * 2, scrollview.Frame.Height);

            /*
             * Handle the viewpager
             */

            this.scrollview.Scrolled += (sender, e) =>
            {
                moveLine(scrollview.ContentOffset.X / this.View.Frame.Width);

                /*
                 * page 1 - adjust scrollview height
                 */
                if (scrollview.ContentOffset.X == 0)
                {
                    scrollview.Frame = new CoreGraphics.CGRect(scrollview.Frame.X, scrollview.Frame.Y, this.View.Frame.Width, 200);
                }

                /*
                 * page 2
                 */
                else if (scrollview.ContentOffset.X > 1 && scrollview.Frame.Height != this.View.Frame.Height - 150)
                {
                    scrollview.Frame = new CoreGraphics.CGRect(scrollview.Frame.X, scrollview.Frame.Y, this.View.Frame.Width, this.View.Frame.Height - 150);
                }
            };
        }
        //
        // Inspect our selected objects (user double-clicked them).
        //
        // Note: this method will not get called until you make all columns in the table
        // as "non-editable".  So long as they are editable, double clicking a row will
        // cause the current cell to be editied.
        //
        partial void inspect(NSArray sender)
        {
            NSArray selectedObjects = sender;

            Console.WriteLine("inspect");

            int  index;
            uint numItems = selectedObjects.Count;

            for (index = 0; index < numItems; index++)
            {
                NSDictionary objectDict = new NSDictionary(selectedObjects.ValueAt(0));

                if (objectDict != null)
                {
                    Console.WriteLine(string.Format("inspector item: [ {0} {1}, {2} ]",
                                                    (NSString)objectDict[FIRST_NAME].ToString(),
                                                    (NSString)objectDict[LAST_NAME].ToString(),
                                                    (NSString)objectDict[PHONE].ToString()));
                }

                // setup the edit sheet controller if one hasn't been setup already
                if (myEditController == null)
                {
                    myEditController = new EditController();
                }

                // remember which selection index we are changing
                int savedSelectionIndex = myContentArray.SelectionIndex;

                NSDictionary editItem = new NSDictionary(selectedObjects.ValueAt(0));

                // get the current selected object and start the edit sheet
                NSMutableDictionary newValues = myEditController.edit(editItem, this);

                if (!myEditController.Cancelled)
                {
                    // remove the current selection and replace it with the newly edited one
                    var currentObjects = myContentArray.SelectedObjects;
                    myContentArray.Remove(currentObjects);

                    // make sure to add the new entry at the same selection location as before
                    myContentArray.Insert(newValues, savedSelectionIndex);
                }
            }
        }
Beispiel #12
0
        static List <NSObject> SubArray(NSArray array, uint skip = 0)
        {
            var result = new List <NSObject>();

            for (uint i = skip; i < array.Count; i++)
            {
                result.Add(ObjCRuntime.Runtime.GetNSObject(array.ValueAt(i)));
            }

            return(result);
        }
        private void inspect(NSArray selectedObjects)
        {
            NSDictionary objectDict = new NSDictionary(selectedObjects.ValueAt(0));

            if (objectDict != null)
            {
                NSString sss = new NSString("url");
                NSUrl    url = new NSUrl(objectDict.ValueForKey(sss).ToString());
                NSWorkspace.SharedWorkspace.OpenUrl(url);
            }
        }
Beispiel #14
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();


            NSArray nibObjects = NSBundle.MainBundle.LoadNib("GamePanel", this, null);

            GamePanel instantiatedView = new GamePanel(nibObjects.ValueAt(0));

            instantiatedView.Frame = new RectangleF(0, 0, this.Frame.Width, this.Frame.Height);
            this.AddSubview(instantiatedView);
        }
Beispiel #15
0
        static SCNMatrix4[] FromNSArray(NSArray nsa)
        {
            if (nsa == null)
                return null;

            var count = nsa.Count;
            var ret = new SCNMatrix4 [count];
            for (nuint i = 0; i < count; i++)
                ret [i] = Runtime.GetNSObject<NSValue> (nsa.ValueAt (i)).SCNMatrix4Value;

            return ret;
        }
Beispiel #16
0
        /// <summary>
        /// This method instantiates and add the HelpCustomView to the parentView provided.
        /// </summary>
        /// <param name="parentView"></param>
        /// <returns></returns>
        public static HelpCustomView Create(UIView parentView, string displayText, string buttonText, UIView initiaterView)
        {
            NSArray        arr = NSBundle.MainBundle.LoadNib(nameof(HelpCustomView), null, null);
            HelpCustomView v   = Runtime.GetNSObject <HelpCustomView>(arr.ValueAt(0));

            v._displayText   = displayText;
            v._buttonText    = buttonText;
            v._initiaterView = initiaterView;
            HelpCustomView.EmbedInParentView(v, parentView);

            return(v);
        }
Beispiel #17
0
        NSString TryFind(NSArray x509Values, NSString key)
        {
            for (uint i = 0; i < x509Values.Count; ++i)
            {
                var curCertValue = Runtime.GetNSObject <NSDictionary>(x509Values.ValueAt(i));
                var valueLabel   = (NSString)curCertValue.ValueForKey(SecPropertyKeyLabel);
                if (valueLabel.Compare(key) == NSComparisonResult.Same)
                {
                    return((NSString)curCertValue.ValueForKey(SecPropertyKeyValue));
                }
            }

            return(null);
        }
        void didAddMessages(NSNotification notification)
        {
            NSArray addedIndexes =
                (NSArray)notification.UserInfo.ObjectForKey(new NSString(TTTMessageServer.AddedMessageIndexesUserInfoKey));
            List <NSIndexPath> addedIndexPaths = new List <NSIndexPath> ();

            for (uint i = 0; i < addedIndexes.Count; i++)
            {
                NSNumber    indexValue = new NSNumber(addedIndexes.ValueAt(i));
                NSIndexPath indexPath  = NSIndexPath.FromRowSection(indexValue.IntValue, 0);
                addedIndexPaths.Add(indexPath);
            }
            TableView.InsertRows(addedIndexPaths.ToArray(), UITableViewRowAnimation.Automatic);
        }
        public void GenerateStockUsedPDFPreview()
        {
            NSArray a = NSBundle.MainBundle.LoadNib("DailyStockUsedPDFTemplate", this, null);

            GeneratedPDFView = (UIView)ObjCRuntime.Runtime.GetNSObject(a.ValueAt(0));

            UILabel tl = (UILabel)GeneratedPDFView.ViewWithTag(1);

            tl.Text = "Employee name: " + MyConstants.EmployeeName;
            tl      = (UILabel)GeneratedPDFView.ViewWithTag(2);
            tl.Text = "Date: " + DateTime.Now.Date.ToString("dd/MM/yyyy");

            UITableViewController usedStock = new UITableViewController();

            usedStock.TableView        = (UITableView)GeneratedPDFView.ViewWithTag(3);
            usedStock.TableView.Source = dvc.CreateSizingSource(false);
            usedStock.TableView.ReloadData();

            // WAS :: usedStock.TableView = (UITableView) ((UIView)dvc.TableView);


            // if (dvc.Root[0].Count > 17)
            {
                float calculatedHeight = (float)(dvc.Root[0].Count * Math.Max(dvc.TableView.RowHeight, 44) + 44);
                GeneratedPDFView.Frame    = new CGRect(GeneratedPDFView.Frame.X, GeneratedPDFView.Frame.Y, GeneratedPDFView.Frame.Width, usedStock.TableView.Frame.Y + calculatedHeight + 114);
                usedStock.TableView.Frame = new CGRect(usedStock.TableView.Frame.X, usedStock.TableView.Frame.Y, usedStock.TableView.Frame.Width, calculatedHeight);

                UIView sig = GeneratedPDFView.ViewWithTag(4);
                sig.Frame = new CGRect(sig.Frame.X, usedStock.TableView.Frame.Y + usedStock.TableView.Frame.Height + 8, sig.Frame.Width, sig.Frame.Height);
                tl        = (UILabel)GeneratedPDFView.ViewWithTag(5);
                tl.Frame  = new CGRect(tl.Frame.X, usedStock.TableView.Frame.Y + usedStock.TableView.Frame.Height + 8, tl.Frame.Width, tl.Frame.Height);


                // sig.Dispose (); sig = null;
            }

            if (a != null)
            {
                a.Dispose(); a = null;
            }
            if (tl != null)
            {
                tl.Dispose(); tl = null;
            }
            if (usedStock != null)
            {
                usedStock.Dispose(); usedStock = null;
            }
        }
    //TODO:revisar que funcione
    public static void enumerateObjectsUsingBlock(this NSArray array, enumerateObjectsAction action)
    {
        bool stop = false;

        for (nuint i = 0; i < array.Count; i++)
        {
            //id key, id obj, BOOL *stop
            NSObject obj = NSObject.FromObject(array.ValueAt(i));
            action(obj, i, out stop);
            if (stop == true)
            {
                break;
            }
        }
    }
Beispiel #21
0
        static SCNMatrix4 [] FromNSArray(NSArray nsa)
        {
            if (nsa == null)
            {
                return(null);
            }

            var count = nsa.Count;
            var ret   = new SCNMatrix4 [count];

            for (nuint i = 0; i < count; i++)
            {
                ret [i] = Runtime.GetNSObject <NSValue> (nsa.ValueAt(i)).SCNMatrix4Value;
            }

            return(ret);
        }
        // register for the notification when iCloud keys are changed
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            Reload(null, null);

            keyValueNotification =
                NSNotificationCenter.DefaultCenter.AddObserver(
                    NSUbiquitousKeyValueStore.DidChangeExternallyNotification
                    , delegate(NSNotification n)
            {
                Console.WriteLine("Cloud notification received");
                NSDictionary userInfo = n.UserInfo;

                NSNumber reasonNumber = (NSNumber)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangeReasonKey);
                int reason            = reasonNumber.IntValue;

                //Console.WriteLine("reason.IntValue: " + ireason);
                //Console.WriteLine("reason (enum): " + (NSUbiquitousKeyValueStoreChangeReason)ireason);

                NSArray changedKeys = (NSArray)userInfo.ObjectForKey(NSUbiquitousKeyValueStore.ChangedKeysKey);
                var changedKeysList = new List <string> ();
                for (uint i = 0; i < changedKeys.Count; i++)
                {
                    var key = new NSString(changedKeys.ValueAt(i));                      // resolve key to a string
                    //Console.WriteLine("changedKey IntPtr: " + changedKeys.ValueAt(i));
                    //Console.WriteLine("changedKey (value): " + key);

                    changedKeysList.Add(key);
                }

                var store        = NSUbiquitousKeyValueStore.DefaultStore;
                var synchronized = store.Synchronize();   Console.WriteLine("Changed synchronized=" + synchronized);
                // now do something with the list...
                InvokeOnMainThread(() => {
                    outputText.Text += "\n--- Cloud Notification \uE049\uE049\uE049 ---";
                    foreach (var k in changedKeysList)
                    {
                        outputText.Text += String.Format("\n{0}: {1}", k, store.GetString(k));
                    }
                    testText.Text  = store.GetString(sharedKeyName);
                    localText.Text = store.GetString(UIDevice.CurrentDevice.Name);
                });
            });
        }
        private void LoadImageDescView()
        {
            NSArray views = NSBundle.MainBundle.LoadNib("VoteImageDescView", this, new NSDictionary());

            if (1 == views.Count)
            {
                UIView tempView = Runtime.GetNSObject(views.ValueAt(0)) as UIView;

                if (tempView is VoteImageDescView)
                {
                    var descView = tempView as VoteImageDescView;
                    descView.UpdateUIWith(SelectedVote);

                    descView.Frame = new System.Drawing.RectangleF(0, 0, (float)View.Bounds.Width, (float)View.Bounds.Height);
                    View.AddSubview(descView);
                }
            }
        }
Beispiel #24
0
        public static T LoadViewFromNib <T>(string filename, NSObject owner) where T : NSView
        {
            //Loading the nib file and getting its items into NSArray
            NSBundle.MainBundle.LoadNibNamed(filename, owner, out xibItems);

            //Traversing the NSArray to look for the item of type T
            for (nuint i = 0; i < xibItems.Count; i++)
            {
                NSObject item = xibItems.GetItem <NSObject>(i);
                if (item is T)
                {
                    index = i;
                    break;
                }
            }

            return(Runtime.GetNSObject <T>(xibItems.ValueAt(index)));
        }
		static internal AudioSessionOutputRouteKind [] GetOutputRoutes (NSArray arr)
		{
			if (arr == null || arr.Count == 0)
				return null;
			
			var result = new AudioSessionOutputRouteKind [arr.Count];
			for (uint i = 0; i < arr.Count; i++) {
				var dict = new NSDictionary ((IntPtr) arr.ValueAt (i));
				
				result [i] = AudioSessionOutputRouteKind.None;
				
				if (dict == null || dict.Count == 0)
					continue;
				
				var val = (NSString) dict [AudioRouteKey_Type];
				
				if (val == null)
					continue;
				
				if (val == OutputRoute_LineOut) {
					result [i] = AudioSessionOutputRouteKind.LineOut;
				} else if (val == OutputRoute_Headphones) {
					result [i] = AudioSessionOutputRouteKind.Headphones;
				} else if (val == OutputRoute_BluetoothHFP) {
					result [i] = AudioSessionOutputRouteKind.BluetoothHFP;
				} else if (val == OutputRoute_BluetoothA2DP) {
					result [i] = AudioSessionOutputRouteKind.BluetoothA2DP;
				} else if (val == OutputRoute_BuiltInReceiver) {
					result [i] = AudioSessionOutputRouteKind.BuiltInReceiver;
				} else if (val == OutputRoute_BuiltInSpeaker) {
					result [i] = AudioSessionOutputRouteKind.BuiltInSpeaker;
				} else if (val == OutputRoute_USBAudio) {
					result [i] = AudioSessionOutputRouteKind.USBAudio;
				} else if (val == OutputRoute_HDMI) {
					result [i] = AudioSessionOutputRouteKind.HDMI;
				} else if (val == OutputRoute_AirPlay) {
					result [i] = AudioSessionOutputRouteKind.AirPlay;
				} else
					result [i] = (AudioSessionOutputRouteKind) val.Handle;
			}
			return result;
		}
        // todo: Can I now skip this since I have a registered an NSObject implementation?
        private List <WindowInfo> MapToTypedArray(NSArray array)
        {
            var windowInfos = new List <WindowInfo>();


            for (uint i = 0; i < array.Count; i++)
            {
                var nsObject = Runtime.GetNSObject <NSObject>(array.ValueAt(i));

                var windowName   = nsObject.ValueForKey(new NSString("kCGWindowOwnerName")).ToString();
                var windowNumber = nint.Parse(nsObject.ValueForKey(new NSString("kCGWindowNumber")).ToString());

                windowInfos.Add(new WindowInfo
                {
                    WindowOwnerName = windowName,
                    WindowNumber    = windowNumber
                });
            }

            return(windowInfos);
        }
Beispiel #27
0
        UIImage[] GetImageArray(IntPtr handle)
        {
            using (var array = new NSArray (handle)) {
                var ret = new UIImage [array.Count];
                for (uint i = 0; i < ret.Length; i++) {
                    var obj = Runtime.GetNSObject (array.ValueAt (i));
                    var data = obj as NSData;
                    UIImage img;

                    if (data != null) {
                        img = new UIImage (data);
                    } else {
                        img = (UIImage) obj;
                    }

                    ret [i] = img;
                }

                return ret;
            }
        }
        /// DEPRECATED for iOS 6 and later, but needed for iOS 5 and earlier to support additional orientations
        public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
        {
            bool shouldAutorotate = IPhoneUtils.GetInstance().ShouldAutorotate();

            if (shouldAutorotate)
            {
                // Check supported orientations
                if (supportedOrientations != null)
                {
                    bool orientationSupported = false;
                    for (uint index = 0; index < supportedOrientations.Count; index++)
                    {
                        NSString mySupportedOrientation = new NSString(supportedOrientations.ValueAt(index));
                        if (("UIInterfaceOrientation" + toInterfaceOrientation.ToString()) == mySupportedOrientation.ToString())
                        {
                            orientationSupported = true;
                            break;
                        }
                    }
                    shouldAutorotate = orientationSupported;
                }
                else
                {
                    log("Supported orientations not configured. All orientations are supported by default");
                }
            }
            else
            {
                log(" ** Autorotation blocked by application at runtime. ");
            }

            log("Should Autorotate to " + toInterfaceOrientation.ToString() + "? " + shouldAutorotate);

            if (shouldAutorotate)
            {
                this.ShowSplashScreenOnStartupTime(toInterfaceOrientation);
            }

            return(shouldAutorotate);
        }
        private void loadResultsFromQuery(NSNotification notif)
        {
            var results = new List <NSMetadataItem> (((NSMetadataQuery)notif.Object).Results);

            Console.WriteLine("search count = {0}", results.Count);
            string foundResultStr = string.Format("Results found: {0}", results.Count);

            progressSearchLabel.StringValue = foundResultStr;

            // iterate through the array of results, and match to the existing stores
            foreach (NSMetadataItem item in results)
            {
                var cityStr  = item.ValueForAttribute("kMDItemCity");
                var nameStr  = item.ValueForAttribute("kMDItemDisplayName");
                var stateStr = item.ValueForAttribute("kMDItemStateOrProvince");

                NSArray phoneNumbers = (NSArray)item.ValueForAttribute("kMDItemPhoneNumbers");
                // grab only the first phone number
                var phoneStr  = phoneNumbers == null ? null : new NSString(phoneNumbers.ValueAt(0));
                var storePath = (NSString)item.ValueForAttribute("kMDItemPath");

                // create a dictionary entry to be added to our search results array
                NSObject [] objects = new NSObject []
                {
                    nameStr ?? emptyStr,
                    phoneStr ?? emptyStr,
                    cityStr ?? emptyStr,
                    stateStr ?? emptyStr,
                    new NSUrl(storePath, false)
                };

                var keys = new object []
                {
                    "name", "phone", "city", "state", "url"
                };
                NSDictionary dict = NSDictionary.FromObjectsAndKeys(objects, keys);
                mySearchResults.AddObject(dict);
            }
        }
Beispiel #30
0
        public override bool PerformDragOperation(NSDraggingInfo sender)
        {
            Console.WriteLine("Drag Delegate received 'PerformDragOperation' sender: {0}", sender);

            //It seems that browserView does not send this message when it is an internal move.
            //It does all the work by sending a moveitems message to the datasource,
            // but I return false here just to be safe.

            NSObject obj = sender.DraggingSource;

            if (obj != null && obj.Equals(browserView))
            {
                Console.WriteLine("\tLet the image browser handle it.");
                return(false);
            }

            NSPasteboard pb   = sender.DraggingPasteboard;
            NSArray      data = null;

            //			if (pb.Types.Contains (NSPasteboard.NSUrlType))
            //				data = pb.GetPropertyListForType (NSPasteboard.NSUrlType) as NSArray;
            if (pb.Types.Contains(NSPasteboard.NSFilenamesType))
            {
                data = pb.GetPropertyListForType(NSPasteboard.NSFilenamesType) as NSArray;
            }
            if (data != null)
            {
                for (int i = 0; i < (int)data.Count; i++)
                {
                    string path = (string)NSString.FromHandle(data.ValueAt((uint)i));
                    Console.WriteLine("From pasteboard Item {0} = {1}", i, path);
                    ((BrowseData)browserView.DataSource).AddImages(
                        NSUrl.FromFilename(path), (int)browserView.GetIndexAtLocationOfDroppedItem());
                    browserView.ReloadData();
                }
            }
            return(true);
        }
Beispiel #31
0
        static CIFilter [] WrapFilters(NSArray filters)
        {
            if (filters == null)
            {
                return(new CIFilter [0]);
            }

            nuint count = filters.Count;

            if (count == 0)
            {
                return(new CIFilter [0]);
            }
            var ret = new CIFilter [count];

            for (nuint i = 0; i < count; i++)
            {
                var    filterHandle = filters.ValueAt(i);
                string?filterName   = CIFilter.GetFilterName(filterHandle);

                ret [i] = CIFilter.FromName(filterName, filterHandle);
            }
            return(ret);
        }
Beispiel #32
0
        public static void LoadDefaults(this NSUserDefaults defaults)
        {
            if (!defaults.BoolForKey("__DefaultsLoaded"))
            {
                using (NSDictionary settings = new NSDictionary(Paths.SettingsPlist))
                {
                    using (NSArray prefs = (NSArray)settings.ObjectForKey(new NSString("PreferenceSpecifiers")))
                    {
                        using (NSString keyString = new NSString("Key"),
                               defaultValueString = new NSString("DefaultValue"))
                        {
                            for (uint i = 0; i < prefs.Count; i++)
                            {
                                using (NSDictionary item = new NSDictionary(prefs.ValueAt(i)))
                                {
                                    using (NSObject key = item[keyString])
                                    {
                                        NSObject defaultValue = item[defaultValueString];
                                        if (defaultValue != null)
                                        {
                                            using (defaultValue)
                                            {
                                                defaults[key.ToString()] = defaultValue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                defaults.SetBool(true, "__DefaultsLoaded");
                defaults.Synchronize();
            }
        }
Beispiel #33
0
		private static Object[] ConvertToArray(NSArray nsArray) {
			Object[] arr = new Object[nsArray.Count];
			for (uint i = 0; i < nsArray.Count; i++) {
				var o = ObjCRuntime.Runtime.GetNSObject(nsArray.ValueAt(i));
				if(o is NSArray) {
					arr[i] = ConvertToArray((o as NSArray));
				} else if (o is NSDictionary) {

				} else if (o is NSMutableDictionary) {
					arr[i] = ConvertToDictionary((o as NSMutableDictionary));
				} if(o is NSString) {
					arr[i] = (o as NSString).Description;
				} else if(o is NSNumber) {
					arr[i] = (o as NSNumber).Int16Value;
				}
			}

			return arr;
		}
		static internal AudioSessionOutputRouteKind [] GetOutputRoutes (NSArray arr)
		{
			if (arr == null || arr.Count == 0)
				return null;
			
			var result = new AudioSessionOutputRouteKind [arr.Count];
			for (uint i = 0; i < arr.Count; i++) {
				var dict = new NSDictionary ((IntPtr) arr.ValueAt (i));
				
				result [i] = AudioSessionOutputRouteKind.None;
				
				if (dict == null || dict.Count == 0)
					continue;
				
				var val = (NSString) dict [AudioRouteKey_Type];
				
				if (val == null)
					continue;
				
				if (val == OutputRoute_LineOut) {
					result [i] = AudioSessionOutputRouteKind.LineOut;
				} else if (val == OutputRoute_Headphones) {
					result [i] = AudioSessionOutputRouteKind.Headphones;
				} else if (val == OutputRoute_BluetoothHFP) {
					result [i] = AudioSessionOutputRouteKind.BluetoothHFP;
				} else if (val == OutputRoute_BluetoothA2DP) {
					result [i] = AudioSessionOutputRouteKind.BluetoothA2DP;
				} else if (val == OutputRoute_BuiltInReceiver) {
					result [i] = AudioSessionOutputRouteKind.BuiltInReceiver;
				} else if (val == OutputRoute_BuiltInSpeaker) {
					result [i] = AudioSessionOutputRouteKind.BuiltInSpeaker;
				} else if (val == OutputRoute_USBAudio) {
					result [i] = AudioSessionOutputRouteKind.USBAudio;
				} else if (val == OutputRoute_HDMI) {
					result [i] = AudioSessionOutputRouteKind.HDMI;
				} else if (val == OutputRoute_AirPlay) {
					result [i] = AudioSessionOutputRouteKind.AirPlay;
				} else
					result [i] = (AudioSessionOutputRouteKind) val.Handle;
			}
			return result;
		}
		/* Could not test what sort of unique CFNumberRef value it's

		[Since (5,0)]
		static public int InputSource {
			get {
				return GetInt (AudioSessionProperty.InputSource);
			}
			set {
				SetInt (AudioSessionProperty.InputSource, value);
			}
		}

		[Since (5,0)]
		static public int OutputDestination {
			get {
				return GetInt (AudioSessionProperty.OutputDestination);
			}
			set {
				SetInt (AudioSessionProperty.OutputDestination, value);
			}
		}

		*/

		static internal AudioSessionInputRouteKind GetInputRoute (NSArray arr)
		{
			if (arr == null || arr.Count == 0)
				return AudioSessionInputRouteKind.None;
			
			var dict = new NSDictionary (arr.ValueAt (0));
			
			if (dict == null || dict.Count == 0)
				return AudioSessionInputRouteKind.None;
			
			var val = (NSString) dict [AudioRouteKey_Type];
			
			if (val == null)
				return AudioSessionInputRouteKind.None;
			
			if (val == InputRoute_LineIn) {
				return AudioSessionInputRouteKind.LineIn;
			} else if (val == InputRoute_BuiltInMic) {
				return AudioSessionInputRouteKind.BuiltInMic;
			} else if (val == InputRoute_HeadsetMic) {
				return AudioSessionInputRouteKind.HeadsetMic;
			} else if (val == InputRoute_BluetoothHFP) {
				return AudioSessionInputRouteKind.BluetoothHFP;
			} else if (val == InputRoute_USBAudio) {
				return AudioSessionInputRouteKind.USBAudio;
			} else {
				return (AudioSessionInputRouteKind) val.Handle;
			}
		}
Beispiel #36
0
        static CIFilter[] WrapFilters(NSArray filters)
        {
            if (filters == null)
                return new CIFilter [0];

            uint count = filters.Count;
            if (count == 0)
                return new CIFilter [0];
            var ret = new CIFilter [count];
            for (uint i = 0; i < count; i++){
                IntPtr filterHandle = filters.ValueAt (i);
                string filterName = CIFilter.GetFilterName (filterHandle);

                ret [i] = CIFilter.FromName (filterName, filterHandle);
            }
            return ret;
        }
        void Initialize()
        {
            log ("Initialize view");
            this.ShowSplashScreenOnStartupTime( UIApplication.SharedApplication.StatusBarOrientation);

            NSObject supportedOrientationsObj = NSBundle.MainBundle.ObjectForInfoDictionary ("CustomUISupportedInterfaceOrientations");
            if (supportedOrientationsObj != null) {
                if (supportedOrientationsObj is NSArray) {
                    supportedOrientations = (NSArray)supportedOrientationsObj;

                    for (uint index = 0; index < supportedOrientations.Count; index++) {
                        NSString mySupportedOrientation = new NSString (supportedOrientations.ValueAt (index));
                        if (("UIInterfaceOrientation" + UIInterfaceOrientation.Portrait.ToString ()) == mySupportedOrientation.ToString ()) {
                            orientationSupportedPortrait = true;
                        }
                        if (("UIInterfaceOrientation" + UIInterfaceOrientation.PortraitUpsideDown.ToString ()) == mySupportedOrientation.ToString ()) {
                            orientationSupportedPortraitUpsideDown = true;
                        }
                        if (("UIInterfaceOrientation" + UIInterfaceOrientation.LandscapeLeft.ToString ()) == mySupportedOrientation.ToString ()) {
                            orientationSupportedLandscapeLeft = true;
                        }
                        if (("UIInterfaceOrientation" + UIInterfaceOrientation.LandscapeRight.ToString ()) == mySupportedOrientation.ToString ()) {
                            orientationSupportedLandscapeRight = true;
                        }
                    }

                }
            }
        }
		private void inspect (NSArray selectedObjects)
		{
			NSDictionary objectDict = new NSDictionary (selectedObjects.ValueAt (0));
			
			if (objectDict != null) {
				NSString sss = new NSString ("url");
				NSUrl url = new NSUrl (objectDict.ValueForKey (sss).ToString ());
				NSWorkspace.SharedWorkspace.OpenUrl (url);                      
			}
		}
Beispiel #39
0
		public static NSData [] QueryAsData (SecRecord query, bool wantPersistentReference, int max, out SecStatusCode status)
		{
			if (query == null)
				throw new ArgumentNullException ("query");

			using (var copy = NSMutableDictionary.FromDictionary (query.queryDict)){
				var n = SetLimit (copy, max);
				copy.LowlevelSetObject (CFBoolean.True.Handle, SecItem.ReturnData);

				IntPtr ptr;
				status = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
				n = null;
				if (status == SecStatusCode.Success){
					if (max == 1)
						return new NSData [] { new NSData (ptr, false) };

					var array = new NSArray (ptr);
					var records = new NSData [array.Count];
					for (uint i = 0; i < records.Length; i++)
						records [i] = new NSData (array.ValueAt (i), false);
					return records;
				}
				return null;
			}
		}
Beispiel #40
0
		public static SecRecord [] QueryAsRecord (SecRecord query, int max, out SecStatusCode result)
		{
			if (query == null)
				throw new ArgumentNullException ("query");
			
			using (var copy = NSMutableDictionary.FromDictionary (query.queryDict)){
				copy.LowlevelSetObject (CFBoolean.True.Handle, SecItem.ReturnAttributes);
				var n = SetLimit (copy, max);
				
				IntPtr ptr;
				result = SecItem.SecItemCopyMatching (copy.Handle, out ptr);
				n = null;
				if (result == SecStatusCode.Success){
					var array = new NSArray (ptr);
					var records = new SecRecord [array.Count];
					for (uint i = 0; i < records.Length; i++)
						records [i] = new SecRecord (new NSMutableDictionary (array.ValueAt (i), false));
					return records;
				}
				return null;
			}
		}