Skip to content

Commit

Permalink
Analysis: Resolve type mismatch type warning for app module
Browse files Browse the repository at this point in the history
Warning Message: "Type mismatch: inferred type is Bitmap? but Bitmap was
expected"
  • Loading branch information
ParaskP7 committed Nov 17, 2022
1 parent 1315ae8 commit d09302b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,13 @@ open class MainActivity : AppCompatActivity(),

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK) {
var bitmap: Bitmap

when (requestCode) {
REQUEST_MEDIA_CAMERA_PHOTO -> {
// By default, BitmapFactory.decodeFile sets the bitmap's density to the device default so, we need
// to correctly set the input density to 160 ourselves.
val options = BitmapFactory.Options()
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
bitmap = BitmapFactory.decodeFile(mediaPath, options)
val bitmap = BitmapFactory.decodeFile(mediaPath, options)
insertImageAndSimulateUpload(bitmap, mediaPath)
}
REQUEST_MEDIA_PHOTO -> {
Expand All @@ -271,7 +269,7 @@ open class MainActivity : AppCompatActivity(),
// to correctly set the input density to 160 ourselves.
val options = BitmapFactory.Options()
options.inDensity = DisplayMetrics.DENSITY_DEFAULT
bitmap = BitmapFactory.decodeStream(stream, null, options)
val bitmap = BitmapFactory.decodeStream(stream, null, options)

insertImageAndSimulateUpload(bitmap, mediaPath)
}
Expand All @@ -287,7 +285,7 @@ open class MainActivity : AppCompatActivity(),

override fun onThumbnailLoaded(drawable: Drawable?) {
val conf = Bitmap.Config.ARGB_8888 // see other conf types
bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
val bitmap = Bitmap.createBitmap(drawable!!.intrinsicWidth, drawable.intrinsicHeight, conf)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
Expand Down

0 comments on commit d09302b

Please sign in to comment.