Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions multiimageview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
buildToolsVersion "25.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "0.1"
versionName "0.1.1"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -29,7 +29,7 @@ android {
publish {
groupId = 'com.github.stfalcon'
artifactId = 'multiimageview'
publishVersion = '0.1'
publishVersion = '0.1.1'
desc = 'Library for display a few images in one MultiImageView like avatar of group chat'
licences = ['Apache-2.0']
uploadName='MultiImageView'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.graphics.*
import android.graphics.drawable.Drawable
import android.media.ThumbnailUtils
import android.util.AttributeSet
import android.util.TypedValue
import android.widget.ImageView
import java.util.*

Expand All @@ -35,9 +36,29 @@ class MultiImageView(context: Context, attrs: AttributeSet) : ImageView(context,
field = value
invalidate()
}

private val paintDivider = Paint(Paint.ANTI_ALIAS_FLAG)

var dividerColor = Color.WHITE
set(value) {
field = value
paintDivider.color = value
invalidate()
}
var dividerWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, resources.displayMetrics)
set(value) {
field = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, resources.displayMetrics)
invalidate()
}

//Corners radius for rectangle shape
var rectCorners = 100

init {
paintDivider.isAntiAlias = true
paintDivider.color = dividerColor
}

private val bitmaps = ArrayList<Bitmap>()
private val path = Path()
private val rect = RectF()
Expand Down Expand Up @@ -68,7 +89,7 @@ class MultiImageView(context: Context, attrs: AttributeSet) : ImageView(context,
* recreate MultiDrawable and set it as Drawable to ImageView
*/
private fun refresh() {
multiDrawable = MultiDrawable(bitmaps)
multiDrawable = MultiDrawable(bitmaps, dividerWidth)
setImageDrawable(multiDrawable)
}

Expand All @@ -89,6 +110,7 @@ class MultiImageView(context: Context, attrs: AttributeSet) : ImageView(context,
path.addOval(rect, Path.Direction.CW)
}
//Clip with shape
canvas.drawPath(path, paintDivider)
canvas.clipPath(path)
}
super.onDraw(canvas)
Expand All @@ -102,10 +124,12 @@ class MultiImageView(context: Context, attrs: AttributeSet) : ImageView(context,
}
}

class MultiDrawable(val bitmaps: ArrayList<Bitmap>) : Drawable() {
class MultiDrawable(val bitmaps: ArrayList<Bitmap>, val dividerWidth: Float) : Drawable() {
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
private val items = ArrayList<PhotoItem>()

fun halfDivider(): Int = (dividerWidth / 2).toInt()

/**
* Create PhotoItem with position and size depends of count of images
*/
Expand All @@ -117,25 +141,25 @@ class MultiDrawable(val bitmaps: ArrayList<Bitmap>) : Drawable() {
} else if (bitmaps.size == 2) {
val bitmap1 = scaleCenterCrop(bitmaps[0], bounds.width(), bounds.height() / 2)
val bitmap2 = scaleCenterCrop(bitmaps[1], bounds.width(), bounds.height() / 2)
items.add(PhotoItem(bitmap1, Rect(0, 0, bounds.width() / 2, bounds.height())))
items.add(PhotoItem(bitmap2, Rect(bounds.width() / 2, 0, bounds.width(), bounds.height())))
items.add(PhotoItem(bitmap1, Rect(0, 0, (bounds.width() / 2) - halfDivider(), bounds.height())))
items.add(PhotoItem(bitmap2, Rect((bounds.width() / 2) + halfDivider(), 0, bounds.width(), bounds.height())))
} else if (bitmaps.size == 3) {
val bitmap1 = scaleCenterCrop(bitmaps[0], bounds.width(), bounds.height() / 2)
val bitmap2 = scaleCenterCrop(bitmaps[1], bounds.width() / 2, bounds.height() / 2)
val bitmap3 = scaleCenterCrop(bitmaps[2], bounds.width() / 2, bounds.height() / 2)
items.add(PhotoItem(bitmap1, Rect(0, 0, bounds.width() / 2, bounds.height())))
items.add(PhotoItem(bitmap2, Rect(bounds.width() / 2, 0, bounds.width(), bounds.height() / 2)))
items.add(PhotoItem(bitmap3, Rect(bounds.width() / 2, bounds.height() / 2, bounds.width(), bounds.height())))
items.add(PhotoItem(bitmap1, Rect(0, 0, (bounds.width() / 2) - halfDivider(), bounds.height())))
items.add(PhotoItem(bitmap2, Rect((bounds.width() / 2) + halfDivider(), 0, bounds.width(), (bounds.height() / 2) - halfDivider())))
items.add(PhotoItem(bitmap3, Rect((bounds.width() / 2) + halfDivider(), (bounds.height() / 2) + halfDivider(), bounds.width(), bounds.height())))
}
if (bitmaps.size == 4) {
val bitmap1 = scaleCenterCrop(bitmaps[0], bounds.width() / 2, bounds.height() / 2)
val bitmap2 = scaleCenterCrop(bitmaps[1], bounds.width() / 2, bounds.height() / 2)
val bitmap3 = scaleCenterCrop(bitmaps[2], bounds.width() / 2, bounds.height() / 2)
val bitmap4 = scaleCenterCrop(bitmaps[3], bounds.width() / 2, bounds.height() / 2)
items.add(PhotoItem(bitmap1, Rect(0, 0, bounds.width() / 2, bounds.height() / 2)))
items.add(PhotoItem(bitmap2, Rect(0, bounds.height() / 2, bounds.width() / 2, bounds.height())))
items.add(PhotoItem(bitmap3, Rect(bounds.width() / 2, 0, bounds.width(), bounds.height() / 2)))
items.add(PhotoItem(bitmap4, Rect(bounds.width() / 2, bounds.height() / 2, bounds.width(), bounds.height())))
items.add(PhotoItem(bitmap1, Rect(0, 0, (bounds.width() / 2) - halfDivider(), (bounds.height() / 2) - halfDivider())))
items.add(PhotoItem(bitmap2, Rect(0, (bounds.height() / 2) + halfDivider(), (bounds.width() / 2) - halfDivider(), bounds.height())))
items.add(PhotoItem(bitmap3, Rect((bounds.width() / 2) + halfDivider(), 0, bounds.width(), (bounds.height() / 2) - halfDivider())))
items.add(PhotoItem(bitmap4, Rect((bounds.width() / 2) + halfDivider(), (bounds.height() / 2) + halfDivider(), bounds.width(), bounds.height())))
}
}

Expand Down Expand Up @@ -176,5 +200,4 @@ class MultiDrawable(val bitmaps: ArrayList<Bitmap>) : Drawable() {
paint.colorFilter = colorFilter
}
//***------------------***//
}

}