/// <summary>
        /// 初始化截屏服务。
        /// </summary>
        /// <param name="data"></param>
        /// <param name="context"></param>
        /// <param name="handler"></param>
        public void Init(Intent data, Context context)
        {
            if (IsInit)
            {
                return;
            }

            volatileDispose           = new VolatileDispose();
            _intent                   = data;
            Context                   = context;
            _mediaProjectionManager   = AppApplication.GetSystemService <MediaProjectionManager>(Context.MediaProjectionService);
            _orientationEventListener = new OrientationEvent(context, i =>
            {
                try
                {
                    RefreshVirtualDisplay();
                }
                catch (Exception)
                {
                }
            });

            if (_orientationEventListener.CanDetectOrientation())
            {
                _orientationEventListener.Enable();
            }

            IsInit = true;
        }
 public bool OnSurfaceTextureDestroyed(SurfaceTexture surface)
 {
     try
     {
         Session.StopRepeating();
         Session.Close();
     }
     catch (Exception)
     {
         Console.WriteLine("Failed to close camera session.");
     }
     try
     {
         cancellationTokenSource.Cancel();
         cancellationTokenSource.Dispose();
     }
     catch (Exception)
     {
     }
     OrientationEventListener.Disable();
     try
     {
         (CurrentContext as MainActivity).OnCameraAccepted -= StartCamera;
     }
     catch (Exception)
     {
         Console.WriteLine("Failed to remove camera accepted handler. This likely means permissions were already accepted.");
     }
     return(true);
 }
        override protected void OnCreate
        (
            Bundle bundle
        )
        {
            base.OnCreate(bundle);

            _orientationListener = new DeviceOrientationEventListener(this,
                                                                      SensorDelay.Normal,
                                                                      OrientationChanged);
            _orientationListener.Enable();
        }
        protected override void OnElementChanged(ElementChangedEventArgs <CameraPreview> args)
        {
            if (DesignMode.IsDesignModeEnabled)
            {
                return;
            }

            if (args.OldElement != null) // Clear old element event
            {
            }

            if (args.NewElement != null)
            {
                args.NewElement.StartRecording = (() => { TakePicture(); });
                args.NewElement.StopRecording  = (() => { CloseCamera(); });

                if (Control == null)
                {
                    Activity = this.Context as Activity;
                    SetNativeControl(new AutoFitTextureView(Context));
                }

                _textureView            = Control as AutoFitTextureView;
                _stateCallback          = new CameraStateListener(this);
                _surfaceTextureListener = new Camera2SurfaceTextureListener(this);

                CaptureCallback = new CameraCaptureListener(this);

                _onImageAvailableListener = new ImageAvailableListener(this, Element.MediaOptions);

                _onImageAvailableListener.ImageAvailable += (s, e) =>
                {
                    Element.OnImageAvailable(e);
                };

                _orientationEventListener = new OrientationChangeListener(Context, (int rotation) => OnRotationChanged(rotation));
                _orientationEventListener.Enable();

                RotationChanged += (s, e) =>
                {
                    args.NewElement.OnRotationChanged(DeviceRotation);
                };

                StartTheCamera();
            }

            base.OnElementChanged(args);
        }
        /// <summary>
        /// Sets up the camera, and requests permissions if needed.
        /// </summary>
        /// <param name="surface"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        public void OnSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
        {
            Activity.RequestedOrientation = ScreenOrientation.Portrait;
            OrientationEventListener.Enable();
            cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       = cancellationTokenSource.Token;

            Surface = surface;

            // if the camera permission has to be accepted, then
            // the camera will be started when that happens.
            //(CurrentContext as MainActivity).OnCameraAccepted += StartCamera;

            if (ContextCompat.CheckSelfPermission(CurrentContext, Manifest.Permission.Camera) != Permission.Granted)
            {
                ActivityCompat.RequestPermissions(CurrentContext, new string[] { Manifest.Permission.Camera }, 1);
            }
            else
            {
                StartCamera();
            }
        }
 static void StopScreenMetricsListeners()
 {
     orientationListener?.Disable();
     orientationListener?.Dispose();
     orientationListener = null;
 }
 static void StartScreenMetricsListeners()
 {
     orientationListener = new Listener(Application.Context, OnScreenMetricsChanaged);
     orientationListener.Enable();
 }
        // Called when the activity is first created.
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Log.Debug(TAG, "onCreate");

            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen);
            Window.AddFlags(WindowManagerFlags.KeepScreenOn);
            RequestedOrientation = ScreenOrientation.Landscape;

            populateCameraOrientations();

            SetContentView(Resource.Layout.tabhost);

            IntentFilter receiverFilter = new IntentFilter(Intent.ActionHeadsetPlug);

            receiver = new BroadcastReceiverAnonymousInnerClassHelper(this);
            RegisterReceiver(receiver, receiverFilter);

            mTabHost = TabHost;

            // Main tab
            mTabSpecVideo = mTabHost.NewTabSpec("tab_video");
            mTabSpecVideo.SetIndicator("Main");
            mTabSpecVideo.SetContent(Resource.Id.tab_video);
            mTabHost.AddTab(mTabSpecVideo);

            // Shared config tab
            mTabHost       = TabHost;
            mTabSpecConfig = mTabHost.NewTabSpec("tab_config");
            mTabSpecConfig.SetIndicator("Settings");
            mTabSpecConfig.SetContent(Resource.Id.tab_config);
            mTabHost.AddTab(mTabSpecConfig);

            TabHost.TabSpec mTabv;
            mTabv = mTabHost.NewTabSpec("tab_vconfig");
            mTabv.SetIndicator("Video");
            mTabv.SetContent(Resource.Id.tab_vconfig);
            mTabHost.AddTab(mTabv);
            TabHost.TabSpec mTaba;
            mTaba = mTabHost.NewTabSpec("tab_aconfig");
            mTaba.SetIndicator("Audio");
            mTaba.SetContent(Resource.Id.tab_aconfig);
            mTabHost.AddTab(mTaba);

            int childCount = mTabHost.TabWidget.ChildCount;

            for (int i = 0; i < childCount; i++)
            {
                mTabHost.TabWidget.GetChildAt(i).LayoutParameters.Height = 50;
            }
            orientationListener = new OrientationEventListenerAnonymousInnerClassHelper(this, SensorDelay.Ui);
            orientationListener.Enable();

            // Create a folder named webrtc in /scard for debugging
            webrtcDebugDir = Android.OS.Environment.ExternalStorageDirectory.ToString() + webrtcName;
            File webrtcDir = new File(webrtcDebugDir);

            if (!webrtcDir.Exists() && webrtcDir.Mkdir() == false)
            {
                Log.Verbose(TAG, "Failed to create " + webrtcDebugDir);
            }
            else if (!webrtcDir.IsAbsolute)
            {
                Log.Verbose(TAG, webrtcDebugDir + " exists but not a folder");
                webrtcDebugDir = null;
            }

            startMain();

            if (AUTO_CALL_RESTART_DELAY_MS > 0)
            {
                StartOrStop();
            }
        }
 static void StartScreenMetricsListeners()
 {
     orientationListener = new Listener(Platform.AppContext, OnScreenMetricsChanged);
     orientationListener.Enable();
 }
 public void Initialize(Application application)
 {
     this.application = application;
     this.application.RegisterActivityLifecycleCallbacks(this);
     this.listener = new OrientationEventListenerImpl(this.application.ApplicationContext, this);
 }
Exemple #11
0
        protected override void OnCreate
        (
            Bundle bundle
        )
        {
            base.OnCreate(bundle);

            _audioPath = Intent.GetStringExtra(AudioPathExtra);

            if (_audioPath == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' extra string missing.",
                                                                  AudioPathExtra));
            }

            _orientationListener = new AndroidCameraActivity.DeviceOrientationEventListener
                                   (
                this,
                SensorDelay.Normal,
                OrientationChanged
                                   );

            _orientationListener.Enable();

            SetContentView(Resource.Layout.PlayVideoLayout);

            _videoView = FindViewById <VideoView>(Resource.Id.PlayedVideo);

            _mediaController = new MediaController(this,
                                                   useFastForward: false);

            _mediaController.SetAnchorView(_videoView);
            _videoView.SetMediaController(_mediaController);

            _videoView.SetOnPreparedListener
            (
                new VideoPreparedListener
                (
                    () =>
            {
                _videoView.SeekTo(1);
                _mediaController.Show();
            }
                )
            );

            _videoView.SetOnCompletionListener
            (
                new VideoCompletionListener
                (
                    () => _mediaController.Show()
                )
            );

            _videoView.SetOnErrorListener
            (
                new VideoErrorListener
                (
                    this,
                    _audioPath,
                    getString: (resource) => { return(GetString(resource)); }
                )
            );

            //_imageView.Touch -= TouchImage;
            //_imageView.Touch += TouchImage;

            /*_videoView.Post // wait with image loading until view fully initialised
             * (
             * () => PlayVideoAsync()
             * );*/

            _videoView.SetVideoPath(_audioPath);
        }
Exemple #12
0
        protected override void OnCreate
        (
            Bundle bundle
        )
        {
            base.OnCreate(bundle);

            _picturePath = Intent.GetStringExtra(PicturePathExtra);

            if (_picturePath == null)
            {
                throw new InvalidOperationException(string.Format("'{0}' extra string missing.",
                                                                  PicturePathExtra));
            }

            _orientationListener = new AndroidCameraActivity.DeviceOrientationEventListener
                                   (
                this,
                SensorDelay.Normal,
                OrientationChanged
                                   );

            _orientationListener.Enable();

            SetContentView(Resource.Layout.EditImageLayout);

            _imageView        = FindViewById <ImageView>(Resource.Id.EditedImage);
            _imageView.Touch -= TouchImage;
            _imageView.Touch += TouchImage;

            _attributesButton            = FindViewById <Button>(Resource.Id.AttributesButton);
            _attributesButton.Visibility = ViewStates.Invisible;
            _attributesButton.Click     -= EditAttributes;
            _attributesButton.Click     += EditAttributes;

            _attributesButton.LongClick -= DragButton;
            _attributesButton.LongClick += DragButton;

            _rotateButton            = FindViewById <Button>(Resource.Id.RotateButton);
            _rotateButton.Visibility = ViewStates.Invisible;
            _rotateButton.Click     -= RotateImage;
            _rotateButton.Click     += RotateImage;

            _rotateButton.LongClick -= DragButton;
            _rotateButton.LongClick += DragButton;

            var scaleListener = new AndroidScaleListener
                                (
                getScaleFactor: () => _scaleFactor,

                setScaleFactor: (scaleFactor) =>
            {
                _scaleFactor      = scaleFactor;
                _imageView.ScaleX = _scaleFactor;
                _imageView.ScaleY = _scaleFactor;
            },

                minScaleFactor: 1,

                maxScaleFactor: 10
                                );

            _scaleDetector = new ScaleGestureDetector(this,
                                                      scaleListener);

            var flingListener = new AndroidFlingListener
                                (
                getViewSize: () => new Size(_imageView.Width,
                                            _imageView.Height),

                getScaleFactor: () => _scaleFactor,

                getScrollPoint: () => new PointF(_imageView.ScrollX,
                                                 _imageView.ScrollY),
                minHorizontalDistance: 100,
                minVerticalDistance: 100,

                minHorizontalVelocity: 200,
                minVerticalVelocity: 200,

                moveScrolledView: (horizontalDistance,
                                   verticalDistance) => _imageView.ScrollBy
                (
                    (int)Math.Round(horizontalDistance),
                    (int)Math.Round(verticalDistance)
                )
                                );

            _scrollDetector = new GestureDetector(flingListener);

            // http://stackoverflow.com/questions/3591784/getwidth-and-getheight-of-view-returns-0
            _imageView.Post // wait with image loading until view fully initialised
            (
                () =>

                Task.Run
                (
                    () =>

                    LoadImageAsync()
                )
            );
        }