Convert Figma logo to code with AI

williamyyu logoSimpleRatingBar

A simple RatingBar that you can easier to customize image and animations

1,365
152
1,365
13

Top Related Projects

A simple RatingBar that you can easier to customize image and animations

This library allows to use Material steppers inside Android applications.

2,178

A star rating control for iOS/tvOS written in Swift

Quick Overview

SimpleRatingBar is a customizable Android rating bar library that allows developers to easily implement and style rating functionality in their applications. It offers a range of customization options and smooth animations, making it a versatile choice for various rating scenarios.

Pros

  • Highly customizable with options for star size, color, spacing, and more
  • Smooth animations for rating changes and user interactions
  • Supports both touch and click events for rating selection
  • Lightweight and easy to integrate into existing Android projects

Cons

  • Limited to star-based rating system, may not be suitable for other rating styles
  • Documentation could be more comprehensive, especially for advanced customization
  • No built-in support for half-star ratings (though it can be implemented with custom drawables)
  • Lacks accessibility features for screen readers

Code Examples

  1. Basic implementation of SimpleRatingBar:
val ratingBar = findViewById<SimpleRatingBar>(R.id.ratingBar)
ratingBar.rating = 3.5f
ratingBar.setOnRatingBarChangeListener { ratingBar, rating, fromUser ->
    Log.d("SimpleRatingBar", "New rating: $rating")
}
  1. Customizing the appearance of SimpleRatingBar:
ratingBar.apply {
    starSize = 60f
    starCornerRadius = 5f
    starBackgroundColor = Color.LTGRAY
    starFillColor = Color.YELLOW
    starBorderColor = Color.BLACK
    starBorderWidth = 2f
    numberOfStars = 5
    stepSize = 0.5f
}
  1. Implementing a custom drawable for the rating stars:
ratingBar.setStarDrawable(R.drawable.custom_star)
ratingBar.setEmptyStarDrawable(R.drawable.custom_empty_star)

Getting Started

To use SimpleRatingBar in your Android project, follow these steps:

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.williamyyu:SimpleRatingBar:1.5.1'
}
  1. Include the SimpleRatingBar in your layout XML:
<com.willy.ratingbar.ScaleRatingBar
    android:id="@+id/simpleRatingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srb_starSize="40dp"
    app:srb_numberOfStars="5"
    app:srb_rating="3"
    app:srb_stepSize="0.5" />
  1. Initialize and use the SimpleRatingBar in your Activity or Fragment:
val ratingBar = findViewById<SimpleRatingBar>(R.id.simpleRatingBar)
ratingBar.rating = 3.5f

Competitor Comparisons

A simple RatingBar that you can easier to customize image and animations

Pros of SimpleRatingBar

  • Identical functionality and features
  • Same customization options for star appearance and behavior
  • Equivalent performance and efficiency

Cons of SimpleRatingBar

  • No significant differences or drawbacks
  • Identical codebase and implementation
  • Same level of documentation and support

Code Comparison

Both repositories contain the same code, as they are identical. Here's a sample from both:

public class SimpleRatingBar extends View {
    private int starNum;
    private float starSize;
    private float starSpace;
    private float starProgress;
    private int starEmptyColor;
    private int starFillColor;
    // ... (rest of the code is identical)
}

Summary

The comparison between SimpleRatingBar and SimpleRatingBar reveals that they are, in fact, the same repository. There are no differences in functionality, features, or implementation. Both offer a customizable rating bar for Android applications with the ability to set the number of stars, star size, spacing, and colors. The repositories share identical code, documentation, and support levels. Users can choose either repository interchangeably without any impact on their project's functionality or performance.

This library allows to use Material steppers inside Android applications.

Pros of android-material-stepper

  • Implements a complete stepper UI component for Android, following Material Design guidelines
  • Offers more customization options and flexibility for multi-step processes
  • Provides built-in validation and error handling for each step

Cons of android-material-stepper

  • More complex to implement and integrate compared to SimpleRatingBar
  • Larger library size and potential performance impact due to additional features
  • May be overkill for simple rating or progress tracking use cases

Code Comparison

SimpleRatingBar:

val ratingBar = SimpleRatingBar(context)
ratingBar.rating = 3.5f
ratingBar.stepSize = 0.5f

android-material-stepper:

class StepperActivity : AbstractStepperActivity() {
    override fun createSteppers(): List<Step> {
        return listOf(
            StepOne(),
            StepTwo(),
            StepThree()
        )
    }
}

While SimpleRatingBar focuses on providing a customizable rating bar component, android-material-stepper offers a comprehensive solution for creating multi-step processes in Android applications. SimpleRatingBar is more suitable for simple rating scenarios, while android-material-stepper is better suited for complex, guided user interactions that require multiple steps and validation.

2,178

A star rating control for iOS/tvOS written in Swift

Pros of Cosmos

  • Written in Swift, providing native iOS support and better performance
  • Offers more customization options, including fill mode and text
  • Supports half-star ratings out of the box

Cons of Cosmos

  • Limited to iOS platform, while SimpleRatingBar is for Android
  • Larger codebase, potentially more complex to integrate and maintain
  • May have a steeper learning curve for developers new to Swift

Code Comparison

SimpleRatingBar (Java):

SimpleRatingBar ratingBar = findViewById(R.id.rating_bar);
ratingBar.setRating(3.5f);
ratingBar.setOnRatingChangeListener(new SimpleRatingBar.OnRatingChangeListener() {
    @Override
    public void onRatingChange(SimpleRatingBar simpleRatingBar, float rating) {
        // Handle rating change
    }
});

Cosmos (Swift):

let cosmosView = CosmosView()
cosmosView.rating = 3.5
cosmosView.didFinishTouchingCosmos = { rating in
    // Handle rating change
}
view.addSubview(cosmosView)

Both libraries provide easy-to-use rating bar functionality, but they cater to different platforms. SimpleRatingBar is more suitable for Android developers, while Cosmos is ideal for iOS projects. The code snippets demonstrate that both libraries offer similar basic functionality, with slight differences in syntax and implementation due to the languages used.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SimpleRatingBar

JitPack

The simplest RatingBar library, create your own animate RatingBar in a few steps!

Provide three RatingBars at the moment:

  • BaseRatingBar
    A RatingBar without any animation.
  • ScaleRatingBar
    A RatingBar with progressive and scale animation.
  • RotationRatingBar (contributed by nappannda)
    A RatingBar with progressive and rotate animation.

What's Next?

  • Release the Kotlin version of the library!
  • Feel free to post any suggestions you would like to improve!

Demo



Icon made by Freepik from www.flaticon.com

What's New (v1.5.1)

  • Fixed stepSize bug (#91)
  • Fixed the match parent issue(start didn't consume the whole width)

Feature

  • Allow half star through click event. (contributed by ANPez)
  • Support step size setting(range from 0.1 to 1.0).
  • Support float rating
    • Now you can set a float rating like 3.5, 2.3, 4.7, etc., but you only need to provide two images: filled and empty, and Library will auto processes your images to support float showing!
  • Stars width and height setting. (contributed by zhangruize)
  • Support use touch to change rating
  • Custom drawable's padding
  • Custom your empty and filled drawable
  • Click again to clear rating
  • IsIndicator, Scrollable, Touchable and Clickable settings
  • Rotate animation
  • Scale animation

How To Use

Install

from JitPack:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    compile 'com.github.ome450901:SimpleRatingBar:LATEST_VERSION'
}

In Xml

<com.willy.ratingbar.ScaleRatingBar
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/simpleRatingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srb_numStars="3"
        app:srb_minimumStars="1"
        app:srb_rating="2"
        app:srb_starWidth="30dp"
        app:srb_starHeight="30dp"
        app:srb_starPadding="15dp"
        app:srb_stepSize="0.5"
        app:srb_isIndicator="false"
        app:srb_clickable="true"
        app:srb_scrollable="true"
        app:srb_clearRatingEnabled="true"
        app:srb_drawableEmpty="@drawable/start_empty"
        app:srb_drawableFilled="@drawable/star_filled">
</com.willy.ratingbar.ScaleRatingBar>

In Your Code

ScaleRatingBar ratingBar = new ScaleRatingBar(this);
ratingBar.setNumStars(5);
ratingBar.setMinimumStars(1);
ratingBar.setRating(3);
ratingBar.setStarPadding(10);
ratingBar.setStepSize(0.5f);
ratingBar.setWidth(105);
ratingBar.setHeight(105);
ratingbar.setIsIndicator(false);
ratingbar.setClickable(true);
ratingbar.setScrollable(true);
ratingbar.setClearRatingEnabled(true);
ratingBar.setEmptyDrawableRes(R.drawable.start_empty);
ratingBar.setFilledDrawableRes(R.drawable.start_empty);
ratingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
    @Override
        public void onRatingChange(BaseRatingBar ratingBar, int rating, boolean fromUser) {
            Log.e(TAG, "onRatingChange: " + rating);
    }
});

Want to Implement Your Own Animation?

Only TWO STEPS you need to do:

  • Create a class that extend BaseRatingBar
  • Override the emptyRatingBar and fillRatingBar this two method, and then you can start implement your own animaion!

You can follow ScaleRatingBar to implement your own class.

Todo

  • Implement some other animations
  • Find a better way to implement animation

About Me

Follow me at Medium.

License

MIT License

Copyright (c) 2019 WilliamYu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.