Skip to content

Commit

Permalink
Merge branch 'release-2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
markormesher committed Feb 7, 2018
2 parents 96910c6 + d74cd21 commit dcb3d68
Show file tree
Hide file tree
Showing 5 changed files with 11,048 additions and 21 deletions.
48 changes: 33 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
<uk.co.markormesher.android_fab.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
...
app:buttonPosition="bottom|end"
/>

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
Expand All @@ -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
<uk.co.markormesher.android_fab.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
Expand All @@ -99,10 +99,10 @@ The background colour of the FAB can be set via XML using a colour reference or

// Java
fab.setButtonBackgroundColour(0xffff9900);

// Kotlin
fab.setButtonBackgroundColour(0xffff9900.toInt())

// XML
<uk.co.markormesher.android_fab.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
Expand All @@ -121,15 +121,15 @@ A click listener can be added to the FAB in the same way as any other button. Th
// ...
}
});

// Kotlin
fab.setOnClickListener { v ->
// ...
}

### Speed-Dial Menu

The speed-dial menu is enabled by creating a class that extends `SpeedDialMenuAdapter` and passing it to `fab.setSpeedDialMenuAdapter(...)`. The adapter class methods are [documented in-situ](fab/src/main/java/uk/co/markormesher/android_fab/SpeedDialMenuAdapter.kt).
The speed-dial menu is enabled by creating a class that extends `SpeedDialMenuAdapter` and passing it to `fab.setSpeedDialMenuAdapter(...)`. The adapter class methods are [documented in-situ](fab/src/main/kotlin/uk/co/markormesher/android_fab/SpeedDialMenuAdapter.kt).

### Speed-Dial Menu Content Cover

Expand All @@ -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())

Expand All @@ -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)
Expand All @@ -164,26 +164,44 @@ State change events are fired when the speed-dial menu opens or closes, which ca
// ...
}
});

// Kotlin
fab.setOnSpeedDialMenuOpenListener { floatingActionButton ->
// ...
}

### 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 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

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.

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
Expand Down
4 changes: 0 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ android {
}

debug {
// signing
//noinspection GroovyAssignabilityCheck
signingConfig signingConfigs.main

// minify
minifyEnabled false

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static def getSecrets() {
@SuppressWarnings("GroovyUnusedDeclaration")
static def getProps() {
Properties properties = new Properties()
properties['version_code'] = 14
properties['version_name'] = '2.0.0'
properties['version_code'] = 15
properties['version_name'] = '2.1.0'
return properties
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -259,7 +260,16 @@ class FloatingActionButton: RelativeLayout {
}
}

@Deprecated(
"This method name is incorrect and is kept only for backwards compatibility",
ReplaceWith("setOnSpeedDialMenuOpenListener"),
DeprecationLevel.WARNING
)
fun setOnSpeedMenuDialOpenListener(listener: SpeedDialMenuOpenListener) {
setOnSpeedDialMenuOpenListener(listener)
}

fun setOnSpeedDialMenuOpenListener(listener: SpeedDialMenuOpenListener) {
speedDialMenuOpenListener = listener
}

Expand Down Expand Up @@ -457,4 +467,14 @@ class FloatingActionButton: RelativeLayout {
})
}
}

val cardView: View
get() = fab_card

val contentCoverView: View
get() = content_cover

val iconWrapper: LinearLayout
get() = fab_icon_wrapper

}
Loading

0 comments on commit dcb3d68

Please sign in to comment.