diff --git a/app/src/main/assets/default_image_vertical.jpg b/app/src/main/assets/default_image_vertical.jpg new file mode 100644 index 0000000..233ef99 Binary files /dev/null and b/app/src/main/assets/default_image_vertical.jpg differ diff --git a/krop/src/main/java/com/avito/android/krop/KropView.kt b/krop/src/main/java/com/avito/android/krop/KropView.kt index ab765ee..fd7cb73 100644 --- a/krop/src/main/java/com/avito/android/krop/KropView.kt +++ b/krop/src/main/java/com/avito/android/krop/KropView.kt @@ -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 diff --git a/krop/src/main/java/com/avito/android/krop/SizeF.kt b/krop/src/main/java/com/avito/android/krop/SizeF.kt index c64a95c..beabcba 100644 --- a/krop/src/main/java/com/avito/android/krop/SizeF.kt +++ b/krop/src/main/java/com/avito/android/krop/SizeF.kt @@ -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 { override fun createFromParcel(parcel: Parcel): SizeF { return SizeF(parcel) diff --git a/krop/src/main/java/com/avito/android/krop/Transformation.kt b/krop/src/main/java/com/avito/android/krop/Transformation.kt index f2fb3cf..a27092c 100644 --- a/krop/src/main/java/com/avito/android/krop/Transformation.kt +++ b/krop/src/main/java/com/avito/android/krop/Transformation.kt @@ -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 { override fun createFromParcel(parcel: Parcel): Transformation { return Transformation(parcel) diff --git a/krop/src/main/java/com/avito/android/krop/ZoomableImageView.kt b/krop/src/main/java/com/avito/android/krop/ZoomableImageView.kt index 8855929..bb0ad77 100644 --- a/krop/src/main/java/com/avito/android/krop/ZoomableImageView.kt +++ b/krop/src/main/java/com/avito/android/krop/ZoomableImageView.kt @@ -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 @@ -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