From 9d989fe1ce6917ccea427b2c3a04a0df4f7e0b8c Mon Sep 17 00:00:00 2001
From: Rey Pham Sets the optional hint text that is displayed at the bottom of the
* the matching list. This can be used as a cue to the user on how to
* best use the list, or to provide extra information. Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI} Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI} Returns the current width for the auto-complete drop down list. This can
* be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or
* {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view. Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI} Sets the current width for the auto-complete drop down list. This can
* be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or
* {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view. Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the height for the drop down list * @@ -695,7 +724,7 @@ public int getDropDownHeight() { * be a fixed height, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill * the screen, or {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the height * of the drop down's content. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param height the height to use * @@ -709,7 +738,7 @@ public void setDropDownHeight(int height) { /** *Returns the id for the view that the auto-complete drop down list is anchored to.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the view's id, or {@link View#NO_ID} if none specified * @@ -725,7 +754,7 @@ public int getDropDownAnchor() { *Sets the view to which the auto-complete drop down list should anchor. The view * corresponding to this id will not be loaded until the next time it is needed to avoid * loading a view which is not yet instantiated.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param id the id to anchor the drop down list view to * @@ -739,7 +768,7 @@ public void setDropDownAnchor(int id) { /** *Gets the background of the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the background drawable * @@ -753,7 +782,7 @@ public Drawable getDropDownBackground() { /** *Sets the background of the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param d the drawable to set as the background * @@ -767,7 +796,7 @@ public void setDropDownBackgroundDrawable(Drawable d) { /** *Sets the background of the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param id the id of the drawable to set as the background * @@ -781,7 +810,7 @@ public void setDropDownBackgroundResource(int id) { /** *Sets the vertical offset used for the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param offset the vertical offset * @@ -795,7 +824,7 @@ public void setDropDownVerticalOffset(int offset) { /** *Gets the vertical offset used for the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the vertical offset * @@ -809,7 +838,7 @@ public int getDropDownVerticalOffset() { /** *Sets the horizontal offset used for the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param offset the horizontal offset * @@ -823,7 +852,7 @@ public void setDropDownHorizontalOffset(int offset) { /** *Gets the horizontal offset used for the auto-complete drop-down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the horizontal offset * @@ -838,7 +867,7 @@ public int getDropDownHorizontalOffset() { /** *Returns the number of characters the user must type before the drop * down list is shown.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the minimum number of characters to type to show the drop down * @@ -859,7 +888,7 @@ public int getThreshold() { *When threshold
is less than or equals 0, a threshold of
* 1 is applied.
Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param threshold the number of characters to type before the drop down * is shown @@ -877,7 +906,7 @@ public void setThreshold(int threshold) { /** *Sets the listener that will be notified when the user clicks an item * in the drop down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param l the item click listener */ @@ -890,7 +919,7 @@ public void setOnItemClickListener(AdapterView.OnItemClickListener l) { /** *Sets the listener that will be notified when the user selects an item * in the drop down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param l the item selected listener */ @@ -903,7 +932,7 @@ public void setOnItemSelectedListener(AdapterView.OnItemSelectedListener l) { /** *Returns the listener that is notified whenever the user clicks an item * in the drop down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the item click listener */ @@ -916,7 +945,7 @@ public AdapterView.OnItemClickListener getOnItemClickListener() { /** *Returns the listener that is notified whenever the user selects an * item in the drop down list.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the item selected listener */ @@ -928,7 +957,7 @@ public AdapterView.OnItemSelectedListener getOnItemSelectedListener() { /** *Returns a filterable list adapter used for auto completion.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return a data adapter used for auto completion */ @@ -951,7 +980,7 @@ public ListAdapter getAdapter() { * startManagingCursor()}), * or by manually closing the cursor when the AutoCompleteTextView is dismissed. * - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param adapter the adapter holding the auto completion data * @@ -970,7 +999,7 @@ publicOnly work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public boolean enoughToFilter() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -980,7 +1009,7 @@ public boolean enoughToFilter() { /** *Indicates whether the popup menu is showing.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return true if the popup menu is showing, false otherwise */ @@ -993,7 +1022,7 @@ public boolean isPopupShowing() { /** *Clear the list selection. This may only be temporary, as user input will often bring * it back. - *
Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public void clearListSelection() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -1003,7 +1032,7 @@ public void clearListSelection() { /** * Set the position of the dropdown view selection. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param position The position to move the selector to. */ @@ -1017,7 +1046,7 @@ public void setListSelection(int position) { * Get the position of the dropdown view selection, if there is one. Returns * {@link android.widget.ListView#INVALID_POSITION ListView.INVALID_POSITION} if there is no dropdown or if * there is no selection. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @return the position of the current selection, if there is one, or * {@link android.widget.ListView#INVALID_POSITION ListView.INVALID_POSITION} if not. @@ -1034,7 +1063,7 @@ public int getListSelection() { *Performs the text completion by converting the selected item from * the drop down list into a string, replacing the text box's content with * this string and finally dismissing the drop down menu.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public void performCompletion() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -1045,7 +1074,7 @@ public void performCompletion() { /** * Identifies whether the view is currently performing a text completion, so subclasses * can decide whether to respond to text changed events. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public boolean isPerformingCompletion() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -1053,7 +1082,7 @@ public boolean isPerformingCompletion() { return ((AutoCompleteTextView)mInputView).isPerformingCompletion(); } - /**Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
*/ + /**Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public void onFilterComplete(int count) { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_SINGLE) ((InternalAutoCompleteTextView)mInputView).superOnFilterComplete(count); @@ -1063,7 +1092,7 @@ else if(mAutoCompleteMode == AUTOCOMPLETE_MODE_MULTI) /** *Closes the drop down if present on screen.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public void dismissDropDown() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -1073,7 +1102,7 @@ public void dismissDropDown() { /** *Displays the drop down on screen.
- *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
*/ public void showDropDown() { if(mAutoCompleteMode == AUTOCOMPLETE_MODE_NONE) @@ -1083,7 +1112,7 @@ public void showDropDown() { /** * Sets the validator used to perform text validation. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @param validator The validator used to validate the text entered in this widget. * @@ -1099,7 +1128,7 @@ public void setValidator(AutoCompleteTextView.Validator validator) { /** * Returns the Validator set with {@link #setValidator}, * ornull
if it was not set.
- * Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @see #setValidator(android.widget.AutoCompleteTextView.Validator) * @see #performValidation() @@ -1113,7 +1142,7 @@ public AutoCompleteTextView.Validator getValidator() { /** * If a validator was set on this view and the current string is not valid, * ask the validator to fix it. - *Only work when autoCompleMode is AUTOCOMPLETE_MODE_SINGLE or AUTOCOMPLETE_MODE_MULTI
+ *Only work when autoComplete mode is {@link #AUTOCOMPLETE_MODE_SINGLE} or {@link #AUTOCOMPLETE_MODE_MULTI}
* * @see #getValidator() * @see #setValidator(android.widget.AutoCompleteTextView.Validator) @@ -1152,11 +1181,28 @@ public void extendSelection (int index){ public Editable getText (){ return mInputView.getText(); } - + + /** + * Convenience for {@link android.text.Selection#selectAll}. + */ public void selectAll (){ mInputView.selectAll(); } - + + /** + * Causes words in the text that are longer than the view is wide + * to be ellipsized instead of broken in the middle. You may also + * want to {@link #setSingleLine} or {@link #setHorizontallyScrolling} + * to constrain the text to a single line. Usenull
+ * to turn off ellipsizing.
+ *
+ * If {@link #setMaxLines} has been used to set two or more lines,
+ * only {@link android.text.TextUtils.TruncateAt#END} and
+ * {@link android.text.TextUtils.TruncateAt#MARQUEE} are supported
+ * (other ellipsizing types will not do anything).
+ *
+ * @attr ref android.R.styleable#TextView_ellipsize
+ */
public void setEllipsize (TruncateAt ellipsis){
mInputView.setEllipsize(ellipsis);
}
diff --git a/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java b/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java
index 6c36cdd6..ed82bbbf 100644
--- a/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java
+++ b/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java
@@ -46,7 +46,7 @@ public class FloatingActionButton extends View {
private SwitchIconAnimator mSwitchIconAnimator;
private int mIconSize;
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
public static FloatingActionButton make(Context context, int resId){
return new FloatingActionButton(context, null, resId);
@@ -112,7 +112,7 @@ else if(mInterpolator == null)
else if(iconSrc != 0)
setIcon(context.getResources().getDrawable(iconSrc), false);
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
Drawable background = getBackground();
if(background != null && background instanceof RippleDrawable){
RippleDrawable drawable = (RippleDrawable)background;
@@ -122,11 +122,18 @@ else if(iconSrc != 0)
setClickable(true);
}
-
+
+ /**
+ * @return The radius of the button.
+ */
public int getRadius(){
return mBackground.getRadius();
}
-
+
+ /**
+ * Set radius of the button.
+ * @param radius The radius in pixel.
+ */
public void setRadius(int radius){
if(mBackground.setRadius(radius))
requestLayout();
@@ -149,27 +156,46 @@ public void setElevation(float elevation) {
else if(mBackground.setShadow(elevation, elevation))
requestLayout();
}
-
+
+ /**
+ * @return The line state of LineMorphingDrawable that is used as this button's icon.
+ */
public int getLineMorphingState(){
if(mIcon != null && mIcon instanceof LineMorphingDrawable)
return ((LineMorphingDrawable)mIcon).getLineState();
return -1;
}
-
+
+ /**
+ * Set the line state of LineMorphingDrawable that is used as this button's icon.
+ * @param state The line state.
+ * @param animation Indicate should show animation when switch line state or not.
+ */
public void setLineMorphingState(int state, boolean animation){
if(mIcon != null && mIcon instanceof LineMorphingDrawable)
((LineMorphingDrawable)mIcon).switchLineState(state, animation);
}
-
+
+ /**
+ * @return The background color of this button.
+ */
public int getBackgroundColor(){
return mBackground.getColor();
}
-
+
+ /**
+ * @return The drawable is used as this button's icon.
+ */
public Drawable getIcon(){
return mIcon;
}
-
+
+ /**
+ * Set the drawable that is used as this button's icon.
+ * @param icon The drawable.
+ * @param animation Indicate should show animation when switch drawable or not.
+ */
public void setIcon(Drawable icon, boolean animation){
if(icon == null)
return;
@@ -197,18 +223,38 @@ public void setBackgroundColor(int color){
mBackground.setColor(color);
invalidate();
}
-
+
+ /**
+ * Show this button at the specific location. If this button isn't attached to any parent view yet,
+ * it will be add to activity's root view. If not, it will just update the location.
+ * @param activity The activity that this button will be attached to.
+ * @param x The x value of anchor point.
+ * @param y The y value of anchor point.
+ * @param gravity The gravity apply with this button.
+ *
+ * @see android.view.Gravity
+ */
public void show(Activity activity, int x, int y, int gravity){
if(getParent() == null){
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mBackground.getIntrinsicWidth(), mBackground.getIntrinsicHeight());
- updateParams(x, y, gravity, params);
-
+ updateParams(x, y, gravity, params);
+
activity.getWindow().addContentView(this, params);
}
else
updateLocation(x, y, gravity);
}
-
+
+ /**
+ * Show this button at the specific location. If this button isn't attached to any parent view yet,
+ * it will be add to activity's root view. If not, it will just update the location.
+ * @param parent The parent view. Should be {@link android.widget.FrameLayout} or {@link android.widget.RelativeLayout}
+ * @param x The x value of anchor point.
+ * @param y The y value of anchor point.
+ * @param gravity The gravity apply with this button.
+ *
+ * @see android.view.Gravity
+ */
public void show(ViewGroup parent, int x, int y, int gravity){
if(getParent() == null){
ViewGroup.LayoutParams params = parent.generateLayoutParams(null);
@@ -221,7 +267,15 @@ public void show(ViewGroup parent, int x, int y, int gravity){
else
updateLocation(x, y, gravity);
}
-
+
+ /**
+ * Update the location of this button. This method only work if it's already attached to a parent view.
+ * @param x The x value of anchor point.
+ * @param y The y value of anchor point.
+ * @param gravity The gravity apply with this button.
+ *
+ * @see android.view.Gravity
+ */
public void updateLocation(int x, int y, int gravity){
if(getParent() != null)
updateParams(x, y, gravity, getLayoutParams());
@@ -284,7 +338,10 @@ else if(params instanceof RelativeLayout.LayoutParams)
else
Log.v(FloatingActionButton.class.getSimpleName(), "cannot recognize LayoutParams: " + params);
}
-
+
+ /**
+ * Remove this button from parent view.
+ */
public void dismiss(){
if(getParent() != null)
((ViewGroup)getParent()).removeView(this);
@@ -325,16 +382,28 @@ public void draw(@NonNull Canvas canvas) {
mIcon.draw(canvas);
}
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
@Override
public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
- }
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
+ }
}
-
+
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
int action = event.getActionMasked();
@@ -343,7 +412,7 @@ public boolean onTouchEvent(@NonNull MotionEvent event) {
return false;
boolean result = super.onTouchEvent(event);
- return mRippleManager.onTouchEvent(event) || result;
+ return getRippleManager().onTouchEvent(event) || result;
}
private class OvalShadowDrawable extends Drawable{
diff --git a/lib/src/main/java/com/rey/material/widget/ImageButton.java b/lib/src/main/java/com/rey/material/widget/ImageButton.java
index b2af1dee..248a84ad 100644
--- a/lib/src/main/java/com/rey/material/widget/ImageButton.java
+++ b/lib/src/main/java/com/rey/material/widget/ImageButton.java
@@ -10,7 +10,7 @@
public class ImageButton extends android.widget.ImageButton {
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
public ImageButton(Context context) {
super(context);
@@ -45,7 +45,7 @@ public void applyStyle(int resId){
}
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
}
@Override
@@ -56,21 +56,33 @@ public void setBackgroundDrawable(Drawable drawable) {
else
super.setBackgroundDrawable(drawable);
}
-
- @Override
- public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
- super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
- }
- }
-
- @Override
+
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
+ @Override
+ public void setOnClickListener(OnClickListener l) {
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
+ super.setOnClickListener(l);
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
+ }
+ }
+
+ @Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
- boolean result = super.onTouchEvent(event);
- return mRippleManager.onTouchEvent(event) || result;
- }
+ boolean result = super.onTouchEvent(event);
+ return getRippleManager().onTouchEvent(event) || result;
+ }
}
diff --git a/lib/src/main/java/com/rey/material/widget/ProgressView.java b/lib/src/main/java/com/rey/material/widget/ProgressView.java
index af46f16f..29ef7aff 100644
--- a/lib/src/main/java/com/rey/material/widget/ProgressView.java
+++ b/lib/src/main/java/com/rey/material/widget/ProgressView.java
@@ -123,40 +123,60 @@ public int getProgressMode(){
else
return ((LinearProgressDrawable)mProgressDrawable).getProgressMode();
}
-
+
+ /**
+ * @return The current progress of this view in [0..1] range.
+ */
public float getProgress(){
if(mCircular)
return ((CircularProgressDrawable)mProgressDrawable).getProgress();
else
return ((LinearProgressDrawable)mProgressDrawable).getProgress();
}
-
+
+ /**
+ * @return The current secondary progress of this view in [0..1] range.
+ */
public float getSecondaryProgress(){
if(mCircular)
return ((CircularProgressDrawable)mProgressDrawable).getSecondaryProgress();
else
return ((LinearProgressDrawable)mProgressDrawable).getSecondaryProgress();
}
-
+
+ /**
+ * Set the current progress of this view.
+ * @param percent The progress value in [0..1] range.
+ */
public void setProgress(float percent){
if(mCircular)
((CircularProgressDrawable)mProgressDrawable).setProgress(percent);
else
((LinearProgressDrawable)mProgressDrawable).setProgress(percent);
}
-
+
+ /**
+ * Set the current secondary progress of this view.
+ * @param percent The progress value in [0..1] range.
+ */
public void setSecondaryProgress(float percent){
if(mCircular)
((CircularProgressDrawable)mProgressDrawable).setSecondaryProgress(percent);
else
((LinearProgressDrawable)mProgressDrawable).setSecondaryProgress(percent);
}
-
+
+ /**
+ * Start showing progress.
+ */
public void start(){
if(mProgressDrawable != null)
((Animatable)mProgressDrawable).start();
}
-
+
+ /**
+ * Stop showing progress.
+ */
public void stop(){
if(mProgressDrawable != null)
((Animatable)mProgressDrawable).stop();
diff --git a/lib/src/main/java/com/rey/material/widget/RadioButton.java b/lib/src/main/java/com/rey/material/widget/RadioButton.java
index edd927d3..6ca00d28 100644
--- a/lib/src/main/java/com/rey/material/widget/RadioButton.java
+++ b/lib/src/main/java/com/rey/material/widget/RadioButton.java
@@ -57,6 +57,10 @@ public void toggle() {
}
}
+ /**
+ * Change the checked state of this button immediately without showing animation.
+ * @param checked The checked state.
+ */
public void setCheckedImmediately(boolean checked){
if(mButtonDrawable instanceof RadioButtonDrawable){
RadioButtonDrawable drawable = (RadioButtonDrawable)mButtonDrawable;
diff --git a/lib/src/main/java/com/rey/material/widget/RippleManager.java b/lib/src/main/java/com/rey/material/widget/RippleManager.java
index a12cf606..996d4398 100644
--- a/lib/src/main/java/com/rey/material/widget/RippleManager.java
+++ b/lib/src/main/java/com/rey/material/widget/RippleManager.java
@@ -21,9 +21,15 @@ public final class RippleManager implements View.OnClickListener, Runnable{
private View mView;
public RippleManager(){}
-
- @SuppressWarnings("deprecation")
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+
+ /**
+ * Should be called in the construction method of view to create a RippleDrawable.
+ * @param v
+ * @param context
+ * @param attrs
+ * @param defStyleAttr
+ * @param defStyleRes
+ */
public void onCreate(View v, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
if(v.isInEditMode())
return;
@@ -79,6 +85,10 @@ public void run() {
mClickListener.onClick(mView);
}
+ /**
+ * Cancel the ripple effect of this view and all of it's children.
+ * @param v
+ */
public static void cancelRipple(View v){
Drawable background = v.getBackground();
if(background instanceof RippleDrawable)
diff --git a/lib/src/main/java/com/rey/material/widget/Slider.java b/lib/src/main/java/com/rey/material/widget/Slider.java
index 6ded996f..4a35e46e 100644
--- a/lib/src/main/java/com/rey/material/widget/Slider.java
+++ b/lib/src/main/java/com/rey/material/widget/Slider.java
@@ -36,7 +36,7 @@
*/
public class Slider extends View{
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
private Paint mPaint;
private RectF mDrawRect;
@@ -148,7 +148,7 @@ public void applyStyle(int resId){
}
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider, defStyleAttr, defStyleRes);
mDiscreteMode = a.getBoolean(R.styleable.Slider_sl_discreteMode, mDiscreteMode);
@@ -217,18 +217,33 @@ private String getValueText(){
return mValueText;
}
+ /**
+ * @return The minimum selectable value.
+ */
public int getMinValue(){
return mMinValue;
}
+ /**
+ * @return The maximum selectable value.
+ */
public int getMaxValue(){
return mMaxValue;
}
+ /**
+ * @return The step value.
+ */
public int getStepValue(){
return mStepValue;
}
+ /**
+ * Set the randge of selectable value.
+ * @param min The minimum selectable value.
+ * @param max The maximum selectable value.
+ * @param animation Indicate that should show animation when thumb's current position changed.
+ */
public void setValueRange(int min, int max, boolean animation){
if(max < min || (min == mMinValue && max == mMaxValue))
return;
@@ -243,18 +258,32 @@ public void setValueRange(int min, int max, boolean animation){
mOnPositionChangeListener.onPositionChanged(this, false, oldPosition, oldPosition, Math.round(oldValue), getValue());
}
+ /**
+ * @return The selected value.
+ */
public int getValue(){
return Math.round(getExactValue());
}
+ /**
+ * @return The exact selected value.
+ */
public float getExactValue(){
return (mMaxValue - mMinValue) * getPosition() + mMinValue;
}
+ /**
+ * @return The current position of thumb in [0..1] range.
+ */
public float getPosition(){
return mThumbMoveAnimator.isRunning() ? mThumbMoveAnimator.getPosition() : mThumbPosition;
}
+ /**
+ * Set current position of thumb.
+ * @param pos The position in [0..1] range.
+ * @param animation Indicate that should show animation when change thumb's position.
+ */
public void setPosition(float pos, boolean animation){
setPosition(pos, animation, animation, false);
}
@@ -286,11 +315,20 @@ private void setPosition(float pos, boolean moveAnimation, boolean transformAnim
mOnPositionChangeListener.onPositionChanged(this, fromUser, oldPos, newPos, oldValue, newValue);
}
+ /**
+ * Set the selected value of this Slider.
+ * @param value The selected value.
+ * @param animation Indicate that should show animation when change thumb's position.
+ */
public void setValue(float value, boolean animation){
value = Math.min(mMaxValue, Math.max(value, mMinValue));
setPosition((value - mMinValue) / (mMaxValue - mMinValue), animation);
}
+ /**
+ * Set a listener will be called when thumb's position changed.
+ * @param listener The {@link Slider.OnPositionChangeListener} will be called.
+ */
public void setOnPositionChangeListener(OnPositionChangeListener listener){
mOnPositionChangeListener = listener;
}
@@ -304,13 +342,25 @@ public void setBackgroundDrawable(Drawable drawable) {
super.setBackgroundDrawable(drawable);
}
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
@Override
public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
}
}
@@ -438,7 +488,7 @@ private float correctPosition(float position){
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
super.onTouchEvent(event);
- mRippleManager.onTouchEvent(event);
+ getRippleManager().onTouchEvent(event);
if(!isEnabled())
return false;
diff --git a/lib/src/main/java/com/rey/material/widget/SnackBar.java b/lib/src/main/java/com/rey/material/widget/SnackBar.java
index 089b0b1b..7659c354 100644
--- a/lib/src/main/java/com/rey/material/widget/SnackBar.java
+++ b/lib/src/main/java/com/rey/material/widget/SnackBar.java
@@ -135,7 +135,6 @@ public SnackBar(Context context, AttributeSet attrs, int defStyleAttr, int defSt
init(context, attrs, defStyleAttr, defStyleRes);
}
- @SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
mText = new TextView(context);
@@ -252,7 +251,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
mText.layout(childLeft, childTop, childRight, childBottom);
}
- @SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackBar, defStyleAttr, defStyleRes);
diff --git a/lib/src/main/java/com/rey/material/widget/Spinner.java b/lib/src/main/java/com/rey/material/widget/Spinner.java
index 9764ff50..c1c1676e 100644
--- a/lib/src/main/java/com/rey/material/widget/Spinner.java
+++ b/lib/src/main/java/com/rey/material/widget/Spinner.java
@@ -53,12 +53,33 @@ public class Spinner extends FrameLayout {
private static final int MAX_ITEMS_MEASURED = 15;
private static final int INVALID_POSITION = -1;
-
+
+ /**
+ * Interface definition for a callback to be invoked when a item's view is clicked.
+ */
public interface OnItemClickListener{
+ /**
+ * Called when a item's view is clicked.
+ * @param parent The Spinner view.
+ * @param view The item view.
+ * @param position The position of item.
+ * @param id The id of item.
+ * @return false will make the Spinner doesn't select this item.
+ */
boolean onItemClick(Spinner parent, View view, int position, long id);
}
-
+
+ /**
+ * Interface definition for a callback to be invoked when an item is selected.
+ */
public interface OnItemSelectedListener{
+ /**
+ * Called when an item is selected.
+ * @param parent The Spinner view.
+ * @param view The item view.
+ * @param position The position of item.
+ * @param id The id of item.
+ */
void onItemSelected(Spinner parent, View view, int position, long id);
}
@@ -99,7 +120,7 @@ public interface OnItemSelectedListener{
private TintManager mTintManager;
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
private boolean mIsRtl = false;
@@ -138,7 +159,7 @@ public void init(Context context, AttributeSet attrs, int defStyleAttr, int defS
super.addView(tv);
}
- setOnClickListener(new View.OnClickListener(){
+ setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showPopup();
@@ -154,7 +175,7 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i
CharSequence memoLabel = mLabelView == null ? null : mLabelView.getText();
removeAllViews();
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr, defStyleRes);
@@ -280,11 +301,18 @@ public void onRtlPropertiesChanged(int layoutDirection) {
}
}
+ /**
+ * @return The selected item's view.
+ */
public View getSelectedView() {
View v = getChildAt(getChildCount() - 1);
return v == mLabelView ? null : v;
}
+ /**
+ * Set the selected position of this Spinner.
+ * @param position The selected position.
+ */
public void setSelection(int position) {
if(mAdapter != null)
position = Math.min(position, mAdapter.getCount() - 1);
@@ -298,19 +326,32 @@ public void setSelection(int position) {
onDataInvalidated();
}
}
-
+
+ /**
+ * @return The selected posiiton.
+ */
public int getSelectedItemPosition(){
return mSelectedPosition;
}
+ /**
+ * @return The selected item.
+ */
public Object getSelectedItem(){
return mAdapter == null ? null : mAdapter.getItem(mSelectedPosition);
}
-
+
+ /**
+ * @return The adapter back this Spinner.
+ */
public SpinnerAdapter getAdapter() {
return mAdapter;
}
+ /**
+ * Set an adapter for this Spinner.
+ * @param adapter
+ */
public void setAdapter(SpinnerAdapter adapter) {
if(mAdapter != null)
mAdapter.unregisterDataSetObserver(mDataSetObserver);
@@ -326,39 +367,110 @@ public void setAdapter(SpinnerAdapter adapter) {
else
mTempAdapter = new DropDownAdapter(adapter);
}
-
+
+ /**
+ * Set the background drawable for the spinner's popup window of choices.
+ *
+ * @param background Background drawable
+ *
+ * @attr ref android.R.styleable#Spinner_popupBackground
+ */
public void setPopupBackgroundDrawable(Drawable background) {
mPopup.setBackgroundDrawable(background);
}
+ /**
+ * Set the background drawable for the spinner's popup window of choices.
+ *
+ * @param resId Resource ID of a background drawable
+ *
+ * @attr ref android.R.styleable#Spinner_popupBackground
+ */
public void setPopupBackgroundResource(int resId) {
setPopupBackgroundDrawable(mTintManager.getDrawable(resId));
}
+ /**
+ * Get the background drawable for the spinner's popup window of choices.
+ *
+ * @return background Background drawable
+ *
+ * @attr ref android.R.styleable#Spinner_popupBackground
+ */
public Drawable getPopupBackground() {
return mPopup.getBackground();
}
+ /**
+ * Set a vertical offset in pixels for the spinner's popup window of choices.
+ *
+ * @param pixels Vertical offset in pixels
+ *
+ * @attr ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset
+ */
public void setDropDownVerticalOffset(int pixels) {
mPopup.setVerticalOffset(pixels);
}
-
+
+ /**
+ * Get the configured vertical offset in pixels for the spinner's popup window of choices.
+ *
+ * @return Vertical offset in pixels
+ *
+ * @attr ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset
+ */
public int getDropDownVerticalOffset() {
return mPopup.getVerticalOffset();
}
+ /**
+ * Set a horizontal offset in pixels for the spinner's popup window of choices.
+ *
+ * @param pixels Horizontal offset in pixels
+ *
+ * @attr ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset
+ */
public void setDropDownHorizontalOffset(int pixels) {
mPopup.setHorizontalOffset(pixels);
}
-
+
+ /**
+ * Get the configured horizontal offset in pixels for the spinner's popup window of choices.
+ *
+ * @return Horizontal offset in pixels
+ *
+ * @attr ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset
+ */
public int getDropDownHorizontalOffset() {
return mPopup.getHorizontalOffset();
}
-
+
+ /**
+ * Set the width of the spinner's popup window of choices in pixels. This value
+ * may also be set to {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
+ * to match the width of the Spinner itself, or
+ * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} to wrap to the measured size
+ * of contained dropdown list items.
+ *
+ * @param pixels Width in pixels, WRAP_CONTENT, or MATCH_PARENT
+ *
+ * @attr ref android.R.styleable#Spinner_dropDownWidth
+ */
public void setDropDownWidth(int pixels) {
mDropDownWidth = pixels;
}
+ /**
+ * Get the configured width of the spinner's popup window of choices in pixels.
+ * The returned value may also be {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}
+ * meaning the popup window will match the width of the Spinner itself, or
+ * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} to wrap to the measured size
+ * of contained dropdown list items.
+ *
+ * @return Width in pixels, WRAP_CONTENT, or MATCH_PARENT
+ *
+ * @attr ref android.R.styleable#Spinner_dropDownWidth
+ */
public int getDropDownWidth() {
return mDropDownWidth;
}
@@ -385,6 +497,13 @@ public void setMinimumWidth(int minWidth) {
super.setMinimumWidth(minWidth);
}
+ /**
+ * Describes how the selected item view is positioned.
+ *
+ * @param gravity See {@link android.view.Gravity}
+ *
+ * @attr ref android.R.styleable#Spinner_gravity
+ */
public void setGravity(int gravity) {
if (mGravity != gravity) {
if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0)
@@ -423,20 +542,46 @@ public void setBackgroundDrawable(Drawable drawable) {
super.setBackgroundDrawable(drawable);
}
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
@Override
- public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
- super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
- }
- }
-
+ public void setOnClickListener(OnClickListener l) {
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
+ super.setOnClickListener(l);
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(@NonNull MotionEvent event) {
+ boolean result = super.onTouchEvent(event);
+ return getRippleManager().onTouchEvent(event) || result;
+ }
+
+ /**
+ * Set a listener that will be called when a item's view is clicked.
+ * @param l The {@link Spinner.OnItemClickListener} will be called.
+ */
public void setOnItemClickListener(OnItemClickListener l) {
mOnItemClickListener = l;
}
-
+
+ /**
+ * Set a listener that will be called when an item is selected.
+ * @param l The {@link Spinner.OnItemSelectedListener} will be called.
+ */
public void setOnItemSelectedListener(OnItemSelectedListener l) {
mOnItemSelectedListener = l;
}
@@ -445,12 +590,6 @@ public void setOnItemSelectedListener(OnItemSelectedListener l) {
public boolean onInterceptTouchEvent(MotionEvent event) {
return true;
}
-
- @Override
- public boolean onTouchEvent(@NonNull MotionEvent event) {
- boolean result = super.onTouchEvent(event);
- return mRippleManager.onTouchEvent(event) || result;
- }
@Override
protected boolean verifyDrawable(Drawable who) {
diff --git a/lib/src/main/java/com/rey/material/widget/Switch.java b/lib/src/main/java/com/rey/material/widget/Switch.java
index b39a7bb1..54366c76 100644
--- a/lib/src/main/java/com/rey/material/widget/Switch.java
+++ b/lib/src/main/java/com/rey/material/widget/Switch.java
@@ -33,7 +33,7 @@
public class Switch extends View implements Checkable {
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
private boolean mRunning = false;
@@ -74,7 +74,15 @@ public class Switch extends View implements Checkable {
private boolean mIsRtl = false;
+ /**
+ * Interface definition for a callback to be invoked when the checked state is changed.
+ */
public interface OnCheckedChangeListener{
+ /**
+ * Called when the checked state is changed.
+ * @param view The Switch view.
+ * @param checked The checked state.
+ */
public void onCheckedChanged(Switch view, boolean checked);
}
@@ -121,7 +129,7 @@ public void applyStyle(int resId){
}
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Switch, defStyleAttr, defStyleRes);
@@ -187,16 +195,32 @@ public void setBackgroundDrawable(Drawable drawable) {
super.setBackgroundDrawable(drawable);
}
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
@Override
public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
}
}
+ /**
+ * Set a listener will be called when the checked state is changed.
+ * @param listener The {@link Switch.OnCheckedChangeListener} will be called.
+ */
public void setOnCheckedChangeListener(OnCheckedChangeListener listener){
mOnCheckedChangeListener = listener;
}
@@ -215,6 +239,20 @@ public void setChecked(boolean checked) {
startAnimation();
}
+ /**
+ * Change the checked state of this Switch immediately without showing animation.
+ * @param checked The checked state.
+ */
+ public void setCheckedImmediately(boolean checked){
+ if(mChecked != checked) {
+ mChecked = checked;
+ if(mOnCheckedChangeListener != null)
+ mOnCheckedChangeListener.onCheckedChanged(this, mChecked);
+ }
+ mThumbPosition = mChecked ? 1f : 0f;
+ invalidate();
+ }
+
@Override
public boolean isChecked() {
return mChecked;
@@ -238,7 +276,7 @@ public void onRtlPropertiesChanged(int layoutDirection) {
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
super.onTouchEvent(event);
- mRippleManager.onTouchEvent(event);
+ getRippleManager().onTouchEvent(event);
float x = event.getX();
if(mIsRtl)
diff --git a/lib/src/main/java/com/rey/material/widget/TabPageIndicator.java b/lib/src/main/java/com/rey/material/widget/TabPageIndicator.java
index 3b3336db..e833ecfe 100644
--- a/lib/src/main/java/com/rey/material/widget/TabPageIndicator.java
+++ b/lib/src/main/java/com/rey/material/widget/TabPageIndicator.java
@@ -32,7 +32,7 @@ public class TabPageIndicator extends HorizontalScrollView implements ViewPager.
private int mMode;
private int mTabPadding;
private int mTabRippleStyle;
- private int mTextApperance;
+ private int mTextAppearance;
private int mIndicatorOffset;
private int mIndicatorWidth;
@@ -115,7 +115,7 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i
mTabRippleStyle = a.getResourceId(R.styleable.TabPageIndicator_tpi_tabRipple, 0);
int indicatorColor = a.getColor(R.styleable.TabPageIndicator_tpi_indicatorColor, ThemeUtil.colorAccent(context, 0xFFFFFFFF));
mIndicatorHeight = a.getDimensionPixelSize(R.styleable.TabPageIndicator_tpi_indicatorHeight, ThemeUtil.dpToPx(context, 2));
- mTextApperance = a.getResourceId(R.styleable.TabPageIndicator_android_textAppearance, 0);
+ mTextAppearance = a.getResourceId(R.styleable.TabPageIndicator_android_textAppearance, 0);
mMode = a.getInteger(R.styleable.TabPageIndicator_tpi_mode, MODE_SCROLL);
a.recycle();
@@ -172,11 +172,19 @@ public void run() {
post(mTabAnimSelector);
}
-
+
+ /**
+ * Set a listener will be called when the current page is changed.
+ * @param listener The {@link android.support.v4.view.ViewPager.OnPageChangeListener} will be called.
+ */
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
mListener = listener;
}
-
+
+ /**
+ * Set the ViewPager associate with this indicator view.
+ * @param view The ViewPager view.
+ */
public void setViewPager(ViewPager view) {
if (mViewPager == view)
return;
@@ -199,7 +207,12 @@ public void setViewPager(ViewPager view) {
notifyDataSetChanged();
}
-
+
+ /**
+ * Set the ViewPager associate with this indicator view and the current position;
+ * @param view The ViewPager view.
+ * @param initialPosition The current position.
+ */
public void setViewPager(ViewPager view, int initialPosition) {
setViewPager(view);
setCurrentItem(initialPosition);
@@ -271,7 +284,11 @@ public void onClick(android.view.View v) {
mViewPager.setCurrentItem(position, true);
}
-
+
+ /**
+ * Set the current page of this TabPageIndicator.
+ * @param position The position of current page.
+ */
public void setCurrentItem(int position) {
if(mSelectedPosition != position){
CheckedTextView tv = getTabView(mSelectedPosition);
@@ -305,7 +322,7 @@ private void notifyDataSetChanged() {
tv.setCheckMarkDrawable(null);
tv.setText(title);
tv.setGravity(Gravity.CENTER);
- tv.setTextAppearance(getContext(), mTextApperance);
+ tv.setTextAppearance(getContext(), mTextAppearance);
tv.setSingleLine(true);
tv.setEllipsize(TruncateAt.END);
tv.setOnClickListener(this);
@@ -359,7 +376,7 @@ else if (i == 2)
tv.setCheckMarkDrawable(null);
tv.setText(title);
tv.setGravity(Gravity.CENTER);
- tv.setTextAppearance(getContext(), mTextApperance);
+ tv.setTextAppearance(getContext(), mTextAppearance);
tv.setSingleLine(true);
tv.setEllipsize(TruncateAt.END);
tv.setTag(i);
diff --git a/lib/src/main/java/com/rey/material/widget/TextView.java b/lib/src/main/java/com/rey/material/widget/TextView.java
index 4a882b2a..a9f99f9d 100644
--- a/lib/src/main/java/com/rey/material/widget/TextView.java
+++ b/lib/src/main/java/com/rey/material/widget/TextView.java
@@ -11,7 +11,7 @@
public class TextView extends android.widget.TextView {
- private RippleManager mRippleManager = new RippleManager();
+ private RippleManager mRippleManager;
public interface OnSelectionChangedListener{
public void onSelectionChanged(View v, int selStart, int selEnd);
@@ -52,7 +52,7 @@ public void applyStyle(int resId){
}
private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes){
- mRippleManager.onCreate(this, context, attrs, defStyleAttr, defStyleRes);
+ getRippleManager().onCreate(this, context, attrs, defStyleAttr, defStyleRes);
}
@Override
@@ -64,21 +64,33 @@ public void setBackgroundDrawable(Drawable drawable) {
super.setBackgroundDrawable(drawable);
}
- @Override
- public void setOnClickListener(OnClickListener l) {
- if(l == mRippleManager)
- super.setOnClickListener(l);
- else{
- mRippleManager.setOnClickListener(l);
- setOnClickListener(mRippleManager);
- }
- }
-
- @Override
+ protected RippleManager getRippleManager(){
+ if(mRippleManager == null){
+ synchronized (RippleManager.class){
+ if(mRippleManager == null)
+ mRippleManager = new RippleManager();
+ }
+ }
+
+ return mRippleManager;
+ }
+
+ @Override
+ public void setOnClickListener(OnClickListener l) {
+ RippleManager rippleManager = getRippleManager();
+ if (l == rippleManager)
+ super.setOnClickListener(l);
+ else {
+ rippleManager.setOnClickListener(l);
+ setOnClickListener(rippleManager);
+ }
+ }
+
+ @Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
- boolean result = super.onTouchEvent(event);
- return mRippleManager.onTouchEvent(event) || result;
- }
+ boolean result = super.onTouchEvent(event);
+ return getRippleManager().onTouchEvent(event) || result;
+ }
public void setOnSelectionChangedListener(OnSelectionChangedListener listener){
mOnSelectionChangedListener = listener;
diff --git a/lib/src/main/java/com/rey/material/widget/TimePicker.java b/lib/src/main/java/com/rey/material/widget/TimePicker.java
index 6901a126..82eaddf1 100644
--- a/lib/src/main/java/com/rey/material/widget/TimePicker.java
+++ b/lib/src/main/java/com/rey/material/widget/TimePicker.java
@@ -68,12 +68,29 @@ public class TimePicker extends View{
private boolean mEdited = false;
+ /**
+ * Interface definition for a callback to be invoked when the selected time is changed.
+ */
public interface OnTimeChangedListener{
+ /**
+ * Called when the select mode is changed
+ * @param mode The current mode. Can be {@link #MODE_HOUR} or {@link #MODE_MINUTE}.
+ */
public void onModeChanged(int mode);
+ /**
+ * Called then the selected hour is changed.
+ * @param oldValue The old hour value.
+ * @param newValue The new hour value.
+ */
public void onHourChanged(int oldValue, int newValue);
+ /**
+ * Called then the selected minute is changed.
+ * @param oldValue The old minute value.
+ * @param newValue The new minute value.
+ */
public void onMinuteChanged(int oldValue, int newValue);
}
@@ -200,22 +217,39 @@ public Interpolator getOutInterpolator(){
return mOutInterpolator;
}
+ /**
+ * @return The current select mode. Can be {@link #MODE_HOUR} or {@link #MODE_MINUTE}.
+ */
public int getMode(){
return mMode;
}
+ /**
+ * @return The selected hour value.
+ */
public int getHour(){
return mHour;
}
+ /**
+ * @return The selected minute value.
+ */
public int getMinute(){
return mMinute;
}
+ /**
+ * @return this TimePicker use 24-hour format or not.
+ */
public boolean is24Hour(){
return m24Hour;
}
+ /**
+ * Set the select mode of this TimePicker.
+ * @param mode The select mode. Can be {@link #MODE_HOUR} or {@link #MODE_MINUTE}.
+ * @param animation Indicate that should show animation when switch select mode or not.
+ */
public void setMode(int mode, boolean animation){
if(mMode != mode){
mMode = mode;
@@ -230,6 +264,10 @@ public void setMode(int mode, boolean animation){
}
}
+ /**
+ * Set the selected hour value.
+ * @param hour The selected hour value.
+ */
public void setHour(int hour){
if(m24Hour)
hour = Math.max(hour, 0) % 24;
@@ -248,6 +286,10 @@ public void setHour(int hour){
}
}
+ /**
+ * Set the selected minute value.
+ * @param minute The selected minute value.
+ */
public void setMinute(int minute){
minute = Math.min(Math.max(minute, 0), 59);
@@ -263,10 +305,18 @@ public void setMinute(int minute){
}
}
+ /**
+ * Set a listener will be called when the selected time is changed.
+ * @param listener The {@link TimePicker.OnTimeChangedListener} will be called.
+ */
public void setOnTimeChangedListener(OnTimeChangedListener listener){
mOnTimeChangedListener = listener;
}
+ /**
+ * Set this TimePicker use 24-hour format or not.
+ * @param b
+ */
public void set24Hour(boolean b){
if(m24Hour != b){
m24Hour = b;
diff --git a/lib/src/main/java/com/rey/material/widget/YearPicker.java b/lib/src/main/java/com/rey/material/widget/YearPicker.java
index ccdb65f5..1531a18c 100644
--- a/lib/src/main/java/com/rey/material/widget/YearPicker.java
+++ b/lib/src/main/java/com/rey/material/widget/YearPicker.java
@@ -49,8 +49,16 @@ public class YearPicker extends ListView{
private Paint mPaint;
+ /**
+ * Interface definition for a callback to be invoked when the selected year is changed.
+ */
public interface OnYearChangedListener{
+ /**
+ * Called then the selected year is changed.
+ * @param oldValue The old year value.
+ * @param newValue The new year value.
+ */
public void onYearChanged(int oldValue, int newValue);
}
@@ -155,10 +163,19 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i
mAdapter.notifyDataSetChanged();
}
+ /**
+ * Set the range of selectable year value.
+ * @param min The minimum selectable year value.
+ * @param max The maximum selectable year value.
+ */
public void setYearRange(int min, int max){
mAdapter.setYearRange(min, max);
}
+ /**
+ * Jump to a specific year.
+ * @param year
+ */
public void goTo(int year){
int position = mAdapter.positionOfYear(year) - mPositionShift;
int offset = mDistanceShift;
@@ -179,6 +196,10 @@ public void run() {
});
}
+ /**
+ * Set the selected year.
+ * @param year The selected year value.
+ */
public void setYear(int year){
if(mAdapter.getYear() == year)
return;
@@ -187,10 +208,17 @@ public void setYear(int year){
goTo(year);
}
+ /**
+ * @return The selected year value.
+ */
public int getYear(){
return mAdapter.getYear();
}
+ /**
+ * Set a listener will be called when the selected year value is changed.
+ * @param listener The {@link YearPicker.OnYearChangedListener} will be called.
+ */
public void setOnYearChangedListener(OnYearChangedListener listener){
mOnYearChangedListener = listener;
}
diff --git a/lib/src/main/res/values/styles.xml b/lib/src/main/res/values/styles.xml
index 0a03dc8a..904faf49 100644
--- a/lib/src/main/res/values/styles.xml
+++ b/lib/src/main/res/values/styles.xml
@@ -258,6 +258,22 @@