private void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            _flashOn = !_flashOn;
            if (_flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

                    camera.StopPreview();
                    camera.Release();
                    camera = Camera.Open((int)cameraType);
                    var parameters = camera.GetParameters();
                    parameters.FlashMode = Camera.Parameters.FlashModeTorch;
                    camera.SetParameters(parameters);
                    camera.SetPreviewTexture(surfaceTexture);
                    PrepareAndStartCamera();
                }
            }
            else
            {
                toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                camera.StopPreview();
                camera.Release();

                camera = Camera.Open((int)cameraType);
                var parameters = camera.GetParameters();
                parameters.FlashMode = Camera.Parameters.FlashModeOff;
                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
        protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
        {
            base.OnElementPropertyChanged(args);

            switch (args.PropertyName)
            {
            case nameof(SelectedButton.IsSelected):
                if (formsElement.Width == -1)
                {
                    return;
                }

                if (formsElement.IsSelected)
                {
                    nativeControl?.SetBackgroundResource(Resource.Layout.button_border);
                    GradientDrawable drawable = (GradientDrawable)nativeControl?.Background;
                    drawable.SetColor(Xamarin.Forms.Color.FromHex("#2e72c0").ToAndroid());
                }
                else
                {
                    nativeControl.SetBackgroundResource(Resource.Layout.unselected_button);
                    GradientDrawable drawable = (GradientDrawable)nativeControl.Background;
                    drawable.SetColor(formsElement.BackgroundColor.ToAndroid());
                }
                break;

            case nameof(SelectedButton.Height):
                if (formsElement.Height == -1)
                {
                    return;
                }

                if (formsElement.IsSelected)
                {
                    nativeControl?.SetBackgroundResource(Resource.Layout.button_border);
                    GradientDrawable drawable = (GradientDrawable)nativeControl?.Background;
                    drawable.SetColor(Xamarin.Forms.Color.FromHex("#2e72c0").ToAndroid());
                }
                else
                {
                    nativeControl.SetBackgroundResource(Resource.Layout.unselected_button);
                    GradientDrawable drawable = (GradientDrawable)nativeControl.Background;
                    drawable.SetColor(formsElement.BackgroundColor.ToAndroid());
                }
                break;
            }
        }
示例#3
0
 private void ToggleFlashButtonTapped(object sender, EventArgs e)
 {
     _flashOn = !_flashOn;
     if (_flashOn)
     {
         _toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
         var newCamparams = _camera.GetParameters();
         newCamparams.FlashMode = Android.Hardware.Camera.Parameters.FlashModeTorch;
         _camera.SetParameters(newCamparams);
     }
     else
     {
         _toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
         var newParameters = _camera.GetParameters();
         newParameters.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
         _camera.SetParameters(newParameters);
     }
 }
        protected override void OnAttached()
        {
            formsElement  = Element as SelectedButton;
            nativeControl = Control as Android.Widget.Button;

            nativeControl.SetBackgroundResource(Resource.Layout.button_border);
            GradientDrawable drawable = (GradientDrawable)nativeControl.Background;

            drawable.SetColor(formsElement.BackgroundColor.ToAndroid());

            nativeControl.LongClick += (s, args) =>
            {
                formsElement.LongPressCommand.Execute(new object());
            };
        }