From 28fbad7bdee5633d6c32943c46436cdc34c840fc Mon Sep 17 00:00:00 2001 From: Mark Ormesher Date: Wed, 7 Feb 2018 16:53:15 +0000 Subject: [PATCH 1/3] Add accessor function for underlying views --- .../uk/co/markormesher/android_fab/FloatingActionButton.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt b/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt index d5efb78..914fc81 100644 --- a/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt +++ b/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt @@ -14,6 +14,7 @@ import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.LinearLayout import android.widget.RelativeLayout import kotlinx.android.synthetic.main.fab_container.view.* import kotlinx.android.synthetic.main.floating_action_button.view.* @@ -457,4 +458,10 @@ class FloatingActionButton: RelativeLayout { }) } } + + fun getCardView(): View = fab_card + + fun getContentCoverView(): View = content_cover + + fun getIconWrapper(): LinearLayout = fab_icon_wrapper } From d6a3d390d469b2fac0ce0a9ee83e40280a38872d Mon Sep 17 00:00:00 2001 From: Mark Ormesher Date: Wed, 7 Feb 2018 16:57:49 +0000 Subject: [PATCH 2/3] Kotlin-style getters --- README.md | 34 +++++++++++-------- .../android_fab/FloatingActionButton.kt | 10 ++++-- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7f5ae34..c2da3ce 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ See [app/proguard-rules.pro](app/proguard-rules.pro) for an example. // Java FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); - + // Kotlin (without Android extensions) val fab = findViewById(R.id.fab) as FloatingActionButton @@ -63,17 +63,17 @@ The FAB can be positioned in any of the four corners of the activity via XML or // Java fab.setButtonPosition(POSITION_BOTTOM | POSITION_END); - + // Kotlin fab.setButtonPosition(POSITION_BOTTOM.or(POSITION_END)) - + // XML - + The FAB is aware of text-direction (right-to-left or left-to-right) and adjusts the meaning of "start" and "end" positions accordingly. This functionality can be overridden using the named constants for left and right. ### FAB Icon @@ -82,10 +82,10 @@ The icon displayed in the centre of the FAB can be set via XML using a `Drawable // Java fab.setButtonIconResource(R.drawable.ic_add); - + // Kotlin fab.setButtonIconResource(R.drawable.ic_add) - + // XML // ... @@ -139,7 +139,7 @@ The colour of the content cover can be set programmatically with `fab.setContent // Java fab.setContentCoverColour(0xffff9900); - + // Kotlin fab.setContentCoverColour(0xffff9900.toInt()) @@ -148,7 +148,7 @@ The cover can be enabled/disabled programmatically with `fab.setContentCoverEnab // Java fab.setContentCoverEnabled(true); fab.setContentCoverEnabled(false); - + // Kotlin fab.setContentCoverEnabled(true) fab.setContentCoverEnabled(false) @@ -164,7 +164,7 @@ State change events are fired when the speed-dial menu opens or closes, which ca // ... } }); - + // Kotlin fab.setOnSpeedDialMenuOpenListener { floatingActionButton -> // ... @@ -172,10 +172,16 @@ State change events are fired when the speed-dial menu opens or closes, which ca ### Show/Hide Controls -The FAB can be hidden and shown with the `fab.hide()` and `fab.show()` methods, and the method `fab.isShown()` will return a boolean indicating the current state. These methods animate the FAB in and out of visibility. If the speed-dial menu is open when `.hide()` is called it will be closed. +The FAB can be hidden and shown with the `fab.hide()` and `fab.show()` methods, and the method `fab.isShown()` will return a boolean indicating the current state. These methods animate the FAB in and out of visibility. If the speed-dial menu is open when `.hide()` is called it will be closed. The speed-dial menu can be manually opened and closed with `fab.openSpeedDialMenu()` and `fab.closeSpeedDialMenu()`. These methods will do nothing if no speed-dial menu adapter is set, if an adapter is set but disabled, if the FAB is hidden, or if they are called when the menu is already in the indicated state (i.e. `fab.openSpeedDialMenu()` will do nothing if the menu is already open). +### Access to Underlying Views + +The FAB's key underlying views can be accessed using the three methods detailed below: + + + ### Note: Click Action Priority As per Material Design specs, the FAB functions as a regular button **or** a trigger for the speed-dial menu, but not both. For this reason, the click listener and the speed-dial menu are never invoked at the same time. @@ -183,7 +189,7 @@ As per Material Design specs, the FAB functions as a regular button **or** a tri The speed-dial menu is given priority: when the FAB is clicked the speed-dial menu will be shown if the speed-dial menu adapter is non-null, the adapter's `isEnabled()` function returns `true` and the adapter's `getCount()` returns a number greater than zero. Otherwise, the FAB's click listener will be called (if it has been set). Setting a speed-dial menu adapter does not remove the click listener, and setting a click listener does not remove the speed-dial menu adapter. For an example of how the two operation modes interact, check the demo app's source code. - + To receive state change updates when the speed-dial menu is opened or closed, use the open/close listeners described above. ### Note: State Preservation diff --git a/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt b/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt index 914fc81..42dfef0 100644 --- a/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt +++ b/fab/src/main/kotlin/uk/co/markormesher/android_fab/FloatingActionButton.kt @@ -459,9 +459,13 @@ class FloatingActionButton: RelativeLayout { } } - fun getCardView(): View = fab_card + val cardView: View + get() = fab_card - fun getContentCoverView(): View = content_cover + val contentCoverView: View + get() = content_cover + + val iconWrapper: LinearLayout + get() = fab_icon_wrapper - fun getIconWrapper(): LinearLayout = fab_icon_wrapper } From 40486b97ad94b9ca72dc6c67269b8df2b3fbc8e2 Mon Sep 17 00:00:00 2001 From: Mark Ormesher Date: Wed, 7 Feb 2018 17:03:13 +0000 Subject: [PATCH 3/3] Update docs --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c2da3ce..1e6d96e 100644 --- a/README.md +++ b/README.md @@ -178,9 +178,21 @@ The speed-dial menu can be manually opened and closed with `fab.openSpeedDialMen ### Access to Underlying Views -The FAB's key underlying views can be accessed using the three methods detailed below: +The FAB's key underlying views can be accessed using the three properties/methods detailed below: + // Java + fab.getCardView() // the card behind the button itself + fab.getContentCoverView() // the view that obscures content behind the speed-dial menu + fab.getIconWrapper() // the wrapper used to place icons in the button + + // Kotlin + fab.cardView + fab.contentCoverView + fab.iconWrapper + +The card view is implemented as a `CardView` on SDK 21+ and a `LinearLayout` on SDK 20 and below. +The content cover view and icon wrapper are implemented as a `View` and `LinearLayout` respectively on all SDKs. ### Note: Click Action Priority