-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Basic Usage
Matisse.from(MainActivity.this)
.choose(MimeType.of(MimeType.JPEG, MimeType.PNG, MimeType.GIF))
.countable(true)
.maxSelectable(9)
.gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
.restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
.thumbnailScale(0.85f)
.imageEngine(new GlideEngine())
.forResult(REQUEST_CODE_CHOOSE);
In onActivityResult()
callback of the starting Activity
or Fragment
:
List<Uri> mSelected;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
mSelected = Matisse.obtainResult(data);
Log.d("Matisse", "mSelected: " + mSelected);
}
}
Matisse supports the following mime types:
Mime type | File extensions | Media type |
---|---|---|
image/jpeg | jpg, jpeg | image |
image/png | png | image |
image/gif | gif | image |
image/x-ms-bmp | bmp | image |
image/webp | webp | image |
video/mpeg | mpeg, mpg | video |
video/mp4 | mp4, m4v | video |
video/quicktime | mov | video |
video/3gpp | 3gp, 3gpp | video |
video/3gpp2 | 3g2, 3gpp2 | video |
video/x-matroska | mkv | video |
video/webm | webm | video |
video/mp2ts | ts | video |
video/avi | avi | video |
Notice: All images and videos will be showing in Matisse, but you can't limit the selectable mime types through MimeType.of**()
.
You can launch Matisse from Activity or Fragment. Meanwhile you should receive results in the corresponding onActivityResult()
callback.
There will be a check mark in the right top corner of the thumbnail and you can't only select one image.
Use countable(true)
to show an auto-increased number check mark from 1. It's like the Dracula Style screenshot in README.
Use maxSelectable(int maxSelectable)
to limit maximum selectable number.
Use restrictOrientation(@ScreenOrientation int orientation)
to set the desired orientation of image selecting and previewing Activity.
If you want a fixed span count, use spanCount(int spanCount)
. The span count will stay the same when orientation changes.
If you expect a grid size which will be flexible fitting different screens, use spanCount(int spanCount)
. This value won't necessarily be applied cause the photo grid should fill the view container. The measured photo grid's size will be as close to this value as possible.
Use thumbnailScale(float scale)
to set thumbnail bitmap's scale compared to the view's size. It should be a float value in (0.0, 1.0].