public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (thisTask == null)
            {
                AppUtils.ShowSimpleDialog(this, "ERROR", "Error loading task data", "Ok");
                NavigationController.PopViewController(true);
                return;
            }

            taskData = JsonConvert.DeserializeObject <MapMarkerTaskData>(thisTask.JsonData);

            markers         = new List <Marker>();
            mapView.MapType = MapViewType.Hybrid;
            mapView.Settings.MyLocationButton = true;

            if (!string.IsNullOrWhiteSpace(thisTask.CompletionData.JsonData))
            {
                // load previously placed markers
                Map_Location[] locs = JsonConvert.DeserializeObject <Map_Location[]>(thisTask.CompletionData.JsonData);

                if (locs != null)
                {
                    foreach (Map_Location loc in locs)
                    {
                        CLLocationCoordinate2D coord = new CLLocationCoordinate2D(loc.Lat, loc.Long);
                        var color  = UIColor.FromHSBA((float)AppUtils.GetRandomNumber(), 1, 1, 1.0f);
                        var marker = Marker.FromPosition(coord);
                        marker.AppearAnimation = MarkerAnimation.Pop;
                        marker.Icon            = Marker.MarkerImage(color);
                        marker.Map             = mapView;
                        markers.Add(marker);
                    }
                }
            }

            UpdateText();
            TaskDescLabel.Text = thisTask.Description;

            // Listen to the myLocation property of GMSMapView.
            mapView.AddObserver(this, new NSString("myLocation"), NSKeyValueObservingOptions.New, IntPtr.Zero);

            mapView.CoordinateTapped += CoordinateTapped;
            mapView.TappedMarker     += TappedMarker;

            // Ask for My Location data after the map has already been added to the UI.
            InvokeOnMainThread(() => mapView.MyLocationEnabled = true);

            MarkLocButton.TouchUpInside        += AddMarkerOnPosition;
            ProgressFinishButton.TouchUpInside += FinishButtonPressed;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.CreateTaskLocationMarker);
            instructions        = FindViewById <EditText>(Resource.Id.taskInstructions);
            userLocOnlyCheckbox = FindViewById <CheckBox>(Resource.Id.checkboxUserLoc);
            minNumText          = FindViewById <EditText>(Resource.Id.minNumMarkers);
            maxNumText          = FindViewById <EditText>(Resource.Id.maxNumMarkers);
            Button addTaskBtn = FindViewById <Button>(Resource.Id.addTaskBtn);

            addTaskBtn.Click += AddTaskBtn_Click;
            minNumText.Text   = "1";
            maxNumText.Text   = "0";

            // Check if this is editing an existing task: if so, populate fields
            string editJson = Intent.GetStringExtra("EDIT") ?? "";

            newTask = JsonConvert.DeserializeObject <LearningTask>(editJson);

            if (newTask != null)
            {
                editing           = true;
                taskType          = newTask.TaskType;
                instructions.Text = newTask.Description;
                addTaskBtn.SetText(Resource.String.saveChanges);

                MapMarkerTaskData data = JsonConvert.DeserializeObject <MapMarkerTaskData>(newTask.JsonData);
                minNumText.Text             = data.MinNumMarkers.ToString();
                maxNumText.Text             = data.MaxNumMarkers.ToString();
                userLocOnlyCheckbox.Checked = data.UserLocationOnly;
            }
            else
            {
                string jsonData = Intent.GetStringExtra("JSON") ?? "";
                taskType = JsonConvert.DeserializeObject <TaskType>(jsonData, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });
            }

            FindViewById <TextView>(Resource.Id.taskTypeNameText).Text = taskType.DisplayName;
            ImageViewAsync image = FindViewById <ImageViewAsync>(Resource.Id.taskIcon);

            AndroidUtils.LoadTaskTypeIcon(taskType, image);
        }
예제 #3
0
        protected override void FinishButton_TouchUpInside(object sender, EventArgs e)
        {
            if (UpdateBasicTask())
            {
                int maxNum = (int)maxPicker.SelectedRowInComponent(0);

                MapMarkerTaskData taskData = new MapMarkerTaskData
                {
                    MaxNumMarkers    = (int)maxPicker.SelectedRowInComponent(0),
                    MinNumMarkers    = ((int)minPicker.SelectedRowInComponent(0)) + 1,
                    UserLocationOnly = limitToCurrentLoc.On
                };

                thisTask.JsonData = JsonConvert.SerializeObject(taskData);

                UpdateActivity();
                Unwind();
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.LocationMarkerActivity);

            string jsonData = Intent.GetStringExtra("JSON") ?? "";

            learningTask = JsonConvert.DeserializeObject <AppTask>(jsonData,
                                                                   new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            taskData = JsonConvert.DeserializeObject <MapMarkerTaskData>(learningTask.JsonData);

            SupportActionBar.Title = learningTask.Description;
            selectedMarkers        = new List <Marker>();

            MapFragment mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            mapFrag.GetMapAsync(this);

            progressDialog = new ProgressDialog(this);
            progressDialog.SetTitle(Resource.String.PleaseWait);
            progressDialog.SetMessage(Resources.GetString(Resource.String.mapLoadingMessage)); // Why Xamarin, why??
            progressDialog.SetCancelable(false);
            progressDialog.Indeterminate = true;
            progressDialog.SetButton(Resources.GetString(Resource.String.dialog_cancel), (a, b) =>
            {
                Finish();
            });
            progressDialog.Show();

            markButton          = FindViewById <Button>(Resource.Id.markBtn);
            markButton.Click   += MarkBtn_Click;
            finishButton        = FindViewById <Button>(Resource.Id.finishBtn);
            finishButton.Click += FinishButton_Click;
            locationCountText   = FindViewById <TextView>(Resource.Id.markersText);

            UpdateButton();
            UpdateText();
        }
예제 #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            minPickerData = new List <string>();

            for (int i = 1; i <= 10; i++)
            {
                minPickerData.Add(i.ToString());
            }

            minPicker.Model = new MapConfigPickerViewModel(minPickerData.ToArray());

            maxPickerData = new List <string>()
            {
                "Unlimited"
            };

            for (int i = 1; i <= 10; i++)
            {
                maxPickerData.Add(i.ToString());
            }

            maxPicker.Model = new MapConfigPickerViewModel(maxPickerData.ToArray());

            // Check if need to load previous edits
            if (!string.IsNullOrWhiteSpace(thisTask?.JsonData))
            {
                MapMarkerTaskData existingData = JsonConvert.DeserializeObject <MapMarkerTaskData>(thisTask.JsonData);

                if (existingData != null)
                {
                    maxPicker.Select(existingData.MaxNumMarkers, 0, true);
                    minPicker.Select(existingData.MinNumMarkers - 1, 0, true);
                    limitToCurrentLoc.On = existingData.UserLocationOnly;
                }
            }
        }
        private void AddTaskBtn_Click(object sender, EventArgs e)
        {
            int errMess = -1;
            int min     = int.Parse(minNumText.Text);
            int max     = int.Parse(maxNumText.Text);

            if (string.IsNullOrWhiteSpace(instructions.Text))
            {
                errMess = Resource.String.createNewActivityTaskInstruct;
            }
            else if (min < 1)
            {
                errMess = Resource.String.createNewMapMarkerErrMinLessThanOne;
            }
            else if (max < min && max != 0)
            {
                errMess = Resource.String.createNewMapMarkerErrMaxLessThanMin;
            }

            if (errMess != -1)
            {
                new global::Android.Support.V7.App.AlertDialog.Builder(this)
                .SetTitle(Resource.String.ErrorTitle)
                .SetMessage(errMess)
                .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { })
                .Show();
                return;
            }

            MapMarkerTaskData taskData = new MapMarkerTaskData
            {
                MaxNumMarkers    = max,
                MinNumMarkers    = min,
                UserLocationOnly = userLocOnlyCheckbox.Checked
            };

            if (newTask == null)
            {
                newTask = new LearningTask()
                {
                    TaskType = taskType
                };
            }

            newTask.Description = instructions.Text;
            newTask.JsonData    = JsonConvert.SerializeObject(taskData);

            string json = JsonConvert.SerializeObject(newTask, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                MaxDepth = 5
            });

            Intent myIntent = (editing) ?
                              new Intent(this, typeof(CreateActivityOverviewActivity)) :
                              new Intent(this, typeof(CreateChooseTaskTypeActivity));

            myIntent.PutExtra("JSON", json);
            SetResult(global::Android.App.Result.Ok, myIntent);
            Finish();
        }