Java Code Examples for com.activeandroid.util.IOUtils

The following examples show how to use com.activeandroid.util.IOUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: umeng_community_android   Source File: AlbumController.java    License: MIT License 6 votes vote down vote up
/**
 * 获取最近使用的照片
 * 
 * @return
 */
public List<PhotoModel> getCurrent() {
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.DATA,
            ImageColumns.DATE_ADDED, ImageColumns.SIZE
    }, null, null, ImageColumns.DATE_ADDED);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<PhotoModel>();
    List<PhotoModel> photos = new ArrayList<PhotoModel>();
    cursor.moveToLast();
    do {
        if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
            PhotoModel photoModel = new PhotoModel();
            photoModel.setOriginalPath(cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            photos.add(photoModel);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return photos;
}
 
Example 2
Source Project: umeng_community_android   Source File: AlbumController.java    License: MIT License 6 votes vote down vote up
/**
 * 获取某个相册中的所有图片
 * 
 * @param name
 * @return
 */
public List<PhotoModel> getAlbum(String name) {
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.BUCKET_DISPLAY_NAME,
            ImageColumns.DATA, ImageColumns.DATE_ADDED, ImageColumns.SIZE
    }, "bucket_display_name = ?",
            new String[] {
                name
            }, ImageColumns.DATE_ADDED);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<PhotoModel>();
    List<PhotoModel> photos = new ArrayList<PhotoModel>();
    cursor.moveToLast();
    do {
        if (cursor.getLong(cursor.getColumnIndex(ImageColumns.SIZE)) > 1024 * 10) {
            PhotoModel photoModel = new PhotoModel();
            photoModel.setOriginalPath(cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            photos.add(photoModel);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return photos;
}
 
Example 3
Source Project: umeng_community_android   Source File: AlbumController.java    License: MIT License 5 votes vote down vote up
/**
 * 获取所有相册
 * 
 * @return
 */
public List<AlbumModel> getAlbums() {
    List<AlbumModel> albums = new ArrayList<AlbumModel>();
    Map<String, AlbumModel> map = new HashMap<String, AlbumModel>();
    Cursor cursor = resolver.query(Media.EXTERNAL_CONTENT_URI, new String[] {
            ImageColumns.DATA,
            ImageColumns.BUCKET_DISPLAY_NAME, ImageColumns.SIZE
    }, null, null, null);
    if (cursor == null || !cursor.moveToNext())
        return new ArrayList<AlbumModel>();
    cursor.moveToLast();
    AlbumModel current = new AlbumModel(ResFinder.getString("umeng_comm_recent_photos"), 0,
            cursor.getString(cursor.getColumnIndex(ImageColumns.DATA)), true); // 最近的照片
    albums.add(current);
    do {
        if (cursor.getInt(cursor.getColumnIndex(ImageColumns.SIZE)) < 1024 * 10) {
            continue;
        }

        current.increaseCount();
        String name = cursor.getString(cursor.getColumnIndex(ImageColumns.BUCKET_DISPLAY_NAME));
        if (map.keySet().contains(name))
            map.get(name).increaseCount();
        else {
            AlbumModel album = new AlbumModel(name, 1, cursor.getString(cursor
                    .getColumnIndex(ImageColumns.DATA)));
            map.put(name, album);
            albums.add(album);
        }
    } while (cursor.moveToPrevious());
    IOUtils.closeQuietly(cursor);
    return albums;
}
 
Example 4
private void executeSqlScript(SQLiteDatabase db, String file) {

	    InputStream stream = null;

		try {
		    stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file);

		    if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) {
		        executeDelimitedSqlScript(db, stream);

		    } else {
		        executeLegacySqlScript(db, stream);

		    }

		} catch (IOException e) {
			Log.e("Failed to execute " + file, e);

		} finally {
		    IOUtils.closeQuietly(stream);

		}
	}
 
Example 5
Source Project: mobile-android-survey-app   Source File: DatabaseHelper.java    License: MIT License 4 votes vote down vote up
private void executeSqlScript(SQLiteDatabase db, String file) {

	    InputStream stream = null;

		try {
		    stream = Cache.getContext().getAssets().open(MIGRATION_PATH + "/" + file);

		    if (Configuration.SQL_PARSER_DELIMITED.equalsIgnoreCase(mSqlParser)) {
		        executeDelimitedSqlScript(db, stream);

		    } else {
		        executeLegacySqlScript(db, stream);

		    }

		} catch (IOException e) {
			Log.e("Failed to execute " + file, e);

		} finally {
		    IOUtils.closeQuietly(stream);

		}
	}