FlyingPumba / SimpleRatingBar

Open source project which features a simple yet powerful RatingBar alternative to Android's default
Apache License 2.0
1.03k stars 142 forks source link

stepSize = 1; tapping on left half of a star doesn't register that star as rating #11

Closed ghost closed 8 years ago

ghost commented 8 years ago

Ideally regardless of the localtion, the full star should be registered for step size 1.

Solution Suggestion: In setNewRatingFromTouch(…)

private void setNewRatingFromTouch(float x, float y) {
  …

  if (stepSize != Float.MAX_VALUE) {
    float mod = rating % stepSize;

    // --> Old code
    if (mod < stepSize/2) {
      rating = rating - mod;
      rating = Math.max(0, rating);
    } else {
      rating =  rating - mod + stepSize;
      rating = Math.min(numberOfStars, rating);
    }
    // <-- Old code

    // --> New
    rating = rating - mod +stepSize;
    rating = Math.min(numberOfStars, rating);
    // <-- New

  }

  …
}
FlyingPumba commented 8 years ago

@iontech I like your suggestion, and I just tried it out. The problem is that once you touch the first star, it's very hard to undo this rating. The current solution is not great, but it ensures that the user can always choose the rating he/she wants.

What do you think of using if (mod < stepSize/4) ? it seems to improve the overall feeling when rating.

ghost commented 8 years ago

The platform provided RatingBar in android doesn't let the user set a zero rating by tapping on the first star. The user has to tap and drag their finger off to the left edge of the rating bar to make it zero stars. So, my best argument is that the platform expects users of the widget to discover this ability and use it as the only means to set zero rating.

FlyingPumba commented 8 years ago

@iontech The gesture you mentioned is something I would like to avoid. Although it might be true that it's the standard imposed by the stock RatingBar, we have to also take into account that this widget is implemented by subclassing ProgressBar, where that gesture makes more sense. I'll use mod < stepSize/4 in next release of this library in hope that it will improve the usability, and leave this issue open in case we decide to change it later.

muddin1 commented 8 years ago

I like mod < stepSize/4's behavior better. Preferable.