GithubHelp home page GithubHelp logo

android-fab's Introduction

Floating Action Button with Speed-Dial Menu

Download

This library provides a clickable floating action button (FAB) with an optional speed-dial menu. The FAB can trigger a standard click listener or a open the speed-dial menu with further options. All aspects of the FAB and speed-dial menu are customisable.

Demo

Demonstration of the speed-dial menu

You can try the demo in one of two ways:

  1. Clone this repository and install the demo app from the app/ folder (you can do this with Gradle, using gradle clean installDebug).

  2. Download the sample app from the Google Play Store: Floating Action Button Demo.

Installation

Gradle

implementation 'uk.co.markormesher:android-fab:2.5.0'

Maven

<dependency>
	<groupId>uk.co.markormesher</groupId>
	<artifactId>android-fab</artifactId>
	<version>2.5.0</version>
	<type>pom</type>
</dependency>

Note: depending on your app's configuration, you may need to add the following to your ProGuard rules:

-dontwarn java.lang.invoke.*

See app/proguard-rules.pro for an example.

Usage & Customisation

Note: all of the instructions below assume that the FAB is referenced by the variable fab, i.e.

// Java
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

// Kotlin (without Android extensions)
val fab = findViewById(R.id.fab) as FloatingActionButton

Placing the FAB in Your Layout

The FloatingActionButton view must be placed at the root of your layout, above all other views, and with maximum width and height. This allows the semi-transparent layer to expand and cover the entire layout when the speed-dial menu is opened.

<uk.co.markormesher.android_fab.FloatingActionButton
	android:id="@+id/fab"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	/>

FAB Position

The FAB can be positioned in any of the four corners of the activity via XML or with fab.setButtonPosition(...). The default position is the bottom-end corner.

// 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.

The FAB can be offset from any of the four edges to precisely control its location, although this is not needed in most applications. The offset can be added to the top, bottom, start, end, left or right of the view. Where left and/or right offsets are specified they will both take precedence over start/end offsets.

// Java
fab.setInternalOffsetBottom(40.0f); // pixels

// Kotlin
fab.setInternalOffsetBottom(40.0f) // pixels

// XML
<uk.co.markormesher.android_fab.FloatingActionButton
	xmlns:app="http://schemas.android.com/apk/res-auto"
	...
	app:internalOffsetBottom="20dp"
	app:internalOffsetEnd="@dimen/some_dimen"
	/>

Note: any offset is applied in addition to the default spacing around the FAB. If you need to counter this, subtract the default spacing (fab.getOriginalInternalOffset() in Java or fab.originalInternalOffset in Kotlin) from the value you want to use.

FAB Icon

The icon displayed in the centre of the FAB can be set via XML using a Drawable reference or with fab.setButtonIconResource(...) using a Drawable resource ID. The icon will be centred in a 24dp x 24dp view group, as per the Android Material Design specs.

// 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"
	...
	app:buttonIcon="@drawable/ic_add"
	/>

FAB Background Colour

The background colour of the FAB can be set via XML using a colour reference or programmatically with fab.setButtonBackgroundColour(...) using an aRGB colour value (e.g. 0xffff9900 for dark orange). Note that the second method does not take a colour resource ID, so passing in R.color.some_colour_name will not work.

// 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"
	...
	app:buttonBackgroundColour="@color/fab_colour"
	/>

FAB Click Listener

A click listener can be added to the FAB in the same way as any other button. The view passed to the listener can be safely cast to a FloatingActionButton.

// Java
fab.setOnClickListener(new View.OnClickListener() {
	@Override
	public void onClick(View v) {
		// ...
	}
});

// 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.

Speed-Dial Menu Content Cover

The content cover expands from the FAB when the speed-dial menu is opened to obscure the rest of the app content and emphasise the menu. It also prevents controls in the rest of the app from being clicked on while the speed-dial menu is open; tapping outside the menu while it is open and the cover is displayed will cause the menu to close.

The colour of the content cover can be set programmatically with fab.setContentCoverColour(...) using an aRGB colour value (e.g. 0x99ff9900 for a semi-transparent dark orange). Note that this method does not take a colour resource ID, so passing in R.color.some_colour_name will not work.

// Java
fab.setContentCoverColour(0xffff9900);

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

The cover can be enabled/disabled programmatically with fab.setContentCoverEnabled(...).

// Java
fab.setContentCoverEnabled(true);
fab.setContentCoverEnabled(false);

// Kotlin
fab.setContentCoverEnabled(true)
fab.setContentCoverEnabled(false)

Speed-Dial Menu State Change Listeners

State change events are fired when the speed-dial menu opens or closes, which can be received with fab.setOnSpeedDialMenuOpenListener(...) and fab.setOnSpeedDialMenuCloseListener(...).

// Java
fab.setOnSpeedDialMenuOpenListener(new SpeedDialMenuOpenListener() {
	@Override
	public void onOpen(FloatingActionButton floatingActionButton) {
		// ...
	}
});

// 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 and set the entire view container's visibility to GONE. If the speed-dial menu is open when .hide() is called it will be closed.

If the FAB is hidden in the XML layout (i.e. with android:visibility="gone") when initialise the FAB will start in the correct hidden state and can still be shown/hidden with the fab.hide() and fab.show() methods.

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: Known Compatibility Issues

In Android 4.x there is an issue with Vector Drawable icons. If you want to use Vector Drawables as icons (e.g app:buttonIcon="@drawable/ic_add") you will need to add the following snippet in your Activity classes.

// Java
static {
	AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

// Kotlin
companion object {
	init() {
		AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
	}
}

Source: Stack Overflow

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

The following properties are preserved when a configuration change (like a screen orientation change) happens:

  • FAB hidden/shown
  • FAB position
  • FAB background colour
  • FAB icon
  • Speed-dial menu content cover colour
  • Speed-dial menu content cover enabled/disabled

The following properties are not preserved and will need to be restored by the parent activity/fragment:

  • FAB click listener
  • Speed-dial menu adapter
  • Speed-dial menu open/close listeners

android-fab's People

Contributors

markormesher avatar proninyaroslav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

android-fab's Issues

Customize the menu

Hi Writing this to know, how can i customize each row in menu item. I dont want to use the icons at right hand side, and the mehu text should have a background color, how can i implement this using your lib. could you please help me on this?

Running app fails with "...variant...is not signed"

If you clone the project, and try to run the app in /app in Android Studio v3.0.1, you get the following:

image

Looks like this is because in build.gradle the debug build type specifies the same keystore process as release. I'll open a PR for this shortly.

Programmatically change expand direction

Currently the expand direction can be changed only in the xml with the expandDirection property. It would be very helpful if this property could be accessed programmatically.

SpeedDialMenu not showing

If a ClickListener is set to the FAB, the speedDialMenu doesn't show when clicked (otherwise it shows).
Cheers

impossible to assembleRelease

Hi,
assembleRelease of a project including this dependency is failing (error bellow).
Could you give some input on how to avoid this.
Cheers

Warning: uk.co.markormesher.android_fab.FloatingActionButton$$Lambda$1: can't find referenced class java.lang.invoke.LambdaForm$Hidden
Warning: uk.co.markormesher.android_fab.FloatingActionButton$$Lambda$4: can't find referenced class java.lang.invoke.LambdaForm$Hidden
Warning: uk.co.markormesher.android_fab.FloatingActionButton$$Lambda$5: can't find referenced class java.lang.invoke.LambdaForm$Hidden

CardView not round in KitKat

Hi there, when library is used on small screen device with Android Jelly Bean (4.2.2) buttons are not circles. I tried to change width, height and radius of CardView but couldn't mange to get the circle. I'm thinking that maybe it's the drawable. I'm attaching the screenshot of your demo app so you understand better. As I said Android version is 4.2.2 and screen size is 320x480.

screenshot_2017-04-24-16-28-33

Cheers

Unable to open speed dial menu automatically

Hi,

In my layout I am having recycler view. Initially I put floating action button as hidden I want that whenever i click on any recyclerview item fab should get visible and speed dial menu should open and when after opening the speed dial menu clicking on content cover speed dial menu should first close and then gets hidden. I tried it using an interface to get the click event of recyclerview item and checked for speed dialmenu is opened or not then tried to toggle that.But speed dial menu is not opening it is getting opened all menu items get overlapped.Below is my code.

interface callback:
public void onLongPressed() {
if(floatingActionButton.isSpeedDialMenuOpen()){
floatingActionButton.hide(true);
floatingActionButton.setVisibility(View.GONE);
}else {
floatingActionButton.setVisibility(View.VISIBLE);
floatingActionButton.setContentCoverEnabled(true);
floatingActionButton.setContentCoverColour(0xffff9900);
floatingActionButton.setContentCoverEnabled(true);
floatingActionButton.callOnClick();
}
}
where floatingActionButton is initialised as in onCreate of activity
floatingActionButton = findViewById(R.id.fabMenu);
floatingActionButton.setSpeedDialMenuAdapter(new CustomSpeedMenuAdapter(this));

In layout


<uk.co.markormesher.android_fab.FloatingActionButton
android:id="@+id/fabMenu"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
app:buttonBackgroundColour="@color/dashboard1"
app:buttonIcon="@drawable/ic_add"
app:buttonPosition="top|start" />

Checking whether or not the SpeedDialMenu is open

Hey there again

I know there is a listener which we could use to set our own property to track whether or not the SpeedDialMenu is open, but it would be nice to have a simple getter for speedDialMenuOpen field instead so on methods like onBackPressed the SpeedDialMenu can be closed via the back button too.

Unable to open speed dial automaticallay

Hi,

In my layout I am having recycler view. Initially I put floating action button as hidden I want that whenever i click on any recyclerview item fab should get visible and speed dial menu should open and when after opening the speed dial menu clicking on content cover speed dial menu should first close and then gets hidden. I tried it using an interface to get the click event of recyclerview item and checked for speed dialmenu is opened or not then tried to toggle that.But speed dial menu is not opening it is getting opened all menu items get overlapped.Below is my code.

interface callback:
public void onLongPressed() {
if(floatingActionButton.isSpeedDialMenuOpen()){
floatingActionButton.hide(true);
floatingActionButton.setVisibility(View.GONE);
}else {
floatingActionButton.setVisibility(View.VISIBLE);
floatingActionButton.setContentCoverEnabled(true);
floatingActionButton.setContentCoverColour(0xffff9900);
floatingActionButton.setContentCoverEnabled(true);
floatingActionButton.callOnClick();
}
}
where floatingActionButton is initialised as in onCreate of activity
floatingActionButton = findViewById(R.id.fabMenu);
floatingActionButton.setSpeedDialMenuAdapter(new CustomSpeedMenuAdapter(this));

In layout

<uk.co.markormesher.android_fab.FloatingActionButton
android:id="@+id/fabMenu"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
app:buttonBackgroundColour="@color/dashboard1"
app:buttonIcon="@drawable/ic_add"
app:buttonPosition="top|start" />

Style is not applied to the FAB button

When I apply a style in XML to the FAB what gets styled is the clickable area that fills the entire screen. Would it be possible to apply the style to the button instead?

Example:

If I use the style tag:
<uk.co.markormesher.android_fab.FloatingActionButton style="my_style_here" />

I get this:
device-2017-06-29-233008

Release version 2.4.0 -- Failed to resolve

Just FYI, when adding implementation 'uk.co.markormesher:android-fab:2.4.0 to dependencies, I got a "Failed to resolve" error.

I checked the releases, and the 2.4.0 release appears to be mislabeled (along with the documentation).

I changed the dependency to implementation 'uk.co.markormesher:android-fab:2.4.1, and it resolved fine.

Thanks for this repo!

show() won't work if button is initially hidden

If the floating action button's visibility is initially set as gone, then the show() method won't work properly.

Show() returns immediately if FloatingActionButton.isShown is true. The problem is that isShown is always initialized as true regardless of the view's visibility attribute.

Feature request - Allow speed dial to remain expanded when item is tapped

Great library!

We're using this library to control which map layers are visible on a map. We currently have it implemented for bikeshare.

The below screenshots show from left to right:

  • Bikes visible and speed dial control closed
  • Bikes visible and speed dial control expanded
  • Bikes disabled and speed dial control expanded

image

The main usability issue we have now is that when the user taps on the bikeshare icon to toggle layer visibility, the control closes and you can't see the color of the control change. Ideally, we'd like to leave the control expanded and change the color so it's easier to visually associate with the same color markers disappearing and appearing on the map. So, the user could tap on the expanded "Bikeshare" control multiple times while it's expanded to toggle the layer on and off, without the control closing on each tap.

Would adding an option to allow the control to remain expanded when tapped be something you'd be interested in integrating? If we find the time to implement this ourselves, would you merge a pull request with this feature?

(FYI, WIP PR that includes this control is at OneBusAway/onebusaway-android#776)

cc @carvalhorr

Text color

Hey markormesher,
I was wondering, is it possible to change the label color in the SpeedDialMenuItem?

Regard, Vladimir

setOnSpeedMenuDialOpenListener() has wrong name

With v2.0, code to set the open and close listener looks like this:

mLayersFab.setSpeedDialMenuAdapter(adapter);
mLayersFab.setOnSpeedMenuDialOpenListener(...);
mLayersFab.setOnSpeedDialMenuCloseListener(...);

The naming convention of the two set listeners methods are different:

  • setOnSpeedMenuDialOpenListener()
  • setOnSpeedDialMenuCloseListener()

Judging by the setSpeedDialMenuAdapter() method, it looks like the open listener method:

setOnSpeedMenuDialOpenListener()

should have been:

setOnSpeedDialMenulOpenListener()

Color Overlay View

Hi, is there any way to customize the background color when the menu is open? That is, that white with alpha?

Congratulations on the lib... tks!

Scrollable speed-dial menu

Is there a way to make speed-dial menu scrollable? If there are too many items, they go out of the screen.

Suggestion: allow to choose the direction of the menu

Currently the only direction that the menu follows when it's opened is up. It would be great if the developer can choose another direction (having by default the menu going up).

In my case I want to put the button on the top of the screen and open the menu as dropdown.

It can be done just introducing a flag and changing a bit this method:

private void setSpeedDialMenuVisible(final boolean visible) {
// busy?
if (busyAnimatingSpeedDialMenu) return;
busyAnimatingSpeedDialMenu = true;

	// animate, setting visibility as well to prevent phantom clicks
	int distance = button.getHeight();
	for (int i = 0, n = speedDialMenuItems.size(); i < n; ++i) {
		final View v = speedDialMenuItems.get(i);
		if (visible) v.setVisibility(VISIBLE);
		v.animate()
				.translationY(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
				.alpha(visible ? 1F : 0F)
				.setDuration(SPEED_DIAL_ANIMATION_DURATION)
				.setListener(new AnimatorListenerAdapter() {
					@Override
					public void onAnimationEnd(Animator animation) {
						busyAnimatingSpeedDialMenu = false;
						if (!visible) v.setVisibility(GONE);
					}
				});
	}
}

This method is inside FloatActionButton.

I have thought in something like this:

private void setSpeedDialMenuVisible(final boolean visible, int direction) {
// busy?
if (busyAnimatingSpeedDialMenu) return;
busyAnimatingSpeedDialMenu = true;

	// animate, setting visibility as well to prevent phantom clicks
	int distance = button.getHeight();
	for (int i = 0, n = speedDialMenuItems.size(); i < n; ++i) {
		final View v = speedDialMenuItems.get(i);
		if (visible) v.setVisibility(VISIBLE);
		v.animate()
				.alpha(visible ? 1F : 0F)
				.setDuration(SPEED_DIAL_ANIMATION_DURATION)
				.setListener(new AnimatorListenerAdapter() {
					@Override
					public void onAnimationEnd(Animator animation) {
						busyAnimatingSpeedDialMenu = false;
						if (!visible) v.setVisibility(GONE);
					}
				});

                     switch(direction){
                           case DOWN:
                                    v.animate().translationY(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
                                     break;
                           case UP:
                                    v.animate().translationY(visible ? ((i + 1) * distance * +1) - (distance / 8) : 0F)
                                     break;
                           case RIGHT:
                                    v.animate().translationX(visible ? ((i + 1) * distance * -1) - (distance / 8) : 0F)
                                     break;
                           case LEFT:
                                    v.animate().translationX(visible ? ((i + 1) * distance * +1) - (distance / 8) : 0F)
                                     break;
                     }
	}
}

What do you think?

Disappearing menu items when using v2 of library

Summary:

@markormesher I did a fairly straightforward port of our project to use v2 of this library - WIP PR at:
OneBusAway/onebusaway-android#856

However, I'm seeing different behavior in terms of the visibility of menu items.

If I tap on the "Bikeshare" menu item (see left screenshot below), the entire menu item disappears (see right screenshot below):

image

If I tap on the FAB twice (to close and re-open it) then the correct state is shown (i.e., after first tapping on the "Bikeshare" menu item, I would expect it to look like this instead of disappearing:

image

Is there new behavior in v2 that I'm missing that's causing this?

Steps to reproduce:

  1. Clone and pull in WIP PR at OneBusAway/onebusaway-android#856
  2. Run gradlew assembleObaGoogleDebug or build this build variant via Android Studio
  3. Run app
  4. Tap on hamburger menu
  5. Tap on "Settings"
  6. Tap on "Your region" and choose Tampa
  7. Tap on "Layers" FAB button (top FAB in lower-right corner)
  8. Tap on "Bikeshare" menu item

Expected behavior:

"Bikeshare" menu item should stay visible and background should change from blue to gray, indicating that the layer is disabled

Observed behavior:

"Bikeshare" menu item disappears

Device and Android version:

Samsung Galaxy S8+ w/ Android 8.0 beta

Not float up animation when snackbar shown

It seems the floating button remains in position when a snackbar is being shown, whilst the native FAB implementation has it float up above the snackbar. Is there a way to get this to work with your implementation?

Thanks alot

XML Drawable not supported on all devices

Hello!
When I set FAB Icon using custom XML drawable not all devices were displaying icon.
Setting icon as normal png helped. I guess it should not work this way :D

Fab button gravity

How can I set fab gravity to the center, not to left right bottom tops

Content cover and padding/margin

When using padding for FAB component, to trim its position in layout, after expanding the content cover, it's not filling the whole area. I'm not sure if this is bug, or expected behavior.

For more info, check the screenshot. The area on left is covered, the area on right is not. FAB is in the layout which is covering whole screen

screenshot_20180821-110102 1

To much work in Fragment

Hi there, I'm trying to implement you library in a project but I found an issue when i'm trying to display a SpeedDialer menu, no only that just when I press click on fab button show me this:

  • Skipped 38 frames! The application may be doing too much work on its main thread.

I'm working on a fragment, don't know if this is part of the issue but it's rare. I Just need to implement a fab with speed dial 2 items, not anymore... so it's an easy implementation.

Can FAB speed dial items be aligned to parent left?

Thanks again for the great library!

We have a setting in our app "Left hand mode" that flips FABs to align the left side of the screen instead of the right (used by a small but appreciative audience :)).

I can't seem to find a way to programmatically flip the FAB speed dial menu items so they align to the left side of the screen instead of the right.

Here's what I have so far - I was able to flip the FAB itself - heres, the screenshot:

image

Here's the code:

...
boolean leftHandMode = true;  // This should flip all FABs to the left side of screen
if (mLayersFab != null) {
	// Update all the Layers FAB-contained layouts
	RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mLayersFab.getFabContainer()
			.getLayoutParams();
	updateLeftHandMode(mLayersFab.getFabContainer(), layoutParams, leftHandMode);

	layoutParams = (RelativeLayout.LayoutParams) mLayersFab
			.getLayoutParams();
	updateLeftHandMode(mLayersFab, layoutParams, leftHandMode);
	layoutParams = (RelativeLayout.LayoutParams) mLayersFab.getButton().getLayoutParams();
	updateLeftHandMode(mLayersFab.getButton(), layoutParams, leftHandMode);

	for (int i = 0; i < mLayersFab.getButton().getChildCount(); i++) {
		View v = mLayersFab.getChildAt(i);
		RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) v.getLayoutParams();
		updateLeftHandMode(v, p, leftHandMode);
	}
}
...
private void updateLeftHandMode(View v, RelativeLayout.LayoutParams layoutParams,
		boolean leftHandMode) {
	if (leftHandMode) {
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
			layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT);
			layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_END);
		}
	} else {
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
			layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_LEFT);
			layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_START);
		}
	}
	v.setLayoutParams(layoutParams);
}

Despite looping through the children views, I can't seem to get the expanded speed dial to align left - here's what it looks like expanded:

image

Ideally the placement of the bike icon and "bikeshare" text would be reversed when changed to the left margin (so the bike icon is against left side of screen), but I'd take just moving the existing label and icon to the left margin as-is.

Am I missing something, or is this just not possible with the current library?

A WIP PR with the above code is at OneBusAway/onebusaway-android#806 if you want to take it for a spin yourself.

Crash when FloatingActionButton.setOnSpeedDialMenuCloseListener() get's null as parameter

Hi,

I just updated from Java to Kotlin (latest) version of the library and my app crashes when I try to pass null to FloatingActionButton.setOnSpeedDialMenuCloseListener() method.

I get the following error

Fatal Exception: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter listener
       at uk.co.markormesher.android_fab.FloatingActionButton.setOnSpeedDialMenuCloseListener(FloatingActionButton.kt)

I don't know Kotlin so I'm not sure what's the problem.

Request: More reliable speed dial animation handling

I’ve run into a bug in our app where, due to how our app is structured and how we handle configuration changes, we can run into a race condition where when we get to animateSpeedDialMenuItems() In FloatingActionButton.kt when trying to close the menu after clearing out speedDialMenuViews (basically, the source of our menu items gets destroyed before we can close the menu). This means speedDialMenuViews.forEachInexed() iterates over no items and busyAnimatingSpeedDialMenuItems is never set to false. When this happens the menu won’t open again.

If you changed line 575 (on master as of today) from

busyAnimatingSpeedDialMenuItems = true

to

busyAnimatingSpeedDialMenuItems = speedDialMenuViews.count() != 0

that would prevent situations where busyAnimatingSpeedDialMenuItems gets stuck when you don’t have any items.

FloatingActionButton Ripple colour

Hi there

I'm having an issue, when I switched from the standard android FAB to this one my ripple effect on the FAB is no longer grey (or a darker orange), it now seems to use my primary colour of my application which is green, and on an orange FAB it really does not look right.

I set the FABs colour via app:buttonBackgroundColour="@color/accent" in the XML.

How would i go about changing this? I've tried setting the cardViews drawable to my own selector which didn't work. Not sure what else to do.

This also happens on the SpeedDialMenuItems but the green isn't so bad on a grey background, though id prefer to use a darker grey then green too.

UPDATE
It is strange though when I press the FAB it does look like it goes grey or possibly a darker orange (which is great), but then suddenly tints a slight green.

Naming

Why was FloatingActionButton chosen for the class name when Android has one with the same name? android.support.design.widget.FloatingActionButton

Make the menu items easier to customize

Hey there!

First, thanks for this brilliant small library.

I have one issue though - I've been trying to customize the round menu items - to make them slightly larger. This became a quite involved exercise as there are sizes (which programatically require conversions of dp to px), multiple offsets, paddings and margins to realign. Is it possible that such customizations are easier to do - via the SpeedDialAdapter for example? Or maybe there is an easy way to override the library resource files (menu_item_icon.xml) that I don't know about? If there is an easy way to achieve what I want, can we document it in the README?

Thanks!

Content cover doesn't cover whole screen

Device: Samsung SM-T580
Version android-fab: v2.2.2

On the tablet device, the cover keeps the left upper corner uncovered. My guess is, the circle which is used for animation has too small diameter. For more details, see the screenshot.

Thanks for your time :)

screenshot_20180620-163858

Allow setting menu item label View in v2

In OneBusAway Android, we use this FAB library for a "Layers" button on top of the map (and it works quite well - thanks! 👍)- see below screenshot (closed on left, open on right):

image

Because the underlying map can be quite busy, we added a solid background to the label on menu items to make them more readable (see solid blue background for "Bikeshare" label in above screenshot on right).

For v1 of this library, in our LayersSpeedDialAdapter we had the following (simplified a bit below - see link for full source code):

@Override
protected MenuItem getViews(Context context, int position) {
	MenuItem menuItem = new MenuItem();
	menuItem.iconDrawableId = layer.getIconDrawableId();

	// Set the TextView (label) background color to be solid
	TextView label = new TextView(context);
	label.setText(layer.getLayerlabel());
	label.setTextColor(Color.WHITE);
        label.setBackground(R.drawable.speed_dial_disabled_item_label);
	menuItem.labelView = label; // <--- This doesn't seem possible in v2?

	return menuItem;
}

It seems like in v2, you can set the menu item label as a String via the constructor or setter method:

SpeedDialMenuItem menuItem = new SpeedDialMenuItem(context, layer.getIconDrawableId(), layer.getLayerlabel());
menuItem.setLabel(layer.getLayerlabel());

...but there is no way of setting the View for the menu item label, or the background color for the menu item label.

@markormesher Am I missing a new way to do this in v2 of the library? If not, could this be added as a new feature?

Right now this blocks our migration to v2 of this library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.