CircleImageView 3.0.0 released

After more than a year without a new release I published CircleImageView 3.0.0 earlier today. The new version is now available on your favorite Maven central mirror.

Why a new release you might ask. Well, that's simple: AndroidX. Google released the first stable version in September and at the same time basically deprecated the Support Library. More and more projects are doing the migration hence more and more people asked for a new release with an updated dependency. CircleImageView depends on the annotation support library for Resource Annotations used in the public API.

As this change alone might be breaking for some projects I decided to do a major version bump. This opened up the possibility to get rid of some deprecated methods in the API at the same time.

The third (and only user-facing) change is a tweak to the touch handling. While CircleImageView visually crops images into a circle, the touchable area of the view was actually still square, hence you could touch outside of the circle (but inside that virtual square enclosing it) and get a click callback. This has now been changed so that only the circle itself is touchable.

So how does it work? A view decides if it wants to handle a touch event in onTouchEvent so all I had to do was override it and implement some logic to determine if a touch event actually happened within the bounds of the circle before calling the super implementation to do the actual handling. This is the whole thing:

@Override
public boolean onTouchEvent(MotionEvent event) {
    return inTouchableArea(event.getX(), event.getY()) && super.onTouchEvent(event);
}

private boolean inTouchableArea(float x, float y) {
    return Math.pow(x - mBorderRect.centerX(), 2) + Math.pow(y - mBorderRect.centerY(), 2) <= Math.pow(mBorderRadius, 2);
}

I guess this is pretty self-explanatory.

Head over to GitHub for the full changelog and update your dependencies to point to the new version:

dependencies {
    ...
    implementation 'de.hdodenhof:circleimageview:3.0.0'
}

Happy coding!