mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Fixes crashes
Implements null checking to prevent app from crashing when URI is invalid or when picture has no GPS information
This commit is contained in:
parent
77b8ab0c4c
commit
4a400df5dd
3 changed files with 50 additions and 29 deletions
|
|
@ -23,7 +23,10 @@ public class FilePathConverter {
|
||||||
* May return null
|
* May return null
|
||||||
*/
|
*/
|
||||||
public String getFilePath(){
|
public String getFilePath(){
|
||||||
|
|
||||||
String filePath ="";
|
String filePath ="";
|
||||||
|
|
||||||
|
try {
|
||||||
// Will return "image:x*"
|
// Will return "image:x*"
|
||||||
String wholeID = DocumentsContract.getDocumentId(uri);
|
String wholeID = DocumentsContract.getDocumentId(uri);
|
||||||
|
|
||||||
|
|
@ -46,4 +49,10 @@ public class FilePathConverter {
|
||||||
Log.d("Image", "File path: " + filePath);
|
Log.d("Image", "File path: " + filePath);
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
Log.w("Image", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,17 @@ public class GPSExtractor {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exif = new ExifInterface(filePath);
|
exif = new ExifInterface(filePath);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.w("Image", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) == null) {
|
||||||
|
Log.w("Image", "Picture has no GPS info");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
|
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
|
||||||
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
|
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
|
||||||
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
|
longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
|
||||||
|
|
@ -35,12 +46,9 @@ public class GPSExtractor {
|
||||||
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
||||||
|
|
||||||
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.w("Image", e);
|
|
||||||
}
|
|
||||||
return decimalCoords;
|
return decimalCoords;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Converts format of coords into decimal coords as required by API for next step
|
//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) {
|
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
|
||||||
|
|
@ -179,11 +179,13 @@ public class ShareActivity
|
||||||
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
|
FilePathConverter uriObj = new FilePathConverter(this, mediaUri);
|
||||||
String filePath = uriObj.getFilePath();
|
String filePath = uriObj.getFilePath();
|
||||||
|
|
||||||
|
if (filePath != null) {
|
||||||
//extract the coordinates of image in decimal degrees
|
//extract the coordinates of image in decimal degrees
|
||||||
GPSExtractor imageObj = new GPSExtractor(filePath);
|
GPSExtractor imageObj = new GPSExtractor(filePath);
|
||||||
String coords = imageObj.getCoords();
|
String coords = imageObj.getCoords();
|
||||||
Log.d("Image", "Coords of image: " + coords);
|
|
||||||
|
|
||||||
|
if (coords != null) {
|
||||||
|
Log.d("Image", "Coords of image: " + coords);
|
||||||
MwVolleyApi apiCall = new MwVolleyApi(this);
|
MwVolleyApi apiCall = new MwVolleyApi(this);
|
||||||
|
|
||||||
//build URL with image coords for MediaWiki API calls
|
//build URL with image coords for MediaWiki API calls
|
||||||
|
|
@ -192,6 +194,8 @@ public class ShareActivity
|
||||||
|
|
||||||
//asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories
|
//asynchronous calls to MediaWiki Commons API to match image coords with nearby Commons categories
|
||||||
apiCall.request(apiUrl);
|
apiCall.request(apiUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue