public MyZXingOverlay()
        {
            BindingContext = this;
            //ColumnSpacing = 0;
            VerticalOptions   = LayoutOptions.FillAndExpand;
            HorizontalOptions = LayoutOptions.FillAndExpand;

            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(3, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            var boxview = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };
            var boxview2 = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };

            Children.Add(boxview, 0, 0);
            Children.Add(boxview2, 0, 2);

            SetColumnSpan(boxview, 5);
            SetColumnSpan(boxview2, 5);
            // Children.Add(boxview, 0, 3);
            Children.Add(new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            }, 0, 1);
            Children.Add(new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            }, 4, 1);
            //Children.Add(new BoxView
            //{
            //    VerticalOptions = LayoutOptions.Fill,
            //    HorizontalOptions = LayoutOptions.FillAndExpand,
            //    BackgroundColor = Color.Black,
            //    Opacity = 0.7,
            //}, 0, 3);
            //Children.Add(new BoxView
            //{
            //    VerticalOptions = LayoutOptions.Fill,
            //    HorizontalOptions = LayoutOptions.FillAndExpand,
            //    BackgroundColor = Color.Black,
            //    Opacity = 0.7,
            //}, 0, 2);
            var AbsoluteLayouts = new AbsoluteLayout();

            var redline = new Image
            {
                Source = "saomiao.png"
            };

            AbsoluteLayout.SetLayoutBounds(redline, new Rectangle(1, weizhi, 1, 1));
            AbsoluteLayout.SetLayoutFlags(redline, AbsoluteLayoutFlags.SizeProportional);
            AbsoluteLayouts.Children.Add(redline);
            Children.Add(AbsoluteLayouts, 1, 1);
            SetColumnSpan(AbsoluteLayouts, 3);
            topText = new Label
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_TopTextLabel",
            };
            topText.SetBinding(Label.TextProperty, new Binding(nameof(TopText)));
            Children.Add(topText, 0, 0);
            SetColumnSpan(topText, 5);
            botText = new Label
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_BottomTextLabel",
            };
            botText.SetBinding(Label.TextProperty, new Binding(nameof(BottomText)));
            //Children.Add(botText, 0, 2);
            //SetColumnSpan(botText, 5);
            var MyStackLayout = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };

            flash = new Button
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                //HeightRequest = 3,
                Text            = "按钮",
                TextColor       = Color.White,
                BackgroundColor = Color.Black,
                Opacity         = 0.7,
                AutomationId    = "zxingDefaultOverlay_FlashButton",
            };
            flash.SetBinding(Button.IsVisibleProperty, new Binding(nameof(ShowFlashButton)));
            flash.SetBinding(Button.TextProperty, new Binding(nameof(ButtonText)));
            flash.Clicked += (sender, e) =>
            {
                FlashButtonClicked?.Invoke(flash, e);
            };
            MyStackLayout.Children.Add(botText);
            MyStackLayout.Children.Add(flash);
            Children.Add(MyStackLayout, 0, 2);
            SetColumnSpan(MyStackLayout, 5);
            //this.ColumnSpacing = 0;
            this.RowSpacing = 0;
            Device.StartTimer(TimeSpan.FromSeconds(0.2), () =>
            {
                weizhi += 7;
                AbsoluteLayout.SetLayoutBounds(redline, new Rectangle(1, weizhi, 1, 1));
                if (weizhi > 150)
                {
                    weizhi = -100;
                }
                return(true);
            });
        }
Beispiel #2
0
        public ZXingOverlay()
        {
            BindingContext    = this;
            VerticalOptions   = LayoutOptions.FillAndExpand;
            HorizontalOptions = LayoutOptions.FillAndExpand;

            // RowDefinitions - 4行
            RowDefinitions.Add(new RowDefinition {
                Height = 30
            });                                                    // *
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });                                                                                      // *
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(3, GridUnitType.Star)
            });                                                                                      // 3*
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });                                                                                      // 2*

            // ColumnDefinitions - 5列
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                           // *
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                           // *
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                           // *
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                           // *
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });                                                                                           // *

            this.RowSpacing    = 0;
            this.ColumnSpacing = 0;

            #region BoxView - Black

            var bv_Top_Black = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };

            var bv_Bottom_Black = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };

            Children.Add(bv_Top_Black, 0, 0);
            Children.Add(bv_Bottom_Black, 0, 3);

            SetColumnSpan(bv_Top_Black, 5);
            SetColumnSpan(bv_Bottom_Black, 5);

            SetRowSpan(bv_Top_Black, 2);

            var bv_Left_Black = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };
            Children.Add(bv_Left_Black, 0, 2);

            var bv_Right_Black = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            };
            Children.Add(bv_Right_Black, 4, 2);

            #endregion

            txtTitle = new Label
            {
                VerticalOptions   = LayoutOptions.Start,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                TextColor         = Color.White,
                FontSize          = 26,
                AutomationId      = "zxingDefaultOverlay_txtTitle",
            };

            txtTitle.SetBinding(Label.TextProperty, new Binding(nameof(TitleInfo)));
            Children.Add(txtTitle, 1, 0);
            SetColumnSpan(txtTitle, 3);

            #region ScanArea

            var slScanArea = new AbsoluteLayout();

            slScanArea.InputTransparent = true;
            Children.Add(slScanArea, 1, 2);
            SetColumnSpan(slScanArea, 3);

            var scanLine = new Image
            {
                Source = Util.XamariN.Common.ImageSourceUtils.String2ImageSource($"stream://{ScanLine_Base64Str}")
            };

            scanLine.InputTransparent = true;
            AbsoluteLayout.SetLayoutBounds(scanLine, new Rectangle(1, scanLineY, 1, 1));
            AbsoluteLayout.SetLayoutFlags(scanLine, AbsoluteLayoutFlags.SizeProportional);
            slScanArea.Children.Add(scanLine);

            Device.StartTimer(TimeSpan.FromSeconds(0.1), () =>
            {
                if (scanLineOriginY == -9999) // 初始化 -- 只执行一次
                {
                    scanLineOriginY = -(((int)slScanArea.Height) / 2);
                    scanLineY       = scanLineOriginY;
                }

                #region   移动效果

                scanLineY += 5;
                AbsoluteLayout.SetLayoutBounds(scanLine, new Rectangle(1, scanLineY, 1, 1));
                if (scanLineY >= slScanArea.Height / 2)
                {
                    scanLineY = scanLineOriginY;
                }

                #endregion

                #region 闪烁效果

                if (scanLineOpacityDirection == true)
                {
                    scanLine.Opacity = scanLine.Opacity - 0.1;
                }

                if (scanLineOpacityDirection == false)
                {
                    scanLine.Opacity = scanLine.Opacity + 0.1;
                }

                if (scanLine.Opacity == 0 || scanLine.Opacity == 1)
                {
                    scanLineOpacityDirection = !scanLineOpacityDirection;
                }

                #endregion

                return(true);
            });

            txtScanTipsText = new Label
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_BottomTextLabel",
            };

            txtScanTipsText.SetBinding(Label.TextProperty, new Binding(nameof(LabelScanTipsText)));

            #endregion

            #region Flash Area

            var slFlash = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };

            btnFlash = new Button
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Padding           = new Thickness(left: 15, top: 0, right: 15, bottom: 0),
                Text            = "按钮",
                TextColor       = Color.White,
                BackgroundColor = Color.Silver,
                Opacity         = 0.7,
                AutomationId    = "zxingDefaultOverlay_FlashButton",
            };
            btnFlash.SetBinding(Button.IsVisibleProperty, new Binding(nameof(ShowFlashButton)));
            btnFlash.SetBinding(Button.TextProperty, new Binding(nameof(ButtonFlashText)));
            btnFlash.Clicked += (sender, e) =>
            {
                FlashButtonClicked?.Invoke(btnFlash, e);
            };

            slFlash.Children.Add(txtScanTipsText);
            slFlash.Children.Add(btnFlash);
            Children.Add(slFlash, 0, 3);
            SetColumnSpan(slFlash, 5);

            #endregion

            #region 返回上一层按钮

            btnBack = new Image()
            {
                HeightRequest = 27,
                WidthRequest  = 27,
                Margin        = new Thickness(left: 5, top: 5, right: 0, bottom: 0),
                Source        = Util.XamariN.Common.ImageSourceUtils.String2ImageSource($"stream://{btnBack_Image_Base64Str}")
            };

            TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer()
            {
            };
            tapGestureRecognizer.Tapped += async(s, e) =>
            {
                if (Application.Current.MainPage is NavigationPage)
                {
                    var index = Application.Current.MainPage.Navigation.NavigationStack.Count - 1;

                    if (Application.Current.MainPage.Navigation.NavigationStack[index] is ZXingBarcodeScanner)
                    {
                        await Application.Current.MainPage.Navigation.PopAsync();
                    }
                }
            };

            btnBack.GestureRecognizers.Add(tapGestureRecognizer);
            btnBack.HorizontalOptions = LayoutOptions.StartAndExpand;
            Children.Add(btnBack, 0, 0);

            #endregion
        }
Beispiel #3
0
        public ZXingDefaultOverlay()
        {
            BindingContext = this;

            VerticalOptions   = LayoutOptions.FillAndExpand;
            HorizontalOptions = LayoutOptions.FillAndExpand;

            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });


            Children.Add(new BoxView {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            }, 0, 0);

            Children.Add(new BoxView {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.7,
            }, 0, 2);

            Children.Add(new BoxView {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = 3,
                BackgroundColor   = Color.Red,
                Opacity           = 0.6,
            }, 0, 1);

            topText = new Label {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_TopTextLabel",
            };
            topText.SetBinding(Label.TextProperty, new Binding(nameof(TopText)));
            Children.Add(topText, 0, 0);

            botText = new Label {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_BottomTextLabel",
            };
            botText.SetBinding(Label.TextProperty, new Binding(nameof(BottomText)));
            Children.Add(botText, 0, 2);

            flash = new Button {
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions   = LayoutOptions.Start,
                Text         = "Flash",
                TextColor    = Color.White,
                AutomationId = "zxingDefaultOverlay_FlashButton",
            };
            flash.SetBinding(Button.IsVisibleProperty, new Binding(nameof(ShowFlashButton)));
            flash.Clicked += (sender, e) => {
                FlashButtonClicked?.Invoke(flash, e);
            };

            Children.Add(flash, 0, 0);
        }
Beispiel #4
0
        public ZXingOverlay()
        {
            BindingContext = this;
            //ColumnSpacing = 0;
            VerticalOptions   = LayoutOptions.FillAndExpand;
            HorizontalOptions = LayoutOptions.FillAndExpand;

            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });
            RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            //ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            //ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            //ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            //ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
            var boxview = new BoxView
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.6,
            };
            var boxview2 = new BoxView
            {
                VerticalOptions   = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                BackgroundColor   = Color.Black,
                Opacity           = 0.6,
            };
            var boxview3 = new BoxView
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = 2,
                BackgroundColor   = Color.Red,
                Opacity           = 0.6,
            };

            Children.Add(boxview, 0, 0);
            Children.Add(boxview2, 0, 2);
            Children.Add(boxview3, 0, 1);
            //SetColumnSpan(boxview, 5);
            //SetColumnSpan(boxview2, 5);
            var AbsoluteLayouts = new AbsoluteLayout();

            SetColumnSpan(AbsoluteLayouts, 1);
            //topText = new Label
            //{
            //    VerticalOptions = LayoutOptions.Center,
            //    HorizontalOptions = LayoutOptions.Center,
            //    TextColor = Color.White,
            //    AutomationId = "zxingDefaultOverlay_TopTextLabel",
            //};
            //topText.SetBinding(Label.TextProperty, new Binding(nameof(TopText)));
            //Children.Add(topText, 0, 0);
            //SetColumnSpan(topText, 5);
            botText = new Label
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                TextColor         = Color.White,
                AutomationId      = "zxingDefaultOverlay_BottomTextLabel",
            };
            botText.SetBinding(Label.TextProperty, new Binding(nameof(BottomText)));
            //Children.Add(botText, 0, 2);
            //SetColumnSpan(botText, 5);
            var MyStackLayout = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center
            };

            flash = new Button
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                //HeightRequest = 3,
                Image = "flash_on.png",
                Scale = 0.3,
                //Opacity=0.4,
                BackgroundColor = Color.FromRgba(255, 255, 255, 0),
                AutomationId    = "zxingDefaultOverlay_FlashButton",
            };
            flash.SetBinding(Button.IsVisibleProperty, new Binding(nameof(ShowFlashButton)));
            flash.SetBinding(Button.TextProperty, new Binding(nameof(ButtonText)));
            flash.Clicked += (sender, e) =>
            {
                FlashButtonClicked?.Invoke(flash, e);
            };
            //MyStackLayout.Children.Add(botText);
            MyStackLayout.Children.Add(flash);
            Children.Add(MyStackLayout, 0, 2);
            //SetColumnSpan(MyStackLayout, 5);
            //this.ColumnSpacing = 0;
            this.RowSpacing = 0;
            //Device.StartTimer(TimeSpan.FromSeconds(0.2), () =>
            //{
            //    weizhi += 7;
            //    AbsoluteLayout.SetLayoutBounds(redline, new Rectangle(1, weizhi, 1, 1));
            //    if (weizhi > 150)
            //    {
            //        weizhi = -100;
            //    }
            //    return true;
            //});
        }