From 8f9e2ba37739909e5f4bbdd6b7f4f7cc2abc1896 Mon Sep 17 00:00:00 2001 From: bigstark Date: Fri, 5 Jan 2018 15:56:45 +0900 Subject: [PATCH 1/3] update grade version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1f92a64..80e9a2e 100644 --- a/build.gradle +++ b/build.gradle @@ -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 From a06cafade35186bea8c92291530e02c4431f6be9 Mon Sep 17 00:00:00 2001 From: bigstark Date: Fri, 5 Jan 2018 15:56:54 +0900 Subject: [PATCH 2/3] some bug fixes --- .../lib/AnimatedRatingBar.java | 55 ++++++++++++------- sample/src/main/res/layout/activity_home.xml | 1 - 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/library/src/main/java/com/bigstark/animatedratingbar/lib/AnimatedRatingBar.java b/library/src/main/java/com/bigstark/animatedratingbar/lib/AnimatedRatingBar.java index 161a24e..d7959a0 100644 --- a/library/src/main/java/com/bigstark/animatedratingbar/lib/AnimatedRatingBar.java +++ b/library/src/main/java/com/bigstark/animatedratingbar/lib/AnimatedRatingBar.java @@ -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; @@ -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; @@ -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); @@ -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() { @@ -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; } } diff --git a/sample/src/main/res/layout/activity_home.xml b/sample/src/main/res/layout/activity_home.xml index c50c166..3524d73 100644 --- a/sample/src/main/res/layout/activity_home.xml +++ b/sample/src/main/res/layout/activity_home.xml @@ -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"> From d80aae994d481229409d914291a8894894c5c897 Mon Sep 17 00:00:00 2001 From: bigstark Date: Fri, 5 Jan 2018 17:41:18 +0900 Subject: [PATCH 3/3] update version code and name --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index ee726f5..c2bdd0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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