开发者

Show selected images from gallery upon some condition

My requirement is to read an input from a date entry to search images between specific date range.

So far I have just created a gallery view to retrieve all images from the images folder.

The code I have is as given.

How do I 开发者_StackOverflow社区create conditions before displaying the thumbnails of the image folder for only those images which satisfy condition?

public void image_search(String st)
{
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent,
    "Select Picture"), SELECT_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();

            //OI FILE Manager
            filemanagerstring = selectedImageUri.getPath();

            //MEDIA GALLERY
            selectedImagePath = getPath(selectedImageUri);

            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + selectedImagePath), "image/*");
            startActivity(intent);
        }
    }
}

//UPDATED!
public String getPath(Uri uri) {
    String selectedImagePath;
    //1:MEDIA GALLERY --- query from MediaStore.Images.Media.DATA
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    if(cursor != null){
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        selectedImagePath = cursor.getString(column_index);
    }else{
        selectedImagePath = null;
    }

    if(selectedImagePath == null){
        //2:OI FILE Manager --- call method: uri.getPath()
        selectedImagePath = uri.getPath();
    }
    return selectedImagePath;
}


If you mean filetype condition then you can simply set filetype you want.
Like intent.setType("image/png"); to fetch only PNG images.

Edit:
You should implement the FileFilter interface to get the list files satisfying your conditions. You can create thumnails out of this list.

File imagesDir = // the File obj of directory containing image files.  
File[] imagelist = imagesDir.listFiles( new FileFilter {

    @override  
    public boolean accept(File file)  
    {  
    // return true if this file meets ur conditions(file.length and file.lastmodified())
    }  

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜