blob: 0f13baaee3680f4318fd4a2681dcf53c9a80cdb3 [file] [log] [blame]
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.gallery3d.picasa;
import org.xml.sax.Attributes;
/**
* This class models the photo entry kind in the Picasa GData API.
*/
@Entry.Table("photos")
public final class PhotoEntry extends Entry {
public static final EntrySchema SCHEMA = new EntrySchema(PhotoEntry.class);
public static class Columns {
public static final String SYNC_ACCOUNT = "sync_account";
public static final String EDIT_URI = "edit_uri";
public static final String ALBUM_ID = "album_id";
public static final String DISPLAY_INDEX = "display_index";
public static final String TITLE = "title";
public static final String SUMMARY = "summary";
public static final String DATE_PUBLISHED = "date_published";
public static final String DATE_UPDATED = "date_updated";
public static final String DATE_EDITED = "date_edited";
public static final String DATE_TAKEN = "date_taken";
public static final String COMMENT_COUNT = "comment_count";
public static final String WIDTH = "width";
public static final String HEIGHT = "height";
public static final String ROTATION = "rotation";
public static final String SIZE = "size";
public static final String LATITUDE = "latitude";
public static final String LONGITUDE = "longitude";
public static final String THUMBNAIL_URL = "thumbnail_url";
public static final String SCREENNAIL_URL = "screennail_url";
public static final String CONTENT_URL = "content_url";
public static final String CONTENT_TYPE = "content_type";
public static final String HTML_PAGE_URL = "html_page_url";
}
/**
* The user account that is the sync source for this entry. Must be set
* before insert/update.
*/
@Column(Columns.SYNC_ACCOUNT)
public String syncAccount;
/**
* The "edit" URI of the photo.
*/
@Column(Columns.EDIT_URI)
public String editUri;
/**
* The containing album ID.
*/
@Column(value = Columns.ALBUM_ID, indexed = true)
public long albumId;
/**
* The display index of the photo within the album. Must be set before
* insert/update.
*/
@Column(value = Columns.DISPLAY_INDEX, indexed = true)
public int displayIndex;
/**
* The title of the photo.
*/
@Column(Columns.TITLE)
public String title;
/**
* A short summary of the photo.
*/
@Column(Columns.SUMMARY)
public String summary;
/**
* The date the photo was added.
*/
@Column(Columns.DATE_PUBLISHED)
public long datePublished;
/**
* The date the photo was last updated.
*/
@Column(Columns.DATE_UPDATED)
public long dateUpdated;
/**
* The date the photo entry was last edited. May be more recent than
* dateUpdated.
*/
@Column(Columns.DATE_EDITED)
public long dateEdited;
/**
* The date the photo was captured as specified in the EXIF data.
*/
@Column(Columns.DATE_TAKEN)
public long dateTaken;
/**
* The number of comments associated with the photo.
*/
@Column(Columns.COMMENT_COUNT)
public int commentCount;
/**
* The width of the photo in pixels.
*/
@Column(Columns.WIDTH)
public int width;
/**
* The height of the photo in pixels.
*/
@Column(Columns.HEIGHT)
public int height;
/**
* The rotation of the photo in degrees, if rotation has not already been
* applied.
*/
@Column(Columns.ROTATION)
public int rotation;
/**
* The size of the photo is bytes.
*/
@Column(Columns.SIZE)
public int size;
/**
* The latitude associated with the photo.
*/
@Column(Columns.LATITUDE)
public double latitude;
/**
* The longitude associated with the photo.
*/
@Column(Columns.LONGITUDE)
public double longitude;
/**
* The "mini-thumbnail" URL for the photo (currently 144px-cropped).
*/
@Column(Columns.THUMBNAIL_URL)
public String thumbnailUrl;
/**
* The "screennail" URL for the photo (currently 800px).
*/
@Column(Columns.SCREENNAIL_URL)
public String screennailUrl;
/**
* The "content" URL for the photo (currently 1280px, or a video). The
* original image URL is not fetched since "imgmax" accepts one size, used
* to get this resource.
*/
@Column(Columns.CONTENT_URL)
public String contentUrl;
/**
* The MIME type of the content URL.
*/
@Column(Columns.CONTENT_TYPE)
public String contentType;
/**
* A link to the HTML page associated with the album.
*/
@Column(Columns.HTML_PAGE_URL)
public String htmlPageUrl;
/**
* Resets values to defaults for object reuse.
*/
@Override
public void clear() {
super.clear();
syncAccount = null;
editUri = null;
albumId = 0;
displayIndex = 0;
title = null;
summary = null;
datePublished = 0;
dateUpdated = 0;
dateEdited = 0;
dateTaken = 0;
commentCount = 0;
width = 0;
height = 0;
rotation = 0;
size = 0;
latitude = 0;
longitude = 0;
thumbnailUrl = null;
screennailUrl = null;
contentUrl = null;
contentType = null;
htmlPageUrl = null;
}
/**
* Sets the property value corresponding to the given XML element, if
* applicable.
*/
@Override
public void setPropertyFromXml(String uri, String localName, Attributes attrs, String content) {
try {
char localNameChar = localName.charAt(0);
if (uri.equals(GDataParser.GPHOTO_NAMESPACE)) {
switch (localNameChar) {
case 'i':
if (localName.equals("id")) {
id = Long.parseLong(content);
}
break;
case 'a':
if (localName.equals("albumid")) {
albumId = Long.parseLong(content);
}
break;
case 't':
if (localName.equals("timestamp")) {
dateTaken = Long.parseLong(content);
}
break;
case 'c':
if (localName.equals("commentCount")) {
commentCount = Integer.parseInt(content);
}
break;
case 'w':
if (localName.equals("width")) {
width = Integer.parseInt(content);
}
break;
case 'h':
if (localName.equals("height")) {
height = Integer.parseInt(content);
}
break;
case 'r':
if (localName.equals("rotation")) {
rotation = Integer.parseInt(content);
}
break;
case 's':
if (localName.equals("size")) {
size = Integer.parseInt(content);
}
break;
case 'l':
if (localName.equals("latitude")) {
latitude = Double.parseDouble(content);
} else if (localName.equals("longitude")) {
longitude = Double.parseDouble(content);
}
break;
}
} else if (uri.equals(GDataParser.ATOM_NAMESPACE)) {
switch (localNameChar) {
case 't':
if (localName.equals("title")) {
title = content;
}
break;
case 's':
if (localName.equals("summary")) {
summary = content;
}
break;
case 'p':
if (localName.equals("published")) {
datePublished = GDataParser.parseAtomTimestamp(content);
}
break;
case 'u':
if (localName.equals("updated")) {
dateUpdated = GDataParser.parseAtomTimestamp(content);
}
break;
case 'l':
if (localName.equals("link")) {
String rel = attrs.getValue("", "rel");
String href = attrs.getValue("", "href");
if (rel.equals("alternate")
&& attrs.getValue("", "type").equals("text/html")) {
htmlPageUrl = href;
} else if (rel.equals("edit")) {
editUri = href;
}
}
break;
}
} else if (uri.equals(GDataParser.APP_NAMESPACE)) {
if (localName.equals("edited")) {
dateEdited = GDataParser.parseAtomTimestamp(content);
}
} else if (uri.equals(GDataParser.MEDIA_RSS_NAMESPACE)) {
if (localName.equals("thumbnail")) {
int width = Integer.parseInt(attrs.getValue("", "width"));
int height = Integer.parseInt(attrs.getValue("", "height"));
int dimension = Math.max(width, height);
String url = attrs.getValue("", "url");
if (dimension <= PicasaApi.THUMBNAIL_SIZE_THRESHOLD) {
thumbnailUrl = url;
} else {
screennailUrl = url;
}
} else if (localName.equals("content")) {
// Only replace an existing URL if the MIME type is video.
String type = attrs.getValue("", "type");
if (contentUrl == null || type.startsWith("video/")) {
contentUrl = attrs.getValue("", "url");
contentType = type;
}
}
} else if (uri.equals(GDataParser.GML_NAMESPACE)) {
if (localName.equals("pos")) {
int spaceIndex = content.indexOf(' ');
if (spaceIndex != -1) {
latitude = Double.parseDouble(content.substring(0, spaceIndex));
longitude = Double.parseDouble(content.substring(spaceIndex + 1));
}
}
}
} catch (Exception e) {
return;
}
}
}