Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to set result min size #480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

HadiHabibza
Copy link

No description provided.

@premacck
Copy link

For people still waiting on this PR to be merged, I created a workaround, Which involves creating a class extending UCropActivity and foloowing code:

  • Add private var isReadyToFinish = true property
  • Add private lateinit var loader: MenuItem property to reference the top right loader and initialize it in onCreateOptionsMenu()
  override fun onCreateOptionsMenu(menu: Menu?): Boolean {
    val result = super.onCreateOptionsMenu(menu)
    loader = menu.findItem(R.id.menu_loader)!!
    return result
  }
  • Also, there's a blocking view set, to get a reference:
  private lateinit var blockingView: View
  //...

  override fun onStart() {
  //...
  blockingView = ucrop_photobox.getChildAt(ucrop_photobox.childCount - 1)  // Last view in the layout
  // ucrop_photobox is a kotlin extension reference to the R.id.ucrop_photobox ViewGroup in the ucrop_activity_photobox.xml file
  // You can override that file if you can't find the reference.
  }
  • Override setResultUri() function like this
  override fun setResultUri(uri: Uri?, resultAspectRatio: Float, offsetX: Int, offsetY: Int, imageWidth: Int, imageHeight: Int) {
    if (imageWidth in MIN_WIDTH .. MAX_WIDTH && imageHeight in MIN_HEIGHT .. MAX_HEIGHT) {
      isReadyToFinish = true
      super.setResultUri(uri, resultAspectRatio, offsetX, offsetY, imageWidth, imageHeight)
    } else {
      isReadyToFinish = false
      loader.isVisible = false
      blockingView.isClickable = false
      
      // Do whatever you want here, when the image dimensions are out of bounds
    }
  }

  override fun finish() {
    if (isReadyToFinish) {
      super.finish()
    }
  }```

I know it looks a little hack-ey but hey, it works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants