16
16
17
17
package androidxc .camera .core .impl .utils ;
18
18
19
- import android .annotation .SuppressLint ;
20
19
import android .location .Location ;
21
20
22
21
import androidx .annotation .NonNull ;
23
22
import androidx .annotation .Nullable ;
24
- import androidx .annotation .RequiresApi ;
23
+ import androidx .annotation .VisibleForTesting ;
25
24
import androidx .camera .core .ImageProxy ;
26
25
import androidx .camera .core .Logger ;
27
26
import androidxc .exifinterface .media .ExifInterface ;
38
37
import java .util .Date ;
39
38
import java .util .List ;
40
39
import java .util .Locale ;
40
+ import java .util .Objects ;
41
41
42
42
/**
43
43
* Utility class for modifying metadata on JPEG files.
44
44
*
45
45
* <p>Call {@link #save()} to persist changes to disc.
46
46
*/
47
- @ SuppressLint ("RestrictedApi" )
48
- @ RequiresApi (21 ) // TODO(b/200306659): Remove and replace with annotation on package-info.java
49
47
public final class Exif {
50
48
51
49
/** Timestamp value indicating a timestamp value that is either not set or not valid */
52
50
public static final long INVALID_TIMESTAMP = -1 ;
51
+ // Forked from ExifInterface.TAG_THUMBNAIL_ORIENTATION. The value is library-internal so we
52
+ // can't depend on it directly.
53
+ public static final String TAG_THUMBNAIL_ORIENTATION = "ThumbnailOrientation" ;
53
54
54
55
private static final String TAG = Exif .class .getSimpleName ();
55
56
@@ -94,7 +95,7 @@ public SimpleDateFormat initialValue() {
94
95
ExifInterface .TAG_JPEG_INTERCHANGE_FORMAT_LENGTH ,
95
96
ExifInterface .TAG_THUMBNAIL_IMAGE_LENGTH ,
96
97
ExifInterface .TAG_THUMBNAIL_IMAGE_WIDTH ,
97
- ExifInterface . TAG_THUMBNAIL_ORIENTATION );
98
+ TAG_THUMBNAIL_ORIENTATION );
98
99
99
100
private final ExifInterface mExifInterface ;
100
101
@@ -187,7 +188,8 @@ public void copyToCroppedImage(@NonNull Exif croppedExif) {
187
188
exifTags .removeAll (DO_NOT_COPY_EXIF_TAGS );
188
189
for (String tag : exifTags ) {
189
190
String originalValue = mExifInterface .getAttribute (tag );
190
- if (originalValue != null ) {
191
+ String croppedExifValue = croppedExif .mExifInterface .getAttribute (tag );
192
+ if (originalValue != null && !Objects .equals (originalValue , croppedExifValue )) {
191
193
croppedExif .mExifInterface .setAttribute (tag , originalValue );
192
194
}
193
195
}
@@ -603,6 +605,17 @@ public void flipHorizontally() {
603
605
mExifInterface .setAttribute (ExifInterface .TAG_ORIENTATION , String .valueOf (orientation ));
604
606
}
605
607
608
+ @ VisibleForTesting
609
+ @ Nullable
610
+ public String getMetadata () {
611
+ return mExifInterface .getAttribute (ExifInterface .TAG_XMP );
612
+ }
613
+
614
+ @ NonNull
615
+ public ExifInterface getExifInterface () {
616
+ return mExifInterface ;
617
+ }
618
+
606
619
/** Attaches the current timestamp to the file. */
607
620
public void attachTimestamp () {
608
621
long now = System .currentTimeMillis ();
@@ -690,11 +703,6 @@ private static final class Speed {
690
703
static Converter fromKilometersPerHour (double kph ) {
691
704
return new Converter (kph * 0.621371 );
692
705
}
693
-
694
- static Converter fromMetersPerSecond (double mps ) {
695
- return new Converter (mps * 2.23694 );
696
- }
697
-
698
706
static Converter fromMilesPerHour (double mph ) {
699
707
return new Converter (mph );
700
708
}
@@ -710,18 +718,6 @@ static final class Converter {
710
718
mMph = mph ;
711
719
}
712
720
713
- double toKilometersPerHour () {
714
- return mMph / 0.621371 ;
715
- }
716
-
717
- double toMilesPerHour () {
718
- return mMph ;
719
- }
720
-
721
- double toKnots () {
722
- return mMph / 1.15078 ;
723
- }
724
-
725
721
double toMetersPerSecond () {
726
722
return mMph / 2.23694 ;
727
723
}
@@ -873,7 +869,7 @@ public static List<String> getAllExifTags() {
873
869
ExifInterface .TAG_INTEROPERABILITY_INDEX ,
874
870
ExifInterface .TAG_THUMBNAIL_IMAGE_LENGTH ,
875
871
ExifInterface .TAG_THUMBNAIL_IMAGE_WIDTH ,
876
- ExifInterface . TAG_THUMBNAIL_ORIENTATION ,
872
+ TAG_THUMBNAIL_ORIENTATION ,
877
873
ExifInterface .TAG_DNG_VERSION ,
878
874
ExifInterface .TAG_DEFAULT_CROP_SIZE ,
879
875
ExifInterface .TAG_ORF_THUMBNAIL_IMAGE ,
@@ -890,9 +886,5 @@ public static List<String> getAllExifTags() {
890
886
ExifInterface .TAG_NEW_SUBFILE_TYPE ,
891
887
ExifInterface .TAG_SUBFILE_TYPE );
892
888
}
893
-
894
- public ExifInterface getExifInterface () {
895
- return mExifInterface ;
896
- }
897
889
}
898
890
0 commit comments