private async void ScanBarcode_ClickHandler(object sender, EventArgs e) { if (ContextCompat.CheckSelfPermission(MainActivity, Manifest.Permission.Camera) != (int)Permission.Granted) { if (ActivityCompat.ShouldShowRequestPermissionRationale(MainActivity, Manifest.Permission.Camera)) { Snackbar snackbar = Snackbar .Make(AndroidCoordinatorLayout, "Allow access to your phone's camera. Swipe right to dismiss", Snackbar.LengthIndefinite) .SetAction("Allow", v => RequestCameraPermission()) .SetActionTextColor(ContextCompat.GetColorStateList(Context, Resource.Color.permission_snackbar_button)); snackbar.View.SetBackgroundResource(Resource.Drawable.rounded_bg_r4); int[][] states = { new[] { Android.Resource.Attribute.StateEnabled } }; int[] colors = { MainActivity.GetColor(Resource.Color.cyclesBlueLight) }; snackbar.View.BackgroundTintList = new ColorStateList(states, colors); ((CoordinatorLayout.LayoutParams)snackbar.View.LayoutParameters).SetMargins(16, 32, 16, 32); snackbar.Show(); } else { RequestCameraPermission(); } } else { var scanPage = new CustomBarcodeScanner(); await Application.Current.MainPage.Navigation.PushModalAsync(scanPage); } }
public MapPage() { try { InitializeComponent(); if (AlreadyLoaded) { MProgressBar.IsVisible = false; } else { // MMap.IsVisible = false; Device.StartTimer(TimeSpan.FromSeconds(.5), () => { if (!(MProgressBar.Progress < 1)) { return(false); } Device.BeginInvokeOnMainThread(() => MProgressBar.ProgressTo(MProgressBar.Progress + 0.005, 500, Easing.Linear)); return(true); }); } #if __ANDROID__ NavigationPage.SetHasNavigationBar(this, false); #endif #if __IOS__ StackLayout NavStack = new StackLayout() { Children = { new Label() { Text = "Cycles" } } }; NavigationPage.SetTitleView(this, NavStack); #endif } catch (Exception ex) { Console.WriteLine(ex.Message); // Crashlytics.Crashlytics.LogException(Java.Lang.Throwable.FromException(ex)); } BindingContext = this; var pin = new CustomPin { Type = PinType.Place, PinType = CustomPin.CustomType.Park, Position = new Position(6.672219, 3.161639), Label = "Cycles Point @Cafe 2", Address = "Cafeteria 2, Goodness Rd, Canaan Land, Ota", MarkerId = "P2" }; var pin2 = new CustomPin { Type = PinType.Place, PinType = CustomPin.CustomType.Park, Position = new Position(6.67369, 3.15922), Label = "Cycles Point @CST", Address = "College of Science and Tech, CU, Canaan Land, Ota", MarkerId = "P3" }; MMap.CustomPins = new List <CustomPin> { pin, pin2 }; MMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(LAGOS_LATITUDE, LAGOS_LONGITUDE), new Distance(15000d))); // MMap.Pins.Add(pin); // MMap.Pins.Add(pin2); MessagingCenter.Subscribe <MapPageRenderer>(this, "Scanner Opened", async(mainActivity) => { var scanPage = new CustomBarcodeScanner(); if (Application.Current.MainPage.Navigation.ModalStack.Count == 0) { await Application.Current.MainPage.Navigation.PushModalAsync(scanPage); } }); MessagingCenter.Subscribe <MainActivity>(this, "Close Scanner", async(sender) => { if (Application.Current.MainPage.Navigation.ModalStack.Count > 0) { await Application.Current.MainPage.Navigation.PopModalAsync(); } }); MessagingCenter.Subscribe <GraphicBarcodeTracker>(this, "Close Scanner", async(sender) => { if (Application.Current.MainPage.Navigation.ModalStack.Count > 0) { await Application.Current.MainPage.Navigation.PopModalAsync(); } }); }