diff --git a/src/main/java/com/example/liliyayankova/unirides/ImageProperties.java b/src/main/java/com/example/liliyayankova/unirides/ImageProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..42aeab403833f5f3f60f1e2920e12035fcdea221 --- /dev/null +++ b/src/main/java/com/example/liliyayankova/unirides/ImageProperties.java @@ -0,0 +1,134 @@ +package com.example.liliyayankova.unirides; + +import android.media.ExifInterface; +import android.net.Uri; +import android.util.Log; + +class ImageProperties { + /** Path to the image we want to display... */ + private Uri imagePath; + + public ImageProperties( Uri imageUri) + { + imagePath = imageUri; + } + + /** + * Method for getting the orientation of the image to be displayed on the main scree. + * We use the ExifInterface class that gives access to the EXIF metadata of an image. + * + * @return The orientation of the image + */ + public int getCameraPhotoOrientation() + { + int rotate = 0; + try { + ExifInterface exif = new ExifInterface(imagePath.getPath()); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED); + + float longitude = convertToDegree(exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE)); + + float latitude = convertToDegree(exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE)); + //this is in a degree minute seconds format a + Log.i("Image Address", longitude + " ," + latitude); + + switch (orientation) { + case ExifInterface.ORIENTATION_ROTATE_270: + rotate = 270; + break; + case ExifInterface.ORIENTATION_ROTATE_180: + rotate = 180; + break; + case ExifInterface.ORIENTATION_ROTATE_90: + rotate = 90; + break; + } + } catch (Exception e) { + e.printStackTrace(); + } + //tells you how much rotation you need + + Log.v("ROTATION:", "Rotate Value: " + rotate); + return rotate; + } + + /** + * Method for returning the longitude of the image to be displayed. + * @return + */ + public Float getCameraAddressLong() + { + String longitude = null; + try { +// context.getContentResolver().notifyChange(imageUri, null); + // File imageFile = new File(imagePath); + + //reading the tags from the JPEG file + ExifInterface exif = new ExifInterface(imagePath.getPath()); + longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); + + + //this is in a degree minute seconds format a + Log.i("Image Address", convertToDegree(longitude) +"as double"); + + + + } catch (Exception e) { + e.printStackTrace(); + } + //tells you how much rotation you need + return convertToDegree(longitude); + } + + /** + * Method for returning the latitude of the image to be displayed. + * @return + */ + public Float getCameraAddressLat() + { + String latitude = null; + try { +// context.getContentResolver().notifyChange(imageUri, null); + // File imageFile = new File(imagePath); + + //reading the tags from the JPEG file + ExifInterface exif = new ExifInterface(imagePath.getPath()); + latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); + + + //this is in a degree minute seconds format a + Log.i("Image Address", convertToDegree(latitude) +"as double"); + + + + } catch (Exception e) { + e.printStackTrace(); + } + //tells you how much rotation you need + return convertToDegree(latitude); + } + + private Float convertToDegree(String stringDMS){ + Float result = null; + String[] DMS = stringDMS.split(",", 3); + + String[] stringD = DMS[0].split("/", 2); + Double D0 = new Double(stringD[0]); + Double D1 = new Double(stringD[1]); + Double FloatD = D0/D1; + + String[] stringM = DMS[1].split("/", 2); + Double M0 = new Double(stringM[0]); + Double M1 = new Double(stringM[1]); + Double FloatM = M0/M1; + + String[] stringS = DMS[2].split("/", 2); + Double S0 = new Double(stringS[0]); + Double S1 = new Double(stringS[1]); + Double FloatS = S0/S1; + + result = new Float(FloatD + (FloatM/60) + (FloatS/3600)); + + return result; + } +}