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();
            }
        }
Ejemplo n.º 2
0
        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 = Android.Hardware.Camera.Open((int)_cameraType);
                    var parameters = _camera.GetParameters();
                    parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeTorch;
                    _camera.SetParameters(parameters);
                    _camera.SetPreviewTexture(_surfaceTexture);
                    PrepareAndStartCamera();
                }
            }
            else
            {
                _toggleFlashButton.SetBackgroundResource(Resource.Drawable.NoFlashButton);
                _camera.StopPreview();
                _camera.Release();

                _camera = global::Android.Hardware.Camera.Open((int)_cameraType);
                var parameters = _camera.GetParameters();
                parameters.FlashMode = global::Android.Hardware.Camera.Parameters.FlashModeOff;
                _camera.SetParameters(parameters);
                _camera.SetPreviewTexture(_surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Ejemplo n.º 3
0
        //turns on or off camera flash
        void ToggleFlashButtonTapped(object sender, EventArgs e)
        {
            //if camera isn't started
            if (!_isCameraStarted)
            {
                return;
            }

            _flashOn = !_flashOn;

            if (_flashOn)
            {
                if (cameraType == CameraFacing.Back)
                {
                    toggleFlashButton.SetBackgroundResource(Resource.Drawable.FlashButton);
                    cameraType = CameraFacing.Back;

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

                camera = Android.Hardware.Camera.Open((int)cameraType);
                var parameters = camera.GetParameters();
                parameters.FlashMode = Android.Hardware.Camera.Parameters.FlashModeOff;
                camera.SetParameters(parameters);
                camera.SetPreviewTexture(surfaceTexture);
                PrepareAndStartCamera();
            }
        }
Ejemplo n.º 4
0
        public View BuildNativeImageButton(string text, string icon, System.Action clickAction)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                text = "(text binding not set)";
            }
            if (string.IsNullOrWhiteSpace(icon))
            {
                icon = "ic_facebook_white.png";
            }

            Android.Widget.Button imgButton = new Android.Widget.Button(Forms.Context)
            {
                Text = text
            };

            if (!string.IsNullOrWhiteSpace(icon))
            {
                int imgRes = 0;
                if (icon == "ic_facebook_white.png")
                {
                    imgRes = Resource.Drawable.ic_facebook_white;
                }
                if (imgRes != 0)
                {
                    imgButton.SetCompoundDrawablesWithIntrinsicBounds(imgRes, 0, 0, 0);
                }
            }
            imgButton.Click += (sender, e) => { clickAction(); };
            imgButton.SetBackgroundResource(Resource.Drawable.bg_button_border);

            var paddingInPixels = ConvertDpToPixels(10);

            imgButton.SetPadding(paddingInPixels, 0, paddingInPixels, 0);

            imgButton.TextAlignment = Android.Views.TextAlignment.Center;

            return(imgButton.ToView());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 标注点击时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMarkerClick(object sender, BaiduMap.MarkerClickEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(e.P0.Title))
                {
                    var pin = Map.Pins.Find(e.P0);
                    if (pin?.Terminal != null)
                    {
                        var color = pin?.Terminal?.RankColor ?? "#4a89dc";

                        //cardView
                        var cardView = new CardView(Context)
                        {
                            Radius = 15
                        };
                        cardView.SetCardBackgroundColor(Color.FromHex(color).ToAndroid());

                        //布局
                        var layout = new LinearLayout(Context)
                        {
                            Orientation = Orientation.Vertical
                        };
                        layout.SetPadding(10, 10, 10, 10);

                        //Title
                        var tview = new TextView(Context);
                        tview.SetPadding(10, 10, 10, 10);
                        tview.SetTextColor(Color.White.ToAndroid());
                        tview.TextSize = 12;
                        tview.Text     = e.P0.Title;

                        //Button
                        var param = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                        {
                            Height = 45
                        };
                        var button = new Android.Widget.Button(Context);
                        button.Text             = "去拜访";
                        button.TextSize         = 10;
                        button.LayoutParameters = param;
                        button.SetBackgroundResource(Resource.Drawable.roundShape);
                        button.SetTextColor(Color.White.ToAndroid());
                        button.Click += (sender, ar) =>
                        {
                            var pin = Map.Pins.Find(e.P0);
                            pin?.SendClicked(pin?.Terminal);
                        };

                        layout.AddView(tview);
                        layout.AddView(button);

                        cardView.AddView(layout);

                        var window = new InfoWindow(cardView, e.P0.Position, -e.P0.Icon.Bitmap.Height);
                        NativeMap.Map.ShowInfoWindow(window);
                    }
                }
            }
            catch (Exception)
            {
            }
        }