Git Product home page Git Product logo

ratingsview's Introduction

RatingsView

An android custom view to show ratings

API Download Generic badge

demo

Dependency

Add this to your module build.gradle:

dependencies {
    implementation 'dev.kunaal:ratings_view:0.0.8'
}

Table of Contents

Usage

Basic

Basic Demo

<dev.kunaal.ratings_view.RatingsView
        app:textColor="@color/colorAccent"
        app:arcColor="@color/colorAccent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
val ratingsView = findViewById<RatingsView>(R.id.ratings_view)

ratingsView.rating = 84

This will animate the number to 84, as well as the arc itself.

Rating Number

Rating Scale Demo

The rating text size can be changed by:

ratingsView.textScale = 1.5F

Or via XML by:

app:textScale="1.5"

This will increase the text size by 50% of it's normal size. By default this value is set to 1F

Rating Text Color

Rating Text Color Demo

The text color can be changed by:

ratingsView.setTextColor(Color.GREEN)

Or via XML by:

app:textColor="@color/green"

By default this value is set to R.attr.colorAccent

Rating Arc Color

Rating Arc Color Demo

The arc color can be changed by:

ratingsView.setArcColor(Color.GREEN)

Or via XML by:

app:arcColor="@color/green"

By default this value is set to R.attr.colorPrimary

Rating Arc Width Scale

Rating Arc Width Demo

The arc width can be changed by:

ratingsView.setArcWidthScale(1.5F)

Or via XML by:

app:arcWidthScale="1.5"

This will increase the text size by 50% of it's normal size. By default this value is set to 1F

Background Color

Background Color Demo

The background color can be changed by:

ratingsView.setBgColor(Color.ORANGE)

Or via XML by:

app:bgColor="@color/orange"

To remove the background color, set the background color to android.R.color.transparent

By default there is no background color.

Multiple Arc (Threshold) Colors

Threshold Colors Demo

Arc color can be changed depending on the ratings value.

ratingsView.addArcThresholdColor(0, Color.RED)
ratingsView.addArcThresholdColor(50, Color.GREEN)

This will change the arc color to red if the rating number is in-between 0-49, and green if the rating number is in-between 50-100

A more convenient way of adding colors is by adding a map.

private val colorsMap = mapOf<Int, Int>(
            0 to Color.RED,
            25 to Color.ORANGE,
            50 to Color.YELLOW,
            75 to Color.GREEN
    )

ratingsView.addArcThresholdColor(colorsMap)

The following colors will apply:

  • 0 - 24 => Red
  • 25 - 49 => Orange
  • 50 - 74 => Yellow
  • 75 - 100 => Green

To replace a color, just set it again:

// 0 - 100 is Red
ratingsView.addArcThresholdColor(0, Color.RED)
// 0 - 100 is Green now
ratingsView.addArcThresholdColor(0, Color.GREEN)

To replace multiple colors, use a map.

All colors can be removed by calling:

ratingsView.removeAllArcThresholdColor()

This will set the arc color to the default color, which is the color defined by app:arcColor in the XML, or the primary color (R.attr.colorPrimary) of the app.

Loading Animation

Loading Animation Demo

A loading animation can be started by ratingsView.startLoadingAnimation() and stopped by ratingsView.stopLoadingAnimation()

More conveniently, as the view is self-aware of it's loading state, ratingsView.toggleLoadingAnimation() can be called to automatically toggle between start and stop loading states

While in loading state, the outer arc uses the arcColor and the inner arc uses the textColor.

ratingsview's People

Contributors

kunaalkumar avatar

Stargazers

 avatar

Watchers

James Cloos avatar

ratingsview's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.