If you think the Android project Locast-Core-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package edu.mit.mobile.android.locast.data;
//www.java2s.comimport android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.location.Location;
import android.net.Uri;
import android.provider.MediaStore.Images.Media;
import android.provider.MediaStore.MediaColumns;
import android.util.Log;
import edu.mit.mobile.android.content.column.DBColumn;
import edu.mit.mobile.android.content.column.TextColumn;
publicabstractclass ImageContent extends CastMedia {
publicstaticfinal String TAG = ImageContent.class.getSimpleName();
@DBColumn(type = TextColumn.class)
publicfinalstatic String COL_THUMBNAIL = "thumbnail";
public ImageContent(Cursor c) {
super(c);
}
publicstatic Location extractLocationFromContentUri(Cursor c) {
// if the current location is null, infer it from the first media that's
// added.
finalint latCol = c.getColumnIndex(Media.LATITUDE);
finalint lonCol = c.getColumnIndex(Media.LONGITUDE);
finaldouble lat = c.getDouble(latCol);
finaldouble lon = c.getDouble(lonCol);
finalboolean isInArmpit = lat == 0 && lon == 0; // Sorry, people in boats
// off the coast
// of Ghana, but you're
// an unfortunate edge
// case...
if (!c.isNull(latCol) && !c.isNull(lonCol) && !isInArmpit) {
final Location l = new Location("internal");
l.setLatitude(c.getDouble(latCol));
l.setLongitude(c.getDouble(lonCol));
return l;
} else {
return null;
}
}
staticvoid extractContent(ContentResolver cr, Uri content, ContentValues cv,
CastMediaInfo castMedia) throws MediaProcessingException {
final Cursor c = cr.query(content, new String[] { MediaColumns._ID, MediaColumns.DATA,
MediaColumns.TITLE, Media.LATITUDE, Media.LONGITUDE, Media.DATE_TAKEN }, null,
null, null);
try {
if (c.moveToFirst()) {
// TODO figure out how titles could work
// cv.put(CastMedia._TITLE,
// c.getString(c.getColumnIndexOrThrow(MediaColumns.TITLE)));
castMedia.path = "file://"
+ c.getString(c.getColumnIndexOrThrow(MediaColumns.DATA));
cv.put(CastMedia.COL_CAPTURE_TIME,
c.getLong(c.getColumnIndexOrThrow(Media.DATE_TAKEN)));
} else {
Log.e(TAG, "couldn't add media from uri " + content);
thrownew MediaProcessingException("could not find content from uri: " + content);
}
} finally {
c.close();
}
}
publicfinalstatic ItemSyncMap SYNC_MAP = new ItemSyncMap();
publicstaticclass ItemSyncMap extends CastMedia.ItemSyncMap {
protectedstaticfinal String RESOURCES_KEY = "_resources";
/**
*
*/privatestaticfinallong serialVersionUID = 7045578635861708298L;
public ItemSyncMap() {
put(RESOURCES_KEY, new ResourcesSync());
}
protectedvoid setResourcesSync(AbsResourcesSync res) {
put(RESOURCES_KEY, res);
}
}
}