Example #1
0
        public override void AddView(AView child)
        {
            if (child is CoordinatorLayout)
            {
                base.AddView(child);
                return;
            }

            ((ViewGroup)child).LayoutParameters =
                new CoordinatorLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            MainViewGroup = (ViewGroup)child;
            AndroidCoordinatorLayout.FindViewById <RelativeLayout>(Resource.Id.map_holder)
            .AddView(child);

            for (var i = 0; i < MainViewGroup.ChildCount; i++)
            {
                AView foundChild = MainViewGroup.GetChildAt(i);

                if (!(foundChild is CyclesMapRenderer cyclesMapRenderer))
                {
                    continue;
                }
                CyclesMapView = cyclesMapRenderer;

                CyclesMapView.MapReady += async sender =>
                {
                    if (!MainActivity.IsLocationAccessGranted || !MainActivity.IsLocationEnabled)
                    {
                        return;
                    }

                    Location lastLocation = await FusedLocationProviderClient.GetLastLocationAsync();

                    if (lastLocation == null)
                    {
                        return;
                    }
                    var addressResultReceiver = new MapPageRendererAddressResultReceiver(new Handler(), this);
                    StartAddressIntentService(addressResultReceiver, lastLocation);

                    var latLng = new LatLng(lastLocation.Latitude, lastLocation.Longitude);
                    CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                    builder.Target(latLng);
                    builder.Zoom(18);
                    CameraPosition cameraPosition = builder.Build();
                    CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                    CyclesMapView.AnimateCamera(cameraUpdate);
                };
            }
        }
Example #2
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (AndroidCoordinatorLayout == null)
            {
                return;
            }
            var msw = MeasureSpec.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly);
            var msh = MeasureSpec.MakeMeasureSpec(b - t, MeasureSpecMode.Exactly);

            //
            AndroidCoordinatorLayout?.Measure(msw, msh);
            AndroidCoordinatorLayout?.Layout(0, 0, r - l, b - t);
        }
Example #3
0
        public MapPageRenderer(Context context) : base(context)
        {
            MainActivity = Context as MainActivity;
            //MessagingCenter.Subscribe<MainActivity>(this, "Close Scanner",
            //    (sender) => { Application.Current.MainPage = MapPage; });
            FusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(MainActivity);
            AlertBuilder = new AlertDialog.Builder(Context);
            MessagingCenter
            .Subscribe <GraphicBarcodeTracker, string>(this, "Barcode Scanned", (main, s) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    AlertBuilder.SetTitle("Start Ride");
                    AlertBuilder.SetMessage("To start ride click Unlock. You are on PAYG");
                    AlertBuilder.SetPositiveButton("Unlock", (senderAlert, args) =>
                    {
                        Toast.MakeText(Context, "Bike Unlocking", ToastLength.Short).Show();
                        //NativeController.getReadDataUUID();
                        StartRideHandlerService();
                    });

                    AlertBuilder.SetNegativeButton("Cancel",
                                                   (senderAlert, args) =>
                    {
                        Toast.MakeText(Context, "Ride Cancelled!", ToastLength.Short).Show();
                    });

                    Dialog dialog = AlertBuilder.Create();
                    dialog.Show();
                });
            });

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                if (MainActivity?.Window != null)
                {
                    AView decorView = MainActivity.Window.DecorView;
                    decorView.SetFitsSystemWindows(false);

                    MainActivity.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
                }
            }

            //BuildGoogleApiClient();

            _startServiceIntent = new Intent(Context, typeof(RideHandlerService));
            _startServiceIntent.SetAction(Constants.ACTION_START_SERVICE);
            _stopServiceIntent = new Intent(Context, typeof(RideHandlerService));
            _stopServiceIntent.SetAction(Constants.ACTION_STOP_SERVICE);

            #region Initialize _androidCoordinatorLayout with LayoutParams

            AndroidCoordinatorLayout = (CoordinatorLayout)LayoutInflater.FromContext(Context)
                                       .Inflate(Resource.Layout.MapWithCoordinator, null);
            AndroidCoordinatorLayout.SetBackgroundColor(Color.Transparent.ToAndroid());
            InfoTextView = AndroidCoordinatorLayout.FindViewById <TextView>(Resource.Id.info_textview);

            CommunityEditText = AndroidCoordinatorLayout.FindViewById <EditText>(Resource.Id.current_community);

            ClosestBikeFab =
                AndroidCoordinatorLayout.FindViewById <FloatingActionButton>(Resource.Id.fab_closest_bicycle);

            RefreshMapFab =
                AndroidCoordinatorLayout.FindViewById <FloatingActionButton>(Resource.Id.fab_refresh_map);

            LocateMeFab = AndroidCoordinatorLayout.FindViewById <FloatingActionButton>(Resource.Id.fab_locate_me);

            ScanButton        = AndroidCoordinatorLayout.FindViewById <MaterialButton>(Resource.Id.scan_button);
            ScanButton.Click += (sender, args) =>
            {
                //                MessagingCenter.Send(this, "Scanner Opened");
                var bottomSheet = AndroidCoordinatorLayout.FindViewById <LinearLayout>(Resource.Id.bottom_sheet);
                bottomSheet.LayoutParameters.Height = AndroidCoordinatorLayout.Height;
                BottomSheetBehavior.From(bottomSheet).PeekHeight = AndroidCoordinatorLayout.Height;

                IVisualElementRenderer renderer = Platform.CreateRendererWithContext(new CustomBarcodeScanner(), context);
                BottomSheetBehavior.From(bottomSheet).State = BottomSheetBehavior.StateExpanded;
                TransitionManager.BeginDelayedTransition(bottomSheet, new Fade());
                bottomSheet.RemoveView(ScanButton);

                bottomSheet.AddView(renderer.View);
            };

            if (!MainActivity.IsLocationAccessGranted || !MainActivity.IsLocationEnabled)
            {
                DisableLocationButtons(ClosestBikeFab, RefreshMapFab, LocateMeFab);
            }

            ClosestBikeFab?.SetVisibility(ViewStates.Gone);
            if (ClosestBikeFab != null)
            {
                ClosestBikeFab.Click += FindClosestBike_ClickHandler;
            }

            if (LocateMeFab != null)
            {
                LocateMeFab.Click += LocateMe_ClickHandler;
            }

            if (RefreshMapFab != null)
            {
                RefreshMapFab.Click += RefreshMap_ClickHandler;
            }

            #endregion

            MainActivity.LocationAccessChanged   += MainActivity_LocationAccessChanged;
            MainActivity.LocationSettingsChanged += MainActivityLocationSettingsChanged;

            #region Initialize _androidAppBarLayout with LayoutParams

            //AndroidAppBarLayout = AndroidCoordinatorLayout.FindViewById<AppBarLayout>(Resource.Id.mappage_appbar);
            var toolbar =
                AndroidCoordinatorLayout.FindViewById <Toolbar>(Resource.Id.mappage_toolbar);

            var giftButton = toolbar.FindViewById <ImageButton>(Resource.Id.gift_button);
            giftButton.Click += GiftButton_ClickHandler;

            if (toolbar.LayoutParameters != null)
            {
                ((AppBarLayout.LayoutParams)toolbar.LayoutParameters).ScrollFlags = ScrollFlagEnterAlways;
            }

            MainActivity?.SetSupportActionBar(toolbar);
            ActionBar actionBar = MainActivity?.SupportActionBar;

            if (actionBar != null)
            {
                actionBar.SetDisplayHomeAsUpEnabled(true);
                actionBar.SetDisplayShowTitleEnabled(false);
                actionBar.SetHomeAsUpIndicator(Resource.Drawable.baseline_menu_white_24);
            }

            #endregion

            AddView(AndroidCoordinatorLayout);
        }