Skip to content

Commit

Permalink
Merge pull request avito-tech#24 from Kutashov/krop-renderer-updates
Browse files Browse the repository at this point in the history
Krop renderer updates
  • Loading branch information
Kutashov authored Jan 26, 2021
2 parents 256e894 + 5b8d83d commit ce267c5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
Binary file added app/src/main/assets/default_image_vertical.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions krop/src/main/java/com/avito/android/krop/KropView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,33 @@ class KropView(context: Context, attrs: AttributeSet) : FrameLayout(context, att
imageView.setZoom(scale)
}

fun setMaxScale(scale: Float) {
imageView.maxZoom = scale
}

fun setMinScale(scale: Float) {
imageView.minZoom = scale
}

fun setBitmap(bitmap: Bitmap) {
this.bitmap = bitmap
imageView.setImageBitmap(bitmap)
}

fun setTransformation(transformation: Transformation) {
with(transformation) {
val scale = if (size.height > size.width) {
size.width / (crop.right - crop.left)
} else {
size.height / (crop.bottom - crop.top)
}
val focusX = (crop.right + crop.left) / (2 * size.width)
val focusY = (crop.bottom + crop.top) / (2 * size.height)

imageView.setZoom(scale = scale, focusX = focusX, focusY = focusY)
}
}

fun getTransformation(): Transformation {
val transformation = Transformation()
val bitmap = bitmap ?: return transformation
Expand Down
5 changes: 5 additions & 0 deletions krop/src/main/java/com/avito/android/krop/SizeF.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class SizeF(var width: Float = 0.0f, var height: Float = 0.0f) : Parcelable {
return 0
}

override fun toString(): String {
return "SizeF(width=$widthInt, height=$heightInt)"
}


companion object CREATOR : Parcelable.Creator<SizeF> {
override fun createFromParcel(parcel: Parcel): SizeF {
return SizeF(parcel)
Expand Down
4 changes: 4 additions & 0 deletions krop/src/main/java/com/avito/android/krop/Transformation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class Transformation(var size: SizeF = SizeF(), var crop: RectF = RectF()) : Par
return 0
}

override fun toString(): String {
return "Transformation(size=$size, crop=$crop)"
}

companion object CREATOR : Parcelable.Creator<Transformation> {
override fun createFromParcel(parcel: Parcel): Transformation {
return Transformation(parcel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ class ZoomableImageView : ImageView {
imgMatrix = Matrix()
prevMatrix = Matrix()
matrix = FloatArray(9)
currentZoom = 1.0f
currentZoom = DEFAULT_MIN_ZOOM
imageScaleType = ScaleType.CENTER_CROP
minScale = 1.0f
maxScale = 5.0f
minScale = DEFAULT_MIN_ZOOM
maxScale = DEFAULT_MAX_ZOOM
superMinScale = SUPER_MIN_MULTIPLIER * minScale
superMaxScale = SUPER_MAX_MULTIPLIER * maxScale
imageMatrix = imgMatrix
Expand Down Expand Up @@ -976,6 +976,8 @@ class ZoomableImageView : ImageView {

}

private const val DEFAULT_MIN_ZOOM = 1f
private const val DEFAULT_MAX_ZOOM = 5f
private const val SUPER_MIN_MULTIPLIER = .75f
private const val SUPER_MAX_MULTIPLIER = 1.25f
private const val ZOOM_TIME = 300f

0 comments on commit ce267c5

Please sign in to comment.