Build 1.0_r1(from source)

android.widget
Class RatingBar

java.lang.Object
  extended by android.view.View
      extended by android.widget.ProgressBar
          extended by android.widget.AbsSeekBar
              extended by android.widget.RatingBar
All Implemented Interfaces:
Drawable.Callback, KeyEvent.Callback

public class RatingBar
extends AbsSeekBar

A RatingBar is an extension of SeekBar and ProgressBar that shows a rating in stars. The user can touch and/or drag to set the rating when using the default size RatingBar. The smaller RatingBar style (R.attr.ratingBarStyleSmall) and the larger indicator-only style (R.attr.ratingBarStyleIndicator) do not support user interaction and should only be used as indicators.

The number of stars set (via setNumStars(int) or in an XML layout) will be shown when the layout width is set to wrap content (if another layout width is set, the results may be unpredictable).

The secondary progress should not be modified by the client as it is used internally as the background for a fractionally filled star.


Nested Class Summary
static interface RatingBar.OnRatingBarChangeListener
          A callback that notifies clients when the rating has been changed.
 
Nested classes/interfaces inherited from class android.view.View
View.BaseSavedState, View.MeasureSpec, View.OnClickListener, View.OnCreateContextMenuListener, View.OnFocusChangeListener, View.OnKeyListener, View.OnLongClickListener, View.OnTouchListener
 
Field Summary
 
Fields inherited from class android.widget.AbsSeekBar
mDisabledAlpha, mIsUserSeekable, mTouchProgressOffset
 
Fields inherited from class android.widget.ProgressBar
mMaxHeight, mMaxWidth, mMinHeight, mMinWidth, mSampleTile
 
Fields inherited from class android.view.View
DRAWING_CACHE_QUALITY_AUTO, DRAWING_CACHE_QUALITY_HIGH, DRAWING_CACHE_QUALITY_LOW, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FIRST_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, INVISIBLE, KEEP_SCREEN_ON, LAST_STATE_SET, mBottom, mContext, mCurrentAnimation, MIDDLE_STATE_SET, mLayoutParams, mLeft, mLocation, mMeasuredHeight, mMeasuredWidth, mOnClickListener, mOnCreateContextMenuListener, mOnFocusChangeListener, mOnLongClickListener, mPaddingBottom, mPaddingLeft, mPaddingRight, mPaddingTop, mParent, mRight, mScrollX, mScrollY, mTag, mTop, NO_ID, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FIRST_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_LAST_STATE_SET, PRESSED_MIDDLE_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_SINGLE_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SINGLE_STATE_SET, SOUND_EFFECTS_ENABLED, VIEW_LOG_TAG, VISIBLE, WINDOW_FOCUSED_STATE_SET
 
Constructor Summary
RatingBar(Context context)
           
RatingBar(Context context, AttributeSet attrs)
           
RatingBar(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
(package private)  void dispatchRatingChange(boolean fromTouch)
           
(package private)  Shape getDrawableShape()
           
 int getNumStars()
          Returns the number of stars shown.
 RatingBar.OnRatingBarChangeListener getOnRatingBarChangeListener()
           
 float getRating()
          Gets the current rating (number of stars filled).
 float getStepSize()
          Gets the step size of this rating bar.
 boolean isIndicator()
           
protected  void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
           Measure the view and its content to determine the measured width and the measured height.
(package private)  void onProgressRefresh(float scale, boolean fromTouch)
           
(package private)  void onStartTrackingTouch()
          This is called when the user has started touching this widget.
(package private)  void onStopTrackingTouch()
          This is called when the user either releases his touch or the touch is canceled.
 void setIsIndicator(boolean isIndicator)
          Whether this rating bar should only be an indicator (thus non-changeable by the user).
 void setMax(int max)
          Set the range of the progress bar to 0...max.
 void setNumStars(int numStars)
          Sets the number of stars to show.
 void setOnRatingBarChangeListener(RatingBar.OnRatingBarChangeListener listener)
          Sets the listener to be called when the rating changes.
 void setRating(float rating)
          Sets the rating (the number of stars filled).
 void setStepSize(float stepSize)
          Sets the step size (granularity) of this rating bar.
 
Methods inherited from class android.widget.AbsSeekBar
drawableStateChanged, getThumbOffset, onDraw, onSizeChanged, onTouchEvent, setThumb, setThumbOffset, verifyDrawable
 
Methods inherited from class android.widget.ProgressBar
getCurrentDrawable, getIndeterminateDrawable, getInterpolator, getMax, getProgress, getProgressDrawable, getSecondaryProgress, incrementProgressBy, incrementSecondaryProgressBy, invalidateDrawable, isIndeterminate, postInvalidate, setIndeterminate, setIndeterminateDrawable, setInterpolator, setInterpolator, setProgress, setProgress, setProgressDrawable, setSecondaryProgress, setVisibility, startAnimation, stopAnimation
 
Methods inherited from class android.view.View
addFocusables, addTouchables, applyDrawableToTransparentRegion, bringToFront, buildDrawingCache, cancelLongPress, clearAnimation, clearFocus, computeHorizontalScrollExtent, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, debug, debug, debugIndent, destroyDrawingCache, dispatchDraw, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchRestoreInstanceState, dispatchSaveInstanceState, dispatchSetPressed, dispatchSetSelected, dispatchTouchEvent, dispatchTrackballEvent, dispatchUnhandledMove, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, draw, finalize, findFocus, findViewById, findViewTraversal, findViewWithTag, findViewWithTagTraversal, fitSystemWindows, focusSearch, forceLayout, gatherTransparentRegion, getAnimation, getApplicationWindowToken, getBackground, getBaseline, getBottom, getBottomFadingEdgeStrength, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingCache, getDrawingCacheBackgroundColor, getDrawingCacheQuality, getDrawingRect, getDrawingTime, getFocusables, getFocusedRect, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHeight, getHitRect, getHorizontalFadingEdgeLength, getHorizontalScrollbarHeight, getId, getKeepScreenOn, getLayoutParams, getLeft, getLeftFadingEdgeStrength, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMeasuredHeight, getMeasuredWidth, getNextFocusDownId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getParent, getResources, getRight, getRightFadingEdgeStrength, getRootView, getScrollBarStyle, getScrollX, getScrollY, getSolidColor, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTop, getTopFadingEdgeStrength, getTouchables, getTouchDelegate, getVerticalFadingEdgeLength, getVerticalScrollbarWidth, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowToken, getWindowVisibility, hasFocus, hasFocusable, hasWindowFocus, inflate, initializeFadingEdge, initializeScrollbars, invalidate, invalidate, invalidate, isClickable, isDrawingCacheEnabled, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isInTouchMode, isLayoutRequested, isLongClickable, isPressed, isRootNamespace, isSaveEnabled, isSelected, isShown, isSoundEffectsEnabled, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, layout, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onAnimationEnd, onAnimationStart, onAttachedToWindow, onCreateContextMenu, onCreateDrawableState, onDetachedFromWindow, onFinishInflate, onFocusChanged, onKeyDown, onKeyMultiple, onKeyShortcut, onKeyUp, onLayout, onRestoreInstanceState, onSaveInstanceState, onScrollChanged, onSetAlpha, onTrackballEvent, onWindowFocusChanged, onWindowVisibilityChanged, performClick, performLongClick, playSoundEffect, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateDelayed, refreshDrawableState, removeCallbacks, requestFocus, requestFocus, requestFocus, requestFocusFromTouch, requestLayout, requestRectangleOnScreen, requestRectangleOnScreen, resolveSize, restoreHierarchyState, saveHierarchyState, scheduleDrawable, scrollBy, scrollTo, setAnimation, setBackgroundColor, setBackgroundDrawable, setBackgroundResource, setClickable, setDrawingCacheBackgroundColor, setDrawingCacheEnabled, setDrawingCacheQuality, setDuplicateParentStateEnabled, setEnabled, setFadingEdgeLength, setFocusable, setFocusableInTouchMode, setFrame, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setId, setIsRootNamespace, setKeepScreenOn, setLayoutParams, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNextFocusDownId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnCreateContextMenuListener, setOnFocusChangeListener, setOnKeyListener, setOnLongClickListener, setOnTouchListener, setPadding, setPressed, setSaveEnabled, setScrollBarStyle, setSelected, setSoundEffectsEnabled, setTag, setTouchDelegate, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setWillNotCacheDrawing, setWillNotDraw, showContextMenu, startAnimation, unscheduleDrawable, unscheduleDrawable, willNotCacheDrawing, willNotDraw
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RatingBar

public RatingBar(Context context,
                 AttributeSet attrs,
                 int defStyle)

RatingBar

public RatingBar(Context context,
                 AttributeSet attrs)

RatingBar

public RatingBar(Context context)
Method Detail

setOnRatingBarChangeListener

public void setOnRatingBarChangeListener(RatingBar.OnRatingBarChangeListener listener)
Sets the listener to be called when the rating changes.

Parameters:
listener - The listener.

getOnRatingBarChangeListener

public RatingBar.OnRatingBarChangeListener getOnRatingBarChangeListener()
Returns:
The listener (may be null) that is listening for rating change events.

setIsIndicator

public void setIsIndicator(boolean isIndicator)
Whether this rating bar should only be an indicator (thus non-changeable by the user).

Parameters:
isIndicator - Whether it should be an indicator.

isIndicator

public boolean isIndicator()
Returns:
Whether this rating bar is only an indicator.

setNumStars

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.

Parameters:
numStars - The number of stars.

getNumStars

public int getNumStars()
Returns the number of stars shown.

Returns:
The number of stars shown.

setRating

public void setRating(float rating)
Sets the rating (the number of stars filled).

Parameters:
rating - The rating to set.

getRating

public float getRating()
Gets the current rating (number of stars filled).

Returns:
The current rating.

setStepSize

public void setStepSize(float stepSize)
Sets the step size (granularity) of this rating bar.

Parameters:
stepSize - The step size of this rating bar. For example, if half-star granularity is wanted, this would be 0.5.

getStepSize

public float getStepSize()
Gets the step size of this rating bar.

Returns:
The step size.

getDrawableShape

Shape getDrawableShape()
Overrides:
getDrawableShape in class ProgressBar

onProgressRefresh

void onProgressRefresh(float scale,
                       boolean fromTouch)
Overrides:
onProgressRefresh in class AbsSeekBar

onMeasure

protected void onMeasure(int widthMeasureSpec,
                         int heightMeasureSpec)
Description copied from class: View

Measure the view and its content to determine the measured width and the measured height. This method is invoked by View.measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.

CONTRACT: When overriding this method, you must call View.setMeasuredDimension(int, int) to store the measured width and height of this view. Failure to do so will trigger an IllegalStateException, thrown by View.measure(int, int). Calling the superclass' View.onMeasure(int, int) is a valid use.

The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override View.onMeasure(int, int) to provide better measurements of their content.

If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (View.getSuggestedMinimumHeight() and View.getSuggestedMinimumWidth()).

Overrides:
onMeasure in class AbsSeekBar
Parameters:
widthMeasureSpec - horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
heightMeasureSpec - vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec.
See Also:
View.getMeasuredWidth(), View.getMeasuredHeight(), View.setMeasuredDimension(int, int), View.getSuggestedMinimumHeight(), View.getSuggestedMinimumWidth(), View.MeasureSpec.getMode(int), View.MeasureSpec.getSize(int)

onStartTrackingTouch

void onStartTrackingTouch()
Description copied from class: AbsSeekBar
This is called when the user has started touching this widget.

Overrides:
onStartTrackingTouch in class AbsSeekBar

onStopTrackingTouch

void onStopTrackingTouch()
Description copied from class: AbsSeekBar
This is called when the user either releases his touch or the touch is canceled.

Overrides:
onStopTrackingTouch in class AbsSeekBar

dispatchRatingChange

void dispatchRatingChange(boolean fromTouch)

setMax

public void setMax(int max)
Description copied from class: ProgressBar

Set the range of the progress bar to 0...max.

Overrides:
setMax in class ProgressBar
Parameters:
max - the upper range of this progress bar
See Also:
ProgressBar.getMax(), ProgressBar.setProgress(int), ProgressBar.setSecondaryProgress(int)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature