3333import java .io .Serializable ;
3434import java .util .regex .Pattern ;
3535
36+ /**
37+ * BootstrapButtons are buttons which provide contextual menus, styled with BootstrapBrand colors,
38+ * roundable corners, and an 'outlineable' mode.
39+ */
3640public class BootstrapDropDown extends AwesomeTextView implements View .OnClickListener , RoundableView , OutlineableView , PopupWindow .OnDismissListener {
3741
3842 private static final String TAG = "com.beardedhen.androidbootstrap.BootstrapDropDown" ;
@@ -99,7 +103,8 @@ private void initialise(AttributeSet attrs) {
99103 dropdownData = getContext ().getResources ().getStringArray (dataOrdinal );
100104 bootstrapSize = DefaultBootstrapSize .fromAttributeValue (sizeOrdinal ).scaleFactor ();
101105 itemHeight = a .getDimensionPixelSize (R .styleable .BootstrapDropDown_itemHeight , (int ) DimenUtils .pixelsFromDpResource (getContext (), R .dimen .bootstrap_dropdown_default_item_height ));
102- } finally {
106+ }
107+ finally {
103108 a .recycle ();
104109 }
105110
@@ -134,8 +139,9 @@ private void createDropDown() {
134139
135140 if (longestStringWidth < getMeasuredWidth ()) {
136141 dropdownWindow .setWidth (DimenUtils .dpToPixels (getMeasuredWidth ()));
137- } else {
138- dropdownWindow .setWidth ((int )longestStringWidth + DimenUtils .dpToPixels (8 ));
142+ }
143+ else {
144+ dropdownWindow .setWidth ((int ) longestStringWidth + DimenUtils .dpToPixels (8 ));
139145 }
140146 }
141147
@@ -163,8 +169,9 @@ private ScrollView createDropDownView() {
163169 @ Override
164170 public void onClick (View v ) {
165171 dropdownWindow .dismiss ();
166- if (onDropDownItemClickListener != null )
172+ if (onDropDownItemClickListener != null ) {
167173 onDropDownItemClickListener .onItemClick (dropdownView , v , v .getId ());
174+ }
168175 }
169176 });
170177
@@ -173,15 +180,18 @@ public void onClick(View v) {
173180 childView .setTextSize ((baselineDropDownViewFontSize - 2F ) * bootstrapSize );
174181 childView .setClickable (false );
175182 childView .setTextColor (getResources ().getColor (R .color .bootstrap_gray_light ));
176- } else if (Pattern .matches (SEARCH_REGEX_SEPARATOR , text )) {
183+ }
184+ else if (Pattern .matches (SEARCH_REGEX_SEPARATOR , text )) {
177185 childView = new DividerView (getContext ());
178186 childView .setClickable (false );
179187 childView .setLayoutParams (new LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , 3 ));
180- } else if (Pattern .matches (SEARCH_REGEX_DISABLED , text )) {
188+ }
189+ else if (Pattern .matches (SEARCH_REGEX_DISABLED , text )) {
181190 childView .setEnabled (false );
182191 childView .setId (clickableChildCounter ++);
183192 childView .setText (text .replaceFirst (REPLACE_REGEX_DISABLED , "" ));
184- } else {
193+ }
194+ else {
185195 childView .setText (text );
186196 childView .setId (clickableChildCounter ++);
187197 }
@@ -217,7 +227,7 @@ private void updateDropDownState() {
217227
218228 setCompoundDrawablesWithIntrinsicBounds (null , null ,
219229 BootstrapDrawableFactory .bootstrapDropDownArrow (getContext (),
220- DimenUtils .dpToPixels (8 *bootstrapSize ),
230+ DimenUtils .dpToPixels (8 * bootstrapSize ),
221231 DimenUtils .dpToPixels (12 * bootstrapSize ),
222232 expandDirection ,
223233 showOutline ,
@@ -240,7 +250,8 @@ private void updateDropDownState() {
240250
241251 if (Build .VERSION .SDK_INT >= 16 ) {
242252 setBackground (bg );
243- } else {
253+ }
254+ else {
244255 setBackgroundDrawable (bg );
245256 }
246257
@@ -290,6 +301,11 @@ private void cleanData() {
290301 dropdownData = cleanArray ;
291302 }
292303
304+ /**
305+ * Sets a listener which will be called when an item is clicked in the dropdown.
306+ *
307+ * @param onDropDownItemClickListener the listener
308+ */
293309 public void setOnDropDownItemClickListener (OnDropDownItemClickListener onDropDownItemClickListener ) {
294310 this .onDropDownItemClickListener = onDropDownItemClickListener ;
295311 }
@@ -302,10 +318,20 @@ public void setOnDropDownItemClickListener(OnDropDownItemClickListener onDropDow
302318 return roundedCorners ;
303319 }
304320
321+ /**
322+ * Gets the direction in which the dropdown expands.
323+ *
324+ * @return the direction
325+ */
305326 public ExpandDirection getExpandDirection () {
306327 return expandDirection ;
307328 }
308329
330+ /**
331+ * Retrieves the data used to populate the dropdown.
332+ *
333+ * @return a string array of values
334+ */
309335 public String [] getDropdownData () {
310336 return dropdownData ;
311337 }
@@ -320,11 +346,21 @@ public String[] getDropdownData() {
320346 updateDropDownState ();
321347 }
322348
349+ /**
350+ * Sets the direction in which the dropdown should expand.
351+ *
352+ * @param expandDirection the direction
353+ */
323354 public void setExpandDirection (ExpandDirection expandDirection ) {
324355 this .expandDirection = expandDirection ;
325356 updateDropDownState ();
326357 }
327358
359+ /**
360+ * Sets the String values which should be used to populate the menu displayed in the dropdown.
361+ *
362+ * @param dropdownData an array of string values.
363+ */
328364 public void setDropdownData (String [] dropdownData ) {
329365 this .dropdownData = dropdownData ;
330366 createDropDown ();
@@ -337,17 +373,20 @@ public void setDropdownData(String[] dropdownData) {
337373 }
338374
339375 @ Override public void onClick (View v ) {
340- if (clickListener != null ) clickListener .onClick (v );
376+ if (clickListener != null ) {
377+ clickListener .onClick (v );
378+ }
341379 //using 8dip on axisX offset to make dropdown view visually be at start of dropdown itself
342380 //using 4dip on axisY offset to make space between dropdown view and dropdown itself
343381 //all offsets are necessary because of the dialog_holo_light_frame to display correctly on screen(shadow was made by inset)
344382 int gravity ;
345383 int axisXOffset ;
346384 if (dropDownViewWidth + getX () > screenWidth ) {
347- gravity = Gravity .TOP | Gravity .RIGHT ;
385+ gravity = Gravity .TOP | Gravity .RIGHT ;
348386 axisXOffset = DimenUtils .dpToPixels (8 );
349- } else {
350- gravity = Gravity .TOP |Gravity .LEFT ;
387+ }
388+ else {
389+ gravity = Gravity .TOP | Gravity .LEFT ;
351390 axisXOffset = -DimenUtils .dpToPixels (8 );
352391 }
353392 int axisYOffset = DimenUtils .dpToPixels (4 );
@@ -401,22 +440,33 @@ public void setDropdownData(String[] dropdownData) {
401440 this .clickListener = clickListener ;
402441 }
403442
443+ /**
444+ * A listener which provides methods relating to {@link BootstrapDropDown}
445+ */
404446 public interface OnDropDownItemClickListener {
447+
448+ /**
449+ * Called when an item is clicked in a {@link BootstrapDropDown}
450+ *
451+ * @param parent the parent viewgroup
452+ * @param v the view
453+ * @param id the id
454+ */
405455 void onItemClick (ViewGroup parent , View v , int id );
406456 }
407457
408- private class DividerView extends TextView {
458+ private static class DividerView extends TextView {
409459
410- private Paint mPaint ;
460+ private final Paint paint ;
411461
412462 public DividerView (Context context ) {
413463 super (context );
414- mPaint = new Paint ();
415- mPaint .setColor (getResources ().getColor (R .color .bootstrap_dropdown_divider ));
464+ paint = new Paint ();
465+ paint .setColor (getResources ().getColor (R .color .bootstrap_dropdown_divider ));
416466 }
417467
418468 @ Override protected void onDraw (Canvas canvas ) {
419- canvas .drawLine (0 , 1 , canvas .getWidth (), 1 , mPaint );
469+ canvas .drawLine (0 , 1 , canvas .getWidth (), 1 , paint );
420470 super .onDraw (canvas );
421471 }
422472 }
0 commit comments