Skip to content

Commit

Permalink
Technical: Update all the dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech committed May 15, 2024
1 parent d382c97 commit 648c3a4
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 144 deletions.
13 changes: 9 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[*.{kt,kts}]
ktlint_code_style=intellij_idea
indent_size=2
continuation_indent_size=2
insert_final_newline=true
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
insert_final_newline=true
ktlint_standard_annotation=disabled
ktlint_standard_argument-list-wrapping=disabled
ktlint_standard_spacing-between-declarations-with-annotations=disabled
ktlint_standard_max-line-length=disabled
ktlint_standard_filename=disabled
ktlint_standard_property-naming=disabled
ktlint_standard_spacing-between-declarations-with-annotations=disabled
ktlint_standard_blank-line-between-when-conditions=disabled
ktlint_standard_backing-property-naming=disabled
ktlint_standard_kdoc=disabled
ktlint_standard_condition-wrapping=disabled
ktlint_experimental=enabled
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ codeQualityTools {
}
ktlint {
toolVersion = libs.versions.ktlint.get()
experimental = true
}
detekt {
enabled = false // Don"t want.
Expand Down
21 changes: 21 additions & 0 deletions cropper/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,24 @@ dependencies {
testImplementation(libs.mock)
testImplementation(libs.robolectric)
}

// Workaround https://github.com/cashapp/paparazzi/issues/1231
plugins.withId("app.cash.paparazzi") {
// Defer until afterEvaluate so that testImplementation is created by Android plugin.
afterEvaluate {
dependencies.constraints {
add("testImplementation", "com.google.guava:guava") {
attributes {
attribute(
TargetJvmEnvironment.TARGET_JVM_ENVIRONMENT_ATTRIBUTE,
objects.named(TargetJvmEnvironment::class.java, TargetJvmEnvironment.STANDARD_JVM),
)
}
because(
"LayoutLib and sdk-common depend on Guava's -jre published variant." +
"See https://github.com/cashapp/paparazzi/issues/906.",
)
}
}
}
}
136 changes: 57 additions & 79 deletions cropper/src/main/kotlin/com/canhub/cropper/BitmapUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,35 +128,33 @@ internal object BitmapUtils {
uri: Uri,
reqWidth: Int,
reqHeight: Int,
): BitmapSampled {
return try {
val resolver = context.contentResolver
// First decode with inJustDecodeBounds=true to check dimensions
val options = decodeImageForOption(resolver, uri)
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
// Calculate inSampleSize
options.inSampleSize = max(
calculateInSampleSizeByRequestedSize(
width = options.outWidth,
height = options.outHeight,
reqWidth = reqWidth,
reqHeight = reqHeight,
),
calculateInSampleSizeByMaxTextureSize(
width = options.outWidth,
height = options.outHeight,
),
)
// Decode bitmap with inSampleSize set
val bitmap = decodeImage(
resolver = resolver,
uri = uri,
options = options,
)
BitmapSampled(bitmap, options.inSampleSize)
} catch (e: Exception) {
throw CropException.FailedToLoadBitmap(uri, e.message)
}
): BitmapSampled = try {
val resolver = context.contentResolver
// First decode with inJustDecodeBounds=true to check dimensions
val options = decodeImageForOption(resolver, uri)
if (options.outWidth == -1 && options.outHeight == -1) throw RuntimeException("File is not a picture")
// Calculate inSampleSize
options.inSampleSize = max(
calculateInSampleSizeByRequestedSize(
width = options.outWidth,
height = options.outHeight,
reqWidth = reqWidth,
reqHeight = reqHeight,
),
calculateInSampleSizeByMaxTextureSize(
width = options.outWidth,
height = options.outHeight,
),
)
// Decode bitmap with inSampleSize set
val bitmap = decodeImage(
resolver = resolver,
uri = uri,
options = options,
)
BitmapSampled(bitmap, options.inSampleSize)
} catch (e: Exception) {
throw CropException.FailedToLoadBitmap(uri, e.message)
}

/**
Expand Down Expand Up @@ -325,58 +323,42 @@ internal object BitmapUtils {
/**
* Get left value of the bounding rectangle of the given points.
*/
fun getRectLeft(points: FloatArray): Float {
return min(min(min(points[0], points[2]), points[4]), points[6])
}
fun getRectLeft(points: FloatArray): Float = min(min(min(points[0], points[2]), points[4]), points[6])

/**
* Get top value of the bounding rectangle of the given points.
*/
fun getRectTop(points: FloatArray): Float {
return min(min(min(points[1], points[3]), points[5]), points[7])
}
fun getRectTop(points: FloatArray): Float = min(min(min(points[1], points[3]), points[5]), points[7])

/**
* Get right value of the bounding rectangle of the given points.
*/
fun getRectRight(points: FloatArray): Float {
return max(max(max(points[0], points[2]), points[4]), points[6])
}
fun getRectRight(points: FloatArray): Float = max(max(max(points[0], points[2]), points[4]), points[6])

/**
* Get bottom value of the bounding rectangle of the given points.
*/
fun getRectBottom(points: FloatArray): Float {
return max(max(max(points[1], points[3]), points[5]), points[7])
}
fun getRectBottom(points: FloatArray): Float = max(max(max(points[1], points[3]), points[5]), points[7])

/**
* Get width of the bounding rectangle of the given points.
*/
fun getRectWidth(points: FloatArray): Float {
return getRectRight(points) - getRectLeft(points)
}
fun getRectWidth(points: FloatArray): Float = getRectRight(points) - getRectLeft(points)

/**
* Get height of the bounding rectangle of the given points.
*/
fun getRectHeight(points: FloatArray): Float {
return getRectBottom(points) - getRectTop(points)
}
fun getRectHeight(points: FloatArray): Float = getRectBottom(points) - getRectTop(points)

/**
* Get horizontal center value of the bounding rectangle of the given points.
*/
fun getRectCenterX(points: FloatArray): Float {
return (getRectRight(points) + getRectLeft(points)) / 2f
}
fun getRectCenterX(points: FloatArray): Float = (getRectRight(points) + getRectLeft(points)) / 2f

/**
* Get vertical center value of the bounding rectangle of the given points.
*/
fun getRectCenterY(points: FloatArray): Float {
return (getRectBottom(points) + getRectTop(points)) / 2f
}
fun getRectCenterY(points: FloatArray): Float = (getRectBottom(points) + getRectTop(points)) / 2f

/**
* Get a rectangle for the given 4 points (x0,y0,x1,y1,x2,y2,x3,y3) by finding the min/max 2
Expand Down Expand Up @@ -457,7 +439,7 @@ internal object BitmapUtils {
): Uri {
val newUri = customOutputUri ?: buildUri(context, compressFormat)

return context.contentResolver.openOutputStream(newUri, WRITE_AND_TRUNCATE).use {
return context.contentResolver.openOutputStream(newUri, WRITE_AND_TRUNCATE)!!.use {
bitmap.compress(compressFormat, compressQuality, it)
newUri
}
Expand Down Expand Up @@ -701,14 +683,12 @@ internal object BitmapUtils {
* Decode image from uri using "inJustDecodeBounds" to get the image dimensions.
*/
@Throws(FileNotFoundException::class)
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options {
return resolver.openInputStream(uri).use {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
options.inJustDecodeBounds = false
options
}
private fun decodeImageForOption(resolver: ContentResolver, uri: Uri): BitmapFactory.Options = resolver.openInputStream(uri).use {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
BitmapFactory.decodeStream(it, EMPTY_RECT, options)
options.inJustDecodeBounds = false
options
}

/**
Expand Down Expand Up @@ -790,14 +770,14 @@ internal object BitmapUtils {
* Note: rotating by 0, 90, 180 or 270 degrees doesn't require extra cropping.
*/
private fun cropForRotatedImage(
bitmap: Bitmap?,
bitmap: Bitmap,
cropPoints: FloatArray,
rect: Rect,
degreesRotated: Int,
fixAspectRatio: Boolean,
aspectRatioX: Int,
aspectRatioY: Int,
): Bitmap? {
): Bitmap {
var tempBitmap = bitmap
if (degreesRotated % 90 != 0) {
var adjLeft = 0
Expand Down Expand Up @@ -888,22 +868,20 @@ internal object BitmapUtils {
degrees: Int,
flipHorizontally: Boolean,
flipVertically: Boolean,
): Bitmap {
return if (degrees > 0 || flipHorizontally || flipVertically) {
val matrix = Matrix()
matrix.setRotate(degrees.toFloat())
matrix.postScale(
(if (flipHorizontally) -1 else 1).toFloat(),
(if (flipVertically) -1 else 1).toFloat(),
)
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
if (newBitmap != bitmap) {
bitmap.recycle()
}
newBitmap
} else {
bitmap
): Bitmap = if (degrees > 0 || flipHorizontally || flipVertically) {
val matrix = Matrix()
matrix.setRotate(degrees.toFloat())
matrix.postScale(
(if (flipHorizontally) -1 else 1).toFloat(),
(if (flipVertically) -1 else 1).toFloat(),
)
val newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, false)
if (newBitmap != bitmap) {
bitmap.recycle()
}
newBitmap
} else {
bitmap
}
// Only need to check for width since opengl textures are always squared
// Keep track of the maximum texture size
Expand Down
4 changes: 3 additions & 1 deletion cropper/src/main/kotlin/com/canhub/cropper/CropImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ object CropImage {
/**
* Result data of Crop Image Activity.
*/
open class ActivityResult : CropResult, Parcelable {
open class ActivityResult :
CropResult,
Parcelable {

constructor(
originalUri: Uri?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import com.canhub.cropper.databinding.CropImageActivityBinding
import com.canhub.cropper.utils.getUriForFile
import java.io.File

open class CropImageActivity : AppCompatActivity(), OnSetImageUriCompleteListener, OnCropImageCompleteListener {
open class CropImageActivity :
AppCompatActivity(),
OnSetImageUriCompleteListener,
OnCropImageCompleteListener {

/** Persist URI image to crop URI if specific permissions are required. */
private var cropImageUri: Uri? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import android.widget.ImageView
internal class CropImageAnimation(
private val imageView: ImageView,
private val cropOverlayView: CropOverlayView,
) : Animation(), AnimationListener {
) : Animation(),
AnimationListener {

private val startBoundPoints = FloatArray(8)
private val endBoundPoints = FloatArray(8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ internal class CropImageIntentChooser(
* See [StackOverflow
* question](http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug).
*/
private fun isExplicitCameraPermissionRequired(context: Context): Boolean {
return SDK_INT >= Build.VERSION_CODES.M &&
hasCameraPermissionInManifest(context) &&
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
}
private fun isExplicitCameraPermissionRequired(context: Context): Boolean = SDK_INT >= Build.VERSION_CODES.M &&
hasCameraPermissionInManifest(context) &&
context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED

/**
* Check if the app requests a specific permission in the manifest.
Expand Down
17 changes: 8 additions & 9 deletions cropper/src/main/kotlin/com/canhub/cropper/CropImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ import kotlin.math.sqrt
class CropImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
) : FrameLayout(context, attrs), CropWindowChangeListener {
) : FrameLayout(context, attrs),
CropWindowChangeListener {

/** Image view widget used to show the image for cropping. */
private val imageView: ImageView
Expand Down Expand Up @@ -1756,15 +1757,13 @@ class CropImageView @JvmOverloads constructor(
*
* [context] used to retrieve the bitmap in case you need from activity result
*/
fun getBitmap(context: Context): Bitmap? {
return bitmap ?: try {
when {
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
}
} catch (e: Exception) {
null
fun getBitmap(context: Context): Bitmap? = bitmap ?: try {
when {
SDK_INT >= 28 -> ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uriContent!!))
else -> @Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(context.contentResolver, uriContent)
}
} catch (e: Exception) {
null
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@ class ContractTestFragment(
cropImage.launch(input)
}

fun cropImageIntent(input: CropImageContractOptions): Intent {
return cropImage.contract.createIntent(requireContext(), input)
}
fun cropImageIntent(input: CropImageContractOptions): Intent = cropImage.contract.createIntent(requireContext(), input)
}
Loading

0 comments on commit 648c3a4

Please sign in to comment.