void SetupLiveCameraStream()
        {
            _captureSession = new AVCaptureSession();

            var viewLayer = _liveCameraStream.Layer;

            _videoPreviewLayer = new AVCaptureVideoPreviewLayer(_captureSession)
            {
                Frame = _liveCameraStream.Bounds
            };

            _liveCameraStream.AddObserver("bounds", NSKeyValueObservingOptions.New, ObservedBoundsChange);

            _liveCameraStream.Layer.AddSublayer(_videoPreviewLayer);

            var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video);

            ConfigureCameraForDevice(captureDevice);
            _captureDeviceInput = AVCaptureDeviceInput.FromDevice(captureDevice);

            var dictionary = new NSMutableDictionary();

            dictionary[AVVideo.CodecKey] = new NSNumber((int)AVVideoCodec.JPEG);
            _stillImageOutput            = new AVCaptureStillImageOutput {
                OutputSettings = new NSDictionary()
            };

            _captureSession.AddOutput(_stillImageOutput);
            _captureSession.AddInput(_captureDeviceInput);
            _captureSession.StartRunning();
        }
        protected override void OnAttached()
        {
            _viewLifecycleEffect = Element.Effects.OfType <ViewLifecycleEffect>().FirstOrDefault();

            UIView nativeView = Control ?? Container;

            _isLoadedObserverDisposable = nativeView?.AddObserver("superview", ObservingOptions, IsViewLoadedObserver);
        }
 public override void WillMoveToSuperview(UIView newsuper)
 {
     base.WillMoveToSuperview(newsuper);
     if (newsuper != null)
     {
         frameObserver = newsuper.AddObserver("frame", NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, OnFrameChanged);
     }
 }
示例#4
0
        void SubscribeToDrawn(UIView elem)
        {
            if (elem is IDrawnObservable)
            {
                _observers.Add(elem.AddObserver(nameof(IDrawnObservable.Drawn), NSKeyValueObservingOptions.OldNew, HandleDrawnObserved));
            }

            foreach (var child in elem.Subviews)
            {
                SubscribeToDrawn(child);
            }
        }
示例#5
0
        public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase,
                                      string updateSourceEventName = null)
        {
            var binding = bindingBase as Binding;

            //This will allow setting bindings from Xaml by reusing the MarkupExtension
            updateSourceEventName = updateSourceEventName ?? binding?.UpdateSourceEventName;

            if (!IsNullOrEmpty(updateSourceEventName))
            {
                NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, updateSourceEventName);
                return;
            }

            NativeViewPropertyListener nativePropertyListener = null;

            if (bindingBase.Mode == BindingMode.TwoWay)
            {
                nativePropertyListener = new NativeViewPropertyListener(propertyName);
                try
                {
                    //TODO: We need to figure a way to map the value back to the real objectiveC property.
                    //the X.IOS camelcase property name won't work
                    var key      = new Foundation.NSString(propertyName.ToLower());
                    var valueKey = view.ValueForKey(key);
                    if (valueKey != null)
                    {
                        view.AddObserver(nativePropertyListener, key, Foundation.NSKeyValueObservingOptions.New, IntPtr.Zero);
                    }
                }
#if __MOBILE__
                catch (Foundation.MonoTouchException ex)
                {
                    nativePropertyListener = null;
                    if (ex.Name == "NSUnknownKeyException")
                    {
                        System.Diagnostics.Debug.WriteLine("KVO not supported, try specify a UpdateSourceEventName instead.");
                        return;
                    }
                    throw ex;
                }
#else
                catch (Exception ex)
                {
                    throw ex;
                }
#endif
            }

            NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener);
        }
示例#6
0
        public void ObserverTest()
        {
            bool observed = false;

            using (var o = new UIView()) {
                using (var observer = o.AddObserver("frame", NSKeyValueObservingOptions.OldNew, change => {
                    var old = ((NSValue)change.OldValue).CGRectValue;
                    var @new = ((NSValue)change.NewValue).CGRectValue;
                    Assert.AreEqual("{X=0,Y=0,Width=0,Height=0}", old.ToString(), "#old");
                    Assert.AreEqual("{X=0,Y=0,Width=123,Height=234}", @new.ToString(), "#new");
                    observed = true;
                })) {
                    o.Frame = new RectangleF(0, 0, 123, 234);
                }
            }
            Assert.IsTrue(observed, "observed");
        }
        public void SubscribeToDrawn(UIView elem)
        {
            if (!PerformanceTrackerRenderer.EnableInstrumentation)
            {
                return;
            }

            if (elem != _View && elem is IDrawnObservable)
            {
                _observers.Add(elem.AddObserver(nameof(IDrawnObservable.Drawn), NSKeyValueObservingOptions.OldNew, HandleDrawnObserved));
            }

            foreach (var child in elem.Subviews)
            {
                SubscribeToDrawn(child);
            }
        }
示例#8
0
		public static void SetBinding(this UIView view, string propertyName, BindingBase bindingBase, string updateSourceEventName = null)
		{
			var binding = bindingBase as Binding;
			//This will allow setting bindings from Xaml by reusing the MarkupExtension
			updateSourceEventName = updateSourceEventName ?? binding?.UpdateSourceEventName;

			if (!IsNullOrEmpty(updateSourceEventName))
			{
				NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, updateSourceEventName);
				return;
			}

			NativeViewPropertyListener nativePropertyListener = null;
			if (bindingBase.Mode == BindingMode.TwoWay) {
				nativePropertyListener = new NativeViewPropertyListener(propertyName);
				view.AddObserver(nativePropertyListener, propertyName, 0, IntPtr.Zero);
			}

			NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener);
		}