Android image selector, written with Kotlin, inspired by zhihu/Matisse.
- Select images in Activity or Fragment
- Select images with size filter and type filter
- Support custom styles
You can copy the source code and do whaterver you want to do.
Or use Gradle.
Step 1. Add JitPack repository in your root build.gradle
allprojects {
repositories {
//... others
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency in your app build.gradle
dependencies {
implementation 'com.github.JosephusZhou:WuDaozi:1.0.11'
}
Step 3. Request permission
- Android 12 and below
android.permission.READ_EXTERNAL_STORAGE
- Android 13 and above
android.permission.READ_MEDIA_IMAGES
Step 4. Start to select images from Activity
or Fragment
val launcher = WuDaozi.getLauncher(this) { result ->
result?.let {
for (uri in it) {
Log.e("WuDaozi", "->$uri")
}
} ?: Toast.makeText(this, "canceled", Toast.LENGTH_SHORT)
.show()
}
WuDaozi.with(this)
.theme(R.style.CustomWuDaoziTheme)
.imageLoader(GlideLoader())
.columnsCount(4)
.maxSelectableCount(9)
.filter(minByteSize = 1024 * 100,
selectedTypes = arrayOf(Filter.Type.GIF),
callback = object: FilterResultHandleCallback {
override fun handleResult(message: String) {
Log.e("WuDaozi", message)
}
}
)
.activityCallback(object : ActivityCallback {
override fun onAlbumActivityOnCreate(activity: AppCompatActivity) {
}
override fun onPreviewActivityOnCreate(activity: AppCompatActivity) {
}
})
.start(launcher)
theme()
: UI themeimageLoader()
: the image engine to load imagescolumnsCount()
: how many images can be displayed in one linemaxSelectableCount()
: how many images can be selected at mostfilter()
: filter images of specific sizes and types
Implement the ImageLoader
interface and all methods.
Build your own theme base on WuDaozi.Theme
.
Copyright 2019 JosephusZhou
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.