Example #1
0
        /// <summary>
        /// Start the QR-scan page (ZXing library). Will add the scan result to history and execute the Javascript-function on the webpage.
        /// </summary>
        public void StartScan()
        {
            //////////////// TEST
            CustomScanPage customPage = new CustomScanPage();

            customPage.Disappearing += (s, e) =>
            {
                ZXing.Result result = customPage.result;

                if (result != null)
                {
                    ScanHistory.Add(result.Text);
                    InjectJSQRCode(result.Text);
                    if (Parameters.Options.UseLocation)
                    {
                        OpenJSFunctionLocation();
                    }
                }

                Parameters.TemporaryOptions.ResetOptions();
            };

            if (Parameters.Options.UseLocation)
            {
                QRLocation.InitLocation();
            }

            NavigateTo(customPage);
            //await App.Current.MainPage.Navigation.PushModalAsync(customPage);
        }
Example #2
0
        /// <summary>
        /// Execute the callback function in the webpage, passing the current location.
        /// </summary>
        /// <param name="scanCode">Code or text parsed from barcode</param>
        public void OpenJSFunctionLocation()
        {
            string jsString = QRLocation.GenerateJavascriptString();

            try
            {
                WebPageWebView.Eval(jsString);
            }
            catch (Exception)
            {
                // BarcodeScanner not available
            }
        }
Example #3
0
        public void LoadMainPage(bool baseInit = true)
        {
            if (baseInit)
            {
                Language.SetLanguage(Parameters.Options.LanguageIndex); // set language for the app from options

                QRPage = new QRMainPage();
            }
            else
            {
                QRScanner   = new Scanner();                    // initialize scanner class (ZXing scanner)
                ScanHistory = new History();

                if (Parameters.Options.UseLocation)
                {
                    QRLocation.InitLocation();
                }

                QRPage.Initialize();
            }
        }
Example #4
0
        /// <summary>
        /// Back button was pressed. If a option was changed, all parameters will be saved.
        /// </summary>
        /// <returns>true to override the functionality of the default handler.</returns>
        /// <remarks>
        /// This works on Windows Phones and Android with the back buttons.
        /// Under Windows the "back button" must be set as visible (UWP main app).
        /// Under iOS a back button must be placed manually somewhere.
        /// </remarks>
        protected override bool OnBackButtonPressed()
        {
            if (saveSettings)
            {
                if (!Parameters.Options.UseLocation && sendLocationSwitch.IsToggled)
                {
                    QRLocation.InitLocation();
                }
                Parameters.Options.HomePage           = webPageValue.Text;
                Parameters.Options.Emulation          = emulationPicker.SelectedIndex;
                Parameters.Options.AcceptBarcode_Code = acceptedCodesSwitch[1].IsToggled;
                Parameters.Options.AcceptBarcode_Ean  = acceptedCodesSwitch[2].IsToggled;
                Parameters.Options.AcceptBarcode_Upc  = acceptedCodesSwitch[3].IsToggled;
                Parameters.Options.LockPortrait       = lockPortraitSwitch.IsToggled;
                Parameters.Options.SaveHistory        = saveHistorySwitch.IsToggled;
                Parameters.Options.LanguageIndex      = languagePicker.SelectedIndex;
                Parameters.Options.UseLocation        = sendLocationSwitch.IsToggled;
            }

            this.Navigation.PopModalAsync();                    // close this page and return the the preview page (main page)
            return(true);
        }
Example #5
0
        /// <summary>
        /// Execute the callback function in the webpage, passing the current location.
        /// </summary>
        /// <param name="scanCode">Code or text parsed from barcode</param>
        public void OpenJSFunctionLocation()
        {
            string jsString = QRLocation.GenerateJavascriptString();

            QRPage.InjectJS(jsString);
        }
Example #6
0
        private Picker languagePicker;                             // language option

        /// <summary>
        /// Constructor. Initialize the page view and the components.
        /// </summary>
        public OptionsPage()
        {
            Label webPageText = new Label {
                Text = Language.GetText("Option1_1")
            };

            webPageValue = new Entry {
                Text = Parameters.Options.HomePage
            };
            webPageValue.TextChanged += (s, e) => { saveSettings = true; };

            Label emulationModeText = new Label {
                Text = Language.GetText("Option2_1")
            };

            emulationPicker = new Picker {
                HorizontalOptions = LayoutOptions.End
            };
            emulationPicker.Items.Add(Language.GetText("Option2_2"));
            emulationPicker.Items.Add("MochaSoft");
            emulationPicker.Items.Add("Pic2Shop");
            emulationPicker.SelectedIndex         = Parameters.Options.Emulation;
            emulationPicker.SelectedIndexChanged += (s, e) => { saveSettings = true; };

            Label acceptedCodesText = new Label {
                Text = Language.GetText("Option3_1")
            };

            acceptedCodesTexts[0] = new Label {
                Text = "QR", WidthRequest = 100, VerticalTextAlignment = TextAlignment.Center
            };
            acceptedCodesSwitch[0] = new Switch {
                IsToggled = true, IsEnabled = false
            };
            acceptedCodesDesc[0] = new Label {
                Text = "QR-Codes", HorizontalTextAlignment = TextAlignment.End
            };
            acceptedCodesTexts[1] = new Label {
                Text = "CODE", WidthRequest = 100, VerticalTextAlignment = TextAlignment.Center
            };
            acceptedCodesSwitch[1] = new Switch {
                IsToggled = Parameters.Options.AcceptBarcode_Code, IsEnabled = true
            };
            acceptedCodesDesc[1] = new Label {
                Text = "Code-39/93/128/bar", HorizontalTextAlignment = TextAlignment.End
            };
            acceptedCodesTexts[2] = new Label {
                Text = "EAN", WidthRequest = 100, VerticalTextAlignment = TextAlignment.Center
            };
            acceptedCodesSwitch[2] = new Switch {
                IsToggled = Parameters.Options.AcceptBarcode_Ean, IsEnabled = true
            };
            acceptedCodesDesc[2] = new Label {
                Text = "Ean 8/13", HorizontalTextAlignment = TextAlignment.End
            };
            acceptedCodesTexts[3] = new Label {
                Text = "UPC", WidthRequest = 100, VerticalTextAlignment = TextAlignment.Center
            };
            acceptedCodesSwitch[3] = new Switch {
                IsToggled = Parameters.Options.AcceptBarcode_Upc, IsEnabled = true
            };
            acceptedCodesDesc[3] = new Label {
                Text = "Upc-A/E/EAN", HorizontalTextAlignment = TextAlignment.End
            };

            for (int i = 0; i < 4; i++)
            {
                acceptedCodesSwitch[i].Toggled += (s, e) => { saveSettings = true; };
            }

            Label lockPortraitText = new Label {
                Text = Language.GetText("Option4_1") + " *", HorizontalOptions = LayoutOptions.StartAndExpand, VerticalTextAlignment = TextAlignment.Center
            };

            lockPortraitSwitch = new Switch {
                IsToggled = Parameters.Options.LockPortrait, HorizontalOptions = LayoutOptions.End
            };
            lockPortraitSwitch.Toggled += (s, e) => { saveSettings = true; };

            Label SaveHistoryText = new Label {
                Text = Language.GetText("Option5_1") + "*", HorizontalOptions = LayoutOptions.StartAndExpand, VerticalTextAlignment = TextAlignment.Center
            };

            saveHistorySwitch = new Switch {
                IsToggled = Parameters.Options.SaveHistory, HorizontalOptions = LayoutOptions.End
            };
            saveHistorySwitch.Toggled += (s, e) => { saveSettings = true; };

            Label languageText = new Label {
                Text = Language.GetText("Option6_1") + " *"
            };

            languagePicker = new Picker {
                HorizontalOptions = LayoutOptions.End
            };
            languagePicker.Items.Add(Language.GetText("Option6_2"));
            languagePicker.Items.Add(Language.GetText("Option6_3"));
            languagePicker.Items.Add(Language.GetText("Option6_4"));
            languagePicker.SelectedIndex         = Parameters.Options.LanguageIndex;
            languagePicker.SelectedIndexChanged += (s, e) => { saveSettings = true; };

            Label sendLocationText = new Label {
                Text = Language.GetText("Option7_1"), HorizontalOptions = LayoutOptions.StartAndExpand, VerticalTextAlignment = TextAlignment.Center
            };

            sendLocationSwitch = new Switch {
                IsToggled = Parameters.Options.UseLocation, HorizontalOptions = LayoutOptions.End
            };
            sendLocationSwitch.Toggled += (s, e) => {
                if (!QRLocation.IsLocationAvailableOnDevice() && sendLocationSwitch.IsToggled)
                {
                    sendLocationSwitch.IsToggled = false;
                    App.IOS.EnablePermissionLocation();
                    return;
                }
                saveSettings = true;
            };

            Label NeedRestartText = new Label {
                Text = "--------------------------\n" + Language.GetText("NeedRestart")
            };

            StackLayout backbuttonLayout = new StackLayout();

            backbuttonLayout.Orientation       = StackOrientation.Horizontal;
            backbuttonLayout.HorizontalOptions = LayoutOptions.FillAndExpand;

            Button backbuttonButton = new Button
            {
                Text         = " < ",
                TextColor    = Color.Blue,
                WidthRequest = 50,
                FontSize     = 20,
            };

            backbuttonButton.Clicked += async(s, e) =>
            {
                OnBackButtonPressed();
                var rootPage = new NavigationPage(this);
                await rootPage.PopAsync();
            };
            Label optionTitle = new Label
            {
                Text     = Language.GetText("Settings"),
                FontSize = 20,
                HorizontalTextAlignment = TextAlignment.Center,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                VerticalTextAlignment   = TextAlignment.Center,
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                TextColor = Color.Blue
            };

            if (Device.RuntimePlatform == Device.iOS)
            {
                backbuttonLayout.Children.Add(backbuttonButton);
            }
            backbuttonLayout.Children.Add(optionTitle);

            var scrollView = new StackLayout
            {
                Padding           = new Thickness(10),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children          =
                {
                    backbuttonLayout,
                    acceptedCodesText,
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            acceptedCodesTexts[0],
                            acceptedCodesSwitch[0],
                            acceptedCodesDesc[0]
                        }
                    },
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            acceptedCodesTexts[1],
                            acceptedCodesSwitch[1],
                            acceptedCodesDesc[1]
                        }
                    },
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            acceptedCodesTexts[2],
                            acceptedCodesSwitch[2],
                            acceptedCodesDesc[2]
                        }
                    },
                    new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        Children    =
                        {
                            acceptedCodesTexts[3],
                            acceptedCodesSwitch[3],
                            acceptedCodesDesc[3]
                        }
                    },
                    webPageText,
                    webPageValue,
                    new StackLayout
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          =
                        {
                            lockPortraitText,
                            lockPortraitSwitch
                        }
                    },
                    new StackLayout
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          =
                        {
                            sendLocationText,
                            sendLocationSwitch
                        }
                    },
                    new StackLayout
                    {
                        Orientation       = StackOrientation.Horizontal,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Children          =
                        {
                            SaveHistoryText,
                            saveHistorySwitch
                        }
                    },
                    languageText,
                    languagePicker,
                    emulationModeText,
                    emulationPicker,

                    NeedRestartText
                },
            };

            Content = new ScrollView {
                Content = scrollView
            };
        }
Example #7
0
        /// <summary>
        /// Constructor. Will initialize the view (for Xamarin), load the parameters and initialize the QR-scanner.
        /// </summary>
        public App()
        {
            Instance  = this;
            QRScanner = new Scanner();                                          // initialize scanner class (ZXing scanner)

            Parameters.LoadHistory(ref History);                                // load scan results history

            if (Parameters.Options.UseLocation)
            {
                QRLocation.InitLocation();
            }

            if (!Parameters.Options.SaveHistory)
            {
                History.Clear();                                                // clear history if no history should be used
            }
            Language.SetLanguage(Parameters.Options.LanguageIndex);             // set language for the app from options


            // create top-bar buttons
            InitButtons();

            // create webView for the page
            WebPageWebView = new WebView
            {
                Source = new UrlWebViewSource
                {
                    Url = Parameters.Options.HomePage,
                },
                VerticalOptions = LayoutOptions.FillAndExpand
            };
            WebPageWebView.Navigating += (sender, /*WebNavigatingEventArgs*/ e) =>
            {
                // catch the pressed link. If link is a valid app protocol (qr2web, barcodereader, ...) start QR scanner
                if (Scanner.IsAppURL(e.Url))
                {
                    e.Cancel = true;
                    StartScanFromWeb(e.Url.ToString());
                }
            };
            WebPageWebView.SizeChanged += (s, e) =>
            {
                if (TitleStack.Children.Count == 1)
                {
                    lastWindowUpdate = DateTime.Now;
                }
                else
                {
                    if ((DateTime.Now - lastWindowUpdate).TotalSeconds > 2)
                    {
                        while (TitleStack.Children.Count > 1)
                        {
                            TitleStack.Children.RemoveAt(1);
                        }
                        lastWindowUpdate = DateTime.Now;
                    }
                }

                if (WebPageWebView.Bounds.Width > 200)
                {
                    TitleStack.Children.Add(ScanButton);
                }
                if (WebPageWebView.Bounds.Width > 400)
                {
                    TitleStack.Children.Add(HomeButton);
                }
                if (WebPageWebView.Bounds.Width > 500)
                {
                    TitleStack.Children.Add(RefreshButton);
                }
                if (WebPageWebView.Bounds.Width > 300)
                {
                    TitleStack.Children.Add(HistoryButton);
                }
                if (WebPageWebView.Bounds.Width > 600)
                {
                    TitleStack.Children.Add(SettingsButton);
                }
                TitleStack.Children.Add(MoreButton);
            };

            TitleStack = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = 45,
                Orientation       = StackOrientation.Horizontal,
                Children          =
                {
                    new Label
                    {
                        Text = Language.GetText("AppTitleShort"),
                        HorizontalOptions     = LayoutOptions.StartAndExpand,
                        VerticalOptions       = LayoutOptions.Fill,
                        VerticalTextAlignment = TextAlignment.Center,
                        TextColor             = Color.Yellow
                    }
                }
            };

            // Don't show button if there is no QR-history
            HistoryButton.IsVisible = Parameters.Options.SaveHistory;

            // The root page of your application
            MainPage = new ContentPage
            {
                Content = new StackLayout
                {
                    VerticalOptions   = LayoutOptions.Fill,
                    HorizontalOptions = LayoutOptions.Fill,
                    Children          =
                    {
                        TitleStack,
                        WebPageWebView
                    }
                },
                Padding         = new Thickness(0),
                BackgroundColor = Color.Black,
            };

            NavigationPage.SetHasBackButton(MainPage, false);
            NavigationPage.SetHasNavigationBar(MainPage, false);
        }