mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Merge pull request #1150 from harisankerPradeep/Bug#954
Bug#954 Take latitude/longitude from picture taken seconds after
This commit is contained in:
commit
38c3eacad4
4 changed files with 259 additions and 4 deletions
|
|
@ -16,6 +16,7 @@ import android.support.annotation.RequiresApi;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.graphics.drawable.VectorDrawableCompat;
|
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -64,7 +65,7 @@ import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
|
||||||
public class ShareActivity
|
public class ShareActivity
|
||||||
extends AuthenticatedActivity
|
extends AuthenticatedActivity
|
||||||
implements SingleUploadFragment.OnUploadActionInitiated,
|
implements SingleUploadFragment.OnUploadActionInitiated,
|
||||||
OnCategoriesSaveHandler {
|
OnCategoriesSaveHandler,SimilarImageDialogFragment.onResponse {
|
||||||
|
|
||||||
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
|
private static final int REQUEST_PERM_ON_CREATE_STORAGE = 1;
|
||||||
private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2;
|
private static final int REQUEST_PERM_ON_CREATE_LOCATION = 2;
|
||||||
|
|
@ -89,6 +90,7 @@ public class ShareActivity
|
||||||
private boolean cacheFound;
|
private boolean cacheFound;
|
||||||
|
|
||||||
private GPSExtractor imageObj;
|
private GPSExtractor imageObj;
|
||||||
|
private GPSExtractor tempImageObj;
|
||||||
private String decimalCoords;
|
private String decimalCoords;
|
||||||
|
|
||||||
private boolean useNewPermissions = false;
|
private boolean useNewPermissions = false;
|
||||||
|
|
@ -99,7 +101,7 @@ public class ShareActivity
|
||||||
private String description;
|
private String description;
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
private boolean duplicateCheckPassed = false;
|
private boolean duplicateCheckPassed = false;
|
||||||
|
private boolean haveCheckedForOtherImages = false;
|
||||||
/**
|
/**
|
||||||
* Called when user taps the submit button.
|
* Called when user taps the submit button.
|
||||||
*/
|
*/
|
||||||
|
|
@ -452,13 +454,93 @@ public class ShareActivity
|
||||||
if (imageObj != null) {
|
if (imageObj != null) {
|
||||||
// Gets image coords from exif data or user location
|
// Gets image coords from exif data or user location
|
||||||
decimalCoords = imageObj.getCoords(gpsEnabled);
|
decimalCoords = imageObj.getCoords(gpsEnabled);
|
||||||
useImageCoords();
|
if(decimalCoords==null || !imageObj.imageCoordsExists){
|
||||||
|
// Check if the location is from GPS or EXIF
|
||||||
|
// Find other photos taken around the same time which has gps coordinates
|
||||||
|
Timber.d("EXIF:false");
|
||||||
|
Timber.d("EXIF call"+(imageObj==tempImageObj));
|
||||||
|
if(!haveCheckedForOtherImages)
|
||||||
|
findOtherImages(gpsEnabled);// Do not do repeat the process
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// As the selected image has GPS data in EXIF go ahead with the same.
|
||||||
|
useImageCoords();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
Timber.w("File not found: " + mediaUri, e);
|
Timber.w("File not found: " + mediaUri, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void findOtherImages(boolean gpsEnabled) {
|
||||||
|
Timber.d("filePath"+getPathOfMediaOrCopy());
|
||||||
|
String filePath = getPathOfMediaOrCopy();
|
||||||
|
long timeOfCreation = new File(filePath).lastModified();//Time when the original image was created
|
||||||
|
File folder = new File(filePath.substring(0,filePath.lastIndexOf('/')));
|
||||||
|
File[] files = folder.listFiles();
|
||||||
|
Timber.d("folderTime Number:"+files.length);
|
||||||
|
|
||||||
|
for(File file : files){
|
||||||
|
if(file.lastModified()-timeOfCreation<=(120*1000) && file.lastModified()-timeOfCreation>=-(120*1000)){
|
||||||
|
//Make sure the photos were taken within 20seconds
|
||||||
|
Timber.d("fild date:"+file.lastModified()+ " time of creation"+timeOfCreation);
|
||||||
|
tempImageObj = null;//Temporary GPSExtractor to extract coords from these photos
|
||||||
|
ParcelFileDescriptor descriptor
|
||||||
|
= null;
|
||||||
|
try {
|
||||||
|
descriptor = getContentResolver().openFileDescriptor(Uri.parse(file.getAbsolutePath()), "r");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
if (descriptor != null) {
|
||||||
|
tempImageObj = new GPSExtractor(descriptor.getFileDescriptor(),this, prefs);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (filePath != null) {
|
||||||
|
tempImageObj = new GPSExtractor(file.getAbsolutePath(), this, prefs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tempImageObj!=null){
|
||||||
|
Timber.d("not null fild EXIF"+tempImageObj.imageCoordsExists +" coords"+tempImageObj.getCoords(gpsEnabled));
|
||||||
|
if(tempImageObj.getCoords(gpsEnabled)!=null && tempImageObj.imageCoordsExists){
|
||||||
|
// Current image has gps coordinates and it's not current gps locaiton
|
||||||
|
Timber.d("This fild has image coords:"+ file.getAbsolutePath());
|
||||||
|
// Create a dialog fragment for the suggestion
|
||||||
|
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
SimilarImageDialogFragment newFragment = new SimilarImageDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putString("originalImagePath",filePath);
|
||||||
|
args.putString("possibleImagePath",file.getAbsolutePath());
|
||||||
|
newFragment.setArguments(args);
|
||||||
|
newFragment.show(fragmentManager, "dialog");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
haveCheckedForOtherImages = true; //Finished checking for other images
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPostiveResponse() {
|
||||||
|
imageObj = tempImageObj;
|
||||||
|
decimalCoords = imageObj.getCoords(false);// Not necessary to use gps as image already ha EXIF data
|
||||||
|
Timber.d("EXIF from tempImageObj");
|
||||||
|
useImageCoords();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNegativeResponse() {
|
||||||
|
Timber.d("EXIF from imageObj");
|
||||||
|
useImageCoords();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates retrieval of image coordinates or user coordinates, and caching of coordinates.
|
* Initiates retrieval of image coordinates or user coordinates, and caching of coordinates.
|
||||||
* Then initiates the calls to MediaWiki API through an instance of MwVolleyApi.
|
* Then initiates the calls to MediaWiki API through an instance of MwVolleyApi.
|
||||||
|
|
@ -466,6 +548,7 @@ public class ShareActivity
|
||||||
public void useImageCoords() {
|
public void useImageCoords() {
|
||||||
if (decimalCoords != null) {
|
if (decimalCoords != null) {
|
||||||
Timber.d("Decimal coords of image: %s", decimalCoords);
|
Timber.d("Decimal coords of image: %s", decimalCoords);
|
||||||
|
Timber.d("is EXIF data present:"+imageObj.imageCoordsExists+" from findOther image:"+(imageObj==tempImageObj));
|
||||||
|
|
||||||
// Only set cache for this point if image has coords
|
// Only set cache for this point if image has coords
|
||||||
if (imageObj.imageCoordsExists) {
|
if (imageObj.imageCoordsExists) {
|
||||||
|
|
@ -489,7 +572,10 @@ public class ShareActivity
|
||||||
Timber.d("Cache found, setting categoryList in MwVolleyApi to %s", displayCatList);
|
Timber.d("Cache found, setting categoryList in MwVolleyApi to %s", displayCatList);
|
||||||
MwVolleyApi.setGpsCat(displayCatList);
|
MwVolleyApi.setGpsCat(displayCatList);
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
Timber.d("EXIF: no coords");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
package fr.free.nrw.commons.upload;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.graphics.drawable.VectorDrawableCompat;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
|
||||||
|
import com.facebook.drawee.view.SimpleDraweeView;
|
||||||
|
import com.facebook.imagepipeline.listener.RequestListener;
|
||||||
|
import com.facebook.imagepipeline.listener.RequestLoggingListener;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by harisanker on 14/2/18.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SimilarImageDialogFragment extends DialogFragment {
|
||||||
|
SimpleDraweeView originalImage;
|
||||||
|
SimpleDraweeView possibleImage;
|
||||||
|
Button positiveButton;
|
||||||
|
Button negativeButton;
|
||||||
|
onResponse mOnResponse;//Implemented interface from shareActivity
|
||||||
|
Boolean gotResponse = false;
|
||||||
|
public SimilarImageDialogFragment() {
|
||||||
|
}
|
||||||
|
public interface onResponse{
|
||||||
|
public void onPostiveResponse();
|
||||||
|
public void onNegativeResponse();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.fragment_similar_image_dialog, container, false);
|
||||||
|
Set<RequestListener> requestListeners = new HashSet<>();
|
||||||
|
requestListeners.add(new RequestLoggingListener());
|
||||||
|
|
||||||
|
originalImage =(SimpleDraweeView) view.findViewById(R.id.orginalImage);
|
||||||
|
possibleImage =(SimpleDraweeView) view.findViewById(R.id.possibleImage);
|
||||||
|
positiveButton = (Button) view.findViewById(R.id.postive_button);
|
||||||
|
negativeButton = (Button) view.findViewById(R.id.negative_button);
|
||||||
|
|
||||||
|
originalImage.setHierarchy(GenericDraweeHierarchyBuilder
|
||||||
|
.newInstance(getResources())
|
||||||
|
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
||||||
|
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
||||||
|
.build());
|
||||||
|
possibleImage.setHierarchy(GenericDraweeHierarchyBuilder
|
||||||
|
.newInstance(getResources())
|
||||||
|
.setPlaceholderImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_image_black_24dp,getContext().getTheme()))
|
||||||
|
.setFailureImage(VectorDrawableCompat.create(getResources(),
|
||||||
|
R.drawable.ic_error_outline_black_24dp, getContext().getTheme()))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
originalImage.setImageURI(Uri.fromFile(new File(getArguments().getString("originalImagePath"))));
|
||||||
|
possibleImage.setImageURI(Uri.fromFile(new File(getArguments().getString("possibleImagePath"))));
|
||||||
|
|
||||||
|
negativeButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
mOnResponse.onNegativeResponse();
|
||||||
|
gotResponse = true;
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
positiveButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
mOnResponse.onPostiveResponse();
|
||||||
|
gotResponse = true;
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
mOnResponse = (onResponse) getActivity();//Interface Implementation
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
Dialog dialog = super.onCreateDialog(savedInstanceState);
|
||||||
|
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
// I user dismisses dialog by pressing outside the dialog.
|
||||||
|
if(!gotResponse)
|
||||||
|
mOnResponse.onNegativeResponse();
|
||||||
|
super.onDismiss(dialog);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
app/src/main/res/layout/fragment_similar_image_dialog.xml
Normal file
57
app/src/main/res/layout/fragment_similar_image_dialog.xml
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
|
android:id="@+id/orginalImage"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="240dp"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
app:actualImageScaleType="centerCrop" />
|
||||||
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
|
android:id="@+id/possibleImage"
|
||||||
|
android:layout_width="160dp"
|
||||||
|
android:layout_height="240dp"
|
||||||
|
android:layout_margin="3dp"
|
||||||
|
app:actualImageScaleType="centerCrop" />
|
||||||
|
</LinearLayout>
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="6dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:text="Did you shoot these two pictures at the same place? Do you want to use the latitude/longitude of the picture on the right?"/>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:id="@+id/negative_button"
|
||||||
|
android:layout_marginRight="3dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="No" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="@style/Widget.AppCompat.Button.Borderless"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/postive_button"
|
||||||
|
android:layout_gravity="right"
|
||||||
|
android:layout_marginLeft="3dp"
|
||||||
|
android:text="Yes" />
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -7,7 +7,7 @@ buildscript {
|
||||||
google()
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath "com.android.tools.build:gradle:${project.gradleVersion}"
|
classpath 'com.android.tools.build:gradle:3.0.1'
|
||||||
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
|
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.1'
|
||||||
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1'
|
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.1'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue