Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

In this page you can find the example usage for android.database Cursor getInt.

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:Main.java

private static Set<Integer> getAllAvailableProtocolVersions(Context context) {
    ContentResolver contentResolver = context.getContentResolver();
    Set<Integer> allAvailableVersions = new HashSet<Integer>();
    Uri uri = Uri.parse("content://com.facebook.orca.provider.MessengerPlatformProvider/versions");
    String[] projection = new String[] { "version" };
    Cursor c = contentResolver.query(uri, projection, null, null, null);
    if (c != null) {
        try {/* ww  w . j  a va  2  s.c o m*/
            int versionColumnIndex = c.getColumnIndex("version");
            while (c.moveToNext()) {
                int version = c.getInt(versionColumnIndex);
                allAvailableVersions.add(version);
            }
        } finally {
            c.close();
        }
    }
    return allAvailableVersions;
}

From source file:Main.java

public static int getRotationFromGallery(Context context, Uri imageUri) {
    String[] columns = { MediaStore.Images.Media.ORIENTATION };
    Cursor cursor = context.getContentResolver().query(imageUri, columns, null, null, null);
    if (cursor == null)
        return 0;

    cursor.moveToFirst();/*from   w  w w.j a v  a2  s .com*/

    int orientationColumnIndex = cursor.getColumnIndex(columns[0]);
    return cursor.getInt(orientationColumnIndex);
}

From source file:br.com.bea.androidtools.api.model.EntityUtils.java

public static final Object convert(final Field field, final Cursor cursor) throws Exception {
    if (field.getType().equals(Long.class))
        return cursor.getLong(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
    if (field.getType().equals(Integer.class))
        return cursor.getInt(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
    if (field.getType().equals(Date.class))
        return DATE_FORMAT
                .parse(cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name())));
    return cursor.getString(cursor.getColumnIndex(field.getAnnotation(Column.class).name()));
}

From source file:Main.java

public static ArrayList<ContentValues> getProvince(SQLiteDatabase db) {
    ArrayList<ContentValues> list = new ArrayList<ContentValues>();
    ContentValues values = null;/* www .j  ava 2s.c o  m*/
    Cursor cursor = db.query(TABLE_NAME, new String[] { "DQXX01", "DQXX02" }, "DQXX03=?", new String[] { "1" },
            null, null, "DQX_DQXX01 ASC");
    if (cursor != null) {
        while (cursor.moveToNext()) {
            values = new ContentValues();
            values.put("province_id", cursor.getInt(0));
            values.put("province", cursor.getString(1));
            list.add(values);
        }
    }
    if (cursor != null && !cursor.isClosed()) {
        cursor.close();
    }
    return list;
}

From source file:Main.java

public static int getOrientation(Context context, Uri photoUri, File file) {
    /* it's on the external media. */
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
    if (cursor != null && cursor.getCount() != 1) {
        cursor.moveToFirst();//from  w  ww. j av a 2s .c  o m
        return cursor.getInt(0);
    }

    int rotate = 0;
    ExifInterface exif = null;

    try {
        exif = new ExifInterface(file == null ? getPath(context, photoUri) : file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
    }
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

    switch (orientation) {
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
        break;
    case ExifInterface.ORIENTATION_NORMAL:
        rotate = 0;
        break;
    }
    return rotate;
}

From source file:Main.java

public static void CheckDwnloadStatus(DownloadManager downloadManager, Activity activity, long id) {

    // TODO Auto-generated method stub
    DownloadManager.Query query = new DownloadManager.Query();
    query.setFilterById(id);//w  w w.j  av a  2  s  .com
    Cursor cursor = downloadManager.query(query);
    if (cursor.moveToFirst()) {
        int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
        int status = cursor.getInt(columnIndex);
        int columnReason = cursor.getColumnIndex(DownloadManager.COLUMN_REASON);
        int reason = cursor.getInt(columnReason);

        switch (status) {
        case DownloadManager.STATUS_FAILED:
            String failedReason = "";
            switch (reason) {
            case DownloadManager.ERROR_CANNOT_RESUME:
                failedReason = "ERROR_CANNOT_RESUME";
                break;
            case DownloadManager.ERROR_DEVICE_NOT_FOUND:
                failedReason = "ERROR_DEVICE_NOT_FOUND";
                break;
            case DownloadManager.ERROR_FILE_ALREADY_EXISTS:
                failedReason = "ERROR_FILE_ALREADY_EXISTS";
                break;
            case DownloadManager.ERROR_FILE_ERROR:
                failedReason = "ERROR_FILE_ERROR";
                break;
            case DownloadManager.ERROR_HTTP_DATA_ERROR:
                failedReason = "ERROR_HTTP_DATA_ERROR";
                break;
            case DownloadManager.ERROR_INSUFFICIENT_SPACE:
                failedReason = "ERROR_INSUFFICIENT_SPACE";
                break;
            case DownloadManager.ERROR_TOO_MANY_REDIRECTS:
                failedReason = "ERROR_TOO_MANY_REDIRECTS";
                break;
            case DownloadManager.ERROR_UNHANDLED_HTTP_CODE:
                failedReason = "ERROR_UNHANDLED_HTTP_CODE";
                break;
            case DownloadManager.ERROR_UNKNOWN:
                failedReason = "ERROR_UNKNOWN";
                break;
            default:
                failedReason = "unknown reason";
                break;
            }

            Toast.makeText(activity, "FAILED: " + failedReason, Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_PAUSED:
            String pausedReason = "";

            switch (reason) {
            case DownloadManager.PAUSED_QUEUED_FOR_WIFI:
                pausedReason = "PAUSED_QUEUED_FOR_WIFI";
                break;
            case DownloadManager.PAUSED_UNKNOWN:
                pausedReason = "PAUSED_UNKNOWN";
                break;
            case DownloadManager.PAUSED_WAITING_FOR_NETWORK:
                pausedReason = "PAUSED_WAITING_FOR_NETWORK";
                break;
            case DownloadManager.PAUSED_WAITING_TO_RETRY:
                pausedReason = "PAUSED_WAITING_TO_RETRY";
                break;
            }

            Toast.makeText(activity, "PAUSED: " + pausedReason, Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_PENDING:
            Toast.makeText(activity, "PENDING", Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_RUNNING:
            Toast.makeText(activity, "RUNNING", Toast.LENGTH_LONG).show();
            break;
        case DownloadManager.STATUS_SUCCESSFUL:

            Toast.makeText(activity, "SUCCESSFUL", Toast.LENGTH_LONG).show();
            break;
        }
    }
}

From source file:Main.java

public static int getOrientation(Context context, Uri photoUri) {
    int orientation = 0;
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);
    if (cursor != null) {
        if (cursor.getCount() != 1) {
            return -1;
        }//from www. j  a va 2 s  .  c o  m
        cursor.moveToFirst();
        orientation = cursor.getInt(0);
        cursor.close();
    }
    return orientation;
}

From source file:Main.java

public static int getOrientation(Context context, Uri bitmapUri) {
    Cursor cursor = context.getContentResolver().query(bitmapUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor == null || cursor.getCount() != 1) {
        return -1;
    }//  ww  w.  ja  v a 2  s  . c  om

    cursor.moveToFirst();
    return cursor.getInt(0);
}

From source file:Main.java

/**
 * Get the unread count for the given shortcut info
 * @param c cursor holding the unread counts
 * @param packageName the package we are looking for
 * @return int of the unread count// ww w  . j a va  2  s .c o m
 */
public static int getUnreadCount(Cursor c, String packageName) {
    int count = 0;

    try {
        if (c.moveToFirst()) {
            String currName = null;
            do {
                currName = c.getString(c.getColumnIndex("package_name"));
                if (currName.equals(packageName)) {
                    count = c.getInt(c.getColumnIndex("count"));
                }
            } while (c.moveToNext());
        }
    } catch (Exception e) {

    }

    return count;
}

From source file:Main.java

public static LinkedList<Integer> retrieveIntegerFromCursor(Cursor cursor, String columnName) {
    if (null == cursor || 0 == cursor.getCount()) {
        return new LinkedList<Integer>();
    }//from  w  ww  . j  av a 2s  . c  om

    LinkedList<Integer> ids = new LinkedList<Integer>();

    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            int id = cursor.getInt(cursor.getColumnIndexOrThrow(columnName));
            ids.add(new Integer(id));
        }
    } catch (Exception e) {
        //do nothing.
    } finally {
        cursor.close();
    }

    return ids;
}