mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Attempt at tidying code into a new class
getContentResolver() method does not work
This commit is contained in:
parent
c5fd006dd5
commit
e74ead1655
2 changed files with 70 additions and 35 deletions
|
|
@ -0,0 +1,66 @@
|
||||||
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.media.ExifInterface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.DocumentsContract;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by misao on 16-Dec-15.
|
||||||
|
*/
|
||||||
|
//Needs to extend Activity in order to call getContentResolver(). Might not be the best way?
|
||||||
|
public class ImageProcessing extends Activity{
|
||||||
|
|
||||||
|
private Uri uri;
|
||||||
|
private ExifInterface exif;
|
||||||
|
|
||||||
|
public ImageProcessing(Uri uri){
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath(){
|
||||||
|
String filePath ="";
|
||||||
|
// Will return "image:x*"
|
||||||
|
String wholeID = DocumentsContract.getDocumentId(uri);
|
||||||
|
|
||||||
|
// Split at colon, use second item in the array
|
||||||
|
String id = wholeID.split(":")[1];
|
||||||
|
String[] column = { MediaStore.Images.Media.DATA };
|
||||||
|
|
||||||
|
// where id is equal to
|
||||||
|
String sel = MediaStore.Images.Media._ID + "=?";
|
||||||
|
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
|
column, sel, new String[]{id}, null);
|
||||||
|
|
||||||
|
int columnIndex = cursor.getColumnIndex(column[0]);
|
||||||
|
|
||||||
|
if (cursor.moveToFirst()) {
|
||||||
|
filePath = cursor.getString(columnIndex);
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
|
Log.d("Image", "File path: " + filePath);
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatitude(String filePath) {
|
||||||
|
String latitude = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
exif = new ExifInterface(filePath);
|
||||||
|
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
|
||||||
|
Log.d("Image", "Latitude: " + latitude);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return latitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -42,8 +42,7 @@ public class ShareActivity
|
||||||
private String source;
|
private String source;
|
||||||
private String mimeType;
|
private String mimeType;
|
||||||
private String mediaUriString;
|
private String mediaUriString;
|
||||||
private String mediaUriPath;
|
private String filePath = "";
|
||||||
private String mediaUriAbsPath;
|
|
||||||
|
|
||||||
private static final String TAG = "Image";
|
private static final String TAG = "Image";
|
||||||
|
|
||||||
|
|
@ -189,43 +188,13 @@ public class ShareActivity
|
||||||
mediaUriString = mediaUri.toString();
|
mediaUriString = mediaUri.toString();
|
||||||
Log.d(TAG, "Uri: " + mediaUriString);
|
Log.d(TAG, "Uri: " + mediaUriString);
|
||||||
|
|
||||||
mediaUriPath = mediaUri.getPath();
|
ImageProcessing imageObj = new ImageProcessing(mediaUri);
|
||||||
|
String filePath = imageObj.getFilePath();
|
||||||
|
String latitude = imageObj.getLatitude(filePath);
|
||||||
|
|
||||||
// Will return "image:x*"
|
|
||||||
String wholeID = DocumentsContract.getDocumentId(mediaUri);
|
|
||||||
|
|
||||||
// Split at colon, use second item in the array
|
|
||||||
String id = wholeID.split(":")[1];
|
|
||||||
|
|
||||||
String[] column = { MediaStore.Images.Media.DATA };
|
|
||||||
|
|
||||||
// where id is equal to
|
|
||||||
String sel = MediaStore.Images.Media._ID + "=?";
|
|
||||||
|
|
||||||
Cursor cursor = getContentResolver().
|
|
||||||
query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
|
||||||
column, sel, new String[]{ id }, null);
|
|
||||||
|
|
||||||
String filePath = "";
|
|
||||||
|
|
||||||
int columnIndex = cursor.getColumnIndex(column[0]);
|
|
||||||
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
filePath = cursor.getString(columnIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.close();
|
|
||||||
|
|
||||||
Log.d(TAG, "Path 1: " + mediaUriPath);
|
|
||||||
Log.d(TAG, "Path 2: " + filePath);
|
|
||||||
|
|
||||||
try {
|
|
||||||
exif = new ExifInterface(filePath);
|
|
||||||
String latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
|
|
||||||
Log.d("Image", "Latitude: " + latitude);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue