Skip to content

Commit

Permalink
Merge branch 'feature/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
bigstark committed Jan 5, 2018
2 parents bd90882 + d80aae9 commit ed8c5cc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_CODE=4
VERSION_NAME=0.2.2
VERSION_CODE=5
VERSION_NAME=0.3.0
GROUP=com.github.bigstark

ANDROID_BUILD_TARGET_SDK_VERSION=24
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;

Expand All @@ -30,7 +31,6 @@ public class AnimatedRatingBar extends LinearLayout implements IAnimatedRatingBa
private int gapSize;
private int starSize = 0;

private AnimatedRatingBarItem[] items;
private boolean isNeedRedraw = true;


Expand Down Expand Up @@ -91,40 +91,54 @@ protected void onDraw(Canvas canvas) {


private void resetItems() {
removeAllViews();
if (items != null) {
int length = items.length;
for (int i = 0; i < length; i++) {
items[i] = null;
if (getChildCount() == 0) {
for (int i = 0; i < numStars; i++) {
AnimatedRatingBarItem item = new AnimatedRatingBarItem(getContext());
LinearLayout.LayoutParams itemParams = new LinearLayout.LayoutParams(starSize, starSize);
itemParams.leftMargin = i == 0 ? 0 : gapSize;
item.setLayoutParams(itemParams);
addView(item);
}
items = null;
}

items = new AnimatedRatingBarItem[numStars];
LinearLayout.LayoutParams itemParams = new LinearLayout.LayoutParams(starSize, starSize);

float progressStars = numStars * rating / max;
int fillStars = (int) progressStars;
float levelStar = progressStars - fillStars;


for (int i = 0; i < numStars; i++) {
itemParams.leftMargin = i == 0 ? 0 : gapSize;
AnimatedRatingBarItem item = (AnimatedRatingBarItem) getChildAt(i);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) item.getLayoutParams();
params.leftMargin = i == 0 ? 0 : gapSize;
item.setLayoutParams(params);

AnimatedRatingBarItem item = new AnimatedRatingBarItem(getContext());
item.setLayoutParams(itemParams);
float level = i < fillStars ? 1 : i == fillStars ? levelStar : 0;
item.setProgressLevel(level);
item.setProgressImageDrawable(progressImage);
item.setSecondaryProgressImageDrawable(secondaryProgressImage);

items[i] = item;
addView(items[i]);
}

isNeedRedraw = false;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!seekable) {
return false;
}
if (event.getX() < 0) {
setRating(0);
return true;
} else if (event.getX() > getWidth()) {
setRating(max);
return true;
}
float rating = event.getX() / getWidth() * 5;
rating = Math.round(rating * 100) / 100f;
Log.v("TAG", "rating : " + rating);
setRating(rating);
return true;
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
Expand Down Expand Up @@ -234,7 +248,8 @@ public void setAnimateDuration(int duration) {
@Override
public void startAnimate() {
int delay = 0;
for (final AnimatedRatingBarItem item : items) {
for (int i = 0; i < numStars; i++) {
final int position = i;
postDelayed(new Runnable() {
@Override
public void run() {
Expand All @@ -244,14 +259,14 @@ public void run() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float fraction = animation.getAnimatedFraction();
item.setRotationY((fraction * 3 * 360) % 360);
getChildAt(position).setRotationY((fraction * 3 * 360) % 360);
}
});
animator.start();
}
}, delay);

delay += duration / items.length;
delay += duration / numStars;
}
}

Expand Down
1 change: 0 additions & 1 deletion sample/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.bigstark.animatedratingbar.HomeActivity">
Expand Down

0 comments on commit ed8c5cc

Please sign in to comment.