Search in sources :

Example 26 with ExifInterface

use of android.support.media.ExifInterface in project iNaturalistAndroid by inaturalist.

the class ObservationEditor method setCurrentLocation.

private void setCurrentLocation(Location location) {
    mCurrentLocation = location;
    // Update any external photos taken through the app with the coordinates
    for (String filename : mCameraPhotos) {
        try {
            ExifInterface exif;
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();
            exif = new ExifInterface(filename);
            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPSEncoder.convert(latitude));
            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, GPSEncoder.latitudeRef(latitude));
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPSEncoder.convert(longitude));
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, GPSEncoder.longitudeRef(longitude));
            exif.saveAttributes();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    mObservation.latitude = location.getLatitude();
    mObservation.longitude = location.getLongitude();
    if ((mObservation.geoprivacy != null) && ((mObservation.geoprivacy.equals("private") || mObservation.geoprivacy.equals("obscured")))) {
        mObservation.private_longitude = mObservation.longitude;
        mObservation.private_latitude = mObservation.latitude;
    }
    mLatitudeView.setText(Double.toString(location.getLatitude()));
    mLongitudeView.setText(Double.toString(location.getLongitude()));
    findViewById(R.id.coordinates).setVisibility(View.VISIBLE);
    if (location.hasAccuracy()) {
        mAccuracyView.setText(Float.toString(location.getAccuracy()));
        mObservation.positional_accuracy = ((Float) location.getAccuracy()).intValue();
        findViewById(R.id.accuracy_prefix).setVisibility(View.VISIBLE);
        findViewById(R.id.accuracy).setVisibility(View.VISIBLE);
    } else {
        findViewById(R.id.accuracy_prefix).setVisibility(View.GONE);
        findViewById(R.id.accuracy).setVisibility(View.GONE);
    }
    if (Intent.ACTION_INSERT.equals(getIntent().getAction())) {
        mObservation.latitude_was = mObservation.latitude;
        mObservation.longitude_was = mObservation.longitude;
        mObservation.positional_accuracy_was = mObservation.positional_accuracy;
    }
    if (isNetworkAvailable()) {
        guessLocation();
    } else {
        setPlaceGuess(null);
    }
}
Also used : ExifInterface(android.support.media.ExifInterface) IOException(java.io.IOException)

Aggregations

ExifInterface (android.support.media.ExifInterface)26 IOException (java.io.IOException)21 InputStream (java.io.InputStream)12 Bitmap (android.graphics.Bitmap)4 Date (java.util.Date)4 BitmapFactory (android.graphics.BitmapFactory)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 ParseException (java.text.ParseException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ContentResolver (android.content.ContentResolver)2 AssetFileDescriptor (android.content.res.AssetFileDescriptor)2 Resources (android.content.res.Resources)2 Cursor (android.database.Cursor)2 Matrix (android.graphics.Matrix)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Locale (java.util.Locale)2