mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
commit
31f78b4b6b
6 changed files with 161 additions and 8 deletions
|
|
@ -80,6 +80,7 @@ public class ContributionController {
|
||||||
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
|
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Log.i("Image", "Image selected");
|
||||||
activity.startActivity(shareIntent);
|
activity.startActivity(shareIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,7 @@ public class MediaDetailFragment extends SherlockFragment {
|
||||||
MediaWikiImageView mwImage = (MediaWikiImageView)image;
|
MediaWikiImageView mwImage = (MediaWikiImageView)image;
|
||||||
mwImage.setLoadingView(loadingProgress); //FIXME: Set this as an attribute
|
mwImage.setLoadingView(loadingProgress); //FIXME: Set this as an attribute
|
||||||
mwImage.setMedia(media, loader);
|
mwImage.setMedia(media, loader);
|
||||||
|
|
||||||
Log.d("Volley", actualUrl);
|
Log.d("Volley", actualUrl);
|
||||||
// FIXME: For transparent images
|
// FIXME: For transparent images
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.provider.DocumentsContract;
|
||||||
|
import android.provider.MediaStore;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class FilePathConverter {
|
||||||
|
|
||||||
|
private Uri uri;
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public FilePathConverter(Context context, Uri uri) {
|
||||||
|
this.context = context;
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets file path of image from its Uri
|
||||||
|
* May return null
|
||||||
|
*/
|
||||||
|
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 = context.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,90 @@
|
||||||
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
import android.media.ExifInterface;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
public class GPSExtractor {
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
public GPSExtractor(String filePath){
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Extract GPS coords of image
|
||||||
|
public String getCoords() {
|
||||||
|
|
||||||
|
ExifInterface exif;
|
||||||
|
String latitude = "";
|
||||||
|
String longitude = "";
|
||||||
|
String latitude_ref = "";
|
||||||
|
String longitude_ref = "";
|
||||||
|
String decimalCoords = "";
|
||||||
|
|
||||||
|
try {
|
||||||
|
exif = new ExifInterface(filePath);
|
||||||
|
latitude = exif.getAttribute(ExifInterface.TAG_GPS_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);
|
||||||
|
|
||||||
|
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w("Image", e);
|
||||||
|
}
|
||||||
|
return decimalCoords;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Converts format of coords into decimal coords as required by API for next step
|
||||||
|
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
||||||
|
double decLatitude, decLongitude;
|
||||||
|
|
||||||
|
if(latitude_ref.equals("N")){
|
||||||
|
decLatitude = convertToDegree(latitude);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
decLatitude = 0 - convertToDegree(latitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(longitude_ref.equals("E")){
|
||||||
|
decLongitude = convertToDegree(longitude);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
decLongitude = 0 - convertToDegree(longitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (String.valueOf(decLatitude) + "|" + String.valueOf(decLongitude));
|
||||||
|
}
|
||||||
|
|
||||||
|
private double convertToDegree(String stringDMS){
|
||||||
|
double result;
|
||||||
|
String[] DMS = stringDMS.split(",", 3);
|
||||||
|
|
||||||
|
String[] stringD = DMS[0].split("/", 2);
|
||||||
|
double d0 = Double.parseDouble(stringD[0]);
|
||||||
|
double d1 = Double.parseDouble(stringD[1]);
|
||||||
|
double degrees = d0/d1;
|
||||||
|
|
||||||
|
String[] stringM = DMS[1].split("/", 2);
|
||||||
|
double m0 = Double.parseDouble(stringM[0]);
|
||||||
|
double m1 = Double.parseDouble(stringM[1]);
|
||||||
|
double minutes = m0/m1;
|
||||||
|
|
||||||
|
String[] stringS = DMS[2].split("/", 2);
|
||||||
|
double s0 = Double.parseDouble(stringS[0]);
|
||||||
|
double s1 = Double.parseDouble(stringS[1]);
|
||||||
|
double seconds = s0/s1;
|
||||||
|
|
||||||
|
result = degrees + (minutes/60) + (seconds/3600);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,8 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import android.net.*;
|
import android.net.*;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
import fr.free.nrw.commons.*;
|
import fr.free.nrw.commons.*;
|
||||||
|
|
@ -30,14 +32,11 @@ public class ShareActivity
|
||||||
private SingleUploadFragment shareView;
|
private SingleUploadFragment shareView;
|
||||||
private CategorizationFragment categorizationFragment;
|
private CategorizationFragment categorizationFragment;
|
||||||
|
|
||||||
public ShareActivity() {
|
|
||||||
super(WikiAccountAuthenticator.COMMONS_ACCOUNT_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private CommonsApplication app;
|
private CommonsApplication app;
|
||||||
|
|
||||||
private String source;
|
private String source;
|
||||||
private String mimeType;
|
private String mimeType;
|
||||||
|
private String mediaUriString;
|
||||||
|
|
||||||
private Uri mediaUri;
|
private Uri mediaUri;
|
||||||
|
|
||||||
|
|
@ -47,10 +46,14 @@ public class ShareActivity
|
||||||
|
|
||||||
private UploadController uploadController;
|
private UploadController uploadController;
|
||||||
|
|
||||||
|
public ShareActivity() {
|
||||||
|
super(WikiAccountAuthenticator.COMMONS_ACCOUNT_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
public void uploadActionInitiated(String title, String description) {
|
public void uploadActionInitiated(String title, String description) {
|
||||||
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
|
Toast startingToast = Toast.makeText(getApplicationContext(), R.string.uploading_started, Toast.LENGTH_LONG);
|
||||||
startingToast.show();
|
startingToast.show();
|
||||||
uploadController.startUpload(title, mediaUri, description, mimeType, source, new UploadController.ContributionUploadProgress() {
|
uploadController.startUpload(title, mediaUri, description, mimeType, source, new UploadController.ContributionUploadProgress() {
|
||||||
public void onUploadStarted(Contribution contribution) {
|
public void onUploadStarted(Contribution contribution) {
|
||||||
ShareActivity.this.contribution = contribution;
|
ShareActivity.this.contribution = contribution;
|
||||||
showPostUpload();
|
showPostUpload();
|
||||||
|
|
@ -154,7 +157,6 @@ public class ShareActivity
|
||||||
setContentView(R.layout.activity_share);
|
setContentView(R.layout.activity_share);
|
||||||
|
|
||||||
app = (CommonsApplication)this.getApplicationContext();
|
app = (CommonsApplication)this.getApplicationContext();
|
||||||
|
|
||||||
backgroundImageView = (ImageView)findViewById(R.id.backgroundImage);
|
backgroundImageView = (ImageView)findViewById(R.id.backgroundImage);
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
|
|
@ -170,7 +172,18 @@ public class ShareActivity
|
||||||
mimeType = intent.getType();
|
mimeType = intent.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(mediaUri.toString(), backgroundImageView);
|
mediaUriString = mediaUri.toString();
|
||||||
|
Log.d("Image", "Uri: " + mediaUriString);
|
||||||
|
|
||||||
|
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
|
||||||
|
String filePath = uriObj.getFilePath();
|
||||||
|
|
||||||
|
GPSExtractor imageObj = new GPSExtractor(filePath);
|
||||||
|
String coords = imageObj.getCoords();
|
||||||
|
Log.d("Image", "Coords of image: " + coords);
|
||||||
|
|
||||||
|
|
||||||
|
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||||
|
|
||||||
if(savedInstanceState != null) {
|
if(savedInstanceState != null) {
|
||||||
contribution = savedInstanceState.getParcelable("contribution");
|
contribution = savedInstanceState.getParcelable("contribution");
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@ public class UploadService extends HandlerService<Contribution> {
|
||||||
this.contribution = contribution;
|
this.contribution = contribution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProgress(long transferred, long total) {
|
public void onProgress(long transferred, long total) {
|
||||||
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
|
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
|
||||||
if(!notificationTitleChanged) {
|
if(!notificationTitleChanged) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue