Skip to content

Commit

Permalink
Merge pull request #79 from ome450901/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
williamyyu committed Dec 14, 2019
2 parents cc95985 + a598c7d commit ab7c579
Show file tree
Hide file tree
Showing 25 changed files with 161 additions and 183 deletions.
16 changes: 10 additions & 6 deletions README.md
@@ -1,23 +1,27 @@
# SimpleRatingBar
[![JitPack](https://jitpack.io/v/ome450901/SimpleRatingBar.svg)](https://jitpack.io/#ome450901/SimpleRatingBar)

>This is a very simple RatingBar library, which you can just simply extend BaseRatingBar to implement your own animation RatingBar in a few steps!
>The simplest RatingBar library, create your own animate RatingBar in a few steps!
Current we already have three RatingBars :
Provide three RatingBars at the moment:
- BaseRatingBar
A RatingBar without any animation.
- ScaleRatingBar
A RatingBar with progressive and scale animation.
- RotationRatingBar (contributed by [nappannda](https://github.com/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
![](images/demo.gif)
![](images/screenshot.png)
Icon made by [Freepik](http://www.freepik.com/) from www.flaticon.com

## What's New (v1.4.3)
- Add `fromUser` parameter in `onRatingChange`
## What's New (v1.5.0)
- Fixed the match parent issue(start didn't consume the whole width)

## Feature
- Allow half star through click event. (contributed by [ANPez](https://github.com/ANPez))
Expand Down Expand Up @@ -46,7 +50,7 @@ allprojects {
}
dependencies {
compile 'com.github.ome450901:SimpleRatingBar:1.4.3'
compile 'com.github.ome450901:SimpleRatingBar:LATEST_VERSION'
}
```

Expand Down Expand Up @@ -92,7 +96,7 @@ 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) {
public void onRatingChange(BaseRatingBar ratingBar, int rating, boolean fromUser) {
Log.e(TAG, "onRatingChange: " + rating);
}
});
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -7,7 +7,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
22 changes: 13 additions & 9 deletions example/build.gradle
@@ -1,17 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileSdkVersion 29
buildToolsVersion '29.0.2'

defaultConfig {
applicationId "com.willy.example"
minSdkVersion 15
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
buildTypes {
Expand All @@ -20,17 +20,21 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
androidTestImplementation 'junit:junit:4.12'
implementation project(':library')
}

This file was deleted.

65 changes: 26 additions & 39 deletions example/src/main/java/com/willy/example/DemoFragment.java
@@ -1,72 +1,59 @@
package com.willy.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.willy.ratingbar.BaseRatingBar;
import com.willy.ratingbar.RotationRatingBar;
import com.willy.ratingbar.ScaleRatingBar;

public class DemoFragment extends Fragment {
public class DemoFragment
extends Fragment {

public static final String TAG = "SimpleRatingBar";

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_demo, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

final BaseRatingBar baseRatingBar = (BaseRatingBar) view.findViewById(R.id.baseratingbar_main);
final ScaleRatingBar scaleRatingBar = (ScaleRatingBar) view.findViewById(R.id.scaleRatingBar);
final RotationRatingBar rotationRatingBar = (RotationRatingBar) view.findViewById(R.id.rotationratingbar_main);
final BaseRatingBar baseRatingBar = view.findViewById(R.id.baseratingbar_main);
final ScaleRatingBar scaleRatingBar = view.findViewById(R.id.scaleRatingBar);
final RotationRatingBar rotationRatingBar = view.findViewById(R.id.rotationratingbar_main);
baseRatingBar.setClearRatingEnabled(false);
baseRatingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
@Override
public void onRatingChange(BaseRatingBar ratingBar, float rating, boolean fromUser) {
Log.d(TAG, "BaseRatingBar onRatingChange: " + rating);
}
});
baseRatingBar.setOnRatingChangeListener((ratingBar, rating, fromUser) -> Log
.d(TAG, "BaseRatingBar onRatingChange: " + rating));

scaleRatingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
@Override
public void onRatingChange(BaseRatingBar ratingBar, float rating, boolean fromUser) {
Log.d(TAG, "ScaleRatingBar onRatingChange: " + rating);
}
});
scaleRatingBar.setOnRatingChangeListener((ratingBar, rating, fromUser) -> Log
.d(TAG, "ScaleRatingBar onRatingChange: " + rating));

rotationRatingBar.setOnRatingChangeListener(new BaseRatingBar.OnRatingChangeListener() {
@Override
public void onRatingChange(BaseRatingBar ratingBar, float rating, boolean fromUser) {
Log.d(TAG, "RotationRatingBar onRatingChange: " + rating);
}
});
rotationRatingBar.setOnRatingChangeListener((ratingBar, rating, fromUser) -> Log
.d(TAG, "RotationRatingBar onRatingChange: " + rating));

Button addRatingButton = (Button) view.findViewById(R.id.button_main_add_rating);
addRatingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float currentRating = baseRatingBar.getRating();
baseRatingBar.setRating(currentRating + 0.25f);
Button addRatingButton = view.findViewById(R.id.button_main_add_rating);
addRatingButton.setOnClickListener(v -> {
float currentRating = baseRatingBar.getRating();
baseRatingBar.setRating(currentRating + 0.25f);

currentRating = scaleRatingBar.getRating();
scaleRatingBar.setRating(currentRating + 0.25f);
currentRating = scaleRatingBar.getRating();
scaleRatingBar.setRating(currentRating + 0.25f);

currentRating = rotationRatingBar.getRating();
rotationRatingBar.setRating(currentRating + 0.25f);
}
currentRating = rotationRatingBar.getRating();
rotationRatingBar.setRating(currentRating + 0.25f);
});
}
}
24 changes: 14 additions & 10 deletions example/src/main/java/com/willy/example/EntryActivity.java
@@ -1,12 +1,14 @@
package com.willy.example;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,17 +17,18 @@
* Created by willy on 2017/10/13.
*/

public class EntryActivity extends AppCompatActivity {
public class EntryActivity
extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);

final ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
final ViewPager viewPager = findViewById(R.id.viewPager);
viewPager.setAdapter(new SamplePagerAdapter(getSupportFragmentManager()));

final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
final TabLayout tabLayout = findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("Animation Demo"));
tabLayout.addTab(tabLayout.newTab().setText("RecyclerView Demo"));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
Expand All @@ -48,7 +51,8 @@ public void onTabReselected(TabLayout.Tab tab) {
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
}

private class SamplePagerAdapter extends FragmentStatePagerAdapter {
private class SamplePagerAdapter
extends FragmentStatePagerAdapter {

private List<Fragment> fragments;

Expand Down
18 changes: 11 additions & 7 deletions example/src/main/java/com/willy/example/ListFragment.java
@@ -1,25 +1,29 @@
package com.willy.example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class ListFragment extends Fragment {
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

public class ListFragment
extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_list, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setAdapter(new MyAdapter(getContext()));
}
}
30 changes: 15 additions & 15 deletions example/src/main/java/com/willy/example/MyAdapter.java
@@ -1,13 +1,13 @@
package com.willy.example;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.willy.ratingbar.BaseRatingBar;
import com.willy.ratingbar.BaseRatingBar.OnRatingChangeListener;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.willy.ratingbar.ScaleRatingBar;

import java.util.ArrayList;
Expand All @@ -17,7 +17,8 @@
* Created by willy on 2017/10/3.
*/

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {
public class MyAdapter
extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

private Context mContext;
private List<Float> list;
Expand All @@ -31,8 +32,9 @@ public MyAdapter(Context context) {
}
}

@NonNull
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.item_ratingbar, null);
return new MyViewHolder(view);
}
Expand All @@ -48,21 +50,19 @@ public int getItemCount() {
return list.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
public class MyViewHolder
extends RecyclerView.ViewHolder {

private ScaleRatingBar ratingBar;

public MyViewHolder(View itemView) {
super(itemView);
// ratingBar = (BaseRatingBar) itemView.findViewById(R.id.ratingBar);
// ratingBar = (ScaleRatingBar) itemView.findViewById(R.id.ratingBar);
ratingBar = (ScaleRatingBar) itemView.findViewById(R.id.ratingBar);
ratingBar.setOnRatingChangeListener(new OnRatingChangeListener() {
@Override
public void onRatingChange(BaseRatingBar ratingBar, float rating, boolean fromUser) {
int position = (int) ratingBar.getTag();
list.set(position, rating);
}
// ratingBar = itemView.findViewById(R.id.ratingBar);
// ratingBar = itemView.findViewById(R.id.ratingBar);
ratingBar = itemView.findViewById(R.id.ratingBar);
ratingBar.setOnRatingChangeListener((ratingBar, rating, fromUser) -> {
int position = (int) ratingBar.getTag();
list.set(position, rating);
});
}
}
Expand Down

0 comments on commit ab7c579

Please sign in to comment.