From 3737a2e3d6d7e49b81a39426a17f8398b0b870c6 Mon Sep 17 00:00:00 2001 From: rey5137 Date: Thu, 14 May 2015 16:22:48 +0700 Subject: [PATCH] Add javadoc. --- .../rey/material/demo/SnackbarFragment.java | 2 +- .../rey/material/app/DatePickerDialog.java | 63 ++++ .../java/com/rey/material/app/Dialog.java | 316 +++++++++++++++++- .../com/rey/material/app/DialogFragment.java | 3 + .../com/rey/material/app/SimpleDialog.java | 77 +++++ .../rey/material/app/TimePickerDialog.java | 35 ++ .../com/rey/material/app/ToolbarManager.java | 36 ++ .../com/rey/material/widget/CheckBox.java | 4 + .../widget/CircleCheckedTextView.java | 4 + .../com/rey/material/widget/DatePicker.java | 51 +++ .../com/rey/material/widget/EditText.java | 132 +++++--- .../material/widget/FloatingActionButton.java | 83 ++++- .../com/rey/material/widget/ProgressView.java | 32 +- .../com/rey/material/widget/RadioButton.java | 4 + .../rey/material/widget/RippleManager.java | 16 +- .../java/com/rey/material/widget/Slider.java | 38 +++ .../com/rey/material/widget/SnackBar.java | 2 - .../java/com/rey/material/widget/Spinner.java | 147 +++++++- .../java/com/rey/material/widget/Switch.java | 26 ++ .../rey/material/widget/TabPageIndicator.java | 33 +- .../com/rey/material/widget/TimePicker.java | 50 +++ .../com/rey/material/widget/YearPicker.java | 28 ++ 22 files changed, 1084 insertions(+), 98 deletions(-) diff --git a/app/src/main/java/com/rey/material/demo/SnackbarFragment.java b/app/src/main/java/com/rey/material/demo/SnackbarFragment.java index e7369cc1..9269679e 100644 --- a/app/src/main/java/com/rey/material/demo/SnackbarFragment.java +++ b/app/src/main/java/com/rey/material/demo/SnackbarFragment.java @@ -35,7 +35,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onClick(View v) { - if(mSnackBar.getState() == SnackBar.STATE_SHOWED) + if(mSnackBar.getState() == SnackBar.STATE_SHOWN) mSnackBar.dismiss(); else{ switch (v.getId()) { diff --git a/lib/src/main/java/com/rey/material/app/DatePickerDialog.java b/lib/src/main/java/com/rey/material/app/DatePickerDialog.java index 3014653d..b08c8cea 100644 --- a/lib/src/main/java/com/rey/material/app/DatePickerDialog.java +++ b/lib/src/main/java/com/rey/material/app/DatePickerDialog.java @@ -36,7 +36,20 @@ public class DatePickerDialog extends Dialog { private DatePickerLayout mDatePickerLayout; private float mCornerRadius; + /** + * Interface definition for a callback to be invoked when the selected date is changed. + */ public interface OnDateChangedListener{ + + /** + * Called when the selected date is changed. + * @param oldDay The day value of old date. + * @param oldMonth The month value of old date. + * @param oldYear The year value of old date. + * @param newDay The day value of new date. + * @param newMonth The month value of new date. + * @param newYear The year value of new date. + */ public void onDateChanged(int oldDay, int oldMonth, int oldYear, int newDay, int newMonth, int newYear); } @@ -79,43 +92,88 @@ public Dialog cornerRadius(float radius){ return super.cornerRadius(radius); } + /** + * Set the range of selectable dates. + * @param minDay The day value of minimum date. + * @param minMonth The month value of minimum date. + * @param minYear The year value of minimum date. + * @param maxDay The day value of maximum date. + * @param maxMonth The month value of maximum date. + * @param maxYear The year value of maximum date. + * @return The DatePickerDialog for chaining methods. + */ public DatePickerDialog dateRange(int minDay, int minMonth, int minYear, int maxDay, int maxMonth, int maxYear){ mDatePickerLayout.setDateRange(minDay, minMonth, minYear, maxDay, maxMonth, maxYear); return this; } + /** + * Set the range of selectable dates. + * @param minTime The minimum date in milis. + * @param maxTime The maximum date in milis + * @return The DatePickerDialog for chaining methods. + */ public DatePickerDialog dateRange(long minTime, long maxTime){ mDatePickerLayout.setDateRange(minTime, maxTime); return this; } + /** + * Set the selected date of this DatePickerDialog. + * @param day The day value of selected date. + * @param month The month value of selected date. + * @param year The year value of selected date. + * @return The DatePickerDialog for chaining methods. + */ public DatePickerDialog date(int day, int month, int year){ mDatePickerLayout.setDate(day, month, year); return this; } + /** + * Set the selected date of this DatePickerDialog. + * @param time The date in milis. + * @return The DatePickerDialog for chaining methods. + */ public DatePickerDialog date(long time){ mDatePickerLayout.setDate(time); return this; } + /** + * Set the listener will be called when the selected date is changed. + * @param listener The {@link DatePickerDialog.OnDateChangedListener} will be called. + * @return The DatePickerDialog for chaining methods. + */ public DatePickerDialog onDateChangedListener(OnDateChangedListener listener){ mOnDateChangedListener = listener; return this; } + /** + * @return The day value of selected date. + */ public int getDay(){ return mDatePickerLayout.getDay(); } + /** + * @return The month value of selected date. + */ public int getMonth(){ return mDatePickerLayout.getMonth(); } + /** + * @return The year value of selected date. + */ public int getYear(){ return mDatePickerLayout.getYear(); } + /** + * @return The selected date. + */ public long getDate(){ Calendar cal = getCalendar(); cal.set(Calendar.MILLISECOND, 0); @@ -132,6 +190,11 @@ public Calendar getCalendar(){ return mDatePickerLayout.getCalendar(); } + /** + * Get the formatted string of selected date. + * @param formatter The DateFormat used to format the date. + * @return + */ public String getFormattedDate(DateFormat formatter){ return mDatePickerLayout.getFormattedDate(formatter); } diff --git a/lib/src/main/java/com/rey/material/app/Dialog.java b/lib/src/main/java/com/rey/material/app/Dialog.java index 1cdb3ad1..14f25cb8 100644 --- a/lib/src/main/java/com/rey/material/app/Dialog.java +++ b/lib/src/main/java/com/rey/material/app/Dialog.java @@ -80,9 +80,21 @@ public void run() { private boolean mCancelable = true; private boolean mCanceledOnTouchOutside = true; + /** + * The viewId of title view. + */ public static final int TITLE = ViewUtil.generateViewId(); + /** + * The viewId of positive action button. + */ public static final int ACTION_POSITIVE = ViewUtil.generateViewId(); + /** + * The viewId of negative action button. + */ public static final int ACTION_NEGATIVE = ViewUtil.generateViewId(); + /** + * The viewId of neutral action button. + */ public static final int ACTION_NEUTRAL = ViewUtil.generateViewId(); public Dialog(Context context) { @@ -241,6 +253,10 @@ public Dialog applyStyle(int resId){ return this; } + /** + * Clear the content of this Dialog. + * @return The Dialog for chaining methods. + */ public Dialog clearContent(){ title(0); positiveAction(0); @@ -253,12 +269,23 @@ public Dialog clearContent(){ return this; } + /** + * Set the params of this Dialog layout. + * @param width The width param. Can be the size in pixels, or {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} or {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}. + * @param height The height param. Can be the size in pixels, or {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT} or {@link android.view.ViewGroup.LayoutParams#MATCH_PARENT}. + * @return The Dialog for chaining methods. + */ public Dialog layoutParams(int width, int height){ mLayoutWidth = width; mLayoutHeight = height; return this; } + /** + * Set the dim amount of the region outside this Dialog. + * @param amount The dim amount in [0..1]. + * @return The Dialog for chaining methods. + */ public Dialog dimAmount(float amount){ Window window = getWindow(); if(amount > 0f){ @@ -272,45 +299,85 @@ public Dialog dimAmount(float amount){ return this; } + /** + * Set the background color of this Dialog + * @param color The color value. + * @return The Dialog for chaining methods. + */ public Dialog backgroundColor(int color){ mCardView.setCardBackgroundColor(color); return this; } - public Dialog elevation(float radius){ - if(mCardView.getMaxCardElevation() < radius) - mCardView.setMaxCardElevation(radius); + /** + * Set the elevation value of this Dialog. + * @param elevation + * @return The Dialog for chaining methods. + */ + public Dialog elevation(float elevation){ + if(mCardView.getMaxCardElevation() < elevation) + mCardView.setMaxCardElevation(elevation); - mCardView.setCardElevation(radius); + mCardView.setCardElevation(elevation); return this; } - public Dialog maxElevation(float radius){ - mCardView.setMaxCardElevation(radius); + /** + * Set the maximum elevation value of this Dialog. + * @param elevation + * @return The Dialog for chaining methods. + */ + public Dialog maxElevation(float elevation){ + mCardView.setMaxCardElevation(elevation); return this; } + /** + * Set the corner radius of this Dialog. + * @param radius The corner radius. + * @return The Dialog for chaining methods. + */ public Dialog cornerRadius(float radius){ mCardView.setRadius(radius); return this; } + /** + * Set the divider's color of this Dialog. + * @param color The color value. + * @return The Dialog for chaining methods. + */ public Dialog dividerColor(int color){ mCardView.setDividerColor(color); return this; } + /** + * Set the height of divider of this Dialog. + * @param height The size value in pixels. + * @return The Dialog for chaining methods. + */ public Dialog dividerHeight(int height){ mCardView.setDividerHeight(height); return this; } + /** + * Set the title of this Dialog. + * @param title The title text. + * @return The Dialog for chaining methods. + */ public Dialog title(CharSequence title){ mTitle.setText(title); mTitle.setVisibility(TextUtils.isEmpty(title) ? View.GONE : View.VISIBLE); return this; } + /** + * Set the title of this Dialog. + * @param id The resourceId of text. + * @return The Dialog for chaining methods. + */ public Dialog title(int id){ return title(id == 0 ? null : getContext().getResources().getString(id)); } @@ -325,16 +392,31 @@ public void setTitle(int titleId) { title(titleId); } + /** + * Set the text's color of Dialog's title. + * @param color The color value. + * @return The Dialog for chaining methods. + */ public Dialog titleColor(int color){ mTitle.setTextColor(color); return this; } + /** + * Sets the text color, size, style of the title view from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The Dialog for chaining methods. + */ public Dialog titleTextAppearance(int resId){ mTitle.setTextAppearance(getContext(), resId); return this; } + /** + * Set the background drawable of all action buttons. + * @param id The resourceId of drawable. + * @return The Dialog for chaining methods. + */ public Dialog actionBackground(int id){ positiveActionBackground(id); negativeActionBackground(id); @@ -342,6 +424,11 @@ public Dialog actionBackground(int id){ return this; } + /** + * Set the background drawable of all action buttons. + * @param drawable The background drawable. + * @return The Dialog for chaining methods. + */ public Dialog actionBackground(Drawable drawable){ positiveActionBackground(drawable); negativeActionBackground(drawable); @@ -349,6 +436,11 @@ public Dialog actionBackground(Drawable drawable){ return this; } + /** + * Set the RippleEffect of all action buttons. + * @param resId The resourceId of style. + * @return The Dialog for chaining methods. + */ public Dialog actionRipple(int resId){ positiveActionRipple(resId); negativeActionRipple(resId); @@ -356,6 +448,11 @@ public Dialog actionRipple(int resId){ return this; } + /** + * Sets the text color, size, style of all action buttons from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The Dialog for chaining methods. + */ public Dialog actionTextAppearance(int resId){ positiveActionTextAppearance(resId); negativeActionTextAppearance(resId); @@ -363,6 +460,11 @@ public Dialog actionTextAppearance(int resId){ return this; } + /** + * Sets the text color of all action buttons. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog actionTextColor(ColorStateList color){ positiveActionTextColor(color); negativeActionTextColor(color); @@ -370,6 +472,11 @@ public Dialog actionTextColor(ColorStateList color){ return this; } + /** + * Sets the text color of all action buttons. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog actionTextColor(int color){ positiveActionTextColor(color); negativeActionTextColor(color); @@ -377,164 +484,318 @@ public Dialog actionTextColor(int color){ return this; } + /** + * Set the text of positive action button. + * @param action + * @return The Dialog for chaining methods. + */ public Dialog positiveAction(CharSequence action){ mPositiveAction.setText(action); mPositiveAction.setVisibility(TextUtils.isEmpty(action) ? View.GONE : View.VISIBLE); return this; } + /** + * Set the text of positive action button. + * @param id The resourceId of text. + * @return The Dialog for chaining methods. + */ public Dialog positiveAction(int id){ return positiveAction(id == 0 ? null : getContext().getResources().getString(id)); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - @SuppressWarnings("deprecation") + /** + * Set the background drawable of positive action button. + * @param drawable The background drawable. + * @return The Dialog for chaining methods. + */ public Dialog positiveActionBackground(Drawable drawable){ ViewUtil.setBackground(mPositiveAction, drawable); return this; } + /** + * Set the background drawable of positive action button. + * @param id The resourceId of drawable. + * @return The Dialog for chaining methods. + */ public Dialog positiveActionBackground(int id){ return positiveActionBackground(id == 0 ? null : getContext().getResources().getDrawable(id)); } + /** + * Set the RippleEffect of positive action button. + * @param resId The resourceId of style. + * @return The Dialog for chaining methods. + */ public Dialog positiveActionRipple(int resId){ RippleDrawable drawable = new RippleDrawable.Builder(getContext(), resId).build(); return positiveActionBackground(drawable); } + /** + * Sets the text color, size, style of positive action button from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The Dialog for chaining methods. + */ public Dialog positiveActionTextAppearance(int resId){ mPositiveAction.setTextAppearance(getContext(), resId); return this; } + /** + * Sets the text color of positive action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog positiveActionTextColor(ColorStateList color){ mPositiveAction.setTextColor(color); return this; } + /** + * Sets the text color of positive action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog positiveActionTextColor(int color){ mPositiveAction.setTextColor(color); return this; } + /** + * Set a listener will be called when positive action button is clicked. + * @param listener The {@link android.view.View.OnClickListener} will be called. + * @return The Dialog for chaining methods. + */ public Dialog positiveActionClickListener(View.OnClickListener listener){ mPositiveAction.setOnClickListener(listener); return this; } + /** + * Set the text of negative action button. + * @param action + * @return The Dialog for chaining methods. + */ public Dialog negativeAction(CharSequence action){ mNegativeAction.setText(action); mNegativeAction.setVisibility(TextUtils.isEmpty(action) ? View.GONE : View.VISIBLE); return this; } + /** + * Set the text of negative action button. + * @param id The resourceId of text. + * @return The Dialog for chaining methods. + */ public Dialog negativeAction(int id){ return negativeAction(id == 0 ? null : getContext().getResources().getString(id)); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - @SuppressWarnings("deprecation") + /** + * Set the background drawable of negative action button. + * @param drawable The background drawable. + * @return The Dialog for chaining methods. + */ public Dialog negativeActionBackground(Drawable drawable){ ViewUtil.setBackground(mNegativeAction, drawable); return this; } + /** + * Set the background drawable of neagtive action button. + * @param id The resourceId of drawable. + * @return The Dialog for chaining methods. + */ public Dialog negativeActionBackground(int id){ return negativeActionBackground(id == 0 ? null : getContext().getResources().getDrawable(id)); } + /** + * Set the RippleEffect of negative action button. + * @param resId The resourceId of style. + * @return The Dialog for chaining methods. + */ public Dialog negativeActionRipple(int resId){ RippleDrawable drawable = new RippleDrawable.Builder(getContext(), resId).build(); return negativeActionBackground(drawable); } + /** + * Sets the text color, size, style of negative action button from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The Dialog for chaining methods. + */ public Dialog negativeActionTextAppearance(int resId){ mNegativeAction.setTextAppearance(getContext(), resId); return this; } + /** + * Sets the text color of negative action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog negativeActionTextColor(ColorStateList color){ mNegativeAction.setTextColor(color); return this; } + /** + * Sets the text color of negative action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog negativeActionTextColor(int color){ mNegativeAction.setTextColor(color); return this; } + /** + * Set a listener will be called when negative action button is clicked. + * @param listener The {@link android.view.View.OnClickListener} will be called. + * @return The Dialog for chaining methods. + */ public Dialog negativeActionClickListener(View.OnClickListener listener){ mNegativeAction.setOnClickListener(listener); return this; } + /** + * Set the text of neutral action button. + * @param action + * @return The Dialog for chaining methods. + */ public Dialog neutralAction(CharSequence action){ mNeutralAction.setText(action); mNeutralAction.setVisibility(TextUtils.isEmpty(action) ? View.GONE : View.VISIBLE); return this; } + /** + * Set the text of neutral action button. + * @param id The resourceId of text. + * @return The Dialog for chaining methods. + */ public Dialog neutralAction(int id){ return neutralAction(id == 0 ? null : getContext().getResources().getString(id)); } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN) - @SuppressWarnings("deprecation") + /** + * Set the background drawable of neutral action button. + * @param drawable The background drawable. + * @return The Dialog for chaining methods. + */ public Dialog neutralActionBackground(Drawable drawable){ ViewUtil.setBackground(mNeutralAction, drawable); return this; } + /** + * Set the background drawable of neutral action button. + * @param id The resourceId of drawable. + * @return The Dialog for chaining methods. + */ public Dialog neutralActionBackground(int id){ return neutralActionBackground(id == 0 ? null : getContext().getResources().getDrawable(id)); } + /** + * Set the RippleEffect of neutral action button. + * @param resId The resourceId of style. + * @return The Dialog for chaining methods. + */ public Dialog neutralActionRipple(int resId){ RippleDrawable drawable = new RippleDrawable.Builder(getContext(), resId).build(); return neutralActionBackground(drawable); } + /** + * Sets the text color, size, style of neutral action button from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The Dialog for chaining methods. + */ public Dialog neutralActionTextAppearance(int resId){ mNeutralAction.setTextAppearance(getContext(), resId); return this; } + /** + * Sets the text color of neutral action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog neutralActionTextColor(ColorStateList color){ mNeutralAction.setTextColor(color); return this; } + /** + * Sets the text color of neutral action button. + * @param color + * @return The Dialog for chaining methods. + */ public Dialog neutralActionTextColor(int color){ mNeutralAction.setTextColor(color); return this; } + /** + * Set a listener will be called when neutral action button is clicked. + * @param listener The {@link android.view.View.OnClickListener} will be called. + * @return The Dialog for chaining methods. + */ public Dialog neutralActionClickListener(View.OnClickListener listener){ mNeutralAction.setOnClickListener(listener); return this; } + /** + * Set the layout direction of this Dialog + * @param direction The layout direction value. Can be {@link android.view.View#LAYOUT_DIRECTION_LTR}, {@link android.view.View#LAYOUT_DIRECTION_RTL} or {@link android.view.View#LAYOUT_DIRECTION_LOCALE} + * @return The Dialog for chaining methods. + */ public Dialog layoutDirection(int direction){ ViewCompat.setLayoutDirection(mCardView, direction); return this; } + /** + * Set the animation when Dialog enter the screen. + * @param resId The resourceId of animation. + * @return The Dialog for chaining methods. + */ public Dialog inAnimation(int resId){ mInAnimationId = resId; return this; } + /** + * Set the animation when Dialog exit the screen. + * @param resId The resourceId of animation. + * @return The Dialog for chaining methods. + */ public Dialog outAnimation(int resId){ mOutAnimationId = resId; return this; } + /** + * Indicate that Dialog should show divider when the content is longer than container view. + * @param show + * @return The Dialog for chaining methods. + */ public Dialog showDivider(boolean show){ mCardView.setShowDivider(show); return this; } + /** + * Set the content view of this Dialog. + * @param v The content view. + * @return The Dialog for chaining methods. + */ public Dialog contentView(View v){ if(mContent != v) { if(mContent != null) @@ -549,6 +810,11 @@ public Dialog contentView(View v){ return this; } + /** + * Set the content view of this Dialog. + * @param layoutId The reourceId of layout. + * @return The Dialog for chaining methods. + */ public Dialog contentView(int layoutId){ if(layoutId == 0) return this; @@ -557,23 +823,49 @@ public Dialog contentView(int layoutId){ return contentView(v); } + /** + * Sets whether this dialog is cancelable with the + * {@link android.view.KeyEvent#KEYCODE_BACK BACK} key. + * @return The Dialog for chaining methods. + */ public Dialog cancelable(boolean cancelable){ super.setCancelable(cancelable); mCancelable = cancelable; return this; } + /** + * Sets whether this dialog is canceled when touched outside the window's + * bounds. If setting to true, the dialog is set to be cancelable if not + * already set. + * + * @param cancel Whether the dialog should be canceled when touched outside + * @return The Dialog for chaining methods. + */ public Dialog canceledOnTouchOutside(boolean cancel){ super.setCanceledOnTouchOutside(cancel); mCanceledOnTouchOutside = cancel; return this; } + /** + * Set the margin between content view and Dialog border. + * @param margin The margin size in pixels. + * @return The Dialog for chaining methods. + */ public Dialog contentMargin(int margin){ mCardView.setContentMargin(margin); return this; } + /** + * Set the margin between content view and Dialog border. + * @param left The left margin size in pixels. + * @param top The top margin size in pixels. + * @param right The right margin size in pixels. + * @param bottom The bottom margin size in pixels. + * @return The Dialog for chaining methods. + */ public Dialog contentMargin(int left, int top, int right, int bottom){ mCardView.setContentMargin(left, top, right, bottom); return this; diff --git a/lib/src/main/java/com/rey/material/app/DialogFragment.java b/lib/src/main/java/com/rey/material/app/DialogFragment.java index e9f54f13..fc845bd4 100644 --- a/lib/src/main/java/com/rey/material/app/DialogFragment.java +++ b/lib/src/main/java/com/rey/material/app/DialogFragment.java @@ -11,6 +11,9 @@ */ public class DialogFragment extends android.support.v4.app.DialogFragment{ + /** + * Interface definition for passing style data. + */ public interface Builder{ /** * Get a Dialog instance used for this fragment. diff --git a/lib/src/main/java/com/rey/material/app/SimpleDialog.java b/lib/src/main/java/com/rey/material/app/SimpleDialog.java index 430d5af9..ef3a272d 100644 --- a/lib/src/main/java/com/rey/material/app/SimpleDialog.java +++ b/lib/src/main/java/com/rey/material/app/SimpleDialog.java @@ -50,7 +50,15 @@ public class SimpleDialog extends Dialog { protected static final int MODE_MULTI_ITEMS = 3; protected static final int MODE_CUSTOM = 4; + /** + * Interface definition for a callback to be invoked when the checked state of an item changed. + */ public interface OnSelectionChangedListener{ + /** + * Called when the checked state of an item changed. + * @param index The index of item. + * @param selected The checked state. + */ public void onSelectionChanged(int index, boolean selected); } @@ -137,6 +145,11 @@ private void initMessageView(){ mMessage.setGravity(Gravity.START | Gravity.CENTER_VERTICAL); } + /** + * Set a message text to this SimpleDialog. + * @param message + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog message(CharSequence message){ if(mScrollView == null) initScrollView(); @@ -157,10 +170,20 @@ public SimpleDialog message(CharSequence message){ return this; } + /** + * Set a message text to this SimpleDialog. + * @param id The resourceId of text. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog message(int id){ return message(id == 0 ? null : getContext().getResources().getString(id)); } + /** + * Sets the text color, size, style of the message view from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog messageTextAppearance(int resId){ if(mMessageTextAppearanceId != resId){ mMessageTextAppearanceId = resId; @@ -170,6 +193,11 @@ public SimpleDialog messageTextAppearance(int resId){ return this; } + /** + * Sets the text color of the message view. + * @param color The color value. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog messageTextColor(int color){ if(mMessageTextColor != color){ mMessageTextColor = color; @@ -179,6 +207,11 @@ public SimpleDialog messageTextColor(int color){ return this; } + /** + * Sets the style of radio button. + * @param resId The resourceId of style. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog radioButtonStyle(int resId){ if(mRadioButtonStyle != resId){ mRadioButtonStyle = resId; @@ -188,6 +221,11 @@ public SimpleDialog radioButtonStyle(int resId){ return this; } + /** + * Sets the style of check box. + * @param resId The resourceId of style. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog checkBoxStyle(int resId){ if(mCheckBoxStyle != resId){ mCheckBoxStyle = resId; @@ -197,6 +235,11 @@ public SimpleDialog checkBoxStyle(int resId){ return this; } + /** + * Sets the height of item + * @param height The size in pixels. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog itemHeight(int height){ if(mItemHeight != height){ mItemHeight = height; @@ -206,6 +249,11 @@ public SimpleDialog itemHeight(int height){ return this; } + /** + * Sets the text color, size, style of the item view from the specified TextAppearance resource. + * @param resId The resourceId value. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog itemTextAppearance(int resId){ if(mItemTextAppearance != resId){ mItemTextAppearance = resId; @@ -231,6 +279,12 @@ private void initListView(){ mListView.setAdapter(mAdapter); } + /** + * Set the list of items in single-choice mode. + * @param items The list of items. + * @param selectedIndex The index of selected item. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog items(CharSequence[] items, int selectedIndex){ if(mListView == null) initListView(); @@ -241,6 +295,12 @@ public SimpleDialog items(CharSequence[] items, int selectedIndex){ return this; } + /** + * Set the list of items in multi-choice mode. + * @param items The list of items. + * @param selectedIndexes The indexes of selected items. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog multiChoiceItems(CharSequence[] items, int... selectedIndexes){ if(mListView == null) initListView(); @@ -251,23 +311,40 @@ public SimpleDialog multiChoiceItems(CharSequence[] items, int... selectedIndexe return this; } + /** + * Set a listener will be called when the checked state of a item is changed. + * @param listener The {@link SimpleDialog.OnSelectionChangedListener} will be called. + * @return The SimpleDialog for chaining methods. + */ public SimpleDialog onSelectionChangedListener(OnSelectionChangedListener listener){ mOnSelectionChangedListener = listener; return this; } + /** + * @return The list of index of all selected items. + */ public int[] getSelectedIndexes(){ return mAdapter == null ? null : mAdapter.getSelectedIndexes(); } + /** + * @return The list of value of all selected items. + */ public CharSequence[] getSelectedValues(){ return mAdapter.getSelectedValues(); } + /** + * @return The index of selected item. + */ public int getSelectedIndex(){ return mAdapter == null ? -1 : mAdapter.getLastSelectedIndex(); } + /** + * @return The value of selected item. + */ public CharSequence getSelectedValue(){ return mAdapter.getLastSelectedValue(); } diff --git a/lib/src/main/java/com/rey/material/app/TimePickerDialog.java b/lib/src/main/java/com/rey/material/app/TimePickerDialog.java index b9ffa7d5..573839c0 100644 --- a/lib/src/main/java/com/rey/material/app/TimePickerDialog.java +++ b/lib/src/main/java/com/rey/material/app/TimePickerDialog.java @@ -35,8 +35,18 @@ public class TimePickerDialog extends Dialog{ private TimePickerLayout mTimePickerLayout; private float mCornerRadius; + /** + * Interface definition for a callback to be invoked when the selected time is changed. + */ public interface OnTimeChangedListener{ + /** + * Called when the selected time is changed. + * @param oldHour The hour value of old time. + * @param oldMinute The minute value of old time. + * @param newHour The hour value of new time. + * @param newMinute The minute value of new time. + */ public void onTimeChanged(int oldHour, int oldMinute, int newHour, int newMinute); } @@ -78,29 +88,54 @@ public Dialog cornerRadius(float radius){ return super.cornerRadius(radius); } + /** + * Set the selected hour value. + * @param hour The selected hour value. + * @return The TimePickerDialog for chaining methods. + */ public TimePickerDialog hour(int hour){ mTimePickerLayout.setHour(hour); return this; } + /** + * Set the selected minute value. + * @param minute The selected minute value. + * @return The TimePickerDialog for chaining methods. + */ public TimePickerDialog minute(int minute){ mTimePickerLayout.setMinute(minute); return this; } + /** + * Set a listener will be called when the selected time is changed. + * @param listener The {@link TimePickerDialog.OnTimeChangedListener} will be called. + */ public TimePickerDialog onTimeChangedListener(OnTimeChangedListener listener){ mTimePickerLayout.setOnTimeChangedListener(listener); return this; } + /** + * @return The selected hour value. + */ public int getHour(){ return mTimePickerLayout.getHour(); } + /** + * @return The selected minute value. + */ public int getMinute(){ return mTimePickerLayout.getMinute(); } + /** + * Get the formatted string of selected time. + * @param formatter The DateFormat used to format the time. + * @return + */ public String getFormattedTime(DateFormat formatter){ return mTimePickerLayout.getFormattedTime(formatter); } diff --git a/lib/src/main/java/com/rey/material/app/ToolbarManager.java b/lib/src/main/java/com/rey/material/app/ToolbarManager.java index fe8117b9..b6a7667a 100644 --- a/lib/src/main/java/com/rey/material/app/ToolbarManager.java +++ b/lib/src/main/java/com/rey/material/app/ToolbarManager.java @@ -41,8 +41,16 @@ public class ToolbarManager { private boolean mGroupChanged = false; private boolean mMenuDataChanged = true; + /** + * Interface definition for a callback to be invoked when the current group is changed. + */ public interface OnToolbarGroupChangedListener { + /** + * Called when the current group changed. + * @param oldGroupId The id of old group. + * @param groupId The id of new group. + */ public void onToolbarGroupChanged(int oldGroupId, int groupId); } @@ -128,10 +136,17 @@ private void dispatchOnToolbarGroupChanged(int oldGroupId, int groupId){ } } + /** + * @return The current group of the Toolbar. + */ public int getCurrentGroup(){ return mCurrentGroup; } + /** + * Set current group of the Toolbar. + * @param groupId The id of group. + */ public void setCurrentGroup(int groupId){ if(mCurrentGroup != groupId){ int oldGroupId = mCurrentGroup; @@ -204,6 +219,9 @@ public void notifyNavigationStateProgressChanged(boolean isBackState, float prog mNavigationManager.notifyStateProgressChanged(isBackState, progress); } + /** + * @return The navigation is in back state or not. + */ public boolean isNavigationBackState(){ return mNavigationManager != null && mNavigationManager.isBackState(); } @@ -292,10 +310,25 @@ private void animateIn(){ } } + /** + * Interface definition for creating animation of menu item view when switch group. + */ public interface Animator{ + /** + * Get the animation of the menu item view will be removed. + * @param v The menu item view. + * @param position The position of item. + * @return + */ public Animation getOutAnimation(View v, int position); + /** + * Get the animation of the menu item view will be added. + * @param v The menu item view. + * @param position The position of item. + * @return + */ public Animation getInAnimation(View v, int position); } @@ -319,6 +352,9 @@ public Animation getInAnimation(View v, int position) { } } + /** + * Abstract class to manage the state of navigation icon. + */ public static abstract class NavigationManager{ protected NavigationDrawerDrawable mNavigationIcon; diff --git a/lib/src/main/java/com/rey/material/widget/CheckBox.java b/lib/src/main/java/com/rey/material/widget/CheckBox.java index c19075b1..90fa9ea3 100644 --- a/lib/src/main/java/com/rey/material/widget/CheckBox.java +++ b/lib/src/main/java/com/rey/material/widget/CheckBox.java @@ -47,6 +47,10 @@ private void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, i drawable.setAnimEnable(true); } + /** + * Change the checked state of this button immediately without showing animation. + * @param checked The checked state. + */ public void setCheckedImmediately(boolean checked){ if(mButtonDrawable instanceof CheckBoxDrawable){ CheckBoxDrawable drawable = (CheckBoxDrawable)mButtonDrawable; diff --git a/lib/src/main/java/com/rey/material/widget/CircleCheckedTextView.java b/lib/src/main/java/com/rey/material/widget/CircleCheckedTextView.java index 069abac5..0b308506 100644 --- a/lib/src/main/java/com/rey/material/widget/CircleCheckedTextView.java +++ b/lib/src/main/java/com/rey/material/widget/CircleCheckedTextView.java @@ -66,6 +66,10 @@ public void setBackgroundColor(int color) { mBackground.setColor(color); } + /** + * Set the duration of background's animation. + * @param duration The duration + */ public void setAnimDuration(int duration) { mBackground.setAnimDuration(duration); } diff --git a/lib/src/main/java/com/rey/material/widget/DatePicker.java b/lib/src/main/java/com/rey/material/widget/DatePicker.java index 399cb5ff..dccfadda 100644 --- a/lib/src/main/java/com/rey/material/widget/DatePicker.java +++ b/lib/src/main/java/com/rey/material/widget/DatePicker.java @@ -65,7 +65,20 @@ public class DatePicker extends ListView implements AbsListView.OnScrollListener private MonthAdapter mAdapter; + /** + * Interface definition for a callback to be invoked when the selected date is changed. + */ public interface OnDateChangedListener { + + /** + * Called when the selected date is changed. + * @param oldDay The day value of old date. + * @param oldMonth The month value of old date. + * @param oldYear The year value of old date. + * @param newDay The day value of new date. + * @param newMonth The month value of new date. + * @param newYear The year value of new date. + */ public void onDateChanged(int oldDay, int oldMonth, int oldYear, int newDay, int newMonth, int newYear); } @@ -293,10 +306,24 @@ private String getDayText(int day){ return mDayTexts[day - 1]; } + /** + * Set the range of selectable dates. + * @param minDay The day value of minimum date. + * @param minMonth The month value of minimum date. + * @param minYear The year value of minimum date. + * @param maxDay The day value of maximum date. + * @param maxMonth The month value of maximum date. + * @param maxYear The year value of maximum date. + */ public void setDateRange(int minDay, int minMonth, int minYear, int maxDay, int maxMonth, int maxYear){ mAdapter.setDateRange(minDay, minMonth, minYear, maxDay, maxMonth, maxYear); } + /** + * Jump to the view of a specific month. + * @param month + * @param year + */ public void goTo(int month, int year){ int position = mAdapter.positionOfMonth(month, year); postSetSelectionFromTop(position, 0); @@ -312,6 +339,12 @@ public void run() { }); } + /** + * Set the selected date of this DatePicker. + * @param day The day value of selected date. + * @param month The month value of selected date. + * @param year The year value of selected date. + */ public void setDate(int day, int month, int year){ if(mAdapter.getYear() == year && mAdapter.getMonth() == month && mAdapter.getDay() == day) return; @@ -320,22 +353,40 @@ public void setDate(int day, int month, int year){ goTo(month, year); } + /** + * Set the listener will be called when the selected date is changed. + * @param listener The {@link DatePicker.OnDateChangedListener} will be called. + */ public void setOnDateChangedListener(OnDateChangedListener listener){ mOnDateChangedListener = listener; } + /** + * @return The day value of selected date. + */ public int getDay(){ return mAdapter.getDay(); } + /** + * @return The month value of selected date. + */ public int getMonth(){ return mAdapter.getMonth(); } + /** + * @return The year value of selected date. + */ public int getYear(){ return mAdapter.getYear(); } + /** + * Get the formatted string of selected date. + * @param formatter The DateFormat used to format the date. + * @return + */ public String getFormattedDate(DateFormat formatter){ mCalendar.set(Calendar.YEAR, mAdapter.getYear()); mCalendar.set(Calendar.MONTH, mAdapter.getMonth()); diff --git a/lib/src/main/java/com/rey/material/widget/EditText.java b/lib/src/main/java/com/rey/material/widget/EditText.java index 79219eee..a3f1def1 100644 --- a/lib/src/main/java/com/rey/material/widget/EditText.java +++ b/lib/src/main/java/com/rey/material/widget/EditText.java @@ -59,10 +59,22 @@ public class EditText extends FrameLayout { private boolean mLabelVisible; private int mSupportMode; private int mAutoCompleteMode; - + + /** + * Indicate this EditText should not show a support text. + */ public static final int SUPPORT_MODE_NONE = 0; + /** + * Indicate this EditText should show a helper text, or error text if it's set. + */ public static final int SUPPORT_MODE_HELPER = 1; + /** + * Indicate this EditText should show a helper text, along with error text if it's set. + */ public static final int SUPPORT_MODE_HELPER_WITH_ERROR = 2; + /** + * Indicate this EditText should show a char counter text. + */ public static final int SUPPORT_MODE_CHAR_COUNTER = 3; public static final int AUTOCOMPLETE_MODE_NONE = 0; @@ -407,15 +419,26 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { mInputView.layout(childLeft, childTop, childRight, childBottom); } + /** + * Set the helper text of this EditText. Only work with support mode {@link #SUPPORT_MODE_HELPER} and {@link #SUPPORT_MODE_HELPER_WITH_ERROR}. + * @param helper The helper text. + */ public void setHelper(CharSequence helper){ mSupportHelper = helper; setError(mSupportError); } - + + /** + * @return The helper text of this EditText. + */ public CharSequence getHelper(){ return mSupportHelper; } - + + /** + * Set the error text of this EditText. Only work with support mode {@link #SUPPORT_MODE_HELPER} and {@link #SUPPORT_MODE_HELPER_WITH_ERROR}. + * @param error The error text. Set null will clear the error. + */ public void setError(CharSequence error){ mSupportError = error; @@ -433,11 +456,17 @@ public void setError(CharSequence error){ mSupportView.setText(mSupportHelper); } } - + + /** + * @return The error text of this EditText. + */ public CharSequence getError(){ return mSupportError; } - + + /** + * Clear the error text. Only work with support mode {@link #SUPPORT_MODE_HELPER} and {@link #SUPPORT_MODE_HELPER_WITH_ERROR}. + */ public void clearError(){ setError(null); } @@ -611,7 +640,7 @@ protected void performFiltering(CharSequence text, int start, int end, int keyCo *

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}

* * @param hint the text to be displayed to the user * @@ -627,7 +656,7 @@ public void setCompletionHint(CharSequence hint) { /** * Gets the optional hint text displayed at the bottom of the the matching 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 hint text, if any * @@ -645,7 +674,7 @@ public CharSequence getCompletionHint() { *

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}

* * @return the width for the drop down list * @@ -661,7 +690,7 @@ public int getDropDownWidth() { *

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}

* * @param width the width to use * @@ -678,7 +707,7 @@ public void setDropDownWidth(int width) { * 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}

* * @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 @@ public void setAdapter(T adapter) { * or exceeds the {@link #getThreshold} requirement. You can override * this to impose a different standard for when filtering will be * triggered. - *

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 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}, * or null 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. Use null + * 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..821fc862 100644 --- a/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java +++ b/lib/src/main/java/com/rey/material/widget/FloatingActionButton.java @@ -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); 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..00dd3519 100644 --- a/lib/src/main/java/com/rey/material/widget/Slider.java +++ b/lib/src/main/java/com/rey/material/widget/Slider.java @@ -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; } 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..73356cf8 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); } @@ -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) @@ -432,11 +551,19 @@ public void setOnClickListener(OnClickListener l) { setOnClickListener(mRippleManager); } } - + + /** + * 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; } 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..064702d9 100644 --- a/lib/src/main/java/com/rey/material/widget/Switch.java +++ b/lib/src/main/java/com/rey/material/widget/Switch.java @@ -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); } @@ -197,6 +205,10 @@ public void setOnClickListener(OnClickListener l) { } } + /** + * 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 +227,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; 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/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; }