Yitimo's image libs for Android. Include:
- Image picker 相册图片选择器
- Image browser 基于ViewPager的图片滑动浏览
- Image grider 信息流九宫格图片组件
- Image cutter 简单图片裁剪组件
To run my sample: clone the repo and run the sample app
To import the lib into your project, add the following line to your app's gradle file:
implementation 'com.yitimo.ymage:ymage:1.3.9'
Then you should add some code to your project's BaseApplication
or any other app-init file as below:
// for ymage over v1.3.7
Ymager.debug = true // to enable debug mode
Ymager.browserClickBack = true // to enable browser close by single click
Ymager.setTheme(R.style.MyYmage) // set custom theme color for ymage, remove to use default
// glide engine code for bitmap load
Ymager.loadBitmap = fun (context: Context, url: String, holderRes: Int, callback: (Bitmap) -> Unit) {
GlideApp.with(context)
.asBitmap()
.load(url)
.placeholder(holderRes)
.error(holderRes)
.listener(object : RequestListener<Bitmap> {
override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (resource == null) {
return false
}
callback(resource)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
return false
}
}).submit()
}
// glide engine code for file load
Ymager.loadFile = fun (context: Context, url: String, holderRes: Int, callback: (File) -> Unit) {
GlideApp.with(context)
.asFile()
.load(url)
.placeholder(holderRes)
.error(holderRes)
.listener(object : RequestListener<File> {
override fun onResourceReady(resource: File?, model: Any?, target: Target<File>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (resource == null) {
return false
}
callback(resource)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<File>?, isFirstResource: Boolean): Boolean {
return false
}
}).submit()
}
// glide engine code for bitmap load with size
Ymager.loadLimitBitmap = fun (context: Context, url: String, holderRes: Int, size: Pair<Int, Int>, callback: (Bitmap) -> Unit) {
GlideApp.with(context)
.asBitmap()
.load(url)
.override(size.first, size.second)
.placeholder(holderRes)
.error(holderRes)
.listener(object : RequestListener<Bitmap> {
override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (resource == null) {
return false
}
callback(resource)
return false
}
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
return false
}
}).submit()
}
// glide engine code for grid image
Ymager.setGridItem = fun (context: Context, imageView: ImageView, src: String, size: Int, fade: Int, holderRes: Int) {
GlideApp.with(context)
.load(src)
.error(holderRes)
.transition(DrawableTransitionOptions.withCrossFade(fade))
.override(size, size)
.centerCrop()
.into(imageView)
}
// glide engine code for gif
Ymager.setGif = fun (context: Context, iv: ImageView, url: String, holderRes: Int) {
GlideApp.with(context)
.load(url)
.placeholder(holderRes)
.error(holderRes)
.centerInside()
.into(iv)
}
// glide engine for pause
Ymager.pauseGlide = fun (context: Context) {
GlideApp.with(context).pauseRequests()
}
// glide engine for resume
Ymager.resumeGlide = fun (context: Context) {
GlideApp.with(context).resumeRequests()
}
For version before v1.3.7 can get code here.
- Thumb list with 4 columns grid layout
- Album switching support (group by
Bucket
) - Single photo review, support scale, drag to switch
Ymager.pick(activity, limitCount, showCamera, lastChosen)
- Custom theme color
- Chosen history support (parse
Ymage
list in and set them chosen) - Light/dark built-in theme support
- Custom nav bar support. (can still use themed colors&values)
- Multi built-in nav bar support.
- Photo database improvement.
- More customizable properties.
- Image list browser base on DialogFragment and ViewPager
- Long tap & single tap listener support
- Long image and GIF support
val dialog = Ymager.browse(fragmentManager, list, index)
dialog.setOnLongClickListener { src, index ->
// todo
}
- Different effect for single/double/multi images.
- Automatically add tag for GIF and long image.
<com.yitimo.ymage.grider.YmageGridView
android:id="@+id/grider_single"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemSpace="@dimen/dimenSpace"/>
val singleYGV = findViewById(R.id.grider_single)
singleYGV.limit = Resources.getSystem().displayMetrics.widthPixels.toFloat()
singleYGV.itemSpace = 30f
singleYGV.items = list
singleYGV.setOnImageClickListener {
Ymager.browse(this, it, list)
}
- Use as custom view, simple to import
- Rotate and scale support
<com.yitimo.ymage.cutter.YmageCutterView
android:id="@+id/cutter_edit_body"
android:layout_width="match_parent"
android:layout_height="0dp"
app:ratio="4:3"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
val bodyYCV = findViewById(R.id.cutter_edit_body)
val result: Bitmap? = bodyYCV.shutter()