mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Remove dependency on Exif parsing library. (#2947)
* Remove dependency on Exif parsing library. * Fix test.
This commit is contained in:
parent
dfe59c4034
commit
04d9db3477
6 changed files with 58 additions and 116 deletions
|
|
@ -1,18 +1,15 @@
|
|||
package fr.free.nrw.commons.filepicker;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.exifinterface.media.ExifInterface;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.drew.imaging.ImageMetadataReader;
|
||||
import com.drew.imaging.ImageProcessingException;
|
||||
import com.drew.metadata.Metadata;
|
||||
import com.drew.metadata.exif.ExifSubIFDDirectory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
|
@ -125,16 +122,13 @@ public class UploadableFile implements Parcelable {
|
|||
* @return
|
||||
*/
|
||||
private DateTimeWithSource getDateTimeFromExif() {
|
||||
Metadata metadata;
|
||||
try {
|
||||
metadata = ImageMetadataReader.readMetadata(file);
|
||||
ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
|
||||
if (directory!=null && directory.containsTag(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL)) {
|
||||
Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
|
||||
ExifInterface exif = new ExifInterface(file.getAbsolutePath());
|
||||
@SuppressLint("RestrictedApi") long dateTime = exif.getDateTime();
|
||||
if (dateTime != -1) {
|
||||
Date date = new Date(dateTime);
|
||||
return new DateTimeWithSource(date, DateTimeWithSource.EXIF_SOURCE);
|
||||
}
|
||||
} catch (ImageProcessingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue