Giter Site home page Giter Site logo

sujithkanna / smileyrating Goto Github PK

View Code? Open in Web Editor NEW
1.1K 22.0 180.0 2.52 MB

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

License: Apache License 2.0

Java 100.00%
smiley rating android canvas morphing-animations vector-graphics

smileyrating's Introduction

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
}

smileyrating's People

Contributors

addisonelliott avatar harsh159357 avatar paulomcnally avatar sujithkanna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smileyrating's Issues

Icon Click listener not working.

I have set setIndicator to false, also implemented click listeners, but still they are not clickable. Its a very weird behaviour, sometimes they work and some times they don't.

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.

How set Rating?

how set programatic a rating.
SmileRating.setRating() does not exist.

setRating in kotlin not work

i try set rating from kotlin silimar your description in my fragment but it not Work

my code is:
smileyRating.setRating(3, true)

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

Default No Selected Smile

I want Rating bar to have no selected rating in the start..
let me know if rating bar has this functionality

Allow to change text colors

It would be nice to be able to change the text colors (black/gray) in XML or in Java code.

Could you implement that?

Thanks!

Selecting terrible first time results in normal color

Selecting the terrible smiley face the very first time results in the color of the terrible face to be the normal color instead of the angry face color setting.

My thought is that it has to do with an animation not taking place since it is the first time and the color is not set.

1

Reverse order

Hi, sujithkanna, how i can use the library with inverse order?

Allow changable Text color

Hi!

First of all, thanks for your work in this!
A slight improvement might be making the text color a variable as well.
I will make a pull request for this somewhere this week!

Edit: It seems to be documented but non functional?

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)

Disable click

How to disallow click?

android:clickable="false" android:focusable="false"

android:clickable setted false don't work.

Imgur

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!

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!

distinct smilies color

i want to set distinct color for all 5 smilies, how can i do it. Any help would be appreciated

Compatible With D-Pads

I tried the Bar on a cellular device where I connected a bluetooth, but when I want to move through the faces, I could not.

Can you make the bar compatible with control navigation?

Initial Value of SmileyRating

Hi I tried this awesome library and I would like to know how to take default value set in it or initially none should be chosen on smileyRating when user done interacts.

set text size?

Hi, thanks for a cool library!

How can I set a text size after I changed Typeface?

thanks

SmileyRating inside BottomSheetDialog

Not able to set rating manually inside BottomSheetDialog. Every time I set the rating to 4 it resets to 1 when showing the bottom sheet.
EDIT not able to set rating even in the alert dialog

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.

Smile new doesn't show

Hi guys! You are making such a great job, i really like your library. I am detect an issue when is select the New Smile, it doesn't show it. Also doesn't show when the smileRating.setSelectedSmile is loaded.

Android version: 5.1.1
Model number: SM-J120M
compile 'com.github.sujithkanna:smileyrating:1.6.7'

screenshot_2017-07-09-17-43-16-1-min

But when i select another Smile and come back with the New, in that case it is show it

screenshot_2017-07-09-17-43-02-1-min

screenshot_2017-07-09-17-43-05-1-min

How to send rating to the mysql database using PHP?

It's a marvelous library, thanks!

I know, to get current rating level, is by adding int level = mSmileRating.getRating();.
But my case is, I want to send current rating level into MySql database.

If it an EditText type, I know we have to create API first by using Volley to make communication between Android and MySql database. It works well because it's a String data type.
But how if the rating of the Smiley that has an int data type?
How to send it?

Do you have any idea?

Currently, I'm using Mysql as database and I use PHP as server-side program language to create API, to connect between Mysql database and Android inputs.

Much appreciate any helps, thanks!

Change text

Hello,

first of all thanks for the great library, it is really helpful.
I want to ask if it is possible to change the text under the faces.

Thanks!

slide from nothing not correctly snapped

Hi,
I see snapping is working properly only if the initial rate is >= 0
but if it is -1 (NONE) sliding can be ended at the middle of any icon and setOnSmileySelectionListener is not called.

please take a look.

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

How to get each of these 5 smiley value for INSERTION INTO DATABASE?

It's a marvelous library, thanks!

I know, to get current rating level, is by adding int level = mSmileRating.getRating();.
But my case is, I want to send current rating level into MySql database.

If it an EditText type, I know we have to create API first by using Volley to make communication between Android and MySql database. It works well because it's a String data type.
But how if the rating of the Smiley that has an int data type?
How to send it?

Do you have any idea?

Currently, I'm using Mysql as database and I use PHP as server-side program language to create API, to connect between Mysql database and Android inputs.

Much appreciate any helps, thanks!

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

Color Smile

It is possible to change the color in each smile?

Set color individually for a smiley

The only smiley color you can change individually is the angry one.
smileyRating.setAngryColor(int color);

The other option is to change all the color of all smileys except Angry/Terrible smiley.
smileRating.setNormalColor(int color);

Is there a way to change individually other smiley, like great smiley?

In Recyclerview

When we use this rating in recyclerview item and try to move emoji, it get stuck between 2 emoji's. Please tell me how i can resolve this?

setRating not work in kotlin

I'm trying to setRating(SmileyRating.Type.GREAT.rating, true) in kotlin similar to your description but it not work for me, and always TERRIBLE is selected what is my mistake?

`    smileyRating.setFaceBackgroundColor(SmileyRating.Type.TERRIBLE, Color.RED)
    smileyRating.setFaceBackgroundColor(SmileyRating.Type.BAD, 0xFFFF8606.toInt())
    smileyRating.setFaceBackgroundColor(SmileyRating.Type.GREAT, 0xFF50DA30.toInt())
    smileyRating.setFaceBackgroundColor(SmileyRating.Type.OKAY, 0xFFF3C641.toInt())

    smileyRating.setRating(SmileyRating.Type.GREAT.rating, true)


    smileyRating.setTitle(SmileyRating.Type.TERRIBLE, "Worst pain")
    smileyRating.setTitle(SmileyRating.Type.BAD, "Very Severe")
    smileyRating.setTitle(SmileyRating.Type.OKAY, "Moderate")
    smileyRating.setTitle(SmileyRating.Type.GOOD, "Mild")
    smileyRating.setTitle(SmileyRating.Type.GREAT, "No Pain")

`
also, I try and it not work

smileyRating.setRating(3, true)

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.