Constructors Summary |
---|
public RatingBar(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
|
public RatingBar(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.RatingBar, defStyleAttr, defStyleRes);
final int numStars = a.getInt(R.styleable.RatingBar_numStars, mNumStars);
setIsIndicator(a.getBoolean(R.styleable.RatingBar_isIndicator, !mIsUserSeekable));
final float rating = a.getFloat(R.styleable.RatingBar_rating, -1);
final float stepSize = a.getFloat(R.styleable.RatingBar_stepSize, -1);
a.recycle();
if (numStars > 0 && numStars != mNumStars) {
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;
|
public RatingBar(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.ratingBarStyle);
|
public RatingBar(android.content.Context context)
this(context, null);
|
Methods Summary |
---|
void | dispatchRatingChange(boolean fromUser)
if (mOnRatingBarChangeListener != null) {
mOnRatingBarChangeListener.onRatingChanged(this, getRating(),
fromUser);
}
|
android.graphics.drawable.shapes.Shape | getDrawableShape()
// TODO: Once ProgressBar's TODOs are fixed, this won't be needed
return new RectShape();
|
public int | getNumStars()Returns the number of stars shown.
return mNumStars;
|
public android.widget.RatingBar$OnRatingBarChangeListener | getOnRatingBarChangeListener()
return mOnRatingBarChangeListener;
|
private float | getProgressPerStar()
if (mNumStars > 0) {
return 1f * getMax() / mNumStars;
} else {
return 1;
}
|
public float | getRating()Gets the current rating (number of stars filled).
return getProgress() / getProgressPerStar();
|
public float | getStepSize()Gets the step size of this rating bar.
return (float) getNumStars() / getMax();
|
public boolean | isIndicator()
return !mIsUserSeekable;
|
public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
event.setClassName(RatingBar.class.getName());
|
public void | onInitializeAccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo info)
super.onInitializeAccessibilityNodeInfo(info);
info.setClassName(RatingBar.class.getName());
|
void | onKeyChange()
super.onKeyChange();
dispatchRatingChange(true);
|
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
final int width = mSampleTile.getWidth() * mNumStars;
setMeasuredDimension(resolveSizeAndState(width, widthMeasureSpec, 0),
getMeasuredHeight());
}
|
void | onProgressRefresh(float scale, boolean fromUser)
super.onProgressRefresh(scale, fromUser);
// Keep secondary progress in sync with primary
updateSecondaryProgress(getProgress());
if (!fromUser) {
// Callback for non-user rating changes
dispatchRatingChange(false);
}
|
void | onStartTrackingTouch()
mProgressOnStartTracking = getProgress();
super.onStartTrackingTouch();
|
void | onStopTrackingTouch()
super.onStopTrackingTouch();
if (getProgress() != mProgressOnStartTracking) {
dispatchRatingChange(true);
}
|
public void | setIsIndicator(boolean isIndicator)Whether this rating bar should only be an indicator (thus non-changeable
by the user).
mIsUserSeekable = !isIndicator;
setFocusable(!isIndicator);
|
public synchronized void | setMax(int max)
// Disallow max progress = 0
if (max <= 0) {
return;
}
super.setMax(max);
|
public void | setNumStars(int numStars)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.
if (numStars <= 0) {
return;
}
mNumStars = numStars;
// This causes the width to change, so re-layout
requestLayout();
|
public void | setOnRatingBarChangeListener(android.widget.RatingBar$OnRatingBarChangeListener listener)Sets the listener to be called when the rating changes.
mOnRatingBarChangeListener = listener;
|
public void | setRating(float rating)Sets the rating (the number of stars filled).
setProgress(Math.round(rating * getProgressPerStar()));
|
public void | setStepSize(float stepSize)Sets the step size (granularity) of this rating bar.
if (stepSize <= 0) {
return;
}
final float newMax = mNumStars / stepSize;
final int newProgress = (int) (newMax / getMax() * getProgress());
setMax((int) newMax);
setProgress(newProgress);
|
private void | updateSecondaryProgress(int progress)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.
final float ratio = getProgressPerStar();
if (ratio > 0) {
final float progressInStars = progress / ratio;
final int secondaryProgress = (int) (Math.ceil(progressInStars) * ratio);
setSecondaryProgress(secondaryProgress);
}
|