/// <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); }
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(); } }
/// <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); }
/// <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); }