From d70f4cc8cd62f6b1e11727a91f40e71627e9cef0 Mon Sep 17 00:00:00 2001 From: Davide Ricci Date: Thu, 1 Feb 2018 16:54:09 +0100 Subject: [PATCH 1/3] Modified gradle: project didn't work properly without these modification --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/build.gradle | 1 - sample/build.gradle | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 04527318..a2bf2649 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.0' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c823c582..5867f486 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Nov 27 11:18:21 CET 2014 +#Thu Feb 01 15:58:50 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/library/build.gradle b/library/build.gradle index 8dcb7025..7a1bd006 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.library' android { compileSdkVersion 22 - buildToolsVersion "22.0.1" defaultConfig { minSdkVersion 14 diff --git a/sample/build.gradle b/sample/build.gradle index 0582f22b..091df605 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.application' android { compileSdkVersion 22 - buildToolsVersion "22.0.1" defaultConfig { applicationId "com.getbase.floatingactionbutton.sample" From 4a207dd8af2b6dc083a518caed7ce459e35491d9 Mon Sep 17 00:00:00 2001 From: Davide Ricci Date: Thu, 1 Feb 2018 17:19:10 +0100 Subject: [PATCH 2/3] Added new custom attr to avoid rotation and setting custom drawable --- .../AddFloatingActionButton.java | 42 +++++++++++-------- .../FloatingActionButton.java | 4 +- .../FloatingActionsMenu.java | 30 ++++++++----- library/src/main/res/values/attrs.xml | 3 ++ sample/src/main/res/drawable/ic_search.xml | 11 +++++ sample/src/main/res/layout/activity_main.xml | 5 ++- sample/src/main/res/values/colors.xml | 2 + 7 files changed, 66 insertions(+), 31 deletions(-) create mode 100644 sample/src/main/res/drawable/ic_search.xml diff --git a/library/src/main/java/com/getbase/floatingactionbutton/AddFloatingActionButton.java b/library/src/main/java/com/getbase/floatingactionbutton/AddFloatingActionButton.java index 42f9787b..9e3aa153 100644 --- a/library/src/main/java/com/getbase/floatingactionbutton/AddFloatingActionButton.java +++ b/library/src/main/java/com/getbase/floatingactionbutton/AddFloatingActionButton.java @@ -14,6 +14,7 @@ public class AddFloatingActionButton extends FloatingActionButton { int mPlusColor; + Drawable mCustomDrawable; public AddFloatingActionButton(Context context) { this(context, null); @@ -61,28 +62,33 @@ public void setIcon(@DrawableRes int icon) { @Override Drawable getIconDrawable() { - final float iconSize = getDimension(R.dimen.fab_icon_size); - final float iconHalfSize = iconSize / 2f; - final float plusSize = getDimension(R.dimen.fab_plus_icon_size); - final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f; - final float plusOffset = (iconSize - plusSize) / 2f; + if (mCustomDrawable == null) { + final float iconSize = getDimension(R.dimen.fab_icon_size); + final float iconHalfSize = iconSize / 2f; - final Shape shape = new Shape() { - @Override - public void draw(Canvas canvas, Paint paint) { - canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint); - canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint); - } - }; + final float plusSize = getDimension(R.dimen.fab_plus_icon_size); + final float plusHalfStroke = getDimension(R.dimen.fab_plus_icon_stroke) / 2f; + final float plusOffset = (iconSize - plusSize) / 2f; - ShapeDrawable drawable = new ShapeDrawable(shape); + final Shape shape = new Shape() { + @Override + public void draw(Canvas canvas, Paint paint) { + canvas.drawRect(plusOffset, iconHalfSize - plusHalfStroke, iconSize - plusOffset, iconHalfSize + plusHalfStroke, paint); + canvas.drawRect(iconHalfSize - plusHalfStroke, plusOffset, iconHalfSize + plusHalfStroke, iconSize - plusOffset, paint); + } + }; - final Paint paint = drawable.getPaint(); - paint.setColor(mPlusColor); - paint.setStyle(Style.FILL); - paint.setAntiAlias(true); + ShapeDrawable drawable = new ShapeDrawable(shape); - return drawable; + final Paint paint = drawable.getPaint(); + paint.setColor(mPlusColor); + paint.setStyle(Style.FILL); + paint.setAntiAlias(true); + + return drawable; + } else { + return mCustomDrawable; + } } } diff --git a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java index b83285d7..2e63544d 100644 --- a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java +++ b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java @@ -55,6 +55,7 @@ public class FloatingActionButton extends ImageButton { private float mShadowRadius; private float mShadowOffset; private int mDrawableSize; + private boolean mIconVisible; boolean mStrokeVisible; public FloatingActionButton(Context context) { @@ -80,6 +81,7 @@ void init(Context context, AttributeSet attributeSet) { mIcon = attr.getResourceId(R.styleable.FloatingActionButton_fab_icon, 0); mTitle = attr.getString(R.styleable.FloatingActionButton_fab_title); mStrokeVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_stroke_visible, true); + mIconVisible = attr.getBoolean(R.styleable.FloatingActionButton_fab_icon_visible, true); attr.recycle(); updateCircleSize(); @@ -305,7 +307,7 @@ private Drawable createCircleDrawable(int color, float strokeWidth) { int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); - + return drawable; } diff --git a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionsMenu.java b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionsMenu.java index b5ae2c20..3e3a8162 100644 --- a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionsMenu.java +++ b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionsMenu.java @@ -60,6 +60,9 @@ public class FloatingActionsMenu extends ViewGroup { private int mLabelsPosition; private int mButtonsCount; + private Drawable customFloatingButtonIcon; + private boolean disableDrawableRotation; + private TouchDelegateGroup mTouchDelegateGroup; private OnFloatingActionsMenuUpdateListener mListener; @@ -100,6 +103,8 @@ private void init(Context context, AttributeSet attributeSet) { mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP); mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0); mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE); + customFloatingButtonIcon = attr.getDrawable(R.styleable.FloatingActionsMenu_fab_addButtonCustomDrawableIcon); + disableDrawableRotation = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_buttonDrawableDisableRotation, false); attr.recycle(); if (mLabelsStyle != 0 && expandsHorizontally()) { @@ -152,26 +157,31 @@ void updateBackground() { mColorNormal = mAddButtonColorNormal; mColorPressed = mAddButtonColorPressed; mStrokeVisible = mAddButtonStrokeVisible; + mCustomDrawable = customFloatingButtonIcon; super.updateBackground(); } @Override Drawable getIconDrawable() { - final RotatingDrawable rotatingDrawable = new RotatingDrawable(super.getIconDrawable()); - mRotatingDrawable = rotatingDrawable; + if (disableDrawableRotation) { + return super.getIconDrawable(); + } else { + final RotatingDrawable rotatingDrawable = new RotatingDrawable(super.getIconDrawable()); + mRotatingDrawable = rotatingDrawable; - final OvershootInterpolator interpolator = new OvershootInterpolator(); + final OvershootInterpolator interpolator = new OvershootInterpolator(); - final ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", EXPANDED_PLUS_ROTATION, COLLAPSED_PLUS_ROTATION); - final ObjectAnimator expandAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", COLLAPSED_PLUS_ROTATION, EXPANDED_PLUS_ROTATION); + final ObjectAnimator collapseAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", EXPANDED_PLUS_ROTATION, COLLAPSED_PLUS_ROTATION); + final ObjectAnimator expandAnimator = ObjectAnimator.ofFloat(rotatingDrawable, "rotation", COLLAPSED_PLUS_ROTATION, EXPANDED_PLUS_ROTATION); - collapseAnimator.setInterpolator(interpolator); - expandAnimator.setInterpolator(interpolator); + collapseAnimator.setInterpolator(interpolator); + expandAnimator.setInterpolator(interpolator); - mExpandAnimation.play(expandAnimator); - mCollapseAnimation.play(collapseAnimator); + mExpandAnimation.play(expandAnimator); + mCollapseAnimation.play(collapseAnimator); - return rotatingDrawable; + return rotatingDrawable; + } } }; diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index b9eaaf55..29528fc4 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -11,6 +11,7 @@ + @@ -22,6 +23,8 @@ + + diff --git a/sample/src/main/res/drawable/ic_search.xml b/sample/src/main/res/drawable/ic_search.xml new file mode 100644 index 00000000..95807aeb --- /dev/null +++ b/sample/src/main/res/drawable/ic_search.xml @@ -0,0 +1,11 @@ + + + diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 3df473e3..07c76d68 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -97,10 +97,11 @@ android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" - fab:fab_addButtonColorNormal="@color/white" + fab:fab_addButtonColorNormal="@color/headerColor" + fab:fab_buttonDrawableDisableRotation="true" fab:fab_addButtonColorPressed="@color/white_pressed" - fab:fab_addButtonPlusIconColor="@color/half_black" fab:fab_labelStyle="@style/menu_labels_style" + fab:fab_addButtonCustomDrawableIcon="@drawable/ic_search" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" android:layout_marginEnd="16dp"> diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml index ff0e9df5..01f5b1d0 100644 --- a/sample/src/main/res/values/colors.xml +++ b/sample/src/main/res/values/colors.xml @@ -9,4 +9,6 @@ #ec407a #805677fc #80738ffe + + #00B6AF From cc4b973d668feb45f2abdb0e7840f0b3fa4c5ecf Mon Sep 17 00:00:00 2001 From: Davide Ricci Date: Fri, 2 Feb 2018 14:01:54 +0100 Subject: [PATCH 3/3] Added control to remove button circle from menu --- .../FloatingActionButton.java | 81 ++++++++++--------- sample/src/main/res/layout/activity_main.xml | 8 +- 2 files changed, 50 insertions(+), 39 deletions(-) diff --git a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java index 2e63544d..b60919d0 100644 --- a/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java +++ b/library/src/main/java/com/getbase/floatingactionbutton/FloatingActionButton.java @@ -55,9 +55,13 @@ public class FloatingActionButton extends ImageButton { private float mShadowRadius; private float mShadowOffset; private int mDrawableSize; - private boolean mIconVisible; + boolean mIconVisible; boolean mStrokeVisible; + public boolean ismIconVisible() { + return mIconVisible; + } + public FloatingActionButton(Context context) { this(context, null); } @@ -93,7 +97,7 @@ void init(Context context, AttributeSet attributeSet) { } private void updateDrawableSize() { - mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius); + mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius); } private void updateCircleSize() { @@ -233,39 +237,43 @@ void updateBackground() { final float strokeWidth = getDimension(R.dimen.fab_stroke_width); final float halfStrokeWidth = strokeWidth / 2f; - LayerDrawable layerDrawable = new LayerDrawable( - new Drawable[] { - getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), - createFillDrawable(strokeWidth), - createOuterStrokeDrawable(strokeWidth), - getIconDrawable() - }); - - int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2; - - int circleInsetHorizontal = (int) (mShadowRadius); - int circleInsetTop = (int) (mShadowRadius - mShadowOffset); - int circleInsetBottom = (int) (mShadowRadius + mShadowOffset); - - layerDrawable.setLayerInset(1, - circleInsetHorizontal, - circleInsetTop, - circleInsetHorizontal, - circleInsetBottom); - - layerDrawable.setLayerInset(2, - (int) (circleInsetHorizontal - halfStrokeWidth), - (int) (circleInsetTop - halfStrokeWidth), - (int) (circleInsetHorizontal - halfStrokeWidth), - (int) (circleInsetBottom - halfStrokeWidth)); - - layerDrawable.setLayerInset(3, - circleInsetHorizontal + iconOffset, - circleInsetTop + iconOffset, - circleInsetHorizontal + iconOffset, - circleInsetBottom + iconOffset); - - setBackgroundCompat(layerDrawable); + if (mIconVisible) { + LayerDrawable layerDrawable = new LayerDrawable( + new Drawable[]{ + getResources().getDrawable(mSize == SIZE_NORMAL ? R.drawable.fab_bg_normal : R.drawable.fab_bg_mini), + createFillDrawable(strokeWidth), + createOuterStrokeDrawable(strokeWidth), + getIconDrawable() + }); + + int iconOffset = (int) (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2; + + int circleInsetHorizontal = (int) (mShadowRadius); + int circleInsetTop = (int) (mShadowRadius - mShadowOffset); + int circleInsetBottom = (int) (mShadowRadius + mShadowOffset); + + layerDrawable.setLayerInset(1, + circleInsetHorizontal, + circleInsetTop, + circleInsetHorizontal, + circleInsetBottom); + + layerDrawable.setLayerInset(2, + (int) (circleInsetHorizontal - halfStrokeWidth), + (int) (circleInsetTop - halfStrokeWidth), + (int) (circleInsetHorizontal - halfStrokeWidth), + (int) (circleInsetBottom - halfStrokeWidth)); + + layerDrawable.setLayerInset(3, + circleInsetHorizontal + iconOffset, + circleInsetTop + iconOffset, + circleInsetHorizontal + iconOffset, + circleInsetBottom + iconOffset); + + setBackgroundCompat(layerDrawable); + } else { + setBackgroundCompat(new LayerDrawable(new Drawable[]{})); + } } Drawable getIconDrawable() { @@ -307,7 +315,8 @@ private Drawable createCircleDrawable(int color, float strokeWidth) { int halfStrokeWidth = (int) (strokeWidth / 2f); drawable.setLayerInset(1, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth, halfStrokeWidth); - + + return drawable; } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 07c76d68..947419a7 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -98,10 +98,10 @@ android:layout_alignParentRight="true" android:layout_alignParentEnd="true" fab:fab_addButtonColorNormal="@color/headerColor" - fab:fab_buttonDrawableDisableRotation="true" fab:fab_addButtonColorPressed="@color/white_pressed" fab:fab_labelStyle="@style/menu_labels_style" fab:fab_addButtonCustomDrawableIcon="@drawable/ic_search" + fab:fab_buttonDrawableDisableRotation="true" android:layout_marginBottom="16dp" android:layout_marginRight="16dp" android:layout_marginEnd="16dp"> @@ -110,7 +110,8 @@ android:id="@+id/action_a" android:layout_width="wrap_content" android:layout_height="wrap_content" - fab:fab_colorNormal="@color/white" + fab:fab_stroke_visible="false" + fab:fab_icon_visible="false" fab:fab_title="Action A" fab:fab_colorPressed="@color/white_pressed"/> @@ -118,7 +119,8 @@ android:id="@+id/action_b" android:layout_width="wrap_content" android:layout_height="wrap_content" - fab:fab_colorNormal="@color/white" + fab:fab_stroke_visible="false" + fab:fab_icon_visible="false" fab:fab_title="Action with a very long name that won\'t fit on the screen" fab:fab_colorPressed="@color/white_pressed"/>