use of android.database.sqlite.SQLiteException in project qksms by moezbhatti.
the class UriImage method getOrientation.
/**
* Returns the number of degrees to rotate the picture, based on the orientation tag in
* the exif data or the orientation column in the database. If there's no tag or column,
* 0 degrees is returned.
*
* @param context Used to get the ContentResolver
* @param uri Path to the image
*/
public static int getOrientation(Context context, Uri uri) {
long dur = System.currentTimeMillis();
if (ContentResolver.SCHEME_FILE.equals(uri.getScheme()) || sURLMatcher.match(uri) == MMS_PART_ID) {
// file for the orientation because there is no column in the db for the orientation.
try {
InputStream inputStream = context.getContentResolver().openInputStream(uri);
ExifInterface exif = new ExifInterface();
try {
exif.readExif(inputStream);
Integer val = exif.getTagIntValue(ExifInterface.TAG_ORIENTATION);
if (val == null) {
return 0;
}
int orientation = ExifInterface.getRotationForOrientationValue(val.shortValue());
return orientation;
} catch (IOException e) {
Log.w(TAG, "Failed to read EXIF orientation", e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
}
}
}
} catch (FileNotFoundException e) {
Log.e(TAG, "Can't open uri: " + uri, e);
} finally {
dur = System.currentTimeMillis() - dur;
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "UriImage.getOrientation (exif path) took: " + dur + " ms");
}
}
} else {
// Try to get the orientation from the ORIENTATION column in the database. This is much
// faster than reading all the exif tags from the file.
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[] { Images.ImageColumns.ORIENTATION }, null, null, null);
if (cursor.moveToNext()) {
int ori = cursor.getInt(0);
return ori;
}
} catch (SQLiteException e) {
} catch (IllegalArgumentException e) {
} finally {
if (cursor != null) {
cursor.close();
}
dur = System.currentTimeMillis() - dur;
if (Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "UriImage.getOrientation (db column path) took: " + dur + " ms");
}
}
}
return 0;
}
use of android.database.sqlite.SQLiteException in project qksms by moezbhatti.
the class PduPersister method convertUriToPath.
/**
* This method expects uri in the following format
* content://media/<table_name>/<row_index> (or)
* file://sdcard/test.mp4
* http://test.com/test.mp4
*
* Here <table_name> shall be "video" or "audio" or "images"
* <row_index> the index of the content in given table
*/
public static String convertUriToPath(Context context, Uri uri) {
String path = null;
if (null != uri) {
String scheme = uri.getScheme();
if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
path = uri.getPath();
} else if (scheme.equals("http")) {
path = uri.toString();
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
String[] projection = new String[] { MediaStore.MediaColumns.DATA };
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, projection, null, null, null);
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
throw new IllegalArgumentException("Given Uri could not be found" + " in media store");
}
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(pathIndex);
} catch (SQLiteException e) {
throw new IllegalArgumentException("Given Uri is not formatted in a way " + "so that it can be found in media store.");
} finally {
if (null != cursor) {
cursor.close();
}
}
} else {
throw new IllegalArgumentException("Given Uri scheme is not supported");
}
}
return path;
}
use of android.database.sqlite.SQLiteException in project qksms by moezbhatti.
the class ContactHelper method getPhoneNumber.
/**
* Get the phone number of a contact given their id
* TODO: The logic for picking the best phone number could be better
*/
public static String getPhoneNumber(Context context, String contactId) {
String number = "";
Cursor cursor;
try {
cursor = context.getContentResolver().query(Phone.CONTENT_URI, null, Phone.CONTACT_ID + " = " + contactId, null, null);
while (cursor.moveToNext()) {
number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER));
int type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE));
switch(type) {
case Phone.TYPE_MOBILE:
// Return right away if it's a mobile number
cursor.close();
return number;
}
}
cursor.close();
} catch (SQLiteException e) {
e.printStackTrace();
}
// Return whatever number we found last, since we don't know which is best
return number;
}
use of android.database.sqlite.SQLiteException in project qksms by moezbhatti.
the class MessageListFragment method startMsgListQuery.
private void startMsgListQuery(int token) {
/*if (mSendDiscreetMode) {
return;
}*/
Uri conversationUri = mConversation.getUri();
if (conversationUri == null) {
Log.v(TAG, "##### startMsgListQuery: conversationUri is null, bail!");
return;
}
long threadId = mConversation.getThreadId();
if (LogTag.VERBOSE || Log.isLoggable(LogTag.APP, Log.VERBOSE)) {
Log.v(TAG, "startMsgListQuery for " + conversationUri + ", threadId=" + threadId + " token: " + token + " mConversation: " + mConversation);
}
// Cancel any pending queries
mBackgroundQueryHandler.cancelOperation(token);
try {
// Kick off the new query
mBackgroundQueryHandler.startQuery(token, threadId, /* cookie */
conversationUri, MessageColumns.PROJECTION, null, null, null);
} catch (SQLiteException e) {
SqliteWrapper.checkSQLiteException(mContext, e);
}
}
use of android.database.sqlite.SQLiteException in project requery by requery.
the class SqlitexStatement method execute.
@Override
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
SQLiteStatement statement = null;
try {
statement = connection.getDatabase().compileStatement(sql);
if (autoGeneratedKeys == RETURN_GENERATED_KEYS) {
long rowId = statement.executeInsert();
insertResult = new SingleResultSet(this, rowId);
return true;
} else {
statement.execute();
}
} catch (SQLiteException e) {
SqlitexConnection.throwSQLException(e);
} finally {
if (statement != null) {
statement.close();
}
}
return false;
}
Aggregations