am f22b7410: Merge change 25464 into eclair
Merge commit 'f22b74103a2ea2fecdb80deb6a0baffa84e66776' into eclair-plus-aosp * commit 'f22b74103a2ea2fecdb80deb6a0baffa84e66776': Improve ExifInterface API.
This commit is contained in:
@@ -77640,8 +77640,8 @@
|
|||||||
<parameter name="tag" type="java.lang.String">
|
<parameter name="tag" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="getDateTime"
|
<method name="getAttributeInt"
|
||||||
return="long"
|
return="int"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
native="false"
|
native="false"
|
||||||
synchronized="false"
|
synchronized="false"
|
||||||
@@ -77650,20 +77650,13 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
|
<parameter name="tag" type="java.lang.String">
|
||||||
|
</parameter>
|
||||||
|
<parameter name="defaultValue" type="int">
|
||||||
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="getLatLong"
|
<method name="getLatLong"
|
||||||
return="float[]"
|
return="boolean"
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
</method>
|
|
||||||
<method name="getOrientationString"
|
|
||||||
return="java.lang.String"
|
|
||||||
abstract="false"
|
abstract="false"
|
||||||
native="false"
|
native="false"
|
||||||
synchronized="false"
|
synchronized="false"
|
||||||
@@ -77672,6 +77665,8 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
|
<parameter name="output" type="float[]">
|
||||||
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="getThumbnail"
|
<method name="getThumbnail"
|
||||||
return="byte[]"
|
return="byte[]"
|
||||||
@@ -77684,17 +77679,6 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
<method name="getWhiteBalanceString"
|
|
||||||
return="java.lang.String"
|
|
||||||
abstract="false"
|
|
||||||
native="false"
|
|
||||||
synchronized="false"
|
|
||||||
static="false"
|
|
||||||
final="false"
|
|
||||||
deprecated="not deprecated"
|
|
||||||
visibility="public"
|
|
||||||
>
|
|
||||||
</method>
|
|
||||||
<method name="hasThumbnail"
|
<method name="hasThumbnail"
|
||||||
return="boolean"
|
return="boolean"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ public class ExifInterface {
|
|||||||
|
|
||||||
private String mFilename;
|
private String mFilename;
|
||||||
private HashMap<String, String> mAttributes;
|
private HashMap<String, String> mAttributes;
|
||||||
private boolean mHasThumbnail = false;
|
private boolean mHasThumbnail;
|
||||||
|
|
||||||
// Because the underlying implementation (jhead) uses static variables,
|
// Because the underlying implementation (jhead) uses static variables,
|
||||||
// there can only be one user at a time for the native functions (and
|
// there can only be one user at a time for the native functions (and
|
||||||
// they cannot keep state in the native code across function calls). We
|
// they cannot keep state in the native code across function calls). We
|
||||||
// use sLock the serialize the accesses.
|
// use sLock to serialize the accesses.
|
||||||
private static Object sLock = new Object();
|
private static Object sLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +81,7 @@ public class ExifInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value of the specified tag or {@code null} if there
|
* Returns the value of the specified tag or {@code null} if there
|
||||||
* is no such tag in the file.
|
* is no such tag in the JPEG file.
|
||||||
*
|
*
|
||||||
* @param tag the name of the tag.
|
* @param tag the name of the tag.
|
||||||
*/
|
*/
|
||||||
@@ -89,6 +89,24 @@ public class ExifInterface {
|
|||||||
return mAttributes.get(tag);
|
return mAttributes.get(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the integer value of the specified tag. If there is no such tag
|
||||||
|
* in the JPEG file or the value cannot be parsed as integer, return
|
||||||
|
* @{code defaultValue}.
|
||||||
|
*
|
||||||
|
* @param tag the name of the tag.
|
||||||
|
* @param defaultValue the value to return if the tag is not available.
|
||||||
|
*/
|
||||||
|
public int getAttributeInt(String tag, int defaultValue) {
|
||||||
|
String value = mAttributes.get(tag);
|
||||||
|
if (value == null) return defaultValue;
|
||||||
|
try {
|
||||||
|
return Integer.valueOf(value);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the value of the specified tag.
|
* Set the value of the specified tag.
|
||||||
*
|
*
|
||||||
@@ -109,7 +127,7 @@ public class ExifInterface {
|
|||||||
* This function also initialize mHasThumbnail to indicate whether the
|
* This function also initialize mHasThumbnail to indicate whether the
|
||||||
* file has a thumbnail inside.
|
* file has a thumbnail inside.
|
||||||
*/
|
*/
|
||||||
private void loadAttributes() {
|
private void loadAttributes() throws IOException {
|
||||||
// format of string passed from native C code:
|
// format of string passed from native C code:
|
||||||
// "attrCnt attr1=valueLen value1attr2=value2Len value2..."
|
// "attrCnt attr1=valueLen value1attr2=value2Len value2..."
|
||||||
// example:
|
// example:
|
||||||
@@ -153,9 +171,9 @@ public class ExifInterface {
|
|||||||
/**
|
/**
|
||||||
* Save the tag data into the JPEG file. This is expensive because it involves
|
* Save the tag data into the JPEG file. This is expensive because it involves
|
||||||
* copying all the JPG data from one file to another and deleting the old file
|
* copying all the JPG data from one file to another and deleting the old file
|
||||||
* and renaming the other. It's best to use {@link #setAttribute(String,String)} to set all
|
* and renaming the other. It's best to use {@link #setAttribute(String,String)}
|
||||||
* attributes to write and make a single call rather than multiple calls for
|
* to set all attributes to write and make a single call rather than multiple
|
||||||
* each attribute.
|
* calls for each attribute.
|
||||||
*/
|
*/
|
||||||
public void saveAttributes() throws IOException {
|
public void saveAttributes() throws IOException {
|
||||||
// format of string passed to native C code:
|
// format of string passed to native C code:
|
||||||
@@ -195,6 +213,8 @@ public class ExifInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the thumbnail inside the JPEG file, or {@code null} if there is no thumbnail.
|
* Returns the thumbnail inside the JPEG file, or {@code null} if there is no thumbnail.
|
||||||
|
* The returned data is in JPEG format and can be decoded using
|
||||||
|
* {@link android.graphics.BitmapFactory#decodeByteArray(byte[],int,int)}
|
||||||
*/
|
*/
|
||||||
public byte[] getThumbnail() {
|
public byte[] getThumbnail() {
|
||||||
synchronized (sLock) {
|
synchronized (sLock) {
|
||||||
@@ -203,98 +223,23 @@ public class ExifInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a human-readable string describing the white balance value. Returns empty
|
* Stores the latitude and longitude value in a float array. The first element is
|
||||||
* string if there is no white balance value or it is not recognized.
|
* the latitude, and the second element is the longitude. Returns false if the
|
||||||
|
* Exif tags are not available.
|
||||||
*/
|
*/
|
||||||
public String getWhiteBalanceString() {
|
public boolean getLatLong(float output[]) {
|
||||||
String value = getAttribute(TAG_WHITE_BALANCE);
|
|
||||||
if (value == null) return "";
|
|
||||||
|
|
||||||
int whitebalance;
|
|
||||||
try {
|
|
||||||
whitebalance = Integer.parseInt(value);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (whitebalance) {
|
|
||||||
case WHITEBALANCE_AUTO:
|
|
||||||
return "Auto";
|
|
||||||
case WHITEBALANCE_MANUAL:
|
|
||||||
return "Manual";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a human-readable string describing the orientation value. Returns empty
|
|
||||||
* string if there is no orientation value or it it not recognized.
|
|
||||||
*/
|
|
||||||
public String getOrientationString() {
|
|
||||||
// TODO: this function needs to be localized.
|
|
||||||
String value = getAttribute(TAG_ORIENTATION);
|
|
||||||
if (value == null) return "";
|
|
||||||
|
|
||||||
int orientation;
|
|
||||||
try {
|
|
||||||
orientation = Integer.parseInt(value);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String orientationString;
|
|
||||||
switch (orientation) {
|
|
||||||
case ORIENTATION_NORMAL:
|
|
||||||
orientationString = "Normal";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_FLIP_HORIZONTAL:
|
|
||||||
orientationString = "Flipped horizontal";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_ROTATE_180:
|
|
||||||
orientationString = "Rotated 180 degrees";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_FLIP_VERTICAL:
|
|
||||||
orientationString = "Upside down mirror";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_TRANSPOSE:
|
|
||||||
orientationString = "Transposed";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_ROTATE_90:
|
|
||||||
orientationString = "Rotated 90 degrees";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_TRANSVERSE:
|
|
||||||
orientationString = "Transversed";
|
|
||||||
break;
|
|
||||||
case ORIENTATION_ROTATE_270:
|
|
||||||
orientationString = "Rotated 270 degrees";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
orientationString = "Undefined";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return orientationString;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the latitude and longitude value in a float array. The first element is
|
|
||||||
* the latitude, and the second element is the longitude.
|
|
||||||
*/
|
|
||||||
public float[] getLatLong() {
|
|
||||||
String latValue = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE);
|
String latValue = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE);
|
||||||
String latRef = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE_REF);
|
String latRef = mAttributes.get(ExifInterface.TAG_GPS_LATITUDE_REF);
|
||||||
String lngValue = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE);
|
String lngValue = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE);
|
||||||
String lngRef = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE_REF);
|
String lngRef = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE_REF);
|
||||||
float[] latlng = null;
|
|
||||||
|
|
||||||
if (latValue != null && latRef != null
|
if (latValue != null && latRef != null && lngValue != null && lngRef != null) {
|
||||||
&& lngValue != null && lngRef != null) {
|
output[0] = convertRationalLatLonToFloat(latValue, latRef);
|
||||||
latlng = new float[2];
|
output[1] = convertRationalLatLonToFloat(lngValue, lngRef);
|
||||||
latlng[0] = convertRationalLatLonToFloat(latValue, latRef);
|
return true;
|
||||||
latlng[1] = convertRationalLatLonToFloat(lngValue, lngRef);
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return latlng;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SimpleDateFormat sFormatter =
|
private static SimpleDateFormat sFormatter =
|
||||||
@@ -303,6 +248,7 @@ public class ExifInterface {
|
|||||||
/**
|
/**
|
||||||
* Returns number of milliseconds since Jan. 1, 1970, midnight GMT.
|
* Returns number of milliseconds since Jan. 1, 1970, midnight GMT.
|
||||||
* Returns -1 if the date time information if not available.
|
* Returns -1 if the date time information if not available.
|
||||||
|
* @hide
|
||||||
*/
|
*/
|
||||||
public long getDateTime() {
|
public long getDateTime() {
|
||||||
String dateTimeString = mAttributes.get(TAG_DATETIME);
|
String dateTimeString = mAttributes.get(TAG_DATETIME);
|
||||||
|
|||||||
@@ -726,8 +726,8 @@ public class MediaScanner
|
|||||||
// exif is null
|
// exif is null
|
||||||
}
|
}
|
||||||
if (exif != null) {
|
if (exif != null) {
|
||||||
float[] latlng = exif.getLatLong();
|
float[] latlng = new float[2];
|
||||||
if (latlng != null) {
|
if (exif.getLatLong(latlng)) {
|
||||||
values.put(Images.Media.LATITUDE, latlng[0]);
|
values.put(Images.Media.LATITUDE, latlng[0]);
|
||||||
values.put(Images.Media.LONGITUDE, latlng[1]);
|
values.put(Images.Media.LONGITUDE, latlng[1]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user