SmileyRating is a simple rating bar for android. It displays animated smileys as rating icon.

Overview

Smiley Rating

SmileyRating is a simple rating bar for android. It displays animated smileys as rating icon.

  • Drawn completely using android canvas
  • Inspired by Bill Labus

Demo

Integration

Integrating SmileyRating in your project is very simple.

Step 1:

Add this dependency in your project's build.gradle file which is in your app folder

compile 'com.github.sujithkanna:smileyrating:2.0.0'

add this to your dependencies.

Step 2:

Now place the SmileyRating in your layout.

Note: The height of the SmileyRating will be automatically adjusted according to the width of this component.
<com.hsalf.smileyrating.SmileyRating
        android:id="@+id/smile_rating"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

Set this SmileySelectedListener to get notified when user selects a smiley

By default the selected smiley will be NONE

smileyRating.setSmileySelectedListener(new SmileyRating.OnSmileySelectedListener() {
            @Override
            public void onSmileySelected(SmileyRating.Type type) {
                // You can compare it with rating Type
                if (SmileyRating.Type.GREAT == type) {
                    Log.i(TAG, "Wow, the user gave high rating");
                }
                // You can get the user rating too
                // rating will between 1 to 5
                int rating = type.getRating();
            }
        });

Get current selection

SmileyRating.Type smiley = smileyRating.getSelectedSmiley();
// You can compare it with rating Type
if (SmileyRating.Type.GREAT == type) {
    Log.i(TAG, "Great rating is given");
}
 // You can get the user rating too
 // rating will between 1 to 5, but -1 is none selected
 int rating = type.getRating();

You can set selected smiley without user interaction

Without animation

smileRating.setRating(SmileyRating.Type.GREAT);
// Or you can give rating as number
// Valid inputs are 1 to 5.
// Giving -1 will reset the rating. Equivalent to Type.NONE
smileRating.setRating(5);

OR

smileRating.setRating(SmileyRating.Type.GREAT, false);
smileRating.setRating(5, false);

The smiley will be selected with animation and the listeners will be triggered

With animation

smileRating.setRating(SmileyRating.Type.GREAT, true);
smileRating.setRating(5, true);

Smiley will be selected with animation and listeners will also be triggered(Only if the second param is true)

Disallow selection

smileRating.disallowSelection(true);

You can disallow user input by passing true to this. You can set the smiley only using this. This is useful when you just want to show the rating.

Styling

smileRating.setTitle(SmileyRating.Type.GREAT, "Awesome");
smileRating.setFaceColor(SmileyRating.Type.GREAT, Color.BLUE);
smileRating.setFaceBackgroundColor(SmileyRating.Type.GREAT, Color.RED);

These are the helper methods to change the color and title of the Smiley. NOTE: The color values must be int colors Color.RED or Color.parse("#fff") or ResourcesCompat.getColor(getResources(), R.color.your_color, null);, not int resources like R.color.primaryColor.

(Currently setting these things in xml will make things complex. So any pull request for this will not be accepted)

Working with RecyclerView

To avoid conflict with RecyclerView touch events, you have to add the following implementation when putting the SmileyRating in RecyclerView. For that you have to create an instance of SmileyActivityIndicator as global variable inside your Activity where you use your RecyclerView.

final SmileyActiveIndicator smileyActiveIndicator = new SmileyActiveIndicator();

Now you have to link the SmileyActiveIndicator to the RecyclerView. This will tell the RecyclerView whether it can scroll or not.

recyclerView.setLayoutManager(new LinearLayoutManager(this) {
    @Override
    public boolean canScrollVertically() {
        return !smileyActiveIndicator.isActive();
    }
});

Now bind your SmileyRating view to the mSmileyActiveIndicator you have created.

@Override
public void onBindViewHolder(@NonNull Holder holder, final int position) {
    SmileyRating rating = holder.smileyRating;
    mSmileyActiveIndicator.bind(rating);
    // your code here
}
Comments
  • fails on nullpointerexception when setting a smiley for the first time

    fails on nullpointerexception when setting a smiley for the first time

    Your work is awsome! but now I need to make it work :) I follow the 3 steps in the usage part and I see the smilies in the designer preview. I did the following in an adapter: RatingViewHolder(View itemView) { super(itemView); srRating = (SmileRating) itemView.findViewById(R.id.smile_rating); srRating.setIndicator(true); //<< srRating is not null and this line works }

    @override public void onBindViewHolder(final RatingViewHolder holder, int position) { Rating theRating = RatingList.get(position); holder.srRating.setSelectedSmile(5,true); << fails* }

    • SmileRating.java, line 194 moveSmile(mTouchPoints.get(mSelectedSmile).x); <<< fails mTouchPoints size is 0 I put a breakpoint in line 255: createTouchPoints() but it never reaches there before the above code so it fails on nullpointerexception because there is no position 5

    Please advice, it seems that this is working for everyone so I wonder if I miss something Thanks

    question 
    opened by ghost 9
  • Selecting BaseRating.GREAT progammatically makes the view only partially visible on the left

    Selecting BaseRating.GREAT progammatically makes the view only partially visible on the left

    When i use smileRating.setSelectedSmile(BaseRating.GREAT); it makes the view invisible(only partially visible on the left) but the rest of the rating work okay during the initialization of the view .When you tap on any rating it reverts to the normal state.Cheers.

    opened by muigukenneth 7
  • Attribute to change line color

    Attribute to change line color

    Hello and thanks again for such a great library. I'm loving it!

    I think a missing feature is one to allow to change the line color, that one:

    Screenshot

    Something like app:lineColor="#FF000000" would be awesome.

    Thanks!

    opened by dgadelha 6
  • Range discordance between getRating and setSelectedSmile

    Range discordance between getRating and setSelectedSmile

    values returned by getRating() range from 1 to 5, with 0 for none selected but values expected by setSelectedSmile range from 0 to 5 with -1 for non selected

    This makes it hazardous to store and display values through the scale : if you store as int userSatisfaction the value from the level variable inside the onRatingSelected of a SmileRating.OnRatingSelectedListener and later you want to display a scale with the same value, you have to set it like : SmileRating.setSelectedSmile(userSatisfaction -1); to adapt the range offset... this is quite unintuitive

    This is not an issue per se but I spent quite some time thinking the #22 was not really fixed when in fact I was setting my SmileRating to level 5, which does not exist...

    Anyway, many thanks for your great work!

    opened by shining-cat 5
  • Rating reset on keyboard open

    Rating reset on keyboard open

    I have multiple smileyrating bars and edittexts in my view. after selecting smileys on ratingbars when i try to enter text in edittext, all ratingbars reset to default smiley.

    videotogif_2017 03 30_15 28 33

    bug 
    opened by haris4063 5
  • setNameForSmile returns null object Reference

    setNameForSmile returns null object Reference

    Hi. I'm trying to change name of Smiles and it throws null object reference; here is my code in a fragment.

    final RatingDiaglogClass ratingDiaglogClass = new RatingDiaglogClass(contextHolder, R.style.RatingDialogTheme);
    LayoutInflater inflater = (LayoutInflater) contextHolder.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View dv = inflater.inflate(R.layout.layout_rating_dialog, null);
    
    ratingDiaglogClass.setContentView(dv);
    
    final SmileRating smileRating = view.findViewById(R.id.smile_rating);
    smileRating.setNameForSmile(BaseRating.BAD, "sthElse");
    
    ratingDiaglogClass.show();
    

    This is the error:

    Attempt to invoke virtual method 'void com.hsalf.smilerating.SmileRating.setNameForSmile(int, java.lang.String)' on a null object reference

    opened by kev7037 4
  • Casting error

    Casting error

    I got an casting error in smileRating = findViewById(R.id.smile_rating); while i tried manually casting too by replacing smileRating = (SmileRating)findViewById(R.id.smile_rating);

    please provide me an solution

    opened by niish03 2
  • Clearing the smiley selection.

    Clearing the smiley selection.

    Hi @sujithkanna.

    First of all, this is a really good library. Using this for a college project and I guess i'll surely use this in the future. Coming to the problem I faced, I wanted to clear the selection after a button click and I couldn't get that to work. Even after reading the documentation I couldn't find a way around this. After playing around for a while, the easiest way to acomplish this would be to set the setSelectedSmiley() function to -1, i.e, smileyRating.setSelectedSmiley(-1);

    Doing this cleared the selection off. This could be handy when it comes to submitting a survey or a rating in general and you would want to clear the selection after submission.

    Just wanted to raise a solution/info. Thanks for the cool library. Cheers (y)

    opened by sivansundar 2
  • Now Different color can be given to Smilies.

    Now Different color can be given to Smilies.

    Now Different color can be given to Smilies. Fixed Issue No.9 sujithkanna#9 (distinct smilies color #9). But it will still need some more tweaking like setting color in while declaring SmileyRating in layout file

    opened by harsh159357 2
  •  Unselect smiley on rating is sent

    Unselect smiley on rating is sent

    I want to unselect smiley on rating is sent. I used smileRating.setSelectedSmile(BaseRating.NONE); which worked but after using this functionality angryColor do not reflect and BaseRating.GREAT animation is not working fine.

    Please suggest any solution for the same.

    opened by rupbhangale 2
  • Support for android:isIndicator

    Support for android:isIndicator

    Great work! Adding support for the android:isIndicator property would make even better as right now you need to extend and override some of the methods just to disable the user actions.

    opened by HussainDerry 2
  • Could not find method compile() for arguments [com.github.sujithkanna:smileyrating:2.0.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

    Could not find method compile() for arguments [com.github.sujithkanna:smileyrating:2.0.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

    Description

    I am getting this error during gradle build process...

    Could not find method compile() for arguments [com.github.sujithkanna:smileyrating:2.0.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

    Screenshot

    image

    @sujithkanna can you help me out??

    opened by Umesh-01 2
  • Manifest merger failed : android:exported needs to be explicitly specified for <activity>.

    Manifest merger failed : android:exported needs to be explicitly specified for .

    Is it please possible to add the attribute 'android:exported' to the Manifest ? Without this attribute, while building the app with the targetSdkVersion 31, android studio elevates the following error:

    "Manifest merger failed : android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details."

    opened by affane1 0
  • smileyrating on a recyclerview when disallowSelection(true)

    smileyrating on a recyclerview when disallowSelection(true)

    Hi

    Thank you for a magnificent component!
    I saw the code you posted regarding working with RecyclerView but from my understanding it's related to touch events conflicts and this is irrelevant in my case, please see code below.

    I have a fragment with a scrollview containing 6 smiley rating component and I have a recyclerview with a scrollview containing 6 smiley rating component. On both I have the following code (for simplicity, the example shows 2 components):

    srRater1.disallowSelection(true);
    srRater2.disallowSelection(true);
    srRater1.setRating(dataSet.get(0).getRate1(), true); //dataSet.get(0).getRate1() = 4
    srRater2.setRating(dataSet.get(0).getRate2(), true);
    

    With the fragment/scrollview everything is working as expected but with the recyclerview/scrollview, the debugger shows the correct smiley selected but the actual selected smiley is 0. image

    Am I missing something? Thanks

    opened by ghost 2
Owner
Sujith Niraikulathan
Sujith Niraikulathan
SystemUiController - Android Ui color controller (status bar, navigation bar)

SystemUiController Android system ui color controller (status bar, navigation bar) Download implementation "land.sungbin:systemuicontroller:${version}

Ji Sungbin 8 Dec 3, 2022
This library offers a simple method to add a small badge icon to your ActionBar-MenuItem

Android-ActionItemBadge ActionItemBadge is a library which offers a simple and easy to use method to add a badge to your action item! Screenshots Incl

Mike Penz 1.3k Jan 1, 2023
Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...

Note: Due to lack of time, Iconify is no longer maintained and icon packs are outdated. I'd be very happy to welcome a new contributor, please reach m

Joan Zapata 3.9k Dec 24, 2022
A material Switch with icon animations and color transitions

Material Animated Switch A material Switch with icon animations and color transitions Sample video: Youtube Material Animated Switch video Sample app:

Adrián Lomas 1.2k Dec 29, 2022
A simple launcher which displays all the apps on a RecyclerView trying to KISS

A simple launcher which displays all the apps on a RecyclerView trying to KISS

Alex Allafi 1 Jun 17, 2022
Snake View is a simple and animated linear chart for Android.

Snake View Snake library is a simple and animation line chart for Android. Latest Version How to use Configuring your project dependencies Add the lib

Txus Ballesteros 339 Dec 14, 2022
TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.

This project isn't maintained anymore. It is now recommended to use https://github.com/peterLaurence/MapView. MapView is maintained by Peter, one of o

Mike Dunn 1.5k Dec 29, 2022
Takes the input from the Android MediaPlayer and displays visualizations, like in iTunes or WinAmp

Android Visualizer A View subclass that Takes the input from the Android MediaPlayer and displays visualizations, like in iTunes or WinAmp The Visuali

null 798 Dec 22, 2022
An android custom view that displays a circle with a colored arc given a mark

MarkView An android custom view that displays a circle with a colored arc given a mark. Usage Add as a dependency compile 'com.github.xiprox.markv

İhsan Işık 200 Nov 25, 2022
Android View that displays different content based on its state

MultiStateView Android View that displays different content based on its state. Based off of MeetMe/MultiStateView The four different states the view

Kenny 1.2k Dec 16, 2022
Displays your screen time in a permanent notification.

Screen Time Displays your screen time in a permanent notification. By making screen time more prominent, you can get a better sense of how much of the

Markus Fisch 24 Nov 29, 2022
TabSlider - An expanding slider widget which displays selected value

TabSlider - An expanding slider widget which displays selected value

null 1 Apr 20, 2022
Android ImageViews animated by Ken Burns Effect

KenBurnsView Android library that provides an extension to ImageView that creates an immersive experience by animating its drawable using the Ken Burn

Flávio Faria 2.7k Dec 23, 2022
Animated SVG Drawing for Android

AnimatedSvgView Animated SVG Drawing for Android Usage Get SVG path data and add it to a string array: <string-array name="google_glyph_strings"> <i

Jared Rummler 2k Dec 12, 2022
ExpandableSelector is an Android library created to show a list of Button/ImageButton widgets inside a animated container which can be collapsed or expanded.

ExpandableSelector ExpandableSelector is an Android library created to show a list of Button/ImageButton widgets inside a animated container which can

Karumi 699 Nov 19, 2022
A util for setting status bar style on Android App.

StatusBarUtil A util for setting status bar style on Android App. It can work above API 19(KitKat 4.4). 中文版点我 Sample Download StatusBarUtil-Demo Chang

Jaeger 8.8k Jan 7, 2023
A swipe button for Android with a circular progress bar for async operations

ProSwipeButton A swipe button for Android with a circular progress bar for async operations Gradle dependencies { ... compile 'in.shadowfax:pr

Shadowfax Technologies 340 Nov 13, 2022
An Index Side Bar With Wave Effect

WaveSideBar You can use WaveSideBar in the contacts page of your application. Refer to AlexLiuSheng/AnimSideBar. Screenshot Include the WaveSideBar to

郭佳哲 1.3k Dec 12, 2022
🪄 It's a library that helps you customize your notification bar

NotificationBarCustom ?? It's a library that helps you customize your notification bar Demo Contrast(white) Contrast(black) Transparent Setup Add it i

박상선 8 Sep 7, 2022