summaryrefslogtreecommitdiffstats
path: root/core/java/android/widget/RatingBar.java
diff options
context:
space:
mode:
authorRoboErik <epastern@google.com>2015-02-11 13:52:05 -0800
committerRoboErik <epastern@google.com>2015-02-11 13:52:05 -0800
commit5b07143e36096168fd95d8e27988b233b2a70ece (patch)
tree2c8d56235a153d11a9402c4638e773c329fcb439 /core/java/android/widget/RatingBar.java
parent7d85bc4c435bc37284a814fb8baf53980396ab5b (diff)
downloadframeworks_base-5b07143e36096168fd95d8e27988b233b2a70ece.zip
frameworks_base-5b07143e36096168fd95d8e27988b233b2a70ece.tar.gz
frameworks_base-5b07143e36096168fd95d8e27988b233b2a70ece.tar.bz2
Pass the new progress when updating a ProgressBar
There was a race condition where the update for a progress change from the user could pass the wrong progress value causing apps to treat a non-user update as a user update. bug:18515012 Change-Id: Ia62a1d07cd15f99effbf644642307c71049748f2
Diffstat (limited to 'core/java/android/widget/RatingBar.java')
-rw-r--r--core/java/android/widget/RatingBar.java70
1 files changed, 35 insertions, 35 deletions
diff --git a/core/java/android/widget/RatingBar.java b/core/java/android/widget/RatingBar.java
index 4268961..f18e372 100644
--- a/core/java/android/widget/RatingBar.java
+++ b/core/java/android/widget/RatingBar.java
@@ -43,7 +43,7 @@ import com.android.internal.R;
* <p>
* The secondary progress should not be modified by the client as it is used
* internally as the background for a fractionally filled star.
- *
+ *
* @attr ref android.R.styleable#RatingBar_numStars
* @attr ref android.R.styleable#RatingBar_rating
* @attr ref android.R.styleable#RatingBar_stepSize
@@ -58,14 +58,14 @@ public class RatingBar extends AbsSeekBar {
* programmatically.
*/
public interface OnRatingBarChangeListener {
-
+
/**
* Notification that the rating has changed. Clients can use the
* fromUser parameter to distinguish user-initiated changes from those
* that occurred programmatically. This will not be called continuously
* while the user is dragging, only when the user finalizes a rating by
* lifting the touch.
- *
+ *
* @param ratingBar The RatingBar whose rating has changed.
* @param rating The current rating. This will be in the range
* 0..numStars.
@@ -79,9 +79,9 @@ public class RatingBar extends AbsSeekBar {
private int mNumStars = 5;
private int mProgressOnStartTracking;
-
+
private OnRatingBarChangeListener mOnRatingBarChangeListener;
-
+
public RatingBar(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
@@ -98,19 +98,19 @@ public class RatingBar extends AbsSeekBar {
a.recycle();
if (numStars > 0 && numStars != mNumStars) {
- setNumStars(numStars);
+ setNumStars(numStars);
}
-
+
if (stepSize >= 0) {
setStepSize(stepSize);
} else {
setStepSize(0.5f);
}
-
+
if (rating >= 0) {
setRating(rating);
}
-
+
// A touch inside a star fill up to that fractional area (slightly more
// than 1 so boundaries round up).
mTouchProgressOffset = 1.1f;
@@ -123,16 +123,16 @@ public class RatingBar extends AbsSeekBar {
public RatingBar(Context context) {
this(context, null);
}
-
+
/**
* Sets the listener to be called when the rating changes.
- *
+ *
* @param listener The listener.
*/
public void setOnRatingBarChangeListener(OnRatingBarChangeListener listener) {
mOnRatingBarChangeListener = listener;
}
-
+
/**
* @return The listener (may be null) that is listening for rating change
* events.
@@ -144,7 +144,7 @@ public class RatingBar extends AbsSeekBar {
/**
* Whether this rating bar should only be an indicator (thus non-changeable
* by the user).
- *
+ *
* @param isIndicator Whether it should be an indicator.
*
* @attr ref android.R.styleable#RatingBar_isIndicator
@@ -153,7 +153,7 @@ public class RatingBar extends AbsSeekBar {
mIsUserSeekable = !isIndicator;
setFocusable(!isIndicator);
}
-
+
/**
* @return Whether this rating bar is only an indicator.
*
@@ -162,21 +162,21 @@ public class RatingBar extends AbsSeekBar {
public boolean isIndicator() {
return !mIsUserSeekable;
}
-
+
/**
* Sets the number of stars to show. In order for these to be shown
* properly, it is recommended the layout width of this widget be wrap
* content.
- *
+ *
* @param numStars The number of stars.
*/
public void setNumStars(final int numStars) {
if (numStars <= 0) {
return;
}
-
+
mNumStars = numStars;
-
+
// This causes the width to change, so re-layout
requestLayout();
}
@@ -188,10 +188,10 @@ public class RatingBar extends AbsSeekBar {
public int getNumStars() {
return mNumStars;
}
-
+
/**
* Sets the rating (the number of stars filled).
- *
+ *
* @param rating The rating to set.
*/
public void setRating(float rating) {
@@ -200,16 +200,16 @@ public class RatingBar extends AbsSeekBar {
/**
* Gets the current rating (number of stars filled).
- *
+ *
* @return The current rating.
*/
public float getRating() {
- return getProgress() / getProgressPerStar();
+ return getProgress() / getProgressPerStar();
}
/**
* Sets the step size (granularity) of this rating bar.
- *
+ *
* @param stepSize The step size of this rating bar. For example, if
* half-star granularity is wanted, this would be 0.5.
*/
@@ -217,7 +217,7 @@ public class RatingBar extends AbsSeekBar {
if (stepSize <= 0) {
return;
}
-
+
final float newMax = mNumStars / stepSize;
final int newProgress = (int) (newMax / getMax() * getProgress());
setMax((int) newMax);
@@ -226,13 +226,13 @@ public class RatingBar extends AbsSeekBar {
/**
* Gets the step size of this rating bar.
- *
+ *
* @return The step size.
*/
public float getStepSize() {
return (float) getNumStars() / getMax();
}
-
+
/**
* @return The amount of progress that fits into a star
*/
@@ -251,12 +251,12 @@ public class RatingBar extends AbsSeekBar {
}
@Override
- void onProgressRefresh(float scale, boolean fromUser) {
- super.onProgressRefresh(scale, fromUser);
+ void onProgressRefresh(float scale, boolean fromUser, int progress) {
+ super.onProgressRefresh(scale, fromUser, progress);
// Keep secondary progress in sync with primary
- updateSecondaryProgress(getProgress());
-
+ updateSecondaryProgress(progress);
+
if (!fromUser) {
// Callback for non-user rating changes
dispatchRatingChange(false);
@@ -267,7 +267,7 @@ public class RatingBar extends AbsSeekBar {
* The secondary progress is used to differentiate the background of a
* partially filled star. This method keeps the secondary progress in sync
* with the progress.
- *
+ *
* @param progress The primary progress level.
*/
private void updateSecondaryProgress(int progress) {
@@ -278,11 +278,11 @@ public class RatingBar extends AbsSeekBar {
setSecondaryProgress(secondaryProgress);
}
}
-
+
@Override
protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-
+
if (mSampleTile != null) {
// TODO: Once ProgressBar's TODOs are gone, this can be done more
// cleanly than mSampleTile
@@ -295,7 +295,7 @@ public class RatingBar extends AbsSeekBar {
@Override
void onStartTrackingTouch() {
mProgressOnStartTracking = getProgress();
-
+
super.onStartTrackingTouch();
}
@@ -327,7 +327,7 @@ public class RatingBar extends AbsSeekBar {
if (max <= 0) {
return;
}
-
+
super.setMax(max);
}