Fixed refactor problem

ImageProcessing class should work now.

TODO: Add conversion method
This commit is contained in:
misaochan 2015-12-17 17:35:24 +13:00
parent e74ead1655
commit 966ff386cd
2 changed files with 17 additions and 9 deletions

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.upload; package fr.free.nrw.commons.upload;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.media.ExifInterface; import android.media.ExifInterface;
import android.net.Uri; import android.net.Uri;
@ -15,12 +16,14 @@ import java.io.IOException;
* Created by misao on 16-Dec-15. * Created by misao on 16-Dec-15.
*/ */
//Needs to extend Activity in order to call getContentResolver(). Might not be the best way? //Needs to extend Activity in order to call getContentResolver(). Might not be the best way?
public class ImageProcessing extends Activity{ public class ImageProcessing {
private Uri uri; private Uri uri;
private ExifInterface exif; private ExifInterface exif;
private Context context;
public ImageProcessing(Uri uri){ public ImageProcessing(Context context, Uri uri){
this.context = context;
this.uri = uri; this.uri = uri;
} }
@ -35,7 +38,7 @@ public class ImageProcessing extends Activity{
// where id is equal to // where id is equal to
String sel = MediaStore.Images.Media._ID + "=?"; String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{id}, null); column, sel, new String[]{id}, null);
int columnIndex = cursor.getColumnIndex(column[0]); int columnIndex = cursor.getColumnIndex(column[0]);
@ -51,14 +54,22 @@ public class ImageProcessing extends Activity{
public String getLatitude(String filePath) { public String getLatitude(String filePath) {
String latitude = ""; String latitude = "";
String longitude = "";
String latitude_ref = "";
String longitude_ref = "";
try { try {
exif = new ExifInterface(filePath); exif = new ExifInterface(filePath);
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
Log.d("Image", "Latitude: " + latitude); latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
longitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.w("Image", e);
} }
return latitude; return latitude;
} }

View file

@ -175,9 +175,6 @@ public class ShareActivity
mediaUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM); mediaUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if(intent.hasExtra(UploadService.EXTRA_SOURCE)) { if(intent.hasExtra(UploadService.EXTRA_SOURCE)) {
source = intent.getStringExtra(UploadService.EXTRA_SOURCE); source = intent.getStringExtra(UploadService.EXTRA_SOURCE);
//Bundle bundle = intent.getExtras();
//String filepath = bundle.getString("file_path");
//Log.d(TAG, "Filepath: " + filepath);
} else { } else {
source = Contribution.SOURCE_EXTERNAL; source = Contribution.SOURCE_EXTERNAL;
} }
@ -188,7 +185,7 @@ public class ShareActivity
mediaUriString = mediaUri.toString(); mediaUriString = mediaUri.toString();
Log.d(TAG, "Uri: " + mediaUriString); Log.d(TAG, "Uri: " + mediaUriString);
ImageProcessing imageObj = new ImageProcessing(mediaUri); ImageProcessing imageObj = new ImageProcessing(getApplicationContext(), mediaUri);
String filePath = imageObj.getFilePath(); String filePath = imageObj.getFilePath();
String latitude = imageObj.getLatitude(filePath); String latitude = imageObj.getLatitude(filePath);