Inheritance: Xamarin.Forms.ContentPage
        public MiniHacksDetailsPage(MiniHack hack)
        {
            InitializeComponent();
            BindingContext = vm = new MiniHackDetailsViewModel(hack);

            ButtonFinish.Clicked += ButtonFinish_Clicked;


            if (string.IsNullOrWhiteSpace (hack.GitHubUrl)) 
            {
                MiniHackDirections1.IsEnabled = false;
                MiniHackDirections1.Text = "Directions coming soon";
                MiniHackDirections2.IsEnabled = false;
                MiniHackDirections2.Text = "Directions coming soon";
            }

            scanPage = new ZXingScannerPage(new MobileBarcodeScanningOptions {  AutoRotate = false, })
                {
                    DefaultOverlayTopText = "Align the barcode within the frame",
                    DefaultOverlayBottomText = string.Empty
                };

            scanPage.OnScanResult += ScanPage_OnScanResult;


            scanPage.Title = "Scan Code";


            var item = new ToolbarItem
                {
                    Text = "Cancel",
                    Command = new Command(async () => 
                        {
                            scanPage.IsScanning = false;
                            await Navigation.PopAsync();
                        })
                };

            if(Device.OS != TargetPlatform.iOS)
                item.Icon = "toolbar_close.png";

            scanPage.ToolbarItems.Add(item);

        }
Ejemplo n.º 2
1
        public HomePage () : base ()
        {
            buttonScanDefaultOverlay = new Button {
                Text = "Scan with Default Overlay",
                AutomationId = "scanWithDefaultOverlay",
            };
            buttonScanDefaultOverlay.Clicked += async delegate {
                scanPage = new ZXingScannerPage ();
                scanPage.OnScanResult += (result) => {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread (() => {
                        Navigation.PopAsync ();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };

                await Navigation.PushAsync (scanPage);
            };


            buttonScanCustomOverlay = new Button {
                Text = "Scan with Custom Overlay",
                AutomationId = "scanWithCustomOverlay",
            };
            buttonScanCustomOverlay.Clicked += async delegate {
                // Create our custom overlay
                var customOverlay = new StackLayout {
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand
                };
                var torch = new Button {
                    Text = "Toggle Torch"
                };
                torch.Clicked += delegate {
                    scanPage.ToggleTorch ();
                };
                customOverlay.Children.Add (torch);

                scanPage = new ZXingScannerPage (customOverlay: customOverlay);
                scanPage.OnScanResult += (result) => {
                    scanPage.IsScanning = false;

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Navigation.PopAsync();
                        DisplayAlert("Scanned Barcode", result.Text, "OK");
                    });
                };
                await Navigation.PushAsync (scanPage);
            };


            buttonScanContinuously = new Button {
                Text = "Scan Continuously",
                AutomationId = "scanContinuously",
            };
            buttonScanContinuously.Clicked += async delegate {
                scanPage = new ZXingScannerPage ();
                scanPage.OnScanResult += (result) =>
                    Device.BeginInvokeOnMainThread (() => 
                        DisplayAlert ("Scanned Barcode", result.Text, "OK"));
                
                await Navigation.PushAsync (scanPage);
            };

            buttonScanCustomPage = new Button {
                Text = "Scan with Custom Page",
                AutomationId = "scanWithCustomPage",
            };
            buttonScanCustomPage.Clicked += async delegate {
                var customScanPage = new CustomScanPage ();
                await Navigation.PushAsync (customScanPage);
            };


            buttonGenerateBarcode = new Button {
                Text = "Barcode Generator",
                AutomationId = "barcodeGenerator",
            };
            buttonGenerateBarcode.Clicked += async delegate {
                await Navigation.PushAsync (new BarcodePage ());    
            };

            var stack = new StackLayout ();
            stack.Children.Add (buttonScanDefaultOverlay);
            stack.Children.Add (buttonScanCustomOverlay);
            stack.Children.Add (buttonScanContinuously);
            stack.Children.Add (buttonScanCustomPage);
            stack.Children.Add (buttonGenerateBarcode);

            Content = stack;
        }
Ejemplo n.º 3
0
        private async void Scanner()
        {
            var scannerPage = new ZXing.Net.Mobile.Forms.ZXingScannerPage();

            scannerPage.Title         = "Lector de QR";
            scannerPage.OnScanResult += (result) =>
            {
                scannerPage.IsScanning = false;

                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopModalAsync();
                    var tots = await ra.GetAllAsync();
                    r        = tots.Where(x => x.CodeReference == result.ToString()).FirstOrDefault();
                    if (r != null)
                    {
                        lblNom.Text       = r.CodeReference;
                        lblInstr.Text     = r.DescReference;
                        lblLast.IsVisible = true;

                        var pdfs = await ai.GetAllAsync();
                        pdf      = pdfs.Where(x => x.Idreference == r.IdReference).FirstOrDefault();

                        btnPDF.IsVisible = pdf != null;
                    }
                    else
                    {
                        await DisplayAlert("Error", "No s'ha trobat cap peça amb el codi escanejat", "OK");
                    }
                    // www.Reload();
                });
            };

            await Navigation.PushModalAsync(scannerPage);
        }
Ejemplo n.º 4
0
        public void UITestBackdoorScan (string param)
        {
            var expectedFormat = ZXing.BarcodeFormat.QR_CODE;
            Enum.TryParse (param, out expectedFormat);
            var opts = new ZXing.Mobile.MobileBarcodeScanningOptions {
                PossibleFormats = new List<ZXing.BarcodeFormat> { expectedFormat }
            };

            System.Diagnostics.Debug.WriteLine ("Scanning " + expectedFormat);

            var scanPage = new ZXingScannerPage (opts);
            scanPage.OnScanResult += (result) => {
                scanPage.IsScanning = false;

                Device.BeginInvokeOnMainThread (() => {
                    var format = result?.BarcodeFormat.ToString () ?? string.Empty;
                    var value = result?.Text ?? string.Empty;

                    MainPage.Navigation.PopAsync ();
                    MainPage.DisplayAlert ("Barcode Result", format + "|" + value, "OK");
                });
            };

            MainPage.Navigation.PushAsync (scanPage);
        }
Ejemplo n.º 5
0
        private async void BtnScan_Clicked(object sender, EventArgs e)
        {
            var scan = new ZXing.Net.Mobile.Forms.ZXingScannerPage();

            scan.Title = "Escaner código de barras";
            await Navigation.PushAsync(scan);

            scan.OnScanResult += (result) =>
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    await Navigation.PopAsync();
                    lblCode.Text = result.Text;
                });
            };
        }
Ejemplo n.º 6
0
		public ScanDevicePage()
		{
			NavigationPage.SetHasNavigationBar(this, false);

			Title = "EvolveApp";
			BackgroundColor = AppColors.BackgroundColor;
			var viewModel = new ScanDeviceViewModel();
			BindingContext = viewModel;

			var layout = new RelativeLayout();

			var titleLabel = new StyledLabel
			{
				Text = "Particle Internet Button",
				CssStyle = "h1",
			};
			var subtitleLabel = new StyledLabel { Text = "Take Control!", CssStyle = "h2" };
			var descriptionLabel = new StyledLabel { Text = "Just scan the QR barcode of any device to take control.", CssStyle = "body" };
			var indicator = new ActivityIndicator();
			var scanBarcodeButton = new StyledButton
			{
				Text = "START SCANNING",
				CssStyle = "button",
				BackgroundColor = AppColors.Blue,
				BorderRadius = 0,
				HeightRequest = AppSettings.ButtonHeight
			};

			layout.Children.Add(titleLabel,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.Constant(AppSettings.Margin * 3),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.Constant(100)
			);
			layout.Children.Add(subtitleLabel,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(titleLabel, (p, v) => v.Height + v.Y + AppSettings.ItemPadding),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
			);
			layout.Children.Add(descriptionLabel,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(subtitleLabel, (p, v) => v.Height + v.Y + AppSettings.Margin),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2)
			);
			layout.Children.Add(indicator,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => v.Y + v.Height),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.RelativeToView(descriptionLabel, (p, v) => p.Height - v.Y - v.Height - AppSettings.Margin - AppSettings.ButtonHeight)
			);
			layout.Children.Add(scanBarcodeButton,
				xConstraint: Constraint.Constant(AppSettings.Margin),
				yConstraint: Constraint.RelativeToParent(p => p.Height - AppSettings.Margin - AppSettings.ButtonHeight),
				widthConstraint: Constraint.RelativeToParent(p => p.Width - AppSettings.Margin * 2),
				heightConstraint: Constraint.Constant(50)
			);

			Content = layout;

#if __IOS__
			scanBarcodeButton.TextColor = Color.FromHex("#ffffff");
#endif

			scanBarcodeButton.Clicked += async (object sender, EventArgs e) =>
			{
				viewModel.SetLock();

				var scanPage = new ZXingScannerPage();

				scanPage.OnScanResult += (result) =>
				{
					scanPage.IsScanning = false;

					Device.BeginInvokeOnMainThread(async () =>
					{
						await Navigation.PopModalAsync();
						System.Diagnostics.Debug.WriteLine($"Result: {result.Text}");
						var isValidDevice = InternetButtonHelper.CheckDeviceId(result.Text);
						System.Diagnostics.Debug.WriteLine($"{isValidDevice}");

						if (isValidDevice)
						{
							var success = await viewModel.GetDevice(result.Text);
							if (!success)
							{
								viewModel.ClearLock();
								return;
							}
							var navPage = new NavigationPage(new DeviceLandingPage(viewModel.Device));
#if __IOS__
							navPage.BarBackgroundColor = AppColors.Blue;
							navPage.BarTextColor = Color.White;
#endif
							await Navigation.PushModalAsync(navPage);
						}
						else
							DisplayAlert("Error", "The barcode scanner had an error. Please try scanning the barcode again", "Ok");

						viewModel.ClearLock();
					});
				};

				await Navigation.PushModalAsync(scanPage);
			};

			indicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
			if (Device.OS != TargetPlatform.iOS && Device.OS != TargetPlatform.Android)
				indicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");

#if __IOS__
			scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock");
#endif
#if __ANDROID__
			scanBarcodeButton.SetBinding(Button.IsEnabledProperty, "ButtonLock");
#endif
		}
Ejemplo n.º 7
0
        /// <summary>
        /// Click method for Add Button. 
        /// </summary>
        /// <returns>The add.</returns>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        public async void OnAdd(object sender, EventArgs e)
        {
            str = newItemName.Text;
            

            if (string.IsNullOrWhiteSpace(str))
            {
                var scanPage = new ZXingScannerPage()
                {
                    Title = "ScanPage",
                    DefaultOverlayTopText = "Scan a ISBN barcode.",
                    DefaultOverlayBottomText = "",
                };
                // スキャナページを表示
                await Navigation.PushModalAsync(scanPage);

                // データが取れると発火
                scanPage.OnScanResult += (result) =>
                {
                    // スキャン停止
                    scanPage.IsScanning = false;
                    System.Diagnostics.Debug.WriteLine("Scanned");

                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        await Navigation.PopModalAsync();

                        str = result.Text;

                        itemInfo = await itemLookup.Lookup(str);
                        System.Diagnostics.Debug.WriteLine("Lookuped");

                        if (itemInfo != null)
                        {
                            if (await DisplayAlert("Add", $"Add {itemInfo.Name} to azure?", "Yes", "No"))
                                await AddItem(itemInfo);
                        }
                        else
                            await DisplayAlert("Error", "Invalid Number", "OK");



                        newItemName.Text = string.Empty;
                        newItemName.Unfocus();

                    });
                };
            }
            else 
            {
                itemInfo = await itemLookup.Lookup(str);

                if (itemInfo != null)
                {
                    if (await DisplayAlert("Add", $"Add {itemInfo.Name} to azure?", "Yes", "No"))
                    {
                        await AddItem(itemInfo);
                    }
                }
                else
                    await DisplayAlert("Error", "Invalid Number", "OK");

            }

        }