Example #1
0
 public void OnPrevFloor(object sender, EventArgs e)
 {
     if (LoadPrevSubLocation())
     {
         adjustTime = NavigineSDK.CurrentTimeMillis() + AdjustTimeout;
     }
 }
Example #2
0
        private void AdjustDevice()
        {
            // Check if location is loaded
            if (location == null || currentSubLocationIndex < 0)
            {
                return;
            }

            // Check if navigation is available
            if (deviceInfo.ErrorCode != 0)
            {
                return;
            }

            // Check if device belongs to the location loaded
            if (deviceInfo.Location != location.Id)
            {
                return;
            }

            long timeNow = NavigineSDK.CurrentTimeMillis();

            // Adjust map, if necessary
            if (timeNow >= adjustTime)
            {
                // Firstly, set the correct sublocation
                SubLocation subLoc = (SubLocation)location.SubLocations[currentSubLocationIndex];
                if (deviceInfo.SubLocation != subLoc.Id)
                {
                    for (int i = 0; i < location.SubLocations.Count; ++i)
                    {
                        if (((SubLocation)location.SubLocations[i]).Id == deviceInfo.SubLocation)
                        {
                            LoadSubLocation(i);
                        }
                    }
                }

                // Secondly, adjust device to the center of the screen
                PointF center = locationView.GetScreenCoordinates(deviceInfo.X, deviceInfo.Y);
                float  deltaX = locationView.Width / 2 - center.X;
                float  deltaY = locationView.Height / 2 - center.Y;
                adjustTime = timeNow;
                locationView.ScrollBy(deltaX, deltaY);
            }
        }
Example #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Log.Debug(TAG, "MainActivity started");

            base.OnCreate(savedInstanceState);

            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Main);

            Window.SetFlags(WindowManagerFlags.TranslucentStatus, WindowManagerFlags.TranslucentStatus);

            // Setting up GUI parameters
            locationView      = FindViewById <LocationView>(Resource.Id.navigation__location_view);
            backView          = FindViewById <View>(Resource.Id.navigation__back_view);
            prevFloorButton   = FindViewById <Button>(Resource.Id.navigation__prev_floor_button);
            nextFloorButton   = FindViewById <Button>(Resource.Id.navigation__next_floor_button);
            prevFloorView     = FindViewById <View>(Resource.Id.navigation__prev_floor_view);
            nextFloorView     = FindViewById <View>(Resource.Id.navigation__next_floor_view);
            currentFloorLabel = FindViewById <TextView>(Resource.Id.navigation__current_floor_label);
            zoomInView        = FindViewById <View>(Resource.Id.navigation__zoom_in_view);
            zoomOutView       = FindViewById <View>(Resource.Id.navigation__zoom_out_view);
            adjustModeView    = FindViewById <View>(Resource.Id.navigation__adjust_mode_view);
            errorMessageLabel = FindViewById <TextView>(Resource.Id.navigation__error_message_label);
            backButton        = FindViewById <Button>(Resource.Id.navigation__back_button);
            zoomInButton      = FindViewById <Button>(Resource.Id.navigation__zoom_in_button);
            zoomOutButton     = FindViewById <Button>(Resource.Id.navigation__zoom_out_button);
            modeButton        = FindViewById <Button>(Resource.Id.navigation__adjust_mode_button);


            locationView.SetBackgroundColor(Color.ParseColor("#ffebebeb"));

            backView.Visibility          = ViewStates.Invisible;
            prevFloorView.Visibility     = ViewStates.Invisible;
            nextFloorView.Visibility     = ViewStates.Invisible;
            currentFloorLabel.Visibility = ViewStates.Invisible;
            zoomInView.Visibility        = ViewStates.Invisible;
            zoomOutView.Visibility       = ViewStates.Invisible;
            adjustModeView.Visibility    = ViewStates.Invisible;
            errorMessageLabel.Visibility = ViewStates.Gone;

            venueBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.elm_venue);

            backButton.Click        += OnCancelRoute;
            backView.Click          += OnCancelRoute;
            prevFloorButton.Click   += OnPrevFloor;
            nextFloorButton.Click   += OnNextFloor;
            zoomInButton.Click      += OnZoomIn;
            zoomOutButton.Click     += OnZoomOut;
            modeButton.Click        += ToggleAdjustMode;
            errorMessageLabel.Click += OnCloseMessage;

            if (!DemoApp.PermissionLocation)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new string[] { Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessCoarseLocation }, 101);
            }

            // Setting up listener
            locationView.SetListener(
                new LocationListener(
                    HandleClick,
                    HandleLongClick,
                    (x, y) => { },
                    (x, y) => { adjustTime = NavigineSDK.CurrentTimeMillis() + AdjustTimeout; },
                    (ratio) => { adjustTime = NavigineSDK.CurrentTimeMillis() + AdjustTimeout; },
                    (canvas) =>
            {
                DrawZones(canvas);
                DrawPoints(canvas);
                DrawVenues(canvas);
                DrawDevice(canvas);
            }));

            DemoApp.Navigation?.SetZoneListener(new ZoneListener(HandleEnterZone, HandleLeaveZone));

            // Loading map only when location view size is known for zomming
            locationView.LayoutChange += OnLayoutChange;

            // Starting interface updates
            timer          = new Timer(TimerInterval);
            timer.Elapsed += OnTimeEvent;
            timer.Interval = TimerInterval;
            timer.Enabled  = true;
            timer.Start();
        }
Example #4
0
 private void SetErrorMessage(string message)
 {
     errorMessageLabel.Text       = message;
     errorMessageLabel.Visibility = ViewStates.Visible;
     errorMessageTime             = NavigineSDK.CurrentTimeMillis();
 }
Example #5
0
        public void RedrawMap()
        {
            if (DemoApp.Navigation == null)
            {
                Log.Debug(TAG, "Sorry, navigation is not supported on your device!");
                return;
            }

            long timeNow = NavigineSDK.CurrentTimeMillis();

            if (errorMessageTime > 0 && timeNow > errorMessageTime + ErrorMessageTimeout)
            {
                errorMessageTime             = 0;
                errorMessageLabel.Visibility = ViewStates.Gone;
            }

            // Check if location is loaded
            if (location == null || currentSubLocationIndex < 0)
            {
                return;
            }

            // Get current sublocation displayed
            SubLocation subLoc = (SubLocation)location.SubLocations[currentSubLocationIndex];

            // Start navigation if necessary
            if (DemoApp.Navigation.Mode == NavigationThread.ModeIdle)
            {
                DemoApp.Navigation.Mode = NavigationThread.ModeNormal;
            }

            // Get device info from NavigationThread
            deviceInfo = DemoApp.Navigation.DeviceInfo;

            if (deviceInfo.ErrorCode == 0)
            {
                errorMessageTime             = 0;
                errorMessageLabel.Visibility = ViewStates.Gone;

                if (adjustMode)
                {
                    AdjustDevice();
                }

                if (targetPoint != null || targetVenue != null)
                {
                    backView.Visibility = ViewStates.Visible;
                }
                else
                {
                    backView.Visibility = ViewStates.Gone;
                }
            }
            else
            {
                switch (deviceInfo.ErrorCode)
                {
                case 4:
                    SetErrorMessage("You are out of navigation zone! Please, check that your bluetooth is enabled!");
                    break;

                case 8:
                case 30:
                    SetErrorMessage("Not enough beacons on the location! Please, add more beacons!");
                    break;

                default:
                    SetErrorMessage(
                        $"Something is wrong with location {location.Name} (error code {deviceInfo.ErrorCode})! Please, contact technical support!");
                    break;
                }

                backView.Visibility = ViewStates.Gone;
            }

            // Secondly, adjust device to the center of the screen
            PointF center = locationView.ScreenCenter;
            float  deltaX = locationView.Width / 2 - center.X;
            float  deltaY = locationView.Height / 2 - center.Y;

            adjustTime = timeNow;
            locationView.ScrollBy(deltaX, deltaY);

            // This causes map redrawing
            locationView.Redraw();
        }