protected override void OnResume()
        {
            try {
                base.OnResume();
                c.Log("LocationActivity resuming, ListActivity.initialized " + ListActivity.initialized);
                if (!ListActivity.initialized)
                {
                    return;
                }

                RegisterReceiver(locationReceiver, new IntentFilter("balintfodor.locationconnection.LocationReceiver"));

                locationList = new List <LocationItem>();

                if (File.Exists(c.locationLogFile))
                {
                    string[] fileLines = File.ReadAllLines(c.locationLogFile);

                    for (int i = fileLines.Length - 1; i >= 0; i--)
                    {
                        string       line = fileLines[i];
                        LocationItem item = new LocationItem();

                        int sep1Pos = line.IndexOf('|');
                        int sep2Pos = line.IndexOf('|', sep1Pos + 1);
                        int sep3Pos = line.IndexOf('|', sep2Pos + 1);

                        item.time       = long.Parse(line.Substring(0, sep1Pos));
                        item.latitude   = double.Parse(line.Substring(sep1Pos + 1, sep2Pos - sep1Pos - 1), CultureInfo.InvariantCulture);
                        item.longitude  = double.Parse(line.Substring(sep2Pos + 1, sep3Pos - sep2Pos - 1), CultureInfo.InvariantCulture);
                        item.inApp      = (line.Substring(sep3Pos + 1) == "0") ? false : true;
                        item.isSelected = false;
                        locationList.Add(item);
                    }
                    locationList[0].isSelected = true;
                    selectedPos = 0;

                    if (mapLoaded)
                    {
                        thisMap.Clear();
                        SetMap();
                    }
                }
                else
                {
                    c.Snack(Resource.String.NoLocationRecords);
                }

                adapter = new LocationListAdapter(this, locationList);
                LocationHistoryList.Adapter = adapter;
            }
            catch (Exception ex)
            {
                c.ReportErrorSilent(ex.Message + System.Environment.NewLine + ex.StackTrace);
            }
        }
        public void AddItem()
        {
            LocationItem           item = new LocationItem();
            CLLocationCoordinate2D location;

            if (!Constants.SafeLocationMode)
            {
                item.time      = (long)Session.LocationTime;
                item.latitude  = (double)Session.Latitude;
                item.longitude = (double)Session.Longitude;

                location = new CLLocationCoordinate2D((double)Session.Latitude, (double)Session.Longitude);
            }
            else
            {
                item.time      = (long)Session.SafeLocationTime;
                item.latitude  = (double)Session.SafeLatitude;
                item.longitude = (double)Session.SafeLongitude;

                location = new CLLocationCoordinate2D((double)Session.SafeLatitude, (double)Session.SafeLongitude);
            }

            item.inApp = true;

            if (selectedPos == 0 && locationList.Count > 0)
            {
                item.isSelected = true;
                locationList[selectedPos].isSelected = false;
                AddCircle(location);
                MoveMap(location, false);
            }
            else if (locationList.Count == 0)
            {
                item.isSelected = true;
                AddCircle(location);
                MoveMap(location, true);
            }
            else
            {
                item.isSelected = false;
                selectedPos++;
            }

            locationList.Insert(0, item);
            LocationHistoryList.ReloadData();

            if (locationList.Count >= 2)
            {
                AddLine(new CLLocationCoordinate2D(locationList[1].latitude, locationList[1].longitude), location, 0, 255, 0);
            }
        }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView;

            if (Settings.DisplaySize == 1)
            {
                if (view == null)
                {
                    view = context.LayoutInflater.Inflate(Resource.Layout.list_item_text_normal, null);
                }
            }
            else
            {
                if (view == null)
                {
                    view = context.LayoutInflater.Inflate(Resource.Layout.list_item_text_small, null);
                }
            }

            LocationItem item = items[position];

            if (item.isSelected)
            {
                if (item.inApp)
                {
                    view.SetBackgroundColor(new Color(ContextCompat.GetColor(context, Resource.Color.ForegroundLocationDark)));
                }
                else
                {
                    view.SetBackgroundColor(new Color(ContextCompat.GetColor(context, Resource.Color.BackgroundLocationDark)));
                }
            }
            else
            {
                if (item.inApp)
                {
                    view.SetBackgroundColor(new Color(ContextCompat.GetColor(context, Resource.Color.ForegroundLocation)));
                }
                else
                {
                    view.SetBackgroundColor(new Color(ContextCompat.GetColor(context, Resource.Color.BackgroundLocation)));
                }
            }

            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(item.time).ToLocalTime();

            ((TextView)view).Text = dt.ToString("HH:mm:ss");

            return(view);
        }
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            LocationHistoryListCell cell = (LocationHistoryListCell)tableView.DequeueReusableCell("LocationHistoryListCell");
            LocationItem            item = items[indexPath.Row];

            if (item.isSelected)
            {
                if (item.inApp)
                {
                    if (!item.sent)
                    {
                        cell.ContentView.BackgroundColor = UIColor.FromName("LocationForegroundSelected"); //hsl(150, 58%, 55%)
                    }
                    else
                    {
                        cell.ContentView.BackgroundColor = UIColor.FromName("LocationSentSelected"); //hsl(15, 77%, 65%)
                    }
                }
                else
                {
                    cell.ContentView.BackgroundColor = UIColor.FromName("LocationBackgroundSelected"); //hsl(40, 77%, 55%)
                }
            }
            else
            {
                if (item.inApp)
                {
                    if (!item.sent)
                    {
                        cell.ContentView.BackgroundColor = UIColor.FromName("LocationForeground"); //85%
                    }
                    else
                    {
                        cell.ContentView.BackgroundColor = UIColor.FromName("LocationSent");
                    }
                }
                else
                {
                    cell.ContentView.BackgroundColor = UIColor.FromName("LocationBackground");
                }
            }

            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(item.time).ToLocalTime();

            cell.LocationHistoryLabel.Text = dt.ToString("HH:mm:ss");

            return(cell);
        }
        public void AddItem(long time, double latitude, double longitude)
        {
            LatLng       location = new LatLng(latitude, longitude);
            LocationItem item     = new LocationItem();

            item.time      = time;
            item.latitude  = latitude;
            item.longitude = longitude;
            item.inApp     = true;

            if (selectedPos == 0 && locationList.Count > 0)
            {
                item.isSelected = true;
                locationList[selectedPos].isSelected = false;
                AddCircle(location);
                MoveMap(location, false);
            }
            else if (locationList.Count == 0)
            {
                item.isSelected = true;
                AddCircle(location);
                MoveMap(location, true);
            }
            else
            {
                item.isSelected = false;
                selectedPos++;
            }

            locationList.Insert(0, item);
            adapter.NotifyDataSetChanged();

            if (locationList.Count >= 2)
            {
                AddLine(location, new LatLng(locationList[1].latitude, locationList[1].longitude), Color.Argb(255, 0, 255, 0));
            }
        }
        private void LoadList()
        {
            locationList = new List <LocationItem>();
            if (lines != null)
            {
                LocationHistoryMap.RemoveOverlays(lines.ToArray());
            }
            lines = new List <MKPolyline>();

            //File.Delete(c.locationLogFile);

            if (File.Exists(c.locationLogFile))
            {
                string[] fileLines = File.ReadAllLines(c.locationLogFile);

                for (int i = fileLines.Length - 1; i >= 0; i--)
                {
                    string       line = fileLines[i];
                    LocationItem item = new LocationItem();

                    int sep1Pos = line.IndexOf('|');
                    int sep2Pos = line.IndexOf('|', sep1Pos + 1);
                    int sep3Pos = line.IndexOf('|', sep2Pos + 1);

                    if (sep2Pos != -1)
                    {
                        item.time      = long.Parse(line.Substring(0, sep1Pos));
                        item.latitude  = double.Parse(line.Substring(sep1Pos + 1, sep2Pos - sep1Pos - 1), CultureInfo.InvariantCulture);
                        item.longitude = double.Parse(line.Substring(sep2Pos + 1, sep3Pos - sep2Pos - 1), CultureInfo.InvariantCulture);
                        string status = line.Substring(sep3Pos + 1);
                        switch (status)
                        {
                        case "0":
                            item.inApp = false;
                            item.sent  = false;
                            break;

                        case "1":
                            item.inApp = true;
                            item.sent  = false;
                            break;

                        case "2":
                            item.inApp = true;
                            item.sent  = true;
                            break;
                        }
                        item.isSelected = false;
                        locationList.Add(item);
                    }
                }
                locationList[0].isSelected = true;
                selectedPos = 0;
            }
            else
            {
                c.Snack(LangEnglish.NoLocationRecords);
            }

            adapter = new LocationListAdapter(locationList);
            LocationHistoryList.Source = adapter;
            LocationHistoryList.ReloadData();
            LocationHistoryList.Delegate = this;
        }