4040import android .support .annotation .NonNull ;
4141import android .support .design .widget .CoordinatorLayout ;
4242import android .support .design .widget .FloatingActionButton ;
43+ import android .support .graphics .drawable .VectorDrawableCompat ;
4344import android .support .v4 .content .ContextCompat ;
4445import android .support .v7 .widget .RecyclerView ;
4546import android .util .AttributeSet ;
@@ -67,6 +68,7 @@ public class FABsMenu extends ViewGroup {
6768 public static final int EXPAND_RIGHT = 3 ;
6869 public static final int LABELS_ON_LEFT_SIDE = 0 ;
6970 public static final int LABELS_ON_RIGHT_SIDE = 1 ;
71+ private static final String TAG = FABsMenu .class .getSimpleName ();
7072 private static final float COLLAPSED_PLUS_ROTATION = 0f ;
7173 private static final float EXPANDED_PLUS_ROTATION = 90f + 45f ;
7274 private static Interpolator expandInterpolator = new OvershootInterpolator ();
@@ -115,17 +117,16 @@ public FABsMenu(Context context, AttributeSet attrs, int defStyle) {
115117 }
116118
117119 private void init (Context context , AttributeSet attributeSet ) {
118- try {
119- buttonSpacing = (int ) DimensionUtils .convertDpToPixel (16 , context );
120- labelsMargin = getResources ().getDimensionPixelSize (R .dimen .fab_labels_margin );
121- labelsVerticalOffset = (int ) DimensionUtils .convertDpToPixel (-1.5f , context );
122-
123- touchDelegateGroup = new TouchDelegateGroup (this );
124- setTouchDelegate (touchDelegateGroup );
120+ buttonSpacing = (int ) DimensionUtils .convertDpToPixel (16 , context );
121+ labelsMargin = getResources ().getDimensionPixelSize (R .dimen .fab_labels_margin );
122+ labelsVerticalOffset = (int ) DimensionUtils .convertDpToPixel (-1.5f , context );
125123
126- TypedArray attr = context . obtainStyledAttributes ( attributeSet , R . styleable . FABsMenu ,
127- 0 , 0 );
124+ touchDelegateGroup = new TouchDelegateGroup ( this );
125+ setTouchDelegate ( touchDelegateGroup );
128126
127+ TypedArray attr = context .obtainStyledAttributes (attributeSet , R .styleable .FABsMenu ,
128+ 0 , 0 );
129+ try {
129130 menuMargins = attr .getDimensionPixelSize (R .styleable .FABsMenu_fab_menuMargins , 0 );
130131
131132 menuTopMargin = attr .getDimensionPixelSize (R .styleable .FABsMenu_fab_menuTopMargin ,
@@ -152,7 +153,10 @@ private void init(Context context, AttributeSet attributeSet) {
152153 : (int ) DimensionUtils
153154 .convertDpToPixel (16 , context ));
154155
155- menuButtonIcon = attr .getDrawable (R .styleable .FABsMenu_fab_moreButtonPlusIcon );
156+ int drawableId = attr .getResourceId (R .styleable .FABsMenu_fab_moreButtonPlusIcon , 0 );
157+ if (drawableId != 0 ){
158+ menuButtonIcon = VectorDrawableCompat .create (getResources (), drawableId , context .getTheme ());
159+ }
156160
157161 menuButtonColor = attr .getColor (R .styleable .FABsMenu_fab_moreButtonBackgroundColor ,
158162 getColor (android .R .color .holo_blue_dark ));
@@ -165,18 +169,20 @@ private void init(Context context, AttributeSet attributeSet) {
165169 expandDirection = attr .getInt (R .styleable .FABsMenu_fab_expandDirection , EXPAND_UP );
166170
167171 labelsPosition = attr .getInt (R .styleable .FABsMenu_fab_labelsPosition ,
168- isRtl () ? LABELS_ON_RIGHT_SIDE : LABELS_ON_LEFT_SIDE );
172+ isRtl () ? LABELS_ON_RIGHT_SIDE : LABELS_ON_LEFT_SIDE );
169173
170- attr .recycle ();
171174
172- if (menuListener == null ) {
173- setMenuListener (new FABsMenuListener () {
174- });
175- }
176- createMenuButton (context );
177175 } catch (Exception e ) {
178- e .printStackTrace ();
176+ Log .w (TAG , "Failure reading attributes" , e );
177+ } finally {
178+ attr .recycle ();
179+ }
180+
181+ if (menuListener == null ) {
182+ setMenuListener (new FABsMenuListener () {
183+ });
179184 }
185+ createMenuButton (context );
180186 }
181187
182188 private boolean expandsHorizontally () {
@@ -235,15 +241,15 @@ public void addAllButtons(TitleFAB... buttons) throws IllegalArgumentException {
235241 public void addButton (TitleFAB button , int index ) throws IllegalArgumentException {
236242 if (buttonsCount >= 6 )
237243 throw new IllegalArgumentException ("A floating action buttons menu should have no " +
238- "more than six options." );
244+ "more than six options." );
239245 addView (button , index );
240246 buttonsCount += 1 ;
241247 createLabels ();
242248 if (buttonsCount > 1 && getVisibility () != View .VISIBLE ) {
243249 show (false );
244250 }
245251 if (buttonsCount < 3 )
246- Log .w ("FABsMenu" , "A floating action buttons menu should have at least three options" );
252+ Log .w (TAG , "A floating action buttons menu should have at least three options" );
247253 }
248254
249255 public void addButton (TitleFAB button ) throws IllegalArgumentException {
@@ -284,7 +290,7 @@ public void removeButton(TitleFAB button) {
284290 buttonsCount -= 1 ;
285291 if (buttonsCount <= 1 ) hide ();
286292 } catch (Exception e ) {
287- e . printStackTrace ( );
293+ Log . e ( TAG , "Failure removing Button" , e );
288294 }
289295 }
290296
@@ -896,7 +902,7 @@ public void setMenuButtonIcon(@NonNull Uri uri) {
896902 Drawable icon = Drawable .createFromStream (inputStream , uri .toString ());
897903 if (icon != null ) setMenuButtonIcon (icon );
898904 } catch (Exception e ) {
899- e . printStackTrace ( );
905+ Log . e ( TAG , "Failure setting MenuButton icon" , e );
900906 }
901907 }
902908
@@ -907,7 +913,7 @@ public void setMenuButtonIcon(@DrawableRes int resId) {
907913 else throw new NullPointerException (
908914 "The icon you try to assign to FABsMenu does not exist" );
909915 } catch (Exception e ) {
910- e . printStackTrace ( );
916+ Log . e ( TAG , "Failure setting MenuButton icon" , e );
911917 }
912918 }
913919
@@ -993,7 +999,7 @@ public void setMenuButtonIcon(@NonNull Bitmap bitmap) {
993999 try {
9941000 setMenuButtonIcon (new BitmapDrawable (getResources (), bitmap ));
9951001 } catch (Exception e ) {
996- e . printStackTrace ( );
1002+ Log . e ( TAG , "Failure setting MenuButton icon" , e );
9971003 }
9981004 }
9991005
@@ -1158,4 +1164,4 @@ public void onAnimationStart(Animator animation) {
11581164 });
11591165 }
11601166 }
1161- }
1167+ }
0 commit comments