Search in sources :

Example 16 with SQLiteException

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;
}
Also used : InputStream(java.io.InputStream) ExifInterface(com.moez.QKSMS.exif.ExifInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 17 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 18 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException) Paint(android.graphics.Paint)

Example 19 with SQLiteException

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);
    }
}
Also used : SQLiteException(android.database.sqlite.SQLiteException) Uri(android.net.Uri)

Example 20 with SQLiteException

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;
}
Also used : SQLiteStatement(io.requery.android.database.sqlite.SQLiteStatement) SingleResultSet(io.requery.android.sqlite.SingleResultSet) SQLiteException(android.database.sqlite.SQLiteException)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)100 Cursor (android.database.Cursor)64 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)33 ContentValues (android.content.ContentValues)10 File (java.io.File)9 HashMap (java.util.HashMap)8 Account (android.accounts.Account)7 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)7 SyncStatusInfo (android.content.SyncStatusInfo)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 Uri (android.net.Uri)5 SuppressLint (android.annotation.SuppressLint)4 ArrayList (java.util.ArrayList)4 SQLiteStatement (android.database.sqlite.SQLiteStatement)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3 SingleResultSet (io.requery.android.sqlite.SingleResultSet)3 Date (java.util.Date)3 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)2