Esempio n. 1
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView;

            if (view == null)
            {
                view = _context.LayoutInflater.Inflate(Resource.Layout.DownloadedElevationDataItem, parent, false);
            }

            view.SetOnClickListener(this);
            view.Tag = position;

            DownloadedElevationData item = this[position];

            view.FindViewById <TextView>(Resource.Id.textViewPlaceName).Text   = $"{item.PlaceName}";
            view.FindViewById <TextView>(Resource.Id.textViewGpsLocation).Text = GpsUtils.LocationAsString(item.Longitude, item.Latitude);
            var sizeInMBytes = item.SizeInBytes / 1024d / 1024d;

            view.FindViewById <TextView>(Resource.Id.textViewSize).Text = $"{item.Distance} km / {sizeInMBytes:F1} MBytes";

            var deleteButton = view.FindViewById <ImageButton>(Resource.Id.PoiDeleteButton);

            deleteButton.Tag = position;
            deleteButton.SetOnClickListener(this);

            return(view);
        }
        protected override void UpdateStatusBar()
        {
            string gpsLocation;

            if (GpsUtils.HasLocation(Context.MyLocation))
            {
                gpsLocation = $"GPS:{Context.MyLocation.LocationAsString()} Alt:{Context.MyLocation.Altitude:F0}";
            }
            else
            {
                gpsLocation = "No GPS location";
            }

            var sign    = Context.HeadingCorrector < 0 ? '-' : '+';
            var heading = $"Hdg:{Context.HeadingX ?? 0:F1}{sign}{Math.Abs(Context.HeadingCorrector):F1}";

            var zoomAndTiltCorrection = $"Scale:{photoView.Scale:F2} ,LT:{Context.LeftTiltCorrector:F2}, RT:{Context.RightTiltCorrector:F2}";

            var viewAngle = $"va-V:{Context.ViewAngleVertical:F1} va-H:{Context.ViewAngleHorizontal:F1}";

            var photoMatrix = $"im-X:{photoView.TranslateX:F1}, im-Y:{photoView.TranslateY:F1}, Sc:{photoView.DisplayScale:F2}/{photoView.Scale:F2}";

            //_GPSTextView.Text = heading + "  /  " + zoomAndTiltCorrection + "  /  " + viewAngle;// + "  /  " + photoMatrix;
            SetStatusLineText(zoomAndTiltCorrection + "  /  " + viewAngle + "  /  " + photoMatrix);
        }
Esempio n. 3
0
        protected void NotifyDataChanged(PoiViewItemList poiData = null)
        {
            if (GpsUtils.HasLocation(MyLocation))
            {
                if (poiData is null)
                {
                    var poiList = Database.GetItems(MyLocation, Settings.MaxDistance);
                    PoiData = new PoiViewItemList(poiList, MyLocation, Settings.MaxDistance, Settings.Categories, iGpsUtilities);
                }
                else
                {
                    PoiData = poiData;
                }

                //fetch selected point again
                if (SelectedPoi != null)
                {
                    var selectedPoi = PoiData.Find(x => x.Poi.Id == SelectedPoi.Poi.Id);
                    if (selectedPoi != null)
                    {
                        selectedPoi.Selected = true;
                        SelectedPoi          = selectedPoi;
                    }
                    else
                    {
                        SelectedPoi = null;
                    }
                }

                var args = new DataChangedEventArgs()
                {
                    PoiData = PoiData
                };
                DataChanged?.Invoke(this, args);
            }
            else
            {
                var args = new DataChangedEventArgs()
                {
                    PoiData = null
                };
                DataChanged?.Invoke(this, args);
            }
        }
Esempio n. 4
0
 public double Distance(GpsLocation loc1, GpsLocation loc2)
 {
     return(GpsUtils.Distance(loc1, loc2));
 }
Esempio n. 5
0
 public double Bearing(GpsLocation loc1, GpsLocation loc2)
 {
     return(GpsUtils.Bearing(loc1, loc2));
 }
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView;

            if (view == null)
            {
                if (DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait)
                {
                    view = _context.LayoutInflater.Inflate(Resource.Layout.PhotosActivityItemPortrait, parent, false);
                }
                else
                {
                    view = _context.LayoutInflater.Inflate(Resource.Layout.PhotosActivityItemLandscape, parent, false);
                }
            }

            PhotoData item        = this[position];
            var       gpsLocation = item.GetPhotoGpsLocation();

            view.FindViewById <TextView>(Resource.Id.textViewTag).Text      = item.Tag;
            view.FindViewById <TextView>(Resource.Id.textViewDate).Text     = item.GetPhotoTakenDateTime().ToShortDateString();
            view.FindViewById <TextView>(Resource.Id.textViewTime).Text     = item.GetPhotoTakenDateTime().ToLongTimeString();
            view.FindViewById <TextView>(Resource.Id.textViewAltitude).Text = $"{Math.Round(item.Altitude)}m ";
            view.FindViewById <TextView>(Resource.Id.textViewAltitude).SetTextColor(GpsUtils.HasAltitude(gpsLocation) ? Color.Black : Color.Red);
            view.FindViewById <TextView>(Resource.Id.textViewDirection).Text = item.Heading.HasValue ? $"{Math.Round(GpsUtils.Normalize360(item.Heading.Value))}°" : "0°";
            view.FindViewById <TextView>(Resource.Id.textViewDirection).SetTextColor(item.Heading.HasValue ? Color.Black : Color.Red);
            view.FindViewById <TextView>(Resource.Id.textViewLocation).Text = gpsLocation.LocationAsShortString();
            view.FindViewById <TextView>(Resource.Id.textViewLocation).SetTextColor(GpsUtils.HasLocation(gpsLocation) ? Color.Black : Color.Red);

            var linearLayoutThumbnail = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutThumbnail);

            linearLayoutThumbnail.SetOnClickListener(this);
            linearLayoutThumbnail.Tag = position;

            var linearLayoutName = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutName);

            linearLayoutName.SetOnClickListener(this);
            linearLayoutName.Tag = position;

            var linearLayoutPhotoData = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutPhotoData);

            linearLayoutPhotoData.SetOnClickListener(this);
            linearLayoutPhotoData.Tag = position;

            var deleteButton = view.FindViewById <ImageButton>(Resource.Id.photoDeleteButton);

            deleteButton.SetOnClickListener(this);
            deleteButton.Tag = position;

            var editButton = view.FindViewById <ImageButton>(Resource.Id.editButton);

            editButton.SetOnClickListener(this);
            editButton.Tag = position;

            var favouriteButton = view.FindViewById <ImageButton>(Resource.Id.favouriteButton);

            favouriteButton.SetOnClickListener(this);
            favouriteButton.Tag = position;
            favouriteButton.SetImageResource(item.Favourite ? Android.Resource.Drawable.ButtonStarBigOn : Android.Resource.Drawable.ButtonStarBigOff);

            if (item.Thumbnail != null)
            {
                var bitmap = BitmapFactory.DecodeByteArray(item.Thumbnail, 0, item.Thumbnail.Length);
                view.FindViewById <ImageView>(Resource.Id.Thumbnail).SetImageBitmap(bitmap);
            }

            return(view);
        }
Esempio n. 7
0
        public void Run()
        {
            var imgWidth  = _context.IsPortrait ? _Image.Height : _Image.Width;
            var imgHeight = _context.IsPortrait ? _Image.Width : _Image.Height;

            var thumbWidth  = _context.IsPortrait ? THUMBNAIL_HEIGHT : THUMBNAIL_WIDTH;
            var thumbHeight = _context.IsPortrait ? THUMBNAIL_WIDTH : THUMBNAIL_HEIGHT;

            ByteBuffer buffer = _Image.GetPlanes()[0].Buffer;

            byte[] bytes = new byte[buffer.Remaining()];
            buffer.Get(bytes);

            var filename = ImageSaverUtils.GetPhotoFileName();
            var filepath = System.IO.Path.Combine(ImageSaverUtils.GetPhotosFileFolder(), filename);

            var file = new Java.IO.File(filepath);

            byte[] thumbnail = ImageResizer.ResizeImageAndroid(bytes, thumbWidth, thumbHeight, THUMBNAIL_QUALITY);

            using (var output = new Java.IO.FileOutputStream(file))
            {
                try
                {
                    output.Write(bytes);

                    PoiDatabase poiDatabase    = new PoiDatabase();
                    string      jsonCategories = JsonConvert.SerializeObject(_context.Settings.Categories);

                    var tag = _context.MyLocationPlaceInfo.PlaceName + " -> ";
                    if (_context.SelectedPoi != null)
                    {
                        tag += _context.SelectedPoi.Poi.Name;
                    }
                    else
                    {
                        tag += Android.App.Application.Context.Resources.GetText(Resource.String.Common_Heading);
                        tag += _context.HeadingX.HasValue ? $" {GpsUtils.Normalize360((_context.HeadingX.Value)):F0}°" : "?°";
                    }

                    PhotoData photodata = new PhotoData
                    {
                        Tag                  = tag,
                        Datetime             = DateTime.Now,
                        DatetimeTaken        = DateTime.Now,
                        PhotoFileName        = filename,
                        Longitude            = _context.MyLocation.Longitude,
                        Latitude             = _context.MyLocation.Latitude,
                        Altitude             = _context.MyLocation.Altitude,
                        Heading              = (_context.HeadingX ?? 0) + _context.HeadingCorrector,
                        LeftTiltCorrector    = _context.LeftTiltCorrector,
                        RightTiltCorrector   = _context.RightTiltCorrector,
                        Thumbnail            = thumbnail,
                        JsonCategories       = jsonCategories,
                        ViewAngleVertical    = _context.ViewAngleVertical,
                        ViewAngleHorizontal  = _context.ViewAngleHorizontal,
                        PictureWidth         = imgWidth,
                        PictureHeight        = imgHeight,
                        MinAltitude          = _context.Settings.MinAltitute,
                        MaxDistance          = _context.Settings.MaxDistance,
                        FavouriteFilter      = _context.ShowFavoritesOnly,
                        ShowElevationProfile = _context.Settings.ShowElevationProfile
                    };
                    if (_context.ElevationProfileData != null)
                    {
                        photodata.JsonElevationProfileData = _context.ElevationProfileData.Serialize();
                    }
                    poiDatabase.InsertItem(photodata);
                }
                catch (Java.IO.IOException e)
                {
                    e.PrintStackTrace();
                }
                finally
                {
                    _Image.Close();
                }
            }
        }
Esempio n. 8
0
        public static async Task <PhotoData> Import(string path, ExifData exifData, IAppContext appContext)
        {
            using (FileStream fs = System.IO.File.OpenRead(path))
            {
                byte[] bytes;
                using (BinaryReader br = new BinaryReader(fs))
                {
                    bytes = br.ReadBytes((int)fs.Length);
                }

                var bmp = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);

                var imgWidth    = bmp.Width;
                var imgHeight   = bmp.Height;
                var thumbWidth  = THUMBNAIL_WIDTH;
                var thumbHeight = THUMBNAIL_HEIGHT;

                var filename = ImageSaverUtils.GetPhotoFileName();
                var filepath = System.IO.Path.Combine(ImageSaverUtils.GetPhotosFileFolder(), filename);

                var    file      = new Java.IO.File(filepath);
                byte[] thumbnail = ImageResizer.ResizeImageAndroid(bytes, thumbWidth, thumbHeight, THUMBNAIL_QUALITY);

                using (var output = new Java.IO.FileOutputStream(file))
                {
                    output.Write(bytes);
                }

                PoiDatabase poiDatabase    = new PoiDatabase();
                string      jsonCategories = JsonConvert.SerializeObject(appContext.Settings.Categories);

                PhotoData photodata = new PhotoData
                {
                    Datetime             = DateTime.Now,
                    DatetimeTaken        = exifData.timeTaken ?? DateTime.Now,
                    PhotoFileName        = filename,
                    Longitude            = exifData.location?.Longitude ?? 0,
                    Latitude             = exifData.location?.Latitude ?? 0,
                    Altitude             = exifData.location?.Altitude ?? 0,
                    Heading              = exifData.heading,
                    LeftTiltCorrector    = 0,
                    RightTiltCorrector   = 0,
                    Thumbnail            = thumbnail,
                    JsonCategories       = jsonCategories,
                    PictureWidth         = imgWidth,
                    PictureHeight        = imgHeight,
                    MinAltitude          = appContext.Settings.MinAltitute,
                    MaxDistance          = appContext.Settings.MaxDistance,
                    FavouriteFilter      = appContext.ShowFavoritesOnly,
                    ShowElevationProfile = appContext.Settings.ShowElevationProfile
                };

                //calculate view angle from focal length equivalent on 35mm camera, or use default viev angle 60dg
                var viewAngle = exifData.focalLength35mm.HasValue ? 2 * System.Math.Tan(35d / 2d / (double)exifData.focalLength35mm.Value) / System.Math.PI * 180 : 60;
                if (imgWidth > imgHeight)
                {
                    photodata.ViewAngleHorizontal = viewAngle;
                    photodata.ViewAngleVertical   = viewAngle / imgWidth * imgHeight;
                }
                else
                {
                    photodata.ViewAngleHorizontal = viewAngle / imgHeight * imgWidth;
                    photodata.ViewAngleVertical   = viewAngle;
                }

                if (GpsUtils.HasLocation(exifData.location))
                {
                    var placeInfo = await PlaceNameProvider.AsyncGetPlaceName(exifData.location);

                    photodata.Tag = placeInfo.PlaceName + " -> ?";
                }
                else
                {
                    photodata.Tag = "? -> ?";
                }

                appContext.PhotosModel.InsertItem(photodata);
                return(photodata);
            }
        }